more moderation ui tweeks, renaming and description, env var for groups

This commit is contained in:
insert 2023-08-18 18:32:05 -04:00
parent 1e2a2a67f8
commit 94e5d8df64
No known key found for this signature in database
GPG key ID: 8F1F3466FB204C55
2 changed files with 71 additions and 23 deletions

View file

@ -11,7 +11,7 @@ const { onShutdown } = require('node-graceful-shutdown')
const ActivitypubExpress = require('activitypub-express') const ActivitypubExpress = require('activitypub-express')
const { version } = require('./package.json') 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 } = process.env const { DOMAIN, KEY_PATH, CERT_PATH, CA_PATH, PORT_HTTPS, DB_URL, DB_NAME, PROXY_MODE, ADMIN_SECRET, USE_ATTACHMENTS, GROUPS } = process.env
const app = express() const app = express()
const client = new MongoClient(DB_URL) const client = new MongoClient(DB_URL)
@ -196,10 +196,10 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => {
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 //idk why but this works
var find2 = await apex.store.db.collection(`keys`).findOne( {id: recipient.id} ) //var find2 = await apex.store.db.collection(`keys`).findOne( {id: recipient.id} )
if (!find2) { //if (!find2) {
await apex.store.db.collection(`keys`).insertOne(recipient) // await apex.store.db.collection(`keys`).insertOne(recipient)
} //}
//apex.addToOutbox(recipient, share) //apex.addToOutbox(recipient, share)
break break
@ -267,16 +267,18 @@ app.get('/stats', async (req, res, next) => {
} }
}) })
app.get('/mod/userinfo', async (req, res, next) => {
try {
object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
res.json(object)
} catch (err) {
next(err)
}
})
app.get('/mod/data', async (req, res, next) => { app.get('/mod/data', async (req, res, next) => {
try { try {
console.log(req.query)
console.log(req.query.name)
console.log(apex.utils.usernameToIRI('test'))
console.log(await apex.utils.usernameToIRI('test'))
const 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")
const queueSize = await apex.store.db.collection(`${object.id}-queue`).find().toArray() const queueSize = await apex.store.db.collection(`${object.id}-queue`).find().toArray()
// console.log(res.json({queueSize})) // console.log(res.json({queueSize}))
console.log(queueSize) console.log(queueSize)
@ -289,13 +291,13 @@ app.get('/mod/data', async (req, res, next) => {
app.get('/mod/approve', async (req, res, next) => { app.get('/mod/approve', async (req, res, next) => {
try { try {
console.log("recived") console.log("recived")
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name)) const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true)
//console.log(object) //console.log(object)
//onsole.log(object.publicKey) //onsole.log(object.publicKey)
const keys = await apex.store.db.collection(`keys`).findOne( {id: object.id} ) //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]} ) const dbout = await apex.store.db.collection(`${object.id}-queue`).findOne( {object: [req.query.id]} )
console.log(keys) //console.log(keys)
apex.addToOutbox(keys, dbout) apex.addToOutbox(object, dbout)
await apex.store.db.collection(`${object.id}-queue`).remove( {object: [req.query.id]} ) await apex.store.db.collection(`${object.id}-queue`).remove( {object: [req.query.id]} )
res.json(dbout) res.json(dbout)
} catch (err) { } catch (err) {
@ -340,10 +342,16 @@ 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('test'), true) const grouparray = GROUPS.split(" ")
if (!apex.group) { var g = 0
const group = await createGuppeActor('test', 'test', 'A project built on guppe groups\, it features a moderation ui', icon, 'Group') while (g < grouparray.length) {
await apex.store.saveObject(group) findgroup = await apex.store.getObject(apex.utils.usernameToIRI(grouparray[g]), true)
console.log(findgroup)
if (!findgroup) {
const newgroup = await createGuppeActor(grouparray[g], grouparray[g], 'A project built on guppe groups\, it features a moderation ui', icon, 'Group')
await apex.store.saveObject(newgroup)
}
g++
} }
let server let server
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {

View file

@ -2,6 +2,11 @@
<div class="w3-container"> <div class="w3-container">
<h1>Moderation for {{name}} </h1> <h1>Moderation for {{name}} </h1>
<ul style="list-style-type:none;"> <ul style="list-style-type:none;">
<h5>Description</h5>
<input v-model="userdescription" :placeholder="userdata.summary[0]" />
<h5>Display Name</h5>
<input v-model="username" :placeholder="userdata.preferredUsername[0]" />
<button class="save" v-on:click="save(name, userdescription, username)">Save</button>
<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>
<button class="deny" v-on:click="deny(name, item.object[0])">Deny</button> <button class="deny" v-on:click="deny(name, item.object[0])">Deny</button>
@ -14,7 +19,7 @@
<script> <script>
export default { export default {
name: 'home', name: 'ModerationUi',
components: {}, components: {},
props: { props: {
name: { name: {
@ -27,6 +32,7 @@ export default {
queue: [], queue: [],
error: null, error: null,
name: this.name, name: this.name,
userdata: this.userdata,
domain: window.location.host domain: window.location.host
} }
}, },
@ -78,7 +84,18 @@ export default {
this.queue = json this.queue = json
}) })
.catch(err => (this.error = err.message)) .catch(err => (this.error = err.message))
} },
save: function (name, description, username) {
window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, {
method: 'get',
headers: {
accept: 'application/json'
}
}).then(res => res.json())
.then(json => {
console.log("test3")
console.log(json)
})
}, },
created () { created () {
window.fetch(`/mod/data?name=${this.name}`, { window.fetch(`/mod/data?name=${this.name}`, {
@ -93,10 +110,30 @@ export default {
this.queue = json this.queue = json
}) })
.catch(err => (this.error = err.message)) .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
})
.catch(err => (this.error = err.message))
}
} }
</script> </script>
<script setup>
import { ref } from 'vue'
const userdescription = ref('');
const username = ref('');
</script>
<style> <style>
button.approve { button.approve {
margin-left:5em; margin-left:5em;
@ -106,4 +143,7 @@ export default {
margin-left:5em; margin-left:5em;
float:right; float:right;
} }
li {
margin: 12px 0;
}
</style> </style>