Added "getAccount" to get an specific actor relevant data for APIs

This commit is contained in:
Niko 2022-02-16 15:45:45 +01:00
parent 51c29b034b
commit 6b17ac70b1
2 changed files with 29 additions and 0 deletions

View File

@ -10,6 +10,15 @@ module.exports = {
return false return false
} }
}, },
firstIfArray: (o) => {
if (o === undefined)
return null
if (o instanceof Array)
if (o.length > 0)
return o[0]
else return null
return o
},
apRandomURL: () => { apRandomURL: () => {
return 'https://'+apex.domain+'/'+crypto.randomUUID() return 'https://'+apex.domain+'/'+crypto.randomUUID()
}, },

View File

@ -25,7 +25,27 @@ async function getRejectedTimes(req, res) {
return times return times
} }
async function getAccount(id) {
const person = await db.getAPObject(id, 'Person')
const username = utils.firstIfArray(person.preferredUsername)
const icon = utils.firstIfArray(person.icon)
const newicon = {
type: utils.firstIfArray(icon.mediaType),
url: utils.firstIfArray(icon.url),
}
return {
_id: person._id,
url: person.id,
acct: username+'@'+(new URL(person.id)).hostname,
name: utils.firstIfArray(person.name),
summary: utils.firstIfArray(person.summary),
avatar: newicon,
username
}
}
module.exports = { module.exports = {
getAccount,
follow: { follow: {
post: [auth.enforceSession, async (req, res) => { post: [auth.enforceSession, async (req, res) => {
if (!utils.isURLValid(req.query.url)) if (!utils.isURLValid(req.query.url))