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/models | |
parent | 84b6dbcc6e8654f39ec798905e1151ba915cd1aa (diff) | |
download | PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.gz PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.tar.zst PeerTube-62689b942b71cd1dd0d050c6ed05f884a0b325c2.zip |
Correctly migrate to fs-extra
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/avatar/avatar.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-caption.ts | 4 | ||||
-rw-r--r-- | server/models/video/video.ts | 33 |
3 files changed, 17 insertions, 24 deletions
diff --git a/server/models/avatar/avatar.ts b/server/models/avatar/avatar.ts index 51e26c87b..5d73e24fa 100644 --- a/server/models/avatar/avatar.ts +++ b/server/models/avatar/avatar.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { join } from 'path' | 1 | import { join } from 'path' |
2 | import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | 3 | import { Avatar } from '../../../shared/models/avatars/avatar.model' |
4 | import { unlinkPromise } from '../../helpers/core-utils' | ||
5 | import { CONFIG, STATIC_PATHS } from '../../initializers' | 4 | import { CONFIG, STATIC_PATHS } from '../../initializers' |
6 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { remove } from 'fs-extra' | ||
7 | 7 | ||
8 | @Table({ | 8 | @Table({ |
9 | tableName: 'avatar' | 9 | tableName: 'avatar' |
@@ -40,6 +40,6 @@ export class AvatarModel extends Model<AvatarModel> { | |||
40 | 40 | ||
41 | removeAvatar () { | 41 | removeAvatar () { |
42 | const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename) | 42 | const avatarPath = join(CONFIG.STORAGE.AVATARS_DIR, this.filename) |
43 | return unlinkPromise(avatarPath) | 43 | return remove(avatarPath) |
44 | } | 44 | } |
45 | } | 45 | } |
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index 3593646a2..10ef46c14 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts | |||
@@ -19,7 +19,7 @@ import { VideoCaption } from '../../../shared/models/videos/caption/video-captio | |||
19 | import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' | 19 | import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' |
20 | import { join } from 'path' | 20 | import { join } from 'path' |
21 | import { logger } from '../../helpers/logger' | 21 | import { logger } from '../../helpers/logger' |
22 | import { unlinkPromise } from '../../helpers/core-utils' | 22 | import { remove } from 'fs-extra' |
23 | 23 | ||
24 | export enum ScopeNames { | 24 | export enum ScopeNames { |
25 | WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' | 25 | WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' |
@@ -172,6 +172,6 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> { | |||
172 | } | 172 | } |
173 | 173 | ||
174 | removeCaptionFile () { | 174 | removeCaptionFile () { |
175 | return unlinkPromise(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) | 175 | return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) |
176 | } | 176 | } |
177 | } | 177 | } |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a956da16e..6271db1b3 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -30,15 +30,7 @@ import { VideoPrivacy, VideoResolution, VideoState } from '../../../shared' | |||
30 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 30 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
31 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' | 31 | import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' |
32 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 32 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
33 | import { | 33 | import { createTorrentPromise, peertubeTruncate } from '../../helpers/core-utils' |
34 | copyFilePromise, | ||
35 | createTorrentPromise, | ||
36 | peertubeTruncate, | ||
37 | renamePromise, | ||
38 | statPromise, | ||
39 | unlinkPromise, | ||
40 | writeFilePromise | ||
41 | } from '../../helpers/core-utils' | ||
42 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 34 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
43 | import { isBooleanValid } from '../../helpers/custom-validators/misc' | 35 | import { isBooleanValid } from '../../helpers/custom-validators/misc' |
44 | import { | 36 | import { |
@@ -95,6 +87,7 @@ import { VideoTagModel } from './video-tag' | |||
95 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | 87 | import { ScheduleVideoUpdateModel } from './schedule-video-update' |
96 | import { VideoCaptionModel } from './video-caption' | 88 | import { VideoCaptionModel } from './video-caption' |
97 | import { VideoBlacklistModel } from './video-blacklist' | 89 | import { VideoBlacklistModel } from './video-blacklist' |
90 | import { copy, remove, rename, stat, writeFile } from 'fs-extra' | ||
98 | 91 | ||
99 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation | 92 | // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation |
100 | const indexes: Sequelize.DefineIndexesOptions[] = [ | 93 | const indexes: Sequelize.DefineIndexesOptions[] = [ |
@@ -1187,7 +1180,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1187 | const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 1180 | const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
1188 | logger.info('Creating torrent %s.', filePath) | 1181 | logger.info('Creating torrent %s.', filePath) |
1189 | 1182 | ||
1190 | await writeFilePromise(filePath, torrent) | 1183 | await writeFile(filePath, torrent) |
1191 | 1184 | ||
1192 | const parsedTorrent = parseTorrent(torrent) | 1185 | const parsedTorrent = parseTorrent(torrent) |
1193 | videoFile.infoHash = parsedTorrent.infoHash | 1186 | videoFile.infoHash = parsedTorrent.infoHash |
@@ -1497,14 +1490,14 @@ export class VideoModel extends Model<VideoModel> { | |||
1497 | await transcode(transcodeOptions) | 1490 | await transcode(transcodeOptions) |
1498 | 1491 | ||
1499 | try { | 1492 | try { |
1500 | await unlinkPromise(videoInputPath) | 1493 | await remove(videoInputPath) |
1501 | 1494 | ||
1502 | // Important to do this before getVideoFilename() to take in account the new file extension | 1495 | // Important to do this before getVideoFilename() to take in account the new file extension |
1503 | inputVideoFile.set('extname', newExtname) | 1496 | inputVideoFile.set('extname', newExtname) |
1504 | 1497 | ||
1505 | const videoOutputPath = this.getVideoFilePath(inputVideoFile) | 1498 | const videoOutputPath = this.getVideoFilePath(inputVideoFile) |
1506 | await renamePromise(videoTranscodedPath, videoOutputPath) | 1499 | await rename(videoTranscodedPath, videoOutputPath) |
1507 | const stats = await statPromise(videoOutputPath) | 1500 | const stats = await stat(videoOutputPath) |
1508 | const fps = await getVideoFileFPS(videoOutputPath) | 1501 | const fps = await getVideoFileFPS(videoOutputPath) |
1509 | 1502 | ||
1510 | inputVideoFile.set('size', stats.size) | 1503 | inputVideoFile.set('size', stats.size) |
@@ -1545,7 +1538,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1545 | 1538 | ||
1546 | await transcode(transcodeOptions) | 1539 | await transcode(transcodeOptions) |
1547 | 1540 | ||
1548 | const stats = await statPromise(videoOutputPath) | 1541 | const stats = await stat(videoOutputPath) |
1549 | const fps = await getVideoFileFPS(videoOutputPath) | 1542 | const fps = await getVideoFileFPS(videoOutputPath) |
1550 | 1543 | ||
1551 | newVideoFile.set('size', stats.size) | 1544 | newVideoFile.set('size', stats.size) |
@@ -1560,7 +1553,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1560 | 1553 | ||
1561 | async importVideoFile (inputFilePath: string) { | 1554 | async importVideoFile (inputFilePath: string) { |
1562 | const { videoFileResolution } = await getVideoFileResolution(inputFilePath) | 1555 | const { videoFileResolution } = await getVideoFileResolution(inputFilePath) |
1563 | const { size } = await statPromise(inputFilePath) | 1556 | const { size } = await stat(inputFilePath) |
1564 | const fps = await getVideoFileFPS(inputFilePath) | 1557 | const fps = await getVideoFileFPS(inputFilePath) |
1565 | 1558 | ||
1566 | let updatedVideoFile = new VideoFileModel({ | 1559 | let updatedVideoFile = new VideoFileModel({ |
@@ -1589,7 +1582,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1589 | } | 1582 | } |
1590 | 1583 | ||
1591 | const outputPath = this.getVideoFilePath(updatedVideoFile) | 1584 | const outputPath = this.getVideoFilePath(updatedVideoFile) |
1592 | await copyFilePromise(inputFilePath, outputPath) | 1585 | await copy(inputFilePath, outputPath) |
1593 | 1586 | ||
1594 | await this.createTorrentAndSetInfoHash(updatedVideoFile) | 1587 | await this.createTorrentAndSetInfoHash(updatedVideoFile) |
1595 | 1588 | ||
@@ -1610,25 +1603,25 @@ export class VideoModel extends Model<VideoModel> { | |||
1610 | 1603 | ||
1611 | removeThumbnail () { | 1604 | removeThumbnail () { |
1612 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) | 1605 | const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) |
1613 | return unlinkPromise(thumbnailPath) | 1606 | return remove(thumbnailPath) |
1614 | .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) | 1607 | .catch(err => logger.warn('Cannot delete thumbnail %s.', thumbnailPath, { err })) |
1615 | } | 1608 | } |
1616 | 1609 | ||
1617 | removePreview () { | 1610 | removePreview () { |
1618 | const previewPath = join(CONFIG.STORAGE.PREVIEWS_DIR + this.getPreviewName()) | 1611 | const previewPath = join(CONFIG.STORAGE.PREVIEWS_DIR + this.getPreviewName()) |
1619 | return unlinkPromise(previewPath) | 1612 | return remove(previewPath) |
1620 | .catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err })) | 1613 | .catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err })) |
1621 | } | 1614 | } |
1622 | 1615 | ||
1623 | removeFile (videoFile: VideoFileModel) { | 1616 | removeFile (videoFile: VideoFileModel) { |
1624 | const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) | 1617 | const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) |
1625 | return unlinkPromise(filePath) | 1618 | return remove(filePath) |
1626 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) | 1619 | .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) |
1627 | } | 1620 | } |
1628 | 1621 | ||
1629 | removeTorrent (videoFile: VideoFileModel) { | 1622 | removeTorrent (videoFile: VideoFileModel) { |
1630 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) | 1623 | const torrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile)) |
1631 | return unlinkPromise(torrentPath) | 1624 | return remove(torrentPath) |
1632 | .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) | 1625 | .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err })) |
1633 | } | 1626 | } |
1634 | 1627 | ||