finished maybe

This commit is contained in:
insert 2023-08-18 10:34:22 -04:00
parent 0455c763fd
commit 2ea5c39939
No known key found for this signature in database
GPG key ID: 8F1F3466FB204C55
3 changed files with 99 additions and 9 deletions

View file

@ -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 //stop here, we can add the activity to the database, we'll handle it if it passes inspection, otherwise no
console.log(share) 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`) //console.log(apex.store.db.collection(`${recipient.id}-queue`)
var find = await apex.store.db.collection(`${recipient.id}-queue`).find().toArray() 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(await apex.store.db.collection(`${recipient.id}-queue`).find().toArray())
console.log(find) 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) //apex.addToOutbox(recipient, share)
break 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 { try {
console.log(req.query) console.log(req.query)
console.log(req.query.name) console.log(req.query.name)
console.log(apex.utils.usernameToIRI('test')) console.log(apex.utils.usernameToIRI('test'))
console.log(await 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)
console.log(object.id) console.log(object.id)
console.log("test") 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) { app.use(function (err, req, res, next) {
console.error(err.message, req.body, err.stack) console.error(err.message, req.body, err.stack)
if (!res.headersSent) { if (!res.headersSent) {
@ -305,7 +340,7 @@ client.connect()
await apex.store.saveObject(systemUser) await apex.store.saveObject(systemUser)
apex.systemUser = 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) { if (!apex.group) {
const group = await createGuppeActor('test', 'test', 'A project built on guppe groups\, it features a moderation ui', icon, '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) await apex.store.saveObject(group)

View file

@ -21,7 +21,7 @@ export default new Router({
props: true props: true
}, },
{ {
path: '/mod/:name', path: '/mod/ui/:name',
name: 'moderation', name: 'moderation',
component: Moderation, component: Moderation,
props: true props: true

View file

@ -4,8 +4,8 @@
<ul style="list-style-type:none;"> <ul style="list-style-type:none;">
<li v-for="item in queue"> <li v-for="item in queue">
<a :href="item.object[0]" target="_blank">{{ item.object[0] }}</a> <a :href="item.object[0]" target="_blank">{{ item.object[0] }}</a>
<a class="approve" :href="item.object[0]" target="_blank">Approve</a> <button class="deny" v-on:click="deny(name, item.object[0])">Deny</button>
<a class="approve" :href="item.object[0]" target="_blank">Deny</a> <button class="approve" v-on:click="approve(name, item.object[0])">Approve</button>
</li> </li>
</ul> </ul>
</div> </div>
@ -30,8 +30,58 @@ export default {
domain: window.location.host 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 () { created () {
window.fetch(`/moddata?name=${this.name}`, { window.fetch(`/mod/data?name=${this.name}`, {
method: 'get', method: 'get',
headers: { headers: {
accept: 'application/json' accept: 'application/json'
@ -48,7 +98,12 @@ export default {
</script> </script>
<style> <style>
a.approve { button.approve {
margin-left:5em;
float:right;
}
button.deny {
margin-left:5em;
float:right; float:right;
} }
</style> </style>