mirror of https://github.com/Chocobozzz/PeerTube
Add id to likes/dislikes/comments/shares collections
parent
c88593f72f
commit
46531a0abd
|
@ -36,10 +36,26 @@ activityPubClientRouter.get('/videos/watch/:id',
|
||||||
executeIfActivityPub(asyncMiddleware(videosGetValidator)),
|
executeIfActivityPub(asyncMiddleware(videosGetValidator)),
|
||||||
executeIfActivityPub(asyncMiddleware(videoController))
|
executeIfActivityPub(asyncMiddleware(videoController))
|
||||||
)
|
)
|
||||||
|
activityPubClientRouter.get('/videos/watch/:id/announces',
|
||||||
|
executeIfActivityPub(asyncMiddleware(videosGetValidator)),
|
||||||
|
executeIfActivityPub(asyncMiddleware(videoAnnouncesController))
|
||||||
|
)
|
||||||
activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
|
activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
|
||||||
executeIfActivityPub(asyncMiddleware(videosShareValidator)),
|
executeIfActivityPub(asyncMiddleware(videosShareValidator)),
|
||||||
executeIfActivityPub(asyncMiddleware(videoAnnounceController))
|
executeIfActivityPub(asyncMiddleware(videoAnnounceController))
|
||||||
)
|
)
|
||||||
|
activityPubClientRouter.get('/videos/watch/:id/likes',
|
||||||
|
executeIfActivityPub(asyncMiddleware(videosGetValidator)),
|
||||||
|
executeIfActivityPub(asyncMiddleware(videoLikesController))
|
||||||
|
)
|
||||||
|
activityPubClientRouter.get('/videos/watch/:id/dislikes',
|
||||||
|
executeIfActivityPub(asyncMiddleware(videosGetValidator)),
|
||||||
|
executeIfActivityPub(asyncMiddleware(videoDislikesController))
|
||||||
|
)
|
||||||
|
activityPubClientRouter.get('/videos/watch/:id/comments',
|
||||||
|
executeIfActivityPub(asyncMiddleware(videosGetValidator)),
|
||||||
|
executeIfActivityPub(asyncMiddleware(videoCommentsController))
|
||||||
|
)
|
||||||
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
|
activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
|
||||||
executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)),
|
executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)),
|
||||||
executeIfActivityPub(asyncMiddleware(videoCommentController))
|
executeIfActivityPub(asyncMiddleware(videoCommentController))
|
||||||
|
@ -105,6 +121,46 @@ async function videoAnnounceController (req: express.Request, res: express.Respo
|
||||||
return res.json(activityPubContextify(object))
|
return res.json(activityPubContextify(object))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
const video: VideoModel = res.locals.video
|
||||||
|
|
||||||
|
// We need more attributes
|
||||||
|
const videoAll = await VideoModel.loadAndPopulateAll(video.id)
|
||||||
|
const object = videoAll.toAnnouncesActivityPubObject()
|
||||||
|
|
||||||
|
return res.json(activityPubContextify(object))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function videoLikesController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
const video: VideoModel = res.locals.video
|
||||||
|
|
||||||
|
// We need more attributes
|
||||||
|
const videoAll = await VideoModel.loadAndPopulateAll(video.id)
|
||||||
|
const { likesObject } = videoAll.toRatesActivityPubObjects()
|
||||||
|
|
||||||
|
return res.json(activityPubContextify(likesObject))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function videoDislikesController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
const video: VideoModel = res.locals.video
|
||||||
|
|
||||||
|
// We need more attributes
|
||||||
|
const videoAll = await VideoModel.loadAndPopulateAll(video.id)
|
||||||
|
const { dislikesObject } = videoAll.toRatesActivityPubObjects()
|
||||||
|
|
||||||
|
return res.json(activityPubContextify(dislikesObject))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function videoCommentsController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
|
const video: VideoModel = res.locals.video
|
||||||
|
|
||||||
|
// We need more attributes
|
||||||
|
const videoAll = await VideoModel.loadAndPopulateAll(video.id)
|
||||||
|
const commentsObject = videoAll.toCommentsActivityPubObject()
|
||||||
|
|
||||||
|
return res.json(activityPubContextify(commentsObject))
|
||||||
|
}
|
||||||
|
|
||||||
async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||||
const videoChannel: VideoChannelModel = res.locals.videoChannel
|
const videoChannel: VideoChannelModel = res.locals.videoChannel
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,9 @@ function activityPubContextify <T> (data: T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function activityPubCollection (results: any[]) {
|
function activityPubCollection (url: string, results: any[]) {
|
||||||
return {
|
return {
|
||||||
|
id: url,
|
||||||
type: 'OrderedCollection',
|
type: 'OrderedCollection',
|
||||||
totalItems: results.length,
|
totalItems: results.length,
|
||||||
orderedItems: results
|
orderedItems: results
|
||||||
|
|
|
@ -37,6 +37,22 @@ function getVideoDislikeActivityPubUrl (byActor: ActorModel, video: VideoModel)
|
||||||
return byActor.url + '/dislikes/' + video.id
|
return byActor.url + '/dislikes/' + video.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVideoSharesActivityPubUrl (video: VideoModel) {
|
||||||
|
return video.url + '/announces'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVideoCommentsActivityPubUrl (video: VideoModel) {
|
||||||
|
return video.url + '/comments'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVideoLikesActivityPubUrl (video: VideoModel) {
|
||||||
|
return video.url + '/likes'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVideoDislikesActivityPubUrl (video: VideoModel) {
|
||||||
|
return video.url + '/dislikes'
|
||||||
|
}
|
||||||
|
|
||||||
function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) {
|
function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) {
|
||||||
const me = actorFollow.ActorFollower
|
const me = actorFollow.ActorFollower
|
||||||
const following = actorFollow.ActorFollowing
|
const following = actorFollow.ActorFollowing
|
||||||
|
@ -81,5 +97,9 @@ export {
|
||||||
getVideoLikeActivityPubUrl,
|
getVideoLikeActivityPubUrl,
|
||||||
getVideoDislikeActivityPubUrl,
|
getVideoDislikeActivityPubUrl,
|
||||||
getVideoCommentActivityPubUrl,
|
getVideoCommentActivityPubUrl,
|
||||||
getDeleteActivityPubUrl
|
getDeleteActivityPubUrl,
|
||||||
|
getVideoSharesActivityPubUrl,
|
||||||
|
getVideoCommentsActivityPubUrl,
|
||||||
|
getVideoLikesActivityPubUrl,
|
||||||
|
getVideoDislikesActivityPubUrl
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,12 @@ import {
|
||||||
VIDEO_LICENCES,
|
VIDEO_LICENCES,
|
||||||
VIDEO_PRIVACIES
|
VIDEO_PRIVACIES
|
||||||
} from '../../initializers'
|
} from '../../initializers'
|
||||||
|
import {
|
||||||
|
getVideoCommentsActivityPubUrl,
|
||||||
|
getVideoDislikesActivityPubUrl,
|
||||||
|
getVideoLikesActivityPubUrl,
|
||||||
|
getVideoSharesActivityPubUrl
|
||||||
|
} from '../../lib/activitypub'
|
||||||
import { sendDeleteVideo } from '../../lib/activitypub/send'
|
import { sendDeleteVideo } from '../../lib/activitypub/send'
|
||||||
import { AccountModel } from '../account/account'
|
import { AccountModel } from '../account/account'
|
||||||
import { AccountVideoRateModel } from '../account/account-video-rate'
|
import { AccountVideoRateModel } from '../account/account-video-rate'
|
||||||
|
@ -958,30 +964,19 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
likesObject = activityPubCollection(likes)
|
const res = this.toRatesActivityPubObjects()
|
||||||
dislikesObject = activityPubCollection(dislikes)
|
likesObject = res.likesObject
|
||||||
|
dislikesObject = res.dislikesObject
|
||||||
}
|
}
|
||||||
|
|
||||||
let sharesObject
|
let sharesObject
|
||||||
if (Array.isArray(this.VideoShares)) {
|
if (Array.isArray(this.VideoShares)) {
|
||||||
const shares: string[] = []
|
sharesObject = this.toAnnouncesActivityPubObject()
|
||||||
|
|
||||||
for (const videoShare of this.VideoShares) {
|
|
||||||
shares.push(videoShare.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
sharesObject = activityPubCollection(shares)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let commentsObject
|
let commentsObject
|
||||||
if (Array.isArray(this.VideoComments)) {
|
if (Array.isArray(this.VideoComments)) {
|
||||||
const comments: string[] = []
|
commentsObject = this.toCommentsActivityPubObject()
|
||||||
|
|
||||||
for (const videoComment of this.VideoComments) {
|
|
||||||
comments.push(videoComment.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
commentsObject = activityPubCollection(comments)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = []
|
const url = []
|
||||||
|
@ -1058,6 +1053,44 @@ export class VideoModel extends Model<VideoModel> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toAnnouncesActivityPubObject () {
|
||||||
|
const shares: string[] = []
|
||||||
|
|
||||||
|
for (const videoShare of this.VideoShares) {
|
||||||
|
shares.push(videoShare.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return activityPubCollection(getVideoSharesActivityPubUrl(this), shares)
|
||||||
|
}
|
||||||
|
|
||||||
|
toCommentsActivityPubObject () {
|
||||||
|
const comments: string[] = []
|
||||||
|
|
||||||
|
for (const videoComment of this.VideoComments) {
|
||||||
|
comments.push(videoComment.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return activityPubCollection(getVideoCommentsActivityPubUrl(this), comments)
|
||||||
|
}
|
||||||
|
|
||||||
|
toRatesActivityPubObjects () {
|
||||||
|
const likes: string[] = []
|
||||||
|
const dislikes: string[] = []
|
||||||
|
|
||||||
|
for (const rate of this.AccountVideoRates) {
|
||||||
|
if (rate.type === 'like') {
|
||||||
|
likes.push(rate.Account.Actor.url)
|
||||||
|
} else if (rate.type === 'dislike') {
|
||||||
|
dislikes.push(rate.Account.Actor.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const likesObject = activityPubCollection(getVideoLikesActivityPubUrl(this), likes)
|
||||||
|
const dislikesObject = activityPubCollection(getVideoDislikesActivityPubUrl(this), dislikes)
|
||||||
|
|
||||||
|
return { likesObject, dislikesObject }
|
||||||
|
}
|
||||||
|
|
||||||
getTruncatedDescription () {
|
getTruncatedDescription () {
|
||||||
if (!this.description) return null
|
if (!this.description) return null
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue