aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/files-cache
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/files-cache')
-rw-r--r--server/lib/files-cache/abstract-video-static-file-cache.ts16
-rw-r--r--server/lib/files-cache/videos-caption-cache.ts5
-rw-r--r--server/lib/files-cache/videos-preview-cache.ts5
3 files changed, 7 insertions, 19 deletions
diff --git a/server/lib/files-cache/abstract-video-static-file-cache.ts b/server/lib/files-cache/abstract-video-static-file-cache.ts
index 84ed74c98..1908cfb06 100644
--- a/server/lib/files-cache/abstract-video-static-file-cache.ts
+++ b/server/lib/files-cache/abstract-video-static-file-cache.ts
@@ -1,7 +1,5 @@
1import { createWriteStream, remove } from 'fs-extra' 1import { remove } from 'fs-extra'
2import { logger } from '../../helpers/logger' 2import { logger } from '../../helpers/logger'
3import { VideoModel } from '../../models/video/video'
4import { fetchRemoteVideoStaticFile } from '../activitypub'
5import * as memoizee from 'memoizee' 3import * as memoizee from 'memoizee'
6 4
7type GetFilePathResult = { isOwned: boolean, path: string } | undefined 5type GetFilePathResult = { isOwned: boolean, path: string } | undefined
@@ -29,16 +27,4 @@ export abstract class AbstractVideoStaticFileCache <T> {
29 } 27 }
30 }) 28 })
31 } 29 }
32
33 protected saveRemoteVideoFileAndReturnPath (video: VideoModel, remoteStaticPath: string, destPath: string) {
34 return new Promise<string>((res, rej) => {
35 const req = fetchRemoteVideoStaticFile(video, remoteStaticPath, rej)
36
37 const stream = createWriteStream(destPath)
38
39 req.pipe(stream)
40 .on('error', (err) => rej(err))
41 .on('finish', () => res(destPath))
42 })
43 }
44} 30}
diff --git a/server/lib/files-cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts
index 305e39c35..440c3fde8 100644
--- a/server/lib/files-cache/videos-caption-cache.ts
+++ b/server/lib/files-cache/videos-caption-cache.ts
@@ -5,6 +5,7 @@ import { VideoCaptionModel } from '../../models/video/video-caption'
5import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 5import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
6import { CONFIG } from '../../initializers/config' 6import { CONFIG } from '../../initializers/config'
7import { logger } from '../../helpers/logger' 7import { logger } from '../../helpers/logger'
8import { fetchRemoteVideoStaticFile } from '../activitypub'
8 9
9type GetPathParam = { videoId: string, language: string } 10type GetPathParam = { videoId: string, language: string }
10 11
@@ -49,9 +50,9 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache <GetPathParam> {
49 const remoteStaticPath = videoCaption.getCaptionStaticPath() 50 const remoteStaticPath = videoCaption.getCaptionStaticPath()
50 const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) 51 const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName())
51 52
52 const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) 53 await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath)
53 54
54 return { isOwned: false, path } 55 return { isOwned: false, path: destPath }
55 } 56 }
56} 57}
57 58
diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts
index c117ae426..14be7f24a 100644
--- a/server/lib/files-cache/videos-preview-cache.ts
+++ b/server/lib/files-cache/videos-preview-cache.ts
@@ -3,6 +3,7 @@ import { FILES_CACHE, STATIC_PATHS } from '../../initializers/constants'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
5import { CONFIG } from '../../initializers/config' 5import { CONFIG } from '../../initializers/config'
6import { fetchRemoteVideoStaticFile } from '../activitypub'
6 7
7class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { 8class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
8 9
@@ -35,9 +36,9 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
35 const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreview().filename) 36 const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreview().filename)
36 const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreview().filename) 37 const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreview().filename)
37 38
38 const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) 39 await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath)
39 40
40 return { isOwned: false, path } 41 return { isOwned: false, path: destPath }
41 } 42 }
42} 43}
43 44