aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-03 15:17:11 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit6a4905602636afd6650c9e6f4d0fcc2105d91100 (patch)
tree1a6ffa4239f62bffa2e6e328ea61a52a65d58d35 /server/controllers/api/videos
parent3a0c2a77b1a6626699514ddaf8135f4397175443 (diff)
downloadPeerTube-6a4905602636afd6650c9e6f4d0fcc2105d91100.tar.gz
PeerTube-6a4905602636afd6650c9e6f4d0fcc2105d91100.tar.zst
PeerTube-6a4905602636afd6650c9e6f4d0fcc2105d91100.zip
Add TMP persistent directory
To store files that must be preserved between peertube restarts
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/studio.ts40
1 files changed, 30 insertions, 10 deletions
diff --git a/server/controllers/api/videos/studio.ts b/server/controllers/api/videos/studio.ts
index 6667532bf..2ccb2fb89 100644
--- a/server/controllers/api/videos/studio.ts
+++ b/server/controllers/api/videos/studio.ts
@@ -1,8 +1,12 @@
1import Bluebird from 'bluebird'
1import express from 'express' 2import express from 'express'
3import { move } from 'fs-extra'
4import { basename, join } from 'path'
2import { createAnyReqFiles } from '@server/helpers/express-utils' 5import { createAnyReqFiles } from '@server/helpers/express-utils'
6import { CONFIG } from '@server/initializers/config'
3import { MIMETYPES } from '@server/initializers/constants' 7import { MIMETYPES } from '@server/initializers/constants'
4import { JobQueue } from '@server/lib/job-queue' 8import { JobQueue } from '@server/lib/job-queue'
5import { buildTaskFileFieldname, getTaskFile } from '@server/lib/video-studio' 9import { buildTaskFileFieldname, getTaskFileFromReq } from '@server/lib/video-studio'
6import { 10import {
7 HttpStatusCode, 11 HttpStatusCode,
8 VideoState, 12 VideoState,
@@ -68,7 +72,7 @@ async function createEditionTasks (req: express.Request, res: express.Response)
68 72
69 const payload = { 73 const payload = {
70 videoUUID: video.uuid, 74 videoUUID: video.uuid,
71 tasks: body.tasks.map((t, i) => buildTaskPayload(t, i, files)) 75 tasks: await Bluebird.mapSeries(body.tasks, (t, i) => buildTaskPayload(t, i, files))
72 } 76 }
73 77
74 JobQueue.Instance.createJobAsync({ type: 'video-studio-edition', payload }) 78 JobQueue.Instance.createJobAsync({ type: 'video-studio-edition', payload })
@@ -77,7 +81,11 @@ async function createEditionTasks (req: express.Request, res: express.Response)
77} 81}
78 82
79const taskPayloadBuilders: { 83const taskPayloadBuilders: {
80 [id in VideoStudioTask['name']]: (task: VideoStudioTask, indice?: number, files?: Express.Multer.File[]) => VideoStudioTaskPayload 84 [id in VideoStudioTask['name']]: (
85 task: VideoStudioTask,
86 indice?: number,
87 files?: Express.Multer.File[]
88 ) => Promise<VideoStudioTaskPayload>
81} = { 89} = {
82 'add-intro': buildIntroOutroTask, 90 'add-intro': buildIntroOutroTask,
83 'add-outro': buildIntroOutroTask, 91 'add-outro': buildIntroOutroTask,
@@ -85,34 +93,46 @@ const taskPayloadBuilders: {
85 'add-watermark': buildWatermarkTask 93 'add-watermark': buildWatermarkTask
86} 94}
87 95
88function buildTaskPayload (task: VideoStudioTask, indice: number, files: Express.Multer.File[]): VideoStudioTaskPayload { 96function buildTaskPayload (task: VideoStudioTask, indice: number, files: Express.Multer.File[]): Promise<VideoStudioTaskPayload> {
89 return taskPayloadBuilders[task.name](task, indice, files) 97 return taskPayloadBuilders[task.name](task, indice, files)
90} 98}
91 99
92function buildIntroOutroTask (task: VideoStudioTaskIntro | VideoStudioTaskOutro, indice: number, files: Express.Multer.File[]) { 100async function buildIntroOutroTask (task: VideoStudioTaskIntro | VideoStudioTaskOutro, indice: number, files: Express.Multer.File[]) {
101 const destination = await moveStudioFileToPersistentTMP(getTaskFileFromReq(files, indice).path)
102
93 return { 103 return {
94 name: task.name, 104 name: task.name,
95 options: { 105 options: {
96 file: getTaskFile(files, indice).path 106 file: destination
97 } 107 }
98 } 108 }
99} 109}
100 110
101function buildCutTask (task: VideoStudioTaskCut) { 111function buildCutTask (task: VideoStudioTaskCut) {
102 return { 112 return Promise.resolve({
103 name: task.name, 113 name: task.name,
104 options: { 114 options: {
105 start: task.options.start, 115 start: task.options.start,
106 end: task.options.end 116 end: task.options.end
107 } 117 }
108 } 118 })
109} 119}
110 120
111function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: number, files: Express.Multer.File[]) { 121async function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: number, files: Express.Multer.File[]) {
122 const destination = await moveStudioFileToPersistentTMP(getTaskFileFromReq(files, indice).path)
123
112 return { 124 return {
113 name: task.name, 125 name: task.name,
114 options: { 126 options: {
115 file: getTaskFile(files, indice).path 127 file: destination
116 } 128 }
117 } 129 }
118} 130}
131
132async function moveStudioFileToPersistentTMP (file: string) {
133 const destination = join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, basename(file))
134
135 await move(file, destination)
136
137 return destination
138}