From 2ea5c399397c8b71d887529de4fcc87fc3ed602b Mon Sep 17 00:00:00 2001 From: insert Date: Fri, 18 Aug 2023 10:34:22 -0400 Subject: [PATCH] finished maybe --- index.js | 43 +++++++++++++++++++++--- web/src/router.js | 2 +- web/src/views/Moderation.vue | 63 +++++++++++++++++++++++++++++++++--- 3 files changed, 99 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 677457e..d9e17b7 100644 --- a/index.js +++ b/index.js @@ -190,11 +190,16 @@ 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(share) - apex.store.db.collection(`${recipient.id}-queue`).insertOne(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) + } //apex.addToOutbox(recipient, share) break @@ -262,13 +267,13 @@ app.get('/stats', async (req, res, next) => { } }) -app.get('/moddata', async (req, res, next) => { +app.get('/mod/data', async (req, res, next) => { try { console.log(req.query) console.log(req.query.name) console.log(apex.utils.usernameToIRI('test')) console.log(await apex.utils.usernameToIRI('test')) - var object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) console.log(object) console.log(object.id) console.log("test") @@ -281,6 +286,36 @@ app.get('/moddata', async (req, res, next) => { } }) +app.get('/mod/approve', async (req, res, next) => { + try { + console.log("recived") + const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) + //console.log(object) + //onsole.log(object.publicKey) + const keys = await apex.store.db.collection(`keys`).findOne( {id: object.id} ) + const dbout = await apex.store.db.collection(`${object.id}-queue`).findOne( {object: [req.query.id]} ) + console.log(keys) + apex.addToOutbox(keys, dbout) + await apex.store.db.collection(`${object.id}-queue`).remove( {object: [req.query.id]} ) + res.json(dbout) + } catch (err) { + next(err) + } +}) + +app.get('/mod/deny', 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( {object: [req.query.id]} ) + res.json(dbout) + } catch (err) { + next(err) + } +}) + app.use(function (err, req, res, next) { console.error(err.message, req.body, err.stack) if (!res.headersSent) { @@ -305,7 +340,7 @@ client.connect() await apex.store.saveObject(systemUser) apex.systemUser = systemUser } - apex.group = await apex.store.getObject(apex.utils.usernameToIRI('testing'), true) + apex.group = await apex.store.getObject(apex.utils.usernameToIRI('test'), true) if (!apex.group) { const group = await createGuppeActor('test', 'test', 'A project built on guppe groups\, it features a moderation ui', icon, 'Group') await apex.store.saveObject(group) diff --git a/web/src/router.js b/web/src/router.js index 08bd77e..83ab7cb 100644 --- a/web/src/router.js +++ b/web/src/router.js @@ -21,7 +21,7 @@ export default new Router({ props: true }, { - path: '/mod/:name', + path: '/mod/ui/:name', name: 'moderation', component: Moderation, props: true diff --git a/web/src/views/Moderation.vue b/web/src/views/Moderation.vue index 97ba8df..4781778 100644 --- a/web/src/views/Moderation.vue +++ b/web/src/views/Moderation.vue @@ -4,8 +4,8 @@ @@ -30,8 +30,58 @@ export default { domain: window.location.host } }, + methods: { + approve: function (name, id) { + window.fetch(`/mod/approve?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?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test2") + console.log(json) + this.queue = json + }) + .catch(err => (this.error = err.message)) + }, + deny: function (name, id) { + window.fetch(`/mod/deny?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?name=${this.name}`, { + method: 'get', + headers: { + accept: 'application/json' + } + }).then(res => res.json()) + .then(json => { + console.log("test2") + console.log(json) + this.queue = json + }) + .catch(err => (this.error = err.message)) + } + }, created () { - window.fetch(`/moddata?name=${this.name}`, { + window.fetch(`/mod/data?name=${this.name}`, { method: 'get', headers: { accept: 'application/json' @@ -48,7 +98,12 @@ export default { \ No newline at end of file