From 6040f87d143a5fa01db79867ece8197c3ce7be47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Dec 2018 16:02:49 +0100 Subject: Add tmp and redundancy directories --- server/helpers/requests.ts | 9 +++++---- server/helpers/utils.ts | 6 +++--- server/helpers/webtorrent.ts | 6 +++--- server/helpers/youtube-dl.ts | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 5760ad1c1..3fc776f1a 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -1,9 +1,9 @@ import * as Bluebird from 'bluebird' import { createWriteStream } from 'fs-extra' import * as request from 'request' -import { ACTIVITY_PUB } from '../initializers' +import { ACTIVITY_PUB, CONFIG } from '../initializers' import { processImage } from './image-utils' -import { extname } from 'path' +import { join } from 'path' function doRequest ( requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } @@ -29,10 +29,11 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U }) } -async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) { - const tmpPath = destPath + '.tmp' + extname(destPath) +async function downloadImage (url: string, destDir: string, destName: string, size: { width: number, height: number }) { + const tmpPath = join(CONFIG.STORAGE.TMP_DIR, 'pending-' + destName) await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath) + const destPath = join(destDir, destName) await processImage({ path: tmpPath }, destPath, size) } diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 5c9d6fe2f..9b89e3e61 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -46,11 +46,11 @@ const getServerActor = memoizee(async function () { return actor }) -function generateVideoTmpPath (target: string | ParseTorrent) { +function generateVideoImportTmpPath (target: string | ParseTorrent) { const id = typeof target === 'string' ? target : target.infoHash const hash = sha256(id) - return join(CONFIG.STORAGE.VIDEOS_DIR, hash + '-import.mp4') + return join(CONFIG.STORAGE.TMP_DIR, hash + '-import.mp4') } function getSecureTorrentName (originalName: string) { @@ -103,6 +103,6 @@ export { getSecureTorrentName, getServerActor, getServerCommit, - generateVideoTmpPath, + generateVideoImportTmpPath, getUUIDFromFilename } diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index ce35b87da..3c9a0b96a 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts @@ -1,5 +1,5 @@ import { logger } from './logger' -import { generateVideoTmpPath } from './utils' +import { generateVideoImportTmpPath } from './utils' import * as WebTorrent from 'webtorrent' import { createWriteStream, ensureDir, remove } from 'fs-extra' import { CONFIG } from '../initializers' @@ -9,10 +9,10 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName const id = target.magnetUri || target.torrentName let timer - const path = generateVideoTmpPath(id) + const path = generateVideoImportTmpPath(id) logger.info('Importing torrent video %s', id) - const directoryPath = join(CONFIG.STORAGE.VIDEOS_DIR, 'import') + const directoryPath = join(CONFIG.STORAGE.TMP_DIR, 'webtorrent') await ensureDir(directoryPath) return new Promise((res, rej) => { diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index 2a5663042..b74351b42 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts @@ -1,7 +1,7 @@ import { truncate } from 'lodash' import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers' import { logger } from './logger' -import { generateVideoTmpPath } from './utils' +import { generateVideoImportTmpPath } from './utils' import { join } from 'path' import { root } from './core-utils' import { ensureDir, writeFile, remove } from 'fs-extra' @@ -40,7 +40,7 @@ function getYoutubeDLInfo (url: string, opts?: string[]): Promise } function downloadYoutubeDLVideo (url: string, timeout: number) { - const path = generateVideoTmpPath(url) + const path = generateVideoImportTmpPath(url) let timer logger.info('Importing youtubeDL video %s', url) -- cgit v1.2.3