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()) {
|
switch (activity.type.toLowerCase()) {
|
||||||
// automatically reshare incoming posts
|
// automatically reshare incoming posts
|
||||||
case 'create': {
|
case 'create': {
|
||||||
|
console.log(activity.object[0].inReplyTo)
|
||||||
const to = [
|
const to = [
|
||||||
recipient.followers[0],
|
recipient.followers[0],
|
||||||
apex.consts.publicAddress
|
apex.consts.publicAddress
|
||||||
|
@ -189,6 +190,7 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => {
|
||||||
cc: actor.id
|
cc: actor.id
|
||||||
})
|
})
|
||||||
//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(activity.object[0].id)
|
||||||
console.log(share)
|
console.log(share)
|
||||||
await 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`)
|
||||||
|
@ -213,6 +215,16 @@ app.on('apex-inbox', async ({ actor, activity, recipient, object }) => {
|
||||||
await apex.addToOutbox(recipient, accept)
|
await apex.addToOutbox(recipient, accept)
|
||||||
return publishUpdatedFollowers()
|
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) => {
|
app.get('/mod/userinfo', async (req, res, next) => {
|
||||||
try {
|
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)
|
res.json(object)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(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 {
|
try {
|
||||||
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
|
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
|
||||||
const queueSize = await apex.store.db.collection(`${object.id}-queue`).find().toArray()
|
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) => {
|
app.get('/mod/approve', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
console.log("recived")
|
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 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)
|
||||||
|
await apex.store.db.collection(`${object.id}-posts`).insertOne(dbout)
|
||||||
apex.addToOutbox(object, 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)
|
||||||
|
@ -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) {
|
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) {
|
||||||
|
|
|
@ -3,15 +3,23 @@
|
||||||
<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>
|
<h5>Description</h5>
|
||||||
<input v-model="userdescription" :placeholder="userdata.summary[0]" />
|
<input v-model="userdescription"/>
|
||||||
<h5>Display Name</h5>
|
<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>
|
<button class="save" v-on:click="save(name, userdescription, username)">Save</button>
|
||||||
|
<h2>Approval Queue</h2>
|
||||||
<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>
|
||||||
<button class="approve" v-on:click="approve(name, item.object[0])">Approve</button>
|
<button class="approve" v-on:click="approve(name, item.object[0])">Approve</button>
|
||||||
</li>
|
</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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -26,13 +34,17 @@ export default {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
queue: [],
|
queue: [],
|
||||||
|
posts: [],
|
||||||
error: null,
|
error: null,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
userdata: this.userdata,
|
userdata: this.userdata,
|
||||||
|
userdescription: this.userdescription,
|
||||||
|
username: this.username,
|
||||||
domain: window.location.host
|
domain: window.location.host
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -85,8 +97,8 @@ export default {
|
||||||
})
|
})
|
||||||
.catch(err => (this.error = err.message))
|
.catch(err => (this.error = err.message))
|
||||||
},
|
},
|
||||||
save: function (name, description, username) {
|
deletepost: function (name, id) {
|
||||||
window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, {
|
window.fetch(`/mod/delete?name=${name}&id=${id}`, {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/json'
|
accept: 'application/json'
|
||||||
|
@ -96,8 +108,6 @@ export default {
|
||||||
console.log("test3")
|
console.log("test3")
|
||||||
console.log(json)
|
console.log(json)
|
||||||
})
|
})
|
||||||
},
|
|
||||||
created () {
|
|
||||||
window.fetch(`/mod/data?name=${this.name}`, {
|
window.fetch(`/mod/data?name=${this.name}`, {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -110,6 +120,48 @@ 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)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
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}`, {
|
window.fetch(`/mod/userinfo?name=${this.name}`, {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -120,18 +172,14 @@ export default {
|
||||||
console.log("test4")
|
console.log("test4")
|
||||||
console.log(json)
|
console.log(json)
|
||||||
this.userdata = json
|
this.userdata = json
|
||||||
|
this.userdescription = json.summary[0]
|
||||||
|
this.username = json.name[0]
|
||||||
})
|
})
|
||||||
.catch(err => (this.error = err.message))
|
.catch(err => (this.error = err.message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref } from 'vue'
|
|
||||||
|
|
||||||
const userdescription = ref('');
|
|
||||||
const username = ref('');
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
Loading…
Reference in a new issue