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-channel-interface.ts | 6 ++++- server/models/video/video-channel.ts | 35 ++++++++++++++++++++++++-- server/models/video/video-interface.ts | 11 ++++---- server/models/video/video.ts | 24 ++++++++++++++++-- 4 files changed, 66 insertions(+), 10 deletions(-) (limited to 'server/models/video') diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.ts index 477f97cd4..55e772063 100644 --- a/server/models/video/video-channel-interface.ts +++ b/server/models/video/video-channel-interface.ts @@ -24,6 +24,8 @@ export namespace VideoChannelMethods { export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise export type LoadByHostAndUUID = (uuid: string, podHost: string, t?: Sequelize.Transaction) => Promise export type LoadAndPopulateAccountAndVideos = (id: number) => Promise + export type LoadByUrl = (uuid: string, t?: Sequelize.Transaction) => Promise + export type LoadByUUIDOrUrl = (uuid: string, url: string, t?: Sequelize.Transaction) => Promise } export interface VideoChannelClass { @@ -37,6 +39,8 @@ export interface VideoChannelClass { loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos + loadByUrl: VideoChannelMethods.LoadByUrl + loadByUUIDOrUrl: VideoChannelMethods.LoadByUUIDOrUrl } export interface VideoChannelAttributes { @@ -45,7 +49,7 @@ export interface VideoChannelAttributes { name: string description: string remote: boolean - url: string + url?: string Account?: AccountInstance Videos?: VideoInstance[] diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index c17828f3e..93a611fa0 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -25,6 +25,8 @@ let loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount let loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount let loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID let loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos +let loadByUrl: VideoChannelMethods.LoadByUrl +let loadByUUIDOrUrl: VideoChannelMethods.LoadByUUIDOrUrl export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { VideoChannel = sequelize.define('VideoChannel', @@ -94,12 +96,14 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da loadByUUID, loadByHostAndUUID, loadAndPopulateAccountAndVideos, - countByAccount + countByAccount, + loadByUrl, + loadByUUIDOrUrl ] const instanceMethods = [ isOwned, toFormattedJSON, - toActivityPubObject, + toActivityPubObject ] addMethodsToModel(VideoChannel, classMethods, instanceMethods) @@ -254,6 +258,33 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) { return VideoChannel.findOne(query) } +loadByUrl = function (url: string, t?: Sequelize.Transaction) { + const query: Sequelize.FindOptions = { + where: { + url + } + } + + if (t !== undefined) query.transaction = t + + return VideoChannel.findOne(query) +} + +loadByUUIDOrUrl = function (uuid: string, url: string, t?: Sequelize.Transaction) { + const query: Sequelize.FindOptions = { + where: { + [Sequelize.Op.or]: [ + { uuid }, + { url } + ] + }, + } + + if (t !== undefined) query.transaction = t + + return VideoChannel.findOne(query) +} + loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index e62e25a82..a0ac43e1e 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts @@ -69,6 +69,7 @@ export namespace VideoMethods { export type LoadAndPopulateAccount = (id: number) => Bluebird export type LoadAndPopulateAccountAndPodAndTags = (id: number) => Bluebird export type LoadByUUIDAndPopulateAccountAndPodAndTags = (uuid: string) => Bluebird + export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird export type RemoveThumbnail = (this: VideoInstance) => Promise export type RemovePreview = (this: VideoInstance) => Promise @@ -89,6 +90,7 @@ export interface VideoClass { loadByHostAndUUID: VideoMethods.LoadByHostAndUUID loadByUUID: VideoMethods.LoadByUUID loadByUrl: VideoMethods.LoadByUrl + loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags @@ -109,7 +111,10 @@ export interface VideoAttributes { likes?: number dislikes?: number remote: boolean - url: string + url?: string + + createdAt?: Date + updatedAt?: Date parentId?: number channelId?: number @@ -120,9 +125,6 @@ export interface VideoAttributes { } export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance { - createdAt: Date - updatedAt: Date - createPreview: VideoMethods.CreatePreview createThumbnail: VideoMethods.CreateThumbnail createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash @@ -158,4 +160,3 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In } export interface VideoModel extends VideoClass, Sequelize.Model {} - 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