From d8755eed1e452d2efbfc983af0e9d228d152bf6b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 Oct 2017 10:05:49 +0200 Subject: Add oembed endpoint --- server/models/video/video-interface.ts | 6 ++++++ server/models/video/video.ts | 29 +++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 6a3db4f3e..1402df26a 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts @@ -32,6 +32,9 @@ export namespace VideoMethods { export type OptimizeOriginalVideofile = (this: VideoInstance) => Promise export type TranscodeOriginalVideofile = (this: VideoInstance, resolution: number) => Promise export type GetOriginalFileHeight = (this: VideoInstance) => Promise + export type GetEmbedPath = (this: VideoInstance) => string + export type GetThumbnailPath = (this: VideoInstance) => string + export type GetPreviewPath = (this: VideoInstance) => string // Return thumbnail name export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise @@ -107,7 +110,9 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In getOriginalFile: VideoMethods.GetOriginalFile generateMagnetUri: VideoMethods.GenerateMagnetUri getPreviewName: VideoMethods.GetPreviewName + getPreviewPath: VideoMethods.GetPreviewPath getThumbnailName: VideoMethods.GetThumbnailName + getThumbnailPath: VideoMethods.GetThumbnailPath getTorrentFileName: VideoMethods.GetTorrentFileName getVideoFilename: VideoMethods.GetVideoFilename getVideoFilePath: VideoMethods.GetVideoFilePath @@ -122,6 +127,7 @@ export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.In optimizeOriginalVideofile: VideoMethods.OptimizeOriginalVideofile transcodeOriginalVideofile: VideoMethods.TranscodeOriginalVideofile getOriginalFileHeight: VideoMethods.GetOriginalFileHeight + getEmbedPath: VideoMethods.GetEmbedPath setTags: Sequelize.HasManySetAssociationsMixin addVideoFile: Sequelize.HasManyAddAssociationMixin diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2ba6cf25f..0d0048b4a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -54,7 +54,9 @@ let getOriginalFile: VideoMethods.GetOriginalFile let generateMagnetUri: VideoMethods.GenerateMagnetUri let getVideoFilename: VideoMethods.GetVideoFilename let getThumbnailName: VideoMethods.GetThumbnailName +let getThumbnailPath: VideoMethods.GetThumbnailPath let getPreviewName: VideoMethods.GetPreviewName +let getPreviewPath: VideoMethods.GetPreviewPath let getTorrentFileName: VideoMethods.GetTorrentFileName let isOwned: VideoMethods.IsOwned let toFormattedJSON: VideoMethods.ToFormattedJSON @@ -67,6 +69,7 @@ let createThumbnail: VideoMethods.CreateThumbnail let getVideoFilePath: VideoMethods.GetVideoFilePath let createTorrentAndSetInfoHash: VideoMethods.CreateTorrentAndSetInfoHash let getOriginalFileHeight: VideoMethods.GetOriginalFileHeight +let getEmbedPath: VideoMethods.GetEmbedPath let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData let list: VideoMethods.List @@ -252,7 +255,9 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da createTorrentAndSetInfoHash, generateMagnetUri, getPreviewName, + getPreviewPath, getThumbnailName, + getThumbnailPath, getTorrentFileName, getVideoFilename, getVideoFilePath, @@ -267,7 +272,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da toUpdateRemoteJSON, optimizeOriginalVideofile, transcodeOriginalVideofile, - getOriginalFileHeight + getOriginalFileHeight, + getEmbedPath ] addMethodsToModel(Video, classMethods, instanceMethods) @@ -375,11 +381,13 @@ createPreview = function (this: VideoInstance, videoFile: VideoFileInstance) { } createThumbnail = function (this: VideoInstance, videoFile: VideoFileInstance) { + const imageSize = THUMBNAILS_SIZE.width + 'x' + THUMBNAILS_SIZE.height + return generateImageFromVideoFile( this.getVideoFilePath(videoFile), CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName(), - THUMBNAILS_SIZE + imageSize ) } @@ -438,6 +446,18 @@ generateMagnetUri = function (this: VideoInstance, videoFile: VideoFileInstance) return magnetUtil.encode(magnetHash) } +getEmbedPath = function (this: VideoInstance) { + return '/videos/embed/' + this.uuid +} + +getThumbnailPath = function (this: VideoInstance) { + return join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName()) +} + +getPreviewPath = function (this: VideoInstance) { + return join(STATIC_PATHS.PREVIEWS, this.getPreviewName()) +} + toFormattedJSON = function (this: VideoInstance) { let podHost @@ -480,8 +500,9 @@ toFormattedJSON = function (this: VideoInstance) { likes: this.likes, dislikes: this.dislikes, tags: map(this.Tags, 'name'), - thumbnailPath: join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName()), - previewPath: join(STATIC_PATHS.PREVIEWS, this.getPreviewName()), + thumbnailPath: this.getThumbnailPath(), + previewPath: this.getPreviewPath(), + embedPath: this.getEmbedPath(), createdAt: this.createdAt, updatedAt: this.updatedAt, files: [] -- cgit v1.2.3