diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 33 |
1 files changed, 13 insertions, 20 deletions
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 | ||