aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-caption.ts4
-rw-r--r--server/models/video/video.ts33
2 files changed, 15 insertions, 22 deletions
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
19import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' 19import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers'
20import { join } from 'path' 20import { join } from 'path'
21import { logger } from '../../helpers/logger' 21import { logger } from '../../helpers/logger'
22import { unlinkPromise } from '../../helpers/core-utils' 22import { remove } from 'fs-extra'
23 23
24export enum ScopeNames { 24export 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'
30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
31import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos' 31import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
32import { VideoFilter } from '../../../shared/models/videos/video-query.type' 32import { VideoFilter } from '../../../shared/models/videos/video-query.type'
33import { 33import { 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'
42import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 34import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
43import { isBooleanValid } from '../../helpers/custom-validators/misc' 35import { isBooleanValid } from '../../helpers/custom-validators/misc'
44import { 36import {
@@ -95,6 +87,7 @@ import { VideoTagModel } from './video-tag'
95import { ScheduleVideoUpdateModel } from './schedule-video-update' 87import { ScheduleVideoUpdateModel } from './schedule-video-update'
96import { VideoCaptionModel } from './video-caption' 88import { VideoCaptionModel } from './video-caption'
97import { VideoBlacklistModel } from './video-blacklist' 89import { VideoBlacklistModel } from './video-blacklist'
90import { 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
100const indexes: Sequelize.DefineIndexesOptions[] = [ 93const 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