Alpha Ready

This commit is contained in:
insert 2023-08-20 17:21:52 -04:00
parent 28e5c64ad1
commit 24278fe242
No known key found for this signature in database
GPG key ID: 8F1F3466FB204C55
2 changed files with 256 additions and 31 deletions

105
index.js
View file

@ -11,7 +11,7 @@ const { onShutdown } = require('node-graceful-shutdown')
const ActivitypubExpress = require('activitypub-express')
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, GROUPS } = process.env
const { DOMAIN, KEY_PATH, CERT_PATH, CA_PATH, PORT_HTTPS, DB_URL, DB_NAME, PROXY_MODE, ADMIN_SECRET, USE_ATTACHMENTS, GROUPS, ALLOW_DELETE, ALLOW_CREATE } = process.env
const app = express()
const client = new MongoClient(DB_URL)
@ -81,6 +81,7 @@ async function actorOnDemand (req, res, next) {
if (!actor) {
return next()
}
console.log(req.params)
const actorIRI = apex.utils.usernameToIRI(actor)
/*try {
if (!(await apex.store.getObject(actorIRI)) && actor.length <= 255) {
@ -192,16 +193,11 @@ 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(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`)
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)
//}
const blocked = await apex.store.db.collection(`${recipient.id}-blocked`).findOne( {user: share.cc[0]} )
console.log(blocked)
if (!blocked) {
await apex.store.db.collection(`${recipient.id}-queue`).insertOne(share)
}
//apex.addToOutbox(recipient, share)
break
@ -288,6 +284,31 @@ app.get('/mod/userinfo', async (req, res, next) => {
}
})
app.get('/mod/userblocks', async (req, res, next) => {
try {
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
const blockSize = await apex.store.db.collection(`${object.id}-blocked`).find().toArray()
// console.log(res.json({queueSize}))
console.log(blockSize)
res.json(blockSize)
} catch (err) {
next(err)
}
})
app.get('/mod/unblockuser', async (req, res, next) => {
try {
const object = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name))
const blockSize = await apex.store.db.collection(`${object.id}-blocked`).find( {user: req.query.id} )
// console.log(res.json({queueSize}))
await apex.store.db.collection(`${object.id}-blocked`).remove( {user: req.query.id} )
console.log(blockSize)
res.json(blockSize)
} catch (err) {
next(err)
}
})
app.get('/mod/changedata', async (req, res, next) => {
try {
var oldobject = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true)
@ -300,7 +321,7 @@ app.get('/mod/changedata', async (req, res, next) => {
object: newgroup
})
apex.addToOutbox(oldobject, share)
await apex.store.updateObject(newgroup, oldobject.id, true)
await apex.store.updateObject(newgroup, oldobject.id, false)
res.json(newgroup)
} catch (err) {
next(err)
@ -362,7 +383,59 @@ app.get('/mod/deny', async (req, res, next) => {
}
})
app.get('/mod/delete', async (req, res, next) => {
app.get('/mod/denyblock', 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( {cc: [dbout.cc[0]]} )
var create = await apex.store.db.collection(`${object.id}-blocked`).insertOne( {user: dbout.cc[0]} )
console.log(create)
var findexisting = await apex.store.db.collection(`${object.id}-blocked`).find().toArray()
console.log(findexisting)
res.json(dbout)
} catch (err) {
next(err)
}
})
app.get('/mod/delete/user', async (req, res, next) => {
if (ALLOW_DELETE != "true") {
res.json(null)
return
}
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('Delete', actor.id, to, {
object: actor
})
apex.addToOutbox(actor, share)
await apex.store.db.collection('objects').remove( {id: actor.id} )
await apex.store.db.collection(`${actor.id}-posts`).drop()
await apex.store.db.collection(`${actor.id}-queue`).drop()
const find = await apex.store.db.collection('streams').find().toArray()
console.log(find)
res.json(find)
} catch (err) {
next(err)
}
})
app.use(function (err, req, res, next) {
console.error(err.message, req.body, err.stack)
if (!res.headersSent) {
res.status(500).send('An error occurred while processing the request')
}
})
app.get('/mod/delete/post', async (req, res, next) => {
try {
console.log("recived")
const actor = await apex.store.getObject(apex.utils.usernameToIRI(req.query.name), true)
@ -383,12 +456,6 @@ app.get('/mod/delete', async (req, res, next) => {
}
})
app.use(function (err, req, res, next) {
console.error(err.message, req.body, err.stack)
if (!res.headersSent) {
res.status(500).send('An error occurred while processing the request')
}
})
client.connect()
.then(async () => {

View file

@ -9,9 +9,11 @@
<h5>Avatar</h5>
<input type="file" @change="previewFiles" accept="image/*">
<button class="save" v-on:click="save(name, userdescription, username)">Save</button>
<button class="deny" v-on:click="deleteuser(name)">Delete Group</button>
<h2>Approval Queue</h2>
<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="denyblock(name, item.object[0])">Block</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>
</li>
@ -20,6 +22,11 @@
<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>
<h2>Blocked Users</h2>
<li v-for="item in blockedusers">
<a :href="item.user" target="_blank">{{ item.user }}</a>
<button class="approve" v-on:click="unblockuser(name, item.user)">Unblock</button>
</li>
</ul>
</div>
</template>
@ -40,7 +47,9 @@ export default {
return {
queue: [],
posts: [],
image: null,
error: null,
blockedusers: this.blockedusers,
name: this.name,
userdata: this.userdata,
userdescription: this.userdescription,
@ -60,7 +69,7 @@ export default {
console.log("test3")
console.log(json)
})
window.fetch(`/mod/data?name=${this.name}`, {
window.fetch(`/mod/data/posts?name=${this.name}`, {
method: 'get',
headers: {
accept: 'application/json'
@ -69,7 +78,21 @@ export default {
.then(json => {
console.log("test2")
console.log(json)
this.queue = json
this.posts = json
})
.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
this.userdescription = json.summary[0]
this.username = json.name[0]
})
.catch(err => (this.error = err.message))
},
@ -84,7 +107,7 @@ export default {
console.log("test3")
console.log(json)
})
window.fetch(`/mod/data?name=${this.name}`, {
window.fetch(`/mod/data/posts?name=${this.name}`, {
method: 'get',
headers: {
accept: 'application/json'
@ -93,12 +116,26 @@ export default {
.then(json => {
console.log("test2")
console.log(json)
this.queue = json
this.posts = json
})
.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
this.userdescription = json.summary[0]
this.username = json.name[0]
})
.catch(err => (this.error = err.message))
},
deletepost: function (name, id) {
window.fetch(`/mod/delete?name=${name}&id=${id}`, {
denyblock: function (name, id) {
window.fetch(`/mod/denyblock?name=${name}&id=${id}`, {
method: 'get',
headers: {
accept: 'application/json'
@ -108,7 +145,7 @@ export default {
console.log("test3")
console.log(json)
})
window.fetch(`/mod/data?name=${this.name}`, {
window.fetch(`/mod/data/posts?name=${this.name}`, {
method: 'get',
headers: {
accept: 'application/json'
@ -117,12 +154,114 @@ export default {
.then(json => {
console.log("test2")
console.log(json)
this.queue = json
this.posts = json
})
.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
this.userdescription = json.summary[0]
this.username = json.name[0]
})
.catch(err => (this.error = err.message))
},
unblockuser: function (name, id) {
window.fetch(`/mod/unblockuser?name=${name}&id=${id}`, {
method: 'get',
headers: {
accept: 'application/json'
}
}).then(res => res.json())
.then(json => {
console.log("test3")
console.log(json)
})
},
deletepost: function (name, id) {
window.fetch(`/mod/delete/post?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/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: {
accept: 'application/json'
}
}).then(res => res.json())
.then(json => {
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))
},
deleteuser: function (name) {
window.fetch(`/mod/delete/user?name=${name}`, {
method: 'get',
headers: {
accept: 'application/json'
}
}).then(res => res.json())
.then(json => {
console.log("test3")
console.log(json)
})
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: {
accept: 'application/json'
}
}).then(res => res.json())
.then(json => {
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))
},
save: function (name, description, username) {
window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, {
window.fetch(`/mod/changedata?name=${name}&description=${description}&username=${username}`, {
method: 'get',
headers: {
accept: 'application/json'
@ -134,7 +273,14 @@ export default {
})
},
previewFiles(event) {
console.log(event.target.files);
const files = event.target.files
let filename = files[0].name
const fileReader = new FileReader()
fileReader.addEventListener('load', () => {
this.imageUrl = fileReader.result
})
fileReader.readAsDataURL(files[0])
this.image = files[0]
}
},
created () {
@ -162,7 +308,19 @@ export default {
this.posts = json
})
.catch(err => (this.error = err.message))
window.fetch(`/mod/userinfo?name=${this.name}`, {
window.fetch(`/mod/userblocks?name=${this.name}`, {
method: 'get',
headers: {
accept: 'application/json'
}
}).then(res => res.json())
.then(json => {
console.log("test4")
console.log(json)
this.blockedusers = json
})
.catch(err => (this.error = err.message))
window.fetch(`/mod/userinfo?name=${this.name}`, {
method: 'get',
headers: {
accept: 'application/json'