aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r--server/helpers/custom-validators/videos.ts24
1 files changed, 23 insertions, 1 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 205d8c62f..276354626 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -130,6 +130,27 @@ function checkVideoExists (id: string, res: Response, callback: () => void) {
130 }) 130 })
131} 131}
132 132
133async function isVideoExistsPromise (id: string, res: Response) {
134 let video: VideoInstance
135
136 if (validator.isInt(id)) {
137 video = await db.Video.loadAndPopulateAccountAndServerAndTags(+id)
138 } else { // UUID
139 video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(id)
140 }
141
142 if (!video) {
143 res.status(404)
144 .json({ error: 'Video not found' })
145 .end()
146
147 return false
148 }
149
150 res.locals.video = video
151 return true
152}
153
133// --------------------------------------------------------------------------- 154// ---------------------------------------------------------------------------
134 155
135export { 156export {
@@ -152,5 +173,6 @@ export {
152 isVideoPrivacyValid, 173 isVideoPrivacyValid,
153 isVideoFileResolutionValid, 174 isVideoFileResolutionValid,
154 isVideoFileSizeValid, 175 isVideoFileSizeValid,
155 checkVideoExists 176 checkVideoExists,
177 isVideoExistsPromise
156} 178}