Added "getAccount" to get an specific actor relevant data for APIs
This commit is contained in:
parent
51c29b034b
commit
6b17ac70b1
|
@ -10,6 +10,15 @@ module.exports = {
|
|||
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: () => {
|
||||
return 'https://'+apex.domain+'/'+crypto.randomUUID()
|
||||
},
|
||||
|
|
|
@ -25,7 +25,27 @@ async function getRejectedTimes(req, res) {
|
|||
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 = {
|
||||
getAccount,
|
||||
follow: {
|
||||
post: [auth.enforceSession, async (req, res) => {
|
||||
if (!utils.isURLValid(req.query.url))
|
||||
|
|
Loading…
Reference in New Issue