2019-09-21 21:20:14 +00:00
|
|
|
'use strict'
|
|
|
|
const config = require('../config.json')
|
|
|
|
const consts = require('./consts')
|
|
|
|
|
|
|
|
module.exports = {
|
2019-09-22 05:20:37 +00:00
|
|
|
usernameToIRI,
|
|
|
|
toJSONLD,
|
|
|
|
arrayToCollection,
|
|
|
|
actorFromActivity
|
2019-09-21 21:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function actorFromActivity (activity) {
|
2019-09-22 05:20:37 +00:00
|
|
|
if (Object.prototype.toString.call(activity.actor) === '[object String]') {
|
|
|
|
return activity.actor
|
|
|
|
}
|
|
|
|
if (activity.actor.type === 'Link') {
|
|
|
|
return activity.actor.href
|
|
|
|
}
|
|
|
|
return activity.actor.id
|
2019-09-21 21:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function arrayToCollection (arr, ordered) {
|
2019-09-22 05:20:37 +00:00
|
|
|
return {
|
|
|
|
'@context': consts.ASContext,
|
|
|
|
totalItems: arr.length,
|
|
|
|
type: ordered ? 'orderedCollection' : 'collection',
|
|
|
|
[ordered ? 'orderedItems' : 'items']: arr
|
|
|
|
}
|
2019-09-21 21:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toJSONLD (obj) {
|
2019-09-22 05:20:37 +00:00
|
|
|
obj['@context'] = obj['@context'] || consts.ASContext
|
|
|
|
return obj
|
2019-09-21 21:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function usernameToIRI (user) {
|
2019-09-22 05:20:37 +00:00
|
|
|
return `https://${config.DOMAIN}/u/${user}`
|
2019-09-21 21:20:14 +00:00
|
|
|
}
|