]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/files-cache/abstract-video-static-file-cache.ts
Fix crash in files cache
[github/Chocobozzz/PeerTube.git] / server / lib / files-cache / abstract-video-static-file-cache.ts
index 84ed74c988d33fd41927e154ca05674bf35b5eb0..c06355446c73fc73cb0da0952f97d9494e2da84c 100644 (file)
@@ -1,7 +1,5 @@
-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
@@ -20,8 +18,8 @@ export abstract class AbstractVideoStaticFileCache <T> {
       maxAge,
       max,
       promise: true,
-      dispose: (result: GetFilePathResult) => {
-        if (result.isOwned !== true) {
+      dispose: (result?: GetFilePathResult) => {
+        if (result && result.isOwned !== true) {
           remove(result.path)
             .then(() => logger.debug('%s removed from %s', result.path, this.constructor.name))
             .catch(err => logger.error('Cannot remove %s from cache %s.', result.path, this.constructor.name, { err }))
@@ -29,16 +27,4 @@ export abstract class AbstractVideoStaticFileCache <T> {
       }
     })
   }
-
-  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))
-    })
-  }
 }