From 0d0e8dd0904b380b70e19ebcb4763d65601c4632 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 14:34:45 +0100 Subject: Continue activitypub --- server/models/video/video.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 94af1ece5..b5d333347 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -25,7 +25,8 @@ import { statPromise, generateImageFromVideoFile, transcode, - getVideoFileHeight + getVideoFileHeight, + getActivityPubUrl } from '../../helpers' import { CONFIG, @@ -88,7 +89,7 @@ let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccount let listOwnedByAccount: VideoMethods.ListOwnedByAccount let load: VideoMethods.Load let loadByUUID: VideoMethods.LoadByUUID -let loadByUrl: VideoMethods.LoadByUrl +let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount let loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags @@ -277,6 +278,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da loadAndPopulateAccount, loadAndPopulateAccountAndPodAndTags, loadByHostAndUUID, + loadByUUIDOrURL, loadByUUID, loadLocalVideoByUUID, loadByUUIDAndPopulateAccountAndPodAndTags, @@ -595,6 +597,7 @@ toActivityPubObject = function (this: VideoInstance) { const videoObject: VideoTorrentObject = { type: 'Video', + id: getActivityPubUrl('video', this.uuid), name: this.name, // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration duration: 'PT' + this.duration + 'S', @@ -731,6 +734,7 @@ getCategoryLabel = function (this: VideoInstance) { getLicenceLabel = function (this: VideoInstance) { let licenceLabel = VIDEO_LICENCES[this.licence] + // Maybe our pod is not up to date and there are new licences since our version if (!licenceLabel) licenceLabel = 'Unknown' @@ -946,6 +950,22 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) { return Video.findOne(query) } +loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) { + const query: Sequelize.FindOptions = { + where: { + [Sequelize.Op.or]: [ + { uuid }, + { url } + ] + }, + include: [ Video['sequelize'].models.VideoFile ] + } + + if (t !== undefined) query.transaction = t + + return Video.findOne(query) +} + loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { -- cgit v1.2.3