X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=c006a91af0f1458978165cd40998776072455274;hb=29837f8885eb37fa300e4b80c90a6d03ab337084;hp=7a9e96210e00ae593df7ec3abddb4891fc5bb043;hpb=693c6586cb896a84ff0f897b1c242bcf7bdcbaee;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 7a9e96210..c006a91af 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -26,12 +26,13 @@ import { } from 'sequelize-typescript' import { setAsUpdated } from '@server/helpers/database-utils' import { buildNSFWFilter } from '@server/helpers/express-utils' +import { uuidToShort } from '@server/helpers/uuid' import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' import { LiveManager } from '@server/lib/live/live-manager' import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' import { getServerActor } from '@server/models/application/application' import { ModelCache } from '@server/models/model-cache' -import { AttributesOnly } from '@shared/core-utils' +import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath } from '@shared/core-utils' import { VideoFile } from '@shared/models/videos/video-file.model' import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' import { VideoObject } from '../../../shared/models/activitypub/objects' @@ -572,7 +573,6 @@ export class VideoModel extends Model>> { foreignKey: { allowNull: true }, - hooks: true, onDelete: 'cascade' }) VideoChannel: VideoChannelModel @@ -763,8 +763,7 @@ export class VideoModel extends Model>> { // Remove physical files and torrents instance.VideoFiles.forEach(file => { - tasks.push(instance.removeFile(file)) - tasks.push(file.removeTorrent()) + tasks.push(instance.removeFileAndTorrent(file)) }) // Remove playlists file @@ -1114,6 +1113,7 @@ export class VideoModel extends Model>> { static async searchAndPopulateAccountAndServer (options: { includeLocalVideos: boolean search?: string + host?: string start?: number count?: number sort?: string @@ -1152,6 +1152,7 @@ export class VideoModel extends Model>> { user: options.user, filter: options.filter, + host: options.host, start: options.start, count: options.count, @@ -1580,11 +1581,11 @@ export class VideoModel extends Model>> { } getWatchStaticPath () { - return '/w/' + this.uuid + return buildVideoWatchPath({ shortUUID: uuidToShort(this.uuid) }) } getEmbedStaticPath () { - return '/videos/embed/' + this.uuid + return buildVideoEmbedPath(this) } getMiniatureStaticPath () { @@ -1671,10 +1672,13 @@ export class VideoModel extends Model>> { .concat(toAdd) } - removeFile (videoFile: MVideoFile, isRedundancy = false) { + removeFileAndTorrent (videoFile: MVideoFile, isRedundancy = false) { const filePath = getVideoFilePath(this, videoFile, isRedundancy) - return remove(filePath) - .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) + + const promises: Promise[] = [ remove(filePath) ] + if (!isRedundancy) promises.push(videoFile.removeTorrent()) + + return Promise.all(promises) } async removeStreamingPlaylistFiles (streamingPlaylist: MStreamingPlaylist, isRedundancy = false) {