diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-23 09:50:57 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:21 +0200 |
commit | 3acc50844047a37698f0618fa235c138e386a053 (patch) | |
tree | e33243bf7fadbcf2df616fc41814245094fd881a /server/controllers | |
parent | 1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff) | |
download | PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip |
Upgrade sequelize
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/video-playlist.ts | 20 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 16 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 31 | ||||
-rw-r--r-- | server/controllers/bots.ts | 2 | ||||
-rw-r--r-- | server/controllers/feeds.ts | 2 | ||||
-rw-r--r-- | server/controllers/static.ts | 12 |
6 files changed, 31 insertions, 52 deletions
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 | |||
41 | import { JobQueue } from '../../lib/job-queue' | 41 | import { JobQueue } from '../../lib/job-queue' |
42 | import { CONFIG } from '../../initializers/config' | 42 | import { CONFIG } from '../../initializers/config' |
43 | import { sequelizeTypescript } from '../../initializers/database' | 43 | import { sequelizeTypescript } from '../../initializers/database' |
44 | import { createPlaylistThumbnailFromExisting } from '../../lib/thumbnail' | 44 | import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail' |
45 | 45 | ||
46 | const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) | 46 | const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) |
47 | 47 | ||
@@ -174,16 +174,13 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) { | |||
174 | 174 | ||
175 | const thumbnailField = req.files['thumbnailfile'] | 175 | const thumbnailField = req.files['thumbnailfile'] |
176 | const thumbnailModel = thumbnailField | 176 | const thumbnailModel = thumbnailField |
177 | ? await createPlaylistThumbnailFromExisting(thumbnailField[0].path, videoPlaylist) | 177 | ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylist) |
178 | : undefined | 178 | : undefined |
179 | 179 | ||
180 | const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => { | 180 | const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => { |
181 | const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) | 181 | const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) |
182 | 182 | ||
183 | if (thumbnailModel) { | 183 | if (thumbnailModel) await videoPlaylistCreated.setAndSaveThumbnail(thumbnailModel, t) |
184 | thumbnailModel.videoPlaylistId = videoPlaylistCreated.id | ||
185 | videoPlaylistCreated.setThumbnail(await thumbnailModel.save({ transaction: t })) | ||
186 | } | ||
187 | 184 | ||
188 | // We need more attributes for the federation | 185 | // We need more attributes for the federation |
189 | videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t) | 186 | videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t) |
@@ -210,7 +207,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) | |||
210 | 207 | ||
211 | const thumbnailField = req.files['thumbnailfile'] | 208 | const thumbnailField = req.files['thumbnailfile'] |
212 | const thumbnailModel = thumbnailField | 209 | const thumbnailModel = thumbnailField |
213 | ? await createPlaylistThumbnailFromExisting(thumbnailField[0].path, videoPlaylistInstance) | 210 | ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylistInstance) |
214 | : undefined | 211 | : undefined |
215 | 212 | ||
216 | try { | 213 | try { |
@@ -239,10 +236,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) | |||
239 | 236 | ||
240 | const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) | 237 | const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) |
241 | 238 | ||
242 | if (thumbnailModel) { | 239 | if (thumbnailModel) await playlistUpdated.setAndSaveThumbnail(thumbnailModel, t) |
243 | thumbnailModel.videoPlaylistId = playlistUpdated.id | ||
244 | playlistUpdated.setThumbnail(await thumbnailModel.save({ transaction: t })) | ||
245 | } | ||
246 | 240 | ||
247 | const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE | 241 | const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE |
248 | 242 | ||
@@ -313,8 +307,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) | |||
313 | if (playlistElement.position === 1 && videoPlaylist.hasThumbnail() === false) { | 307 | if (playlistElement.position === 1 && videoPlaylist.hasThumbnail() === false) { |
314 | logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url) | 308 | logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url) |
315 | 309 | ||
316 | const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnail().filename) | 310 | const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getMiniature().filename) |
317 | const thumbnailModel = await createPlaylistThumbnailFromExisting(inputPath, videoPlaylist, true) | 311 | const thumbnailModel = await createPlaylistMiniatureFromExisting(inputPath, videoPlaylist, true) |
318 | 312 | ||
319 | thumbnailModel.videoPlaylistId = videoPlaylist.id | 313 | thumbnailModel.videoPlaylistId = videoPlaylist.id |
320 | 314 | ||
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' | |||
23 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | 23 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' |
24 | import { CONFIG } from '../../../initializers/config' | 24 | import { CONFIG } from '../../../initializers/config' |
25 | import { sequelizeTypescript } from '../../../initializers/database' | 25 | import { sequelizeTypescript } from '../../../initializers/database' |
26 | import { createVideoThumbnailFromExisting } from '../../../lib/thumbnail' | 26 | import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' |
27 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 27 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
28 | import { ThumbnailModel } from '../../../models/video/thumbnail' | 28 | import { ThumbnailModel } from '../../../models/video/thumbnail' |
29 | 29 | ||
@@ -204,7 +204,7 @@ async function processThumbnail (req: express.Request, video: VideoModel) { | |||
204 | if (thumbnailField) { | 204 | if (thumbnailField) { |
205 | const thumbnailPhysicalFile = thumbnailField[ 0 ] | 205 | const thumbnailPhysicalFile = thumbnailField[ 0 ] |
206 | 206 | ||
207 | return createVideoThumbnailFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.THUMBNAIL) | 207 | return createVideoMiniatureFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.MINIATURE) |
208 | } | 208 | } |
209 | 209 | ||
210 | return undefined | 210 | return undefined |
@@ -215,7 +215,7 @@ async function processPreview (req: express.Request, video: VideoModel) { | |||
215 | if (previewField) { | 215 | if (previewField) { |
216 | const previewPhysicalFile = previewField[0] | 216 | const previewPhysicalFile = previewField[0] |
217 | 217 | ||
218 | return createVideoThumbnailFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW) | 218 | return createVideoMiniatureFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW) |
219 | } | 219 | } |
220 | 220 | ||
221 | return undefined | 221 | return undefined |
@@ -238,14 +238,8 @@ function insertIntoDB (parameters: { | |||
238 | const videoCreated = await video.save(sequelizeOptions) | 238 | const videoCreated = await video.save(sequelizeOptions) |
239 | videoCreated.VideoChannel = videoChannel | 239 | videoCreated.VideoChannel = videoChannel |
240 | 240 | ||
241 | if (thumbnailModel) { | 241 | if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) |
242 | thumbnailModel.videoId = videoCreated.id | 242 | if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) |
243 | videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
244 | } | ||
245 | if (previewModel) { | ||
246 | previewModel.videoId = videoCreated.id | ||
247 | videoCreated.addThumbnail(await previewModel.save({ transaction: t })) | ||
248 | } | ||
249 | 243 | ||
250 | await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t) | 244 | await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t) |
251 | 245 | ||
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' | |||
52 | import { sendView } from '../../../lib/activitypub/send/send-view' | 52 | import { sendView } from '../../../lib/activitypub/send/send-view' |
53 | import { CONFIG } from '../../../initializers/config' | 53 | import { CONFIG } from '../../../initializers/config' |
54 | import { sequelizeTypescript } from '../../../initializers/database' | 54 | import { sequelizeTypescript } from '../../../initializers/database' |
55 | import { createVideoThumbnailFromExisting, generateVideoThumbnail } from '../../../lib/thumbnail' | 55 | import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail' |
56 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | 56 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' |
57 | 57 | ||
58 | const auditLogger = auditLoggerFactory('videos') | 58 | const auditLogger = auditLoggerFactory('videos') |
@@ -214,14 +214,14 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
214 | // Process thumbnail or create it from the video | 214 | // Process thumbnail or create it from the video |
215 | const thumbnailField = req.files['thumbnailfile'] | 215 | const thumbnailField = req.files['thumbnailfile'] |
216 | const thumbnailModel = thumbnailField | 216 | const thumbnailModel = thumbnailField |
217 | ? await createVideoThumbnailFromExisting(thumbnailField[0].path, video, ThumbnailType.THUMBNAIL) | 217 | ? await createVideoMiniatureFromExisting(thumbnailField[0].path, video, ThumbnailType.MINIATURE) |
218 | : await generateVideoThumbnail(video, videoFile, ThumbnailType.THUMBNAIL) | 218 | : await generateVideoMiniature(video, videoFile, ThumbnailType.MINIATURE) |
219 | 219 | ||
220 | // Process preview or create it from the video | 220 | // Process preview or create it from the video |
221 | const previewField = req.files['previewfile'] | 221 | const previewField = req.files['previewfile'] |
222 | const previewModel = previewField | 222 | const previewModel = previewField |
223 | ? await createVideoThumbnailFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW) | 223 | ? await createVideoMiniatureFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW) |
224 | : await generateVideoThumbnail(video, videoFile, ThumbnailType.PREVIEW) | 224 | : await generateVideoMiniature(video, videoFile, ThumbnailType.PREVIEW) |
225 | 225 | ||
226 | // Create the torrent file | 226 | // Create the torrent file |
227 | await video.createTorrentAndSetInfoHash(videoFile) | 227 | await video.createTorrentAndSetInfoHash(videoFile) |
@@ -231,11 +231,8 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
231 | 231 | ||
232 | const videoCreated = await video.save(sequelizeOptions) | 232 | const videoCreated = await video.save(sequelizeOptions) |
233 | 233 | ||
234 | thumbnailModel.videoId = videoCreated.id | 234 | await videoCreated.addAndSaveThumbnail(thumbnailModel, t) |
235 | previewModel.videoId = videoCreated.id | 235 | await videoCreated.addAndSaveThumbnail(previewModel, t) |
236 | |||
237 | videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
238 | videoCreated.addThumbnail(await previewModel.save({ transaction: t })) | ||
239 | 236 | ||
240 | // Do not forget to add video channel information to the created video | 237 | // Do not forget to add video channel information to the created video |
241 | videoCreated.VideoChannel = res.locals.videoChannel | 238 | videoCreated.VideoChannel = res.locals.videoChannel |
@@ -308,11 +305,11 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
308 | 305 | ||
309 | // Process thumbnail or create it from the video | 306 | // Process thumbnail or create it from the video |
310 | const thumbnailModel = req.files && req.files['thumbnailfile'] | 307 | const thumbnailModel = req.files && req.files['thumbnailfile'] |
311 | ? await createVideoThumbnailFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.THUMBNAIL) | 308 | ? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE) |
312 | : undefined | 309 | : undefined |
313 | 310 | ||
314 | const previewModel = req.files && req.files['previewfile'] | 311 | const previewModel = req.files && req.files['previewfile'] |
315 | ? await createVideoThumbnailFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW) | 312 | ? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW) |
316 | : undefined | 313 | : undefined |
317 | 314 | ||
318 | try { | 315 | try { |
@@ -346,14 +343,8 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
346 | 343 | ||
347 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) | 344 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) |
348 | 345 | ||
349 | if (thumbnailModel) { | 346 | if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t) |
350 | thumbnailModel.videoId = videoInstanceUpdated.id | 347 | if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t) |
351 | videoInstanceUpdated.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
352 | } | ||
353 | if (previewModel) { | ||
354 | previewModel.videoId = videoInstanceUpdated.id | ||
355 | videoInstanceUpdated.addThumbnail(await previewModel.save({ transaction: t })) | ||
356 | } | ||
357 | 348 | ||
358 | // Video tags update? | 349 | // Video tags update? |
359 | if (videoInfoToUpdate.tags !== undefined) { | 350 | 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 () { | |||
85 | // Sitemap description should be < 2000 characters | 85 | // Sitemap description should be < 2000 characters |
86 | description: truncate(v.description || v.name, { length: 2000, omission: '...' }), | 86 | description: truncate(v.description || v.name, { length: 2000, omission: '...' }), |
87 | player_loc: WEBSERVER.URL + '/videos/embed/' + v.uuid, | 87 | player_loc: WEBSERVER.URL + '/videos/embed/' + v.uuid, |
88 | thumbnail_loc: WEBSERVER.URL + v.getThumbnailStaticPath() | 88 | thumbnail_loc: WEBSERVER.URL + v.getMiniatureStaticPath() |
89 | } | 89 | } |
90 | ] | 90 | ] |
91 | })) | 91 | })) |
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) { | |||
137 | torrent: torrents, | 137 | torrent: torrents, |
138 | thumbnail: [ | 138 | thumbnail: [ |
139 | { | 139 | { |
140 | url: WEBSERVER.URL + video.getThumbnailStaticPath(), | 140 | url: WEBSERVER.URL + video.getMiniatureStaticPath(), |
141 | height: THUMBNAILS_SIZE.height, | 141 | height: THUMBNAILS_SIZE.height, |
142 | width: THUMBNAILS_SIZE.width | 142 | width: THUMBNAILS_SIZE.width |
143 | } | 143 | } |
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 { | |||
165 | // --------------------------------------------------------------------------- | 165 | // --------------------------------------------------------------------------- |
166 | 166 | ||
167 | async function getPreview (req: express.Request, res: express.Response) { | 167 | async function getPreview (req: express.Request, res: express.Response) { |
168 | const path = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) | 168 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) |
169 | if (!path) return res.sendStatus(404) | 169 | if (!result) return res.sendStatus(404) |
170 | 170 | ||
171 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) | 171 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) |
172 | } | 172 | } |
173 | 173 | ||
174 | async function getVideoCaption (req: express.Request, res: express.Response) { | 174 | async function getVideoCaption (req: express.Request, res: express.Response) { |
175 | const path = await VideosCaptionCache.Instance.getFilePath({ | 175 | const result = await VideosCaptionCache.Instance.getFilePath({ |
176 | videoId: req.params.videoId, | 176 | videoId: req.params.videoId, |
177 | language: req.params.captionLanguage | 177 | language: req.params.captionLanguage |
178 | }) | 178 | }) |
179 | if (!path) return res.sendStatus(404) | 179 | if (!result) return res.sendStatus(404) |
180 | 180 | ||
181 | return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) | 181 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) |
182 | } | 182 | } |
183 | 183 | ||
184 | async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) { | 184 | async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) { |