From 24278fe242011fbe620a56539362506d2123d471 Mon Sep 17 00:00:00 2001 From: insert Date: Sun, 20 Aug 2023 17:21:52 -0400 Subject: [PATCH] Alpha Ready --- index.js | 105 ++++++++++++++++---- web/src/views/Moderation.vue | 182 ++++++++++++++++++++++++++++++++--- 2 files changed, 256 insertions(+), 31 deletions(-) diff --git a/index.js b/index.js index 1df95eb..0071f03 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const { onShutdown } = require('node-graceful-shutdown') const ActivitypubExpress = require('activitypub-express') const { version } = require('./package.json') -const { DOMAIN, KEY_PATH, CERT_PATH, CA_PATH, PORT_HTTPS, DB_URL, DB_NAME, PROXY_MODE, ADMIN_SECRET, USE_ATTACHMENTS, GROUPS } = process.env +const { DOMAIN, KEY_PATH, CERT_PATH, CA_PATH, PORT_HTTPS, DB_URL, DB_NAME, PROXY_MODE, ADMIN_SECRET, USE_ATTACHMENTS, GROUPS, ALLOW_DELETE, ALLOW_CREATE } = process.env const app = express() const client = new MongoClient(DB_URL) @@ -81,6 +81,7 @@ async function actorOnDemand (req, res, next) { if (!actor) { return next() } + console.log(req.params) const actorIRI = apex.utils.usernameToIRI(actor) /*try { if (!(await apex.store.getObject(actorIRI)) && actor.length <= 255) { @@ -192,16 +193,11 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => { //stop here, we can add the activity to the database, we'll handle it if it passes inspection, otherwise no console.log(activity.object[0].id) console.log(share) - await apex.store.db.collection(`${recipient.id}-queue`).insertOne(share) - //console.log(apex.store.db.collection(`${recipient.id}-queue`) - var find = await apex.store.db.collection(`${recipient.id}-queue`).find().toArray() - console.log(await apex.store.db.collection(`${recipient.id}-queue`).find().toArray()) - console.log(find) - //idk why but this works - //var find2 = await apex.store.db.collection(`keys`).findOne( {id: recipient.id} ) - //if (!find2) { - // await apex.store.db.collection(`keys`).insertOne(recipient) - //} + const blocked = await apex.store.db.collection(`${recipient.id}-blocked`).findOne( {user: share.cc[0]} ) + console.log(blocked) + if (!blocked) { + await apex.store.db.collection(`${recipient.id}-queue`).insertOne(share) + } //apex.addToOutbox(recipient, share) break @@ -288,6 +284,31 @@ app.get('/mod/userinfo', async (req, res, next) => { } }) +app.get('/mod/userblocks', async (req, res, next) => { + try { + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + const blockSize = await apex.store.db.collection(`${object.id}-blocked`).find().toArray() + // console.log(res.json({queueSize})) + console.log(blockSize) + res.json(blockSize) + } catch (err) { + next(err) + } +}) + +app.get('/mod/unblockuser', async (req, res, next) => { + try { + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + const blockSize = await apex.store.db.collection(`${object.id}-blocked`).find( {user: req.query.id} ) + // console.log(res.json({queueSize})) + await apex.store.db.collection(`${object.id}-blocked`).remove( {user: req.query.id} ) + console.log(blockSize) + res.json(blockSize) + } catch (err) { + next(err) + } +}) + app.get('/mod/changedata', async (req, res, next) => { try { var oldobject = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true) @@ -300,7 +321,7 @@ app.get('/mod/changedata', async (req, res, next) => { object: newgroup }) apex.addToOutbox(oldobject, share) - await apex.store.updateObject(newgroup, oldobject.id, true) + await apex.store.updateObject(newgroup, oldobject.id, false) res.json(newgroup) } catch (err) { next(err) @@ -362,7 +383,59 @@ app.get('/mod/deny', async (req, res, next) => { } }) -app.get('/mod/delete', async (req, res, next) => { +app.get('/mod/denyblock', async (req, res, next) => { + try { + console.log("recived") + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + var dbout = await apex.store.db.collection(`${object.id}-queue`).findOne( {object: [req.query.id]} ) + //apex.addToOutbox(await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)), share) + await apex.store.db.collection(`${object.id}-queue`).remove( {cc: [dbout.cc[0]]} ) + var create = await apex.store.db.collection(`${object.id}-blocked`).insertOne( {user: dbout.cc[0]} ) + console.log(create) + var findexisting = await apex.store.db.collection(`${object.id}-blocked`).find().toArray() + console.log(findexisting) + res.json(dbout) + } catch (err) { + next(err) + } +}) + +app.get('/mod/delete/user', async (req, res, next) => { + if (ALLOW_DELETE != "true") { + res.json(null) + return + } + try { + console.log("recived") + const actor = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true) + //var dbout = await apex.store.db.collection(`${actor.id}-posts`).findOne( {object: [req.query.id]} ) + const to = [ + actor.followers[0], + apex.consts.publicAddress + ] + const share = await apex.buildActivity('Delete', actor.id, to, { + object: actor + }) + apex.addToOutbox(actor, share) + await apex.store.db.collection('objects').remove( {id: actor.id} ) + await apex.store.db.collection(`${actor.id}-posts`).drop() + await apex.store.db.collection(`${actor.id}-queue`).drop() + const find = await apex.store.db.collection('streams').find().toArray() + console.log(find) + res.json(find) + } catch (err) { + next(err) + } +}) + +app.use(function (err, req, res, next) { + console.error(err.message, req.body, err.stack) + if (!res.headersSent) { + res.status(500).send('An error occurred while processing the request') + } +}) + +app.get('/mod/delete/post', async (req, res, next) => { try { console.log("recived") const actor = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true) @@ -383,12 +456,6 @@ app.get('/mod/delete', async (req, res, next) => { } }) -app.use(function (err, req, res, next) { - console.error(err.message, req.body, err.stack) - if (!res.headersSent) { - res.status(500).send('An error occurred while processing the request') - } -}) client.connect() .then(async () => { diff --git a/web/src/views/Moderation.vue b/web/src/views/Moderation.vue index 9afd5d9..8a50ea9 100644 --- a/web/src/views/Moderation.vue +++ b/web/src/views/Moderation.vue @@ -9,9 +9,11 @@
Avatar
+

Approval Queue

  • - {{ item.object[0] }} + {{ item.object[0] }} +
  • @@ -20,6 +22,11 @@ {{ item.object[0] }} +

    Blocked Users

    +
  • + {{ item.user }} + +
  • @@ -40,7 +47,9 @@ export default { return { queue: [], posts: [], + image: null, error: null, + blockedusers: this.blockedusers, name: this.name, userdata: this.userdata, userdescription: this.userdescription, @@ -60,7 +69,7 @@ export default { console.log("test3") console.log(json) }) - window.fetch(`/mod/data?name=${this.name}`, { + window.fetch(`/mod/data/posts?name=${this.name}`, { method: 'get', headers: { accept: 'application/json' @@ -69,7 +78,21 @@ export default { .then(json => { console.log("test2") console.log(json) - this.queue = json + this.posts = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/userinfo?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test4") + console.log(json) + this.userdata = json + this.userdescription = json.summary[0] + this.username = json.name[0] }) .catch(err => (this.error = err.message)) }, @@ -84,7 +107,7 @@ export default { console.log("test3") console.log(json) }) - window.fetch(`/mod/data?name=${this.name}`, { + window.fetch(`/mod/data/posts?name=${this.name}`, { method: 'get', headers: { accept: 'application/json' @@ -93,12 +116,26 @@ export default { .then(json => { console.log("test2") console.log(json) - this.queue = json + this.posts = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/userinfo?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test4") + console.log(json) + this.userdata = json + this.userdescription = json.summary[0] + this.username = json.name[0] }) .catch(err => (this.error = err.message)) }, - deletepost: function (name, id) { - window.fetch(`/mod/delete?name=${name}&id=${id}`, { + denyblock: function (name, id) { + window.fetch(`/mod/denyblock?name=${name}&id=${id}`, { method: 'get', headers: { accept: 'application/json' @@ -108,7 +145,7 @@ export default { console.log("test3") console.log(json) }) - window.fetch(`/mod/data?name=${this.name}`, { + window.fetch(`/mod/data/posts?name=${this.name}`, { method: 'get', headers: { accept: 'application/json' @@ -117,12 +154,114 @@ export default { .then(json => { console.log("test2") console.log(json) - this.queue = json + this.posts = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/userinfo?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test4") + console.log(json) + this.userdata = json + this.userdescription = json.summary[0] + this.username = json.name[0] + }) + .catch(err => (this.error = err.message)) + }, + unblockuser: function (name, id) { + window.fetch(`/mod/unblockuser?name=${name}&id=${id}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test3") + console.log(json) + }) + }, + deletepost: function (name, id) { + window.fetch(`/mod/delete/post?name=${name}&id=${id}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test3") + console.log(json) + }) + window.fetch(`/mod/data/posts?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test2") + console.log(json) + this.posts = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/userinfo?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test4") + console.log(json) + this.userdata = json + this.userdescription = json.summary[0] + this.username = json.name[0] + }) + .catch(err => (this.error = err.message)) + }, + deleteuser: function (name) { + window.fetch(`/mod/delete/user?name=${name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test3") + console.log(json) + }) + window.fetch(`/mod/data/posts?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test2") + console.log(json) + this.posts = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/userinfo?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test4") + console.log(json) + this.userdata = json + this.userdescription = json.summary[0] + this.username = json.name[0] }) .catch(err => (this.error = err.message)) }, save: function (name, description, username) { - window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, { + window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, { method: 'get', headers: { accept: 'application/json' @@ -134,7 +273,14 @@ export default { }) }, previewFiles(event) { - console.log(event.target.files); + const files = event.target.files + let filename = files[0].name + const fileReader = new FileReader() + fileReader.addEventListener('load', () => { + this.imageUrl = fileReader.result + }) + fileReader.readAsDataURL(files[0]) + this.image = files[0] } }, created () { @@ -162,7 +308,19 @@ export default { this.posts = json }) .catch(err => (this.error = err.message)) - window.fetch(`/mod/userinfo?name=${this.name}`, { + window.fetch(`/mod/userblocks?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test4") + console.log(json) + this.blockedusers = json + }) + .catch(err => (this.error = err.message)) + window.fetch(`/mod/userinfo?name=${this.name}`, { method: 'get', headers: { accept: 'application/json'