X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideo-playlist.ts;h=2f81cf43c1d59bd013ad59f1ca94bc5c3ddf1cde;hb=5cf027bdc46f1bf214c4cf26eee17ebda228004f;hp=b8613699bde900b65f3895027471807ea5bbc711;hpb=1e4d2cb5aef11898585fae4053da4ebd0a69b480;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index b8613699b..2f81cf43c 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -1,7 +1,12 @@ -import * as express from 'express' +import express from 'express' import { join } from 'path' +import { uuidToShort } from '@server/helpers/uuid' +import { scheduleRefreshIfNeeded } from '@server/lib/activitypub/playlists' +import { Hooks } from '@server/lib/plugins/hooks' import { getServerActor } from '@server/models/application/application' import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models' +import { VideoPlaylistCreateResult, VideoPlaylistElementCreateResult } from '@shared/models' +import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/video-playlist-create.model' import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model' import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model' @@ -17,8 +22,7 @@ import { MIMETYPES, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers/constant import { sequelizeTypescript } from '../../initializers/database' import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send' import { getLocalVideoPlaylistActivityPubUrl, getLocalVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url' -import { JobQueue } from '../../lib/job-queue' -import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail' +import { updatePlaylistMiniatureFromExisting } from '../../lib/thumbnail' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -42,7 +46,6 @@ import { import { AccountModel } from '../../models/account/account' import { VideoPlaylistModel } from '../../models/video/video-playlist' import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) @@ -144,9 +147,7 @@ async function listVideoPlaylists (req: express.Request, res: express.Response) function getVideoPlaylist (req: express.Request, res: express.Response) { const videoPlaylist = res.locals.videoPlaylistSummary - if (videoPlaylist.isOutdated()) { - JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video-playlist', url: videoPlaylist.url } }) - } + scheduleRefreshIfNeeded(videoPlaylist) return res.json(videoPlaylist.toFormattedJSON()) } @@ -173,7 +174,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createPlaylistMiniatureFromExisting({ + ? await updatePlaylistMiniatureFromExisting({ inputPath: thumbnailField[0].path, playlist: videoPlaylist, automaticallyGenerated: false @@ -200,8 +201,9 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { return res.json({ videoPlaylist: { id: videoPlaylistCreated.id, + shortUUID: uuidToShort(videoPlaylistCreated.uuid), uuid: videoPlaylistCreated.uuid - } + } as VideoPlaylistCreateResult }) } @@ -215,7 +217,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createPlaylistMiniatureFromExisting({ + ? await updatePlaylistMiniatureFromExisting({ inputPath: thumbnailField[0].path, playlist: videoPlaylistInstance, automaticallyGenerated: false @@ -332,11 +334,13 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) logger.info('Video added in playlist %s at position %d.', videoPlaylist.uuid, playlistElement.position) + Hooks.runAction('action:api.video-playlist-element.created', { playlistElement }) + return res.json({ videoPlaylistElement: { id: playlistElement.id - } - }).end() + } as VideoPlaylistElementCreateResult + }) } async function updateVideoPlaylistElement (req: express.Request, res: express.Response) { @@ -482,7 +486,7 @@ async function generateThumbnailForPlaylist (videoPlaylist: MVideoPlaylistThumbn } const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoMiniature.filename) - const thumbnailModel = await createPlaylistMiniatureFromExisting({ + const thumbnailModel = await updatePlaylistMiniatureFromExisting({ inputPath, playlist: videoPlaylist, automaticallyGenerated: true,