diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-27 16:23:34 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 16:23:34 +0200 |
commit | 62689b942b71cd1dd0d050c6ed05f884a0b325c2 (patch) | |
tree | c45c35d35d7a3e32621fba06edc63646930c8efd /server/controllers/api | |
parent | 84b6dbcc6e8654f39ec798905e1151ba915cd1aa (diff) | |
download | PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.gz PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.zst PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.zip |
Correctly migrate to fs-extra
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/config.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index e0539c414..b25f739bb 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -3,13 +3,13 @@ import { omit } from 'lodash' | |||
3 | import { ServerConfig, UserRight } from '../../../shared' | 3 | import { ServerConfig, UserRight } from '../../../shared' |
4 | import { About } from '../../../shared/models/server/about.model' | 4 | import { About } from '../../../shared/models/server/about.model' |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' | ||
7 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' | 6 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' |
8 | import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' | 7 | import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' |
9 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | 8 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
10 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | 9 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' |
11 | import { ClientHtml } from '../../lib/client-html' | 10 | import { ClientHtml } from '../../lib/client-html' |
12 | import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger' | 11 | import { auditLoggerFactory, CustomConfigAuditView } from '../../helpers/audit-logger' |
12 | import { remove, writeJSON } from 'fs-extra' | ||
13 | 13 | ||
14 | const packageJSON = require('../../../../package.json') | 14 | const packageJSON = require('../../../../package.json') |
15 | const configRouter = express.Router() | 15 | const configRouter = express.Router() |
@@ -130,7 +130,7 @@ async function getCustomConfig (req: express.Request, res: express.Response, nex | |||
130 | } | 130 | } |
131 | 131 | ||
132 | async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 132 | async function deleteCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { |
133 | await unlinkPromise(CONFIG.CUSTOM_FILE) | 133 | await remove(CONFIG.CUSTOM_FILE) |
134 | 134 | ||
135 | auditLogger.delete( | 135 | auditLogger.delete( |
136 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), | 136 | res.locals.oauth.token.User.Account.Actor.getIdentifier(), |
@@ -163,7 +163,7 @@ async function updateCustomConfig (req: express.Request, res: express.Response, | |||
163 | toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription | 163 | toUpdateJSON.instance['short_description'] = toUpdate.instance.shortDescription |
164 | toUpdateJSON.instance['default_nsfw_policy'] = toUpdate.instance.defaultNSFWPolicy | 164 | toUpdateJSON.instance['default_nsfw_policy'] = toUpdate.instance.defaultNSFWPolicy |
165 | 165 | ||
166 | await writeFilePromise(CONFIG.CUSTOM_FILE, JSON.stringify(toUpdateJSON, undefined, 2)) | 166 | await writeJSON(CONFIG.CUSTOM_FILE, toUpdateJSON, { spaces: 2 }) |
167 | 167 | ||
168 | reloadConfig() | 168 | reloadConfig() |
169 | ClientHtml.invalidCache() | 169 | ClientHtml.invalidCache() |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index b2f73fa48..44f15ef74 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -27,8 +27,8 @@ import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' | |||
27 | import { VideoChannelModel } from '../../../models/video/video-channel' | 27 | import { VideoChannelModel } from '../../../models/video/video-channel' |
28 | import * as Bluebird from 'bluebird' | 28 | import * as Bluebird from 'bluebird' |
29 | import * as parseTorrent from 'parse-torrent' | 29 | import * as parseTorrent from 'parse-torrent' |
30 | import { readFileBufferPromise, renamePromise } from '../../../helpers/core-utils' | ||
31 | import { getSecureTorrentName } from '../../../helpers/utils' | 30 | import { getSecureTorrentName } from '../../../helpers/utils' |
31 | import { readFile, rename } from 'fs-extra' | ||
32 | 32 | ||
33 | const auditLogger = auditLoggerFactory('video-imports') | 33 | const auditLogger = auditLoggerFactory('video-imports') |
34 | const videoImportsRouter = express.Router() | 34 | const videoImportsRouter = express.Router() |
@@ -78,10 +78,10 @@ async function addTorrentImport (req: express.Request, res: express.Response, to | |||
78 | 78 | ||
79 | // Rename the torrent to a secured name | 79 | // Rename the torrent to a secured name |
80 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName)) | 80 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName)) |
81 | await renamePromise(torrentfile.path, newTorrentPath) | 81 | await rename(torrentfile.path, newTorrentPath) |
82 | torrentfile.path = newTorrentPath | 82 | torrentfile.path = newTorrentPath |
83 | 83 | ||
84 | const buf = await readFileBufferPromise(torrentfile.path) | 84 | const buf = await readFile(torrentfile.path) |
85 | const parsedTorrent = parseTorrent(buf) | 85 | const parsedTorrent = parseTorrent(buf) |
86 | 86 | ||
87 | videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[ 0 ] : parsedTorrent.name as string | 87 | videoName = isArray(parsedTorrent.name) ? parsedTorrent.name[ 0 ] : parsedTorrent.name as string |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index e973aa43f..a86cf4f99 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { extname, join } from 'path' | 2 | import { extname, join } from 'path' |
3 | import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' | 3 | import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' |
4 | import { renamePromise } from '../../../helpers/core-utils' | ||
5 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 4 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
6 | import { processImage } from '../../../helpers/image-utils' | 5 | import { processImage } from '../../../helpers/image-utils' |
7 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
@@ -56,6 +55,7 @@ import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-u | |||
56 | import { videoCaptionsRouter } from './captions' | 55 | import { videoCaptionsRouter } from './captions' |
57 | import { videoImportsRouter } from './import' | 56 | import { videoImportsRouter } from './import' |
58 | import { resetSequelizeInstance } from '../../../helpers/database-utils' | 57 | import { resetSequelizeInstance } from '../../../helpers/database-utils' |
58 | import { rename } from 'fs-extra' | ||
59 | 59 | ||
60 | const auditLogger = auditLoggerFactory('videos') | 60 | const auditLogger = auditLoggerFactory('videos') |
61 | const videosRouter = express.Router() | 61 | const videosRouter = express.Router() |
@@ -194,7 +194,7 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
194 | // Move physical file | 194 | // Move physical file |
195 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR | 195 | const videoDir = CONFIG.STORAGE.VIDEOS_DIR |
196 | const destination = join(videoDir, video.getVideoFilename(videoFile)) | 196 | const destination = join(videoDir, video.getVideoFilename(videoFile)) |
197 | await renamePromise(videoPhysicalFile.path, destination) | 197 | await rename(videoPhysicalFile.path, destination) |
198 | // This is important in case if there is another attempt in the retry process | 198 | // This is important in case if there is another attempt in the retry process |
199 | videoPhysicalFile.filename = video.getVideoFilename(videoFile) | 199 | videoPhysicalFile.filename = video.getVideoFilename(videoFile) |
200 | videoPhysicalFile.path = destination | 200 | videoPhysicalFile.path = destination |