More options in the mod ui
This commit is contained in:
parent
94e5d8df64
commit
28e5c64ad1
2 changed files with 127 additions and 14 deletions
69
index.js
69
index.js
|
@ -179,6 +179,7 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => {
|
|||
switch (activity.type.toLowerCase()) {
|
||||
// automatically reshare incoming posts
|
||||
case 'create': {
|
||||
console.log(activity.object[0].inReplyTo)
|
||||
const to = [
|
||||
recipient.followers[0],
|
||||
apex.consts.publicAddress
|
||||
|
@ -189,6 +190,7 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => {
|
|||
cc: actor.id
|
||||
})
|
||||
//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`)
|
||||
|
@ -213,6 +215,16 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => {
|
|||
await apex.addToOutbox(recipient, accept)
|
||||
return publishUpdatedFollowers()
|
||||
}
|
||||
case 'delete': {
|
||||
const queuefind = await apex.store.db.collection(`${recipient.id}-queue`).findOne( {object: [activity.object[0].id]} )
|
||||
if (queuefind) {
|
||||
await apex.store.db.collection(`${recipient.id}-queue`).remove( {object: [activity.object[0].id]} )
|
||||
}
|
||||
const postfind = await apex.store.db.collection(`${recipient.id}-posts`).findOne( {object: [activity.object[0].id]} )
|
||||
if (postfind) {
|
||||
await apex.store.db.collection(`${recipient.id}-posts`).remove( {object: [activity.object[0].id]} )
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -269,14 +281,33 @@ 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))
|
||||
const 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/changedata', async (req, res, next) => {
|
||||
try {
|
||||
var oldobject = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true)
|
||||
const newgroup = await createGuppeActor(req.query.name, req.query.username, req.query.description, icon, 'Group')
|
||||
const to = [
|
||||
oldobject.followers[0],
|
||||
apex.consts.publicAddress
|
||||
]
|
||||
const share = await apex.buildActivity('Update', oldobject.id, to, {
|
||||
object: newgroup
|
||||
})
|
||||
apex.addToOutbox(oldobject, share)
|
||||
await apex.store.updateObject(newgroup, oldobject.id, true)
|
||||
res.json(newgroup)
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/mod/data/queue', async (req, res, next) => {
|
||||
try {
|
||||
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
|
||||
const queueSize = await apex.store.db.collection(`${object.id}-queue`).find().toArray()
|
||||
|
@ -288,6 +319,18 @@ app.get('/mod/data', async (req, res, next) => {
|
|||
}
|
||||
})
|
||||
|
||||
app.get('/mod/data/posts', async (req, res, next) => {
|
||||
try {
|
||||
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
|
||||
const queueSize = await apex.store.db.collection(`${object.id}-posts`).find().toArray()
|
||||
// console.log(res.json({queueSize}))
|
||||
console.log(queueSize)
|
||||
res.json(queueSize)
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
app.get('/mod/approve', async (req, res, next) => {
|
||||
try {
|
||||
console.log("recived")
|
||||
|
@ -297,6 +340,7 @@ app.get('/mod/approve', async (req, res, next) => {
|
|||
//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)
|
||||
await apex.store.db.collection(`${object.id}-posts`).insertOne(dbout)
|
||||
apex.addToOutbox(object, dbout)
|
||||
await apex.store.db.collection(`${object.id}-queue`).remove( {object: [req.query.id]} )
|
||||
res.json(dbout)
|
||||
|
@ -318,6 +362,27 @@ app.get('/mod/deny', async (req, res, next) => {
|
|||
}
|
||||
})
|
||||
|
||||
app.get('/mod/delete', async (req, res, next) => {
|
||||
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('Undo', actor.id, to, {
|
||||
object: dbout
|
||||
})
|
||||
apex.addToOutbox(actor, share)
|
||||
|
||||
await apex.store.db.collection(`${actor.id}-posts`).remove( {object: [req.query.id]} )
|
||||
res.json(share)
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
console.error(err.message, req.body, err.stack)
|
||||
if (!res.headersSent) {
|
||||
|
|
|
@ -3,15 +3,23 @@
|
|||
<h1>Moderation for {{name}} </h1>
|
||||
<ul style="list-style-type:none;">
|
||||
<h5>Description</h5>
|
||||
<input v-model="userdescription" :placeholder="userdata.summary[0]" />
|
||||
<input v-model="userdescription"/>
|
||||
<h5>Display Name</h5>
|
||||
<input v-model="username" :placeholder="userdata.preferredUsername[0]" />
|
||||
<input v-model="username"/>
|
||||
<h5>Avatar</h5>
|
||||
<input type="file" @change="previewFiles" accept="image/*">
|
||||
<button class="save" v-on:click="save(name, userdescription, username)">Save</button>
|
||||
<h2>Approval Queue</h2>
|
||||
<li v-for="item in queue">
|
||||
<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="approve" v-on:click="approve(name, item.object[0])">Approve</button>
|
||||
</li>
|
||||
<h2>Posts</h2>
|
||||
<li v-for="item in posts">
|
||||
<a :href="item.object[0]" target="_blank">{{ item.object[0] }}</a>
|
||||
<button class="deny" v-on:click="deletepost(name, item.object[0])">Delete</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -26,13 +34,17 @@ export default {
|
|||
type: String,
|
||||
required: true,
|
||||
}
|
||||
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
queue: [],
|
||||
posts: [],
|
||||
error: null,
|
||||
name: this.name,
|
||||
userdata: this.userdata,
|
||||
userdescription: this.userdescription,
|
||||
username: this.username,
|
||||
domain: window.location.host
|
||||
}
|
||||
},
|
||||
|
@ -85,8 +97,8 @@ export default {
|
|||
})
|
||||
.catch(err => (this.error = err.message))
|
||||
},
|
||||
save: function (name, description, username) {
|
||||
window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, {
|
||||
deletepost: function (name, id) {
|
||||
window.fetch(`/mod/delete?name=${name}&id=${id}`, {
|
||||
method: 'get',
|
||||
headers: {
|
||||
accept: 'application/json'
|
||||
|
@ -96,8 +108,6 @@ export default {
|
|||
console.log("test3")
|
||||
console.log(json)
|
||||
})
|
||||
},
|
||||
created () {
|
||||
window.fetch(`/mod/data?name=${this.name}`, {
|
||||
method: 'get',
|
||||
headers: {
|
||||
|
@ -110,6 +120,48 @@ export default {
|
|||
this.queue = json
|
||||
})
|
||||
.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)
|
||||
})
|
||||
},
|
||||
previewFiles(event) {
|
||||
console.log(event.target.files);
|
||||
}
|
||||
},
|
||||
created () {
|
||||
window.fetch(`/mod/data/queue?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))
|
||||
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: {
|
||||
|
@ -120,18 +172,14 @@ export default {
|
|||
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))
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
const userdescription = ref('');
|
||||
const username = ref('');
|
||||
</script>
|
||||
|
||||
|
||||
<style>
|
||||
|
|
Loading…
Reference in a new issue