import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
import { resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils'
import { logger } from '../../helpers/logger'
-import { doRequest } from '../../helpers/requests'
+import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
import {
ACTIVITY_PUB,
MIMETYPES,
return body.description ? body.description : ''
}
-function fetchRemoteVideoStaticFile (video: VideoModel, path: string, reject: Function) {
+function fetchRemoteVideoStaticFile (video: VideoModel, path: string, destPath: string) {
const url = buildRemoteBaseUrl(video, path)
// We need to provide a callback, if no we could have an uncaught exception
- return request.get(url, err => {
- if (err) reject(err)
- })
+ return doRequestAndSaveToFile({ uri: url }, destPath)
}
function buildRemoteBaseUrl (video: VideoModel, path: string) {
-import { createWriteStream, remove } from 'fs-extra'
+import { remove } from 'fs-extra'
import { logger } from '../../helpers/logger'
-import { VideoModel } from '../../models/video/video'
-import { fetchRemoteVideoStaticFile } from '../activitypub'
import * as memoizee from 'memoizee'
type GetFilePathResult = { isOwned: boolean, path: string } | undefined
}
})
}
-
- protected saveRemoteVideoFileAndReturnPath (video: VideoModel, remoteStaticPath: string, destPath: string) {
- return new Promise<string>((res, rej) => {
- const req = fetchRemoteVideoStaticFile(video, remoteStaticPath, rej)
-
- const stream = createWriteStream(destPath)
-
- req.pipe(stream)
- .on('error', (err) => rej(err))
- .on('finish', () => res(destPath))
- })
- }
}
import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
import { CONFIG } from '../../initializers/config'
import { logger } from '../../helpers/logger'
+import { fetchRemoteVideoStaticFile } from '../activitypub'
type GetPathParam = { videoId: string, language: string }
const remoteStaticPath = videoCaption.getCaptionStaticPath()
const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName())
- const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
+ await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath)
- return { isOwned: false, path }
+ return { isOwned: false, path: destPath }
}
}
import { VideoModel } from '../../models/video/video'
import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
import { CONFIG } from '../../initializers/config'
+import { fetchRemoteVideoStaticFile } from '../activitypub'
class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreview().filename)
const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreview().filename)
- const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
+ await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath)
- return { isOwned: false, path }
+ return { isOwned: false, path: destPath }
}
}