]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/videos/index.ts
Move activitypub functions from helpers/ to lib/
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / index.ts
index 22a88620a8ac12fa75cb8d14ac8fefa07c8b7306..0d114dcd2d37fcb983299faff9824ad96675fdfe 100644 (file)
@@ -3,7 +3,6 @@ import * as multer from 'multer'
 import { extname, join } from 'path'
 import { VideoCreate, VideoPrivacy, VideoUpdate } from '../../../../shared'
 import {
-  fetchRemoteVideoDescription,
   generateRandomString,
   getFormattedObjects,
   getVideoFileHeight,
@@ -12,10 +11,10 @@ import {
   resetSequelizeInstance,
   retryTransactionWrapper
 } from '../../../helpers'
-import { getActivityPubUrl, shareVideoByServer } from '../../../helpers/activitypub'
 import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers'
 import { database as db } from '../../../initializers/database'
-import { sendAddVideo, sendUpdateVideo } from '../../../lib/activitypub/send-request'
+import { sendAddVideo } from '../../../lib/activitypub/send/send-add'
+import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update'
 import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler'
 import {
   asyncMiddleware,
@@ -36,6 +35,9 @@ import { abuseVideoRouter } from './abuse'
 import { blacklistRouter } from './blacklist'
 import { videoChannelRouter } from './channel'
 import { rateVideoRouter } from './rate'
+import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
+import { shareVideoByServer } from '../../../lib/activitypub/share'
+import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
 
 const videosRouter = express.Router()
 
@@ -175,7 +177,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
       channelId: res.locals.videoChannel.id
     }
     const video = db.Video.build(videoData)
-    video.url = getActivityPubUrl('video', video.uuid)
+    video.url = getVideoActivityPubUrl(video)
 
     const videoFilePath = join(CONFIG.STORAGE.VIDEOS_DIR, videoPhysicalFile.filename)
     const videoFileHeight = await getVideoFileHeight(videoFilePath)
@@ -274,7 +276,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
       if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', videoInfoToUpdate.privacy)
       if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
 
-      await videoInstance.save(sequelizeOptions)
+      const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
 
       if (videoInfoToUpdate.tags) {
         const tagInstances = await db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t)
@@ -285,7 +287,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
 
       // Now we'll update the video's meta data to our friends
       if (wasPrivateVideo === false) {
-        await sendUpdateVideo(videoInstance, t)
+        await sendUpdateVideo(videoInstanceUpdated, t)
       }
 
       // Video is not private anymore, send a create action to remote servers