2022-03-23 08:24:50 -05:00
|
|
|
import { ContextType } from '@shared/models'
|
2020-02-03 04:12:29 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
function activityPubContextify <T> (data: T, type: ContextType) {
|
|
|
|
return { ...getContextData(type), ...data }
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
getContextData,
|
|
|
|
activityPubContextify
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) }
|
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = {
|
2022-03-23 10:14:33 -05:00
|
|
|
Video: buildContext({
|
|
|
|
Hashtag: 'as:Hashtag',
|
|
|
|
uuid: 'sc:identifier',
|
|
|
|
category: 'sc:category',
|
|
|
|
licence: 'sc:license',
|
|
|
|
subtitleLanguage: 'sc:subtitleLanguage',
|
|
|
|
sensitive: 'as:sensitive',
|
|
|
|
language: 'sc:inLanguage',
|
|
|
|
|
|
|
|
// TODO: remove in a few versions, introduced in 4.2
|
|
|
|
icons: 'as:icon',
|
|
|
|
|
|
|
|
isLiveBroadcast: 'sc:isLiveBroadcast',
|
|
|
|
liveSaveReplay: {
|
|
|
|
'@type': 'sc:Boolean',
|
|
|
|
'@id': 'pt:liveSaveReplay'
|
|
|
|
},
|
|
|
|
permanentLive: {
|
|
|
|
'@type': 'sc:Boolean',
|
|
|
|
'@id': 'pt:permanentLive'
|
|
|
|
},
|
|
|
|
latencyMode: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:latencyMode'
|
|
|
|
},
|
|
|
|
|
|
|
|
Infohash: 'pt:Infohash',
|
|
|
|
|
|
|
|
originallyPublishedAt: 'sc:datePublished',
|
|
|
|
views: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:views'
|
|
|
|
},
|
|
|
|
state: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:state'
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:size'
|
|
|
|
},
|
|
|
|
fps: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:fps'
|
|
|
|
},
|
|
|
|
commentsEnabled: {
|
|
|
|
'@type': 'sc:Boolean',
|
|
|
|
'@id': 'pt:commentsEnabled'
|
|
|
|
},
|
|
|
|
downloadEnabled: {
|
|
|
|
'@type': 'sc:Boolean',
|
|
|
|
'@id': 'pt:downloadEnabled'
|
|
|
|
},
|
|
|
|
waitTranscoding: {
|
|
|
|
'@type': 'sc:Boolean',
|
|
|
|
'@id': 'pt:waitTranscoding'
|
|
|
|
},
|
|
|
|
support: {
|
|
|
|
'@type': 'sc:Text',
|
|
|
|
'@id': 'pt:support'
|
|
|
|
},
|
|
|
|
likes: {
|
|
|
|
'@id': 'as:likes',
|
|
|
|
'@type': '@id'
|
|
|
|
},
|
|
|
|
dislikes: {
|
|
|
|
'@id': 'as:dislikes',
|
|
|
|
'@type': '@id'
|
|
|
|
},
|
|
|
|
shares: {
|
|
|
|
'@id': 'as:shares',
|
|
|
|
'@type': '@id'
|
|
|
|
},
|
|
|
|
comments: {
|
|
|
|
'@id': 'as:comments',
|
|
|
|
'@type': '@id'
|
2020-02-04 09:34:46 -06:00
|
|
|
}
|
2022-03-23 10:14:33 -05:00
|
|
|
}),
|
2020-02-03 04:12:29 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
Playlist: buildContext({
|
|
|
|
Playlist: 'pt:Playlist',
|
|
|
|
PlaylistElement: 'pt:PlaylistElement',
|
|
|
|
position: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:position'
|
|
|
|
},
|
|
|
|
startTimestamp: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:startTimestamp'
|
|
|
|
},
|
|
|
|
stopTimestamp: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:stopTimestamp'
|
2022-03-24 07:36:47 -05:00
|
|
|
},
|
|
|
|
uuid: 'sc:identifier'
|
2022-03-23 10:14:33 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
CacheFile: buildContext({
|
|
|
|
expires: 'sc:expires',
|
|
|
|
CacheFile: 'pt:CacheFile'
|
|
|
|
}),
|
2020-02-04 09:34:46 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
Flag: buildContext({
|
|
|
|
Hashtag: 'as:Hashtag'
|
|
|
|
}),
|
|
|
|
|
|
|
|
Actor: buildContext({
|
|
|
|
playlists: {
|
|
|
|
'@id': 'pt:playlists',
|
|
|
|
'@type': '@id'
|
2020-02-04 09:34:46 -06:00
|
|
|
}
|
2022-03-23 10:14:33 -05:00
|
|
|
}),
|
2020-02-04 09:34:46 -06:00
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
WatchAction: buildContext({
|
|
|
|
WatchAction: 'sc:WatchAction',
|
|
|
|
startTimestamp: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:startTimestamp'
|
|
|
|
},
|
|
|
|
stopTimestamp: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:stopTimestamp'
|
|
|
|
},
|
|
|
|
watchSection: {
|
|
|
|
'@type': 'sc:Number',
|
|
|
|
'@id': 'pt:stopTimestamp'
|
|
|
|
},
|
|
|
|
uuid: 'sc:identifier'
|
|
|
|
}),
|
|
|
|
|
|
|
|
Collection: buildContext(),
|
2022-03-23 10:14:33 -05:00
|
|
|
Follow: buildContext(),
|
|
|
|
Reject: buildContext(),
|
|
|
|
Accept: buildContext(),
|
|
|
|
View: buildContext(),
|
|
|
|
Announce: buildContext(),
|
|
|
|
Comment: buildContext(),
|
|
|
|
Delete: buildContext(),
|
|
|
|
Rate: buildContext()
|
|
|
|
}
|
2020-02-03 04:12:29 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
function getContextData (type: ContextType) {
|
2020-02-04 09:34:46 -06:00
|
|
|
return {
|
2022-03-23 10:14:33 -05:00
|
|
|
'@context': contextStore[type]
|
2020-02-04 09:34:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
function buildContext (contextValue?: ContextValue) {
|
|
|
|
const baseContext = [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
{
|
|
|
|
RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
|
|
|
|
}
|
|
|
|
]
|
2017-11-09 10:51:58 -06:00
|
|
|
|
2022-03-23 10:14:33 -05:00
|
|
|
if (!contextValue) return baseContext
|
|
|
|
|
|
|
|
return [
|
|
|
|
...baseContext,
|
|
|
|
|
|
|
|
{
|
|
|
|
pt: 'https://joinpeertube.org/ns#',
|
|
|
|
sc: 'http://schema.org#',
|
|
|
|
|
|
|
|
...contextValue
|
|
|
|
}
|
|
|
|
]
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|