From 3acc50844047a37698f0618fa235c138e386a053 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Apr 2019 09:50:57 +0200 Subject: Upgrade sequelize --- server/controllers/api/video-playlist.ts | 20 +++++++------------- server/controllers/api/videos/import.ts | 16 +++++----------- server/controllers/api/videos/index.ts | 31 +++++++++++-------------------- server/controllers/bots.ts | 2 +- server/controllers/feeds.ts | 2 +- server/controllers/static.ts | 12 ++++++------ 6 files changed, 31 insertions(+), 52 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index 99325aa9d..6a1d23529 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -41,7 +41,7 @@ import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/vid import { JobQueue } from '../../lib/job-queue' import { CONFIG } from '../../initializers/config' import { sequelizeTypescript } from '../../initializers/database' -import { createPlaylistThumbnailFromExisting } from '../../lib/thumbnail' +import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail' const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) @@ -174,16 +174,13 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createPlaylistThumbnailFromExisting(thumbnailField[0].path, videoPlaylist) + ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylist) : undefined const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => { const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) - if (thumbnailModel) { - thumbnailModel.videoPlaylistId = videoPlaylistCreated.id - videoPlaylistCreated.setThumbnail(await thumbnailModel.save({ transaction: t })) - } + if (thumbnailModel) await videoPlaylistCreated.setAndSaveThumbnail(thumbnailModel, t) // We need more attributes for the federation videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t) @@ -210,7 +207,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createPlaylistThumbnailFromExisting(thumbnailField[0].path, videoPlaylistInstance) + ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylistInstance) : undefined try { @@ -239,10 +236,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) - if (thumbnailModel) { - thumbnailModel.videoPlaylistId = playlistUpdated.id - playlistUpdated.setThumbnail(await thumbnailModel.save({ transaction: t })) - } + if (thumbnailModel) await playlistUpdated.setAndSaveThumbnail(thumbnailModel, t) const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE @@ -313,8 +307,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) if (playlistElement.position === 1 && videoPlaylist.hasThumbnail() === false) { logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url) - const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnail().filename) - const thumbnailModel = await createPlaylistThumbnailFromExisting(inputPath, videoPlaylist, true) + const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getMiniature().filename) + const thumbnailModel = await createPlaylistMiniatureFromExisting(inputPath, videoPlaylist, true) thumbnailModel.videoPlaylistId = videoPlaylist.id diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index a4ec41d44..bfb690906 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts @@ -23,7 +23,7 @@ import { move, readFile } from 'fs-extra' import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' -import { createVideoThumbnailFromExisting } from '../../../lib/thumbnail' +import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { ThumbnailModel } from '../../../models/video/thumbnail' @@ -204,7 +204,7 @@ async function processThumbnail (req: express.Request, video: VideoModel) { if (thumbnailField) { const thumbnailPhysicalFile = thumbnailField[ 0 ] - return createVideoThumbnailFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.THUMBNAIL) + return createVideoMiniatureFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.MINIATURE) } return undefined @@ -215,7 +215,7 @@ async function processPreview (req: express.Request, video: VideoModel) { if (previewField) { const previewPhysicalFile = previewField[0] - return createVideoThumbnailFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW) + return createVideoMiniatureFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW) } return undefined @@ -238,14 +238,8 @@ function insertIntoDB (parameters: { const videoCreated = await video.save(sequelizeOptions) videoCreated.VideoChannel = videoChannel - if (thumbnailModel) { - thumbnailModel.videoId = videoCreated.id - videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) - } - if (previewModel) { - previewModel.videoId = videoCreated.id - videoCreated.addThumbnail(await previewModel.save({ transaction: t })) - } + if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) + if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t) diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index ad2fe958c..5bbce11b4 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -52,7 +52,7 @@ import { Notifier } from '../../../lib/notifier' import { sendView } from '../../../lib/activitypub/send/send-view' import { CONFIG } from '../../../initializers/config' import { sequelizeTypescript } from '../../../initializers/database' -import { createVideoThumbnailFromExisting, generateVideoThumbnail } from '../../../lib/thumbnail' +import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' const auditLogger = auditLoggerFactory('videos') @@ -214,14 +214,14 @@ async function addVideo (req: express.Request, res: express.Response) { // Process thumbnail or create it from the video const thumbnailField = req.files['thumbnailfile'] const thumbnailModel = thumbnailField - ? await createVideoThumbnailFromExisting(thumbnailField[0].path, video, ThumbnailType.THUMBNAIL) - : await generateVideoThumbnail(video, videoFile, ThumbnailType.THUMBNAIL) + ? await createVideoMiniatureFromExisting(thumbnailField[0].path, video, ThumbnailType.MINIATURE) + : await generateVideoMiniature(video, videoFile, ThumbnailType.MINIATURE) // Process preview or create it from the video const previewField = req.files['previewfile'] const previewModel = previewField - ? await createVideoThumbnailFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW) - : await generateVideoThumbnail(video, videoFile, ThumbnailType.PREVIEW) + ? await createVideoMiniatureFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW) + : await generateVideoMiniature(video, videoFile, ThumbnailType.PREVIEW) // Create the torrent file await video.createTorrentAndSetInfoHash(videoFile) @@ -231,11 +231,8 @@ async function addVideo (req: express.Request, res: express.Response) { const videoCreated = await video.save(sequelizeOptions) - thumbnailModel.videoId = videoCreated.id - previewModel.videoId = videoCreated.id - - videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) - videoCreated.addThumbnail(await previewModel.save({ transaction: t })) + await videoCreated.addAndSaveThumbnail(thumbnailModel, t) + await videoCreated.addAndSaveThumbnail(previewModel, t) // Do not forget to add video channel information to the created video videoCreated.VideoChannel = res.locals.videoChannel @@ -308,11 +305,11 @@ async function updateVideo (req: express.Request, res: express.Response) { // Process thumbnail or create it from the video const thumbnailModel = req.files && req.files['thumbnailfile'] - ? await createVideoThumbnailFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.THUMBNAIL) + ? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE) : undefined const previewModel = req.files && req.files['previewfile'] - ? await createVideoThumbnailFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW) + ? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW) : undefined try { @@ -346,14 +343,8 @@ async function updateVideo (req: express.Request, res: express.Response) { const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) - if (thumbnailModel) { - thumbnailModel.videoId = videoInstanceUpdated.id - videoInstanceUpdated.addThumbnail(await thumbnailModel.save({ transaction: t })) - } - if (previewModel) { - previewModel.videoId = videoInstanceUpdated.id - videoInstanceUpdated.addThumbnail(await previewModel.save({ transaction: t })) - } + if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t) + if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t) // Video tags update? if (videoInfoToUpdate.tags !== undefined) { diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts index 7e8e6eff6..e25d9c21b 100644 --- a/server/controllers/bots.ts +++ b/server/controllers/bots.ts @@ -85,7 +85,7 @@ async function getSitemapLocalVideoUrls () { // Sitemap description should be < 2000 characters description: truncate(v.description || v.name, { length: 2000, omission: '...' }), player_loc: WEBSERVER.URL + '/videos/embed/' + v.uuid, - thumbnail_loc: WEBSERVER.URL + v.getThumbnailStaticPath() + thumbnail_loc: WEBSERVER.URL + v.getMiniatureStaticPath() } ] })) diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index 5064097cd..d3f581615 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts @@ -137,7 +137,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response) { torrent: torrents, thumbnail: [ { - url: WEBSERVER.URL + video.getThumbnailStaticPath(), + url: WEBSERVER.URL + video.getMiniatureStaticPath(), height: THUMBNAILS_SIZE.height, width: THUMBNAILS_SIZE.width } diff --git a/server/controllers/static.ts b/server/controllers/static.ts index d75b95f52..05019fcc2 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts @@ -165,20 +165,20 @@ export { // --------------------------------------------------------------------------- async function getPreview (req: express.Request, res: express.Response) { - const path = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) - if (!path) return res.sendStatus(404) + const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) + if (!result) return res.sendStatus(404) - return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) + return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) } async function getVideoCaption (req: express.Request, res: express.Response) { - const path = await VideosCaptionCache.Instance.getFilePath({ + const result = await VideosCaptionCache.Instance.getFilePath({ videoId: req.params.videoId, language: req.params.captionLanguage }) - if (!path) return res.sendStatus(404) + if (!result) return res.sendStatus(404) - return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) + return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) } async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) { -- cgit v1.2.3