]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/video-playlist.ts
Remove traefik docker support
[github/Chocobozzz/PeerTube.git] / server / controllers / api / video-playlist.ts
index 375d711fdcde9f1e04998a7a2cba547ead17437e..f3dc8b2a98d3ebb03a6ca785da0a8c8964dd3076 100644 (file)
@@ -1,5 +1,24 @@
 import * as express from 'express'
+import { join } from 'path'
+import { getServerActor } from '@server/models/application/application'
+import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models'
+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'
+import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
+import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
+import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
+import { resetSequelizeInstance } from '../../helpers/database-utils'
+import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils'
+import { logger } from '../../helpers/logger'
 import { getFormattedObjects } from '../../helpers/utils'
+import { CONFIG } from '../../initializers/config'
+import { MIMETYPES, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers/constants'
+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 {
   asyncMiddleware,
   asyncRetryTransactionMiddleware,
@@ -10,11 +29,6 @@ import {
   setDefaultSort
 } from '../../middlewares'
 import { videoPlaylistsSortValidator } from '../../middlewares/validators'
-import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils'
-import { MIMETYPES, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers/constants'
-import { logger } from '../../helpers/logger'
-import { resetSequelizeInstance } from '../../helpers/database-utils'
-import { VideoPlaylistModel } from '../../models/video/video-playlist'
 import {
   commonVideoPlaylistFiltersValidator,
   videoPlaylistsAddValidator,
@@ -25,23 +39,10 @@ import {
   videoPlaylistsUpdateOrRemoveVideoValidator,
   videoPlaylistsUpdateValidator
 } from '../../middlewares/validators/videos/video-playlists'
-import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/video-playlist-create.model'
-import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { join } from 'path'
-import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'
-import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'
-import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
-import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
-import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model'
-import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model'
 import { AccountModel } from '../../models/account/account'
-import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
-import { JobQueue } from '../../lib/job-queue'
-import { CONFIG } from '../../initializers/config'
-import { sequelizeTypescript } from '../../initializers/database'
-import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail'
-import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/typings/models'
-import { getServerActor } from '@server/models/application/application'
+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 })
 
@@ -161,7 +162,7 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
     ownerAccountId: user.Account.id
   }) as MVideoPlaylistFull
 
-  videoPlaylist.url = getVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object
+  videoPlaylist.url = getLocalVideoPlaylistActivityPubUrl(videoPlaylist) // We use the UUID, so set the URL after building the object
 
   if (videoPlaylistInfo.videoChannelId) {
     const videoChannel = res.locals.videoChannel
@@ -271,7 +272,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
     throw err
   }
 
-  return res.type('json').status(204).end()
+  return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function removeVideoPlaylist (req: express.Request, res: express.Response) {
@@ -285,7 +286,7 @@ async function removeVideoPlaylist (req: express.Request, res: express.Response)
     logger.info('Video playlist %s deleted.', videoPlaylistInstance.uuid)
   })
 
-  return res.type('json').status(204).end()
+  return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function addVideoInPlaylist (req: express.Request, res: express.Response) {
@@ -297,7 +298,6 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
     const position = await VideoPlaylistElementModel.getNextPositionOf(videoPlaylist.id, t)
 
     const playlistElement = await VideoPlaylistElementModel.create({
-      url: getVideoPlaylistElementActivityPubUrl(videoPlaylist, video),
       position,
       startTimestamp: body.startTimestamp || null,
       stopTimestamp: body.stopTimestamp || null,
@@ -305,6 +305,9 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
       videoId: video.id
     }, { transaction: t })
 
+    playlistElement.url = getLocalVideoPlaylistElementActivityPubUrl(videoPlaylist, playlistElement)
+    await playlistElement.save({ transaction: t })
+
     videoPlaylist.changed('updatedAt', true)
     await videoPlaylist.save({ transaction: t })
 
@@ -349,7 +352,7 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
 
   logger.info('Element of position %d of playlist %s updated.', playlistElement.position, videoPlaylist.uuid)
 
-  return res.type('json').status(204).end()
+  return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function removeVideoFromPlaylist (req: express.Request, res: express.Response) {
@@ -377,7 +380,7 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
   sendUpdateVideoPlaylist(videoPlaylist, undefined)
     .catch(err => logger.error('Cannot send video playlist update.', { err }))
 
-  return res.type('json').status(204).end()
+  return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function reorderVideosPlaylist (req: express.Request, res: express.Response) {
@@ -389,7 +392,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
   const reorderLength: number = body.reorderLength || 1
 
   if (start === insertAfter) {
-    return res.status(204).end()
+    return res.status(HttpStatusCode.NO_CONTENT_204).end()
   }
 
   // Example: if we reorder position 2 and insert after position 5 (so at position 6): # 1 2 3 4 5 6 7 8 9
@@ -430,7 +433,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
     videoPlaylist.uuid, insertAfter, start, start + reorderLength - 1
   )
 
-  return res.type('json').status(204).end()
+  return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function getVideoPlaylistVideos (req: express.Request, res: express.Response) {