X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=b0fff65268fd8542153fb16649ab6f915cfd42a7;hb=9d3ef9fe052ed29bd67566754cb28662bd122234;hp=240a2b5a2584d5271d9545d79290e979f7976b22;hpb=244e76a552ef05a5067134b1065d26dd89246d8c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 240a2b5a2..b0fff6526 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -95,7 +95,7 @@ enum ScopeNames { } @Scopes({ - [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, filter?: VideoFilter, withFiles?: boolean) => { + [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean) => { const query: IFindOptions = { where: { id: { @@ -161,6 +161,11 @@ enum ScopeNames { }) } + // Hide nsfw videos? + if (hideNSFW === true) { + query.where['nsfw'] = false + } + return query }, [ScopeNames.WITH_ACCOUNT_DETAILS]: { @@ -317,8 +322,8 @@ export class VideoModel extends Model { @AllowNull(true) @Default(null) @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language')) - @Column - language: number + @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max)) + language: string @AllowNull(false) @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy')) @@ -640,7 +645,7 @@ export class VideoModel extends Model { }) } - static listUserVideosForApi (userId: number, start: number, count: number, sort: string, withFiles = false) { + static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, hideNSFW: boolean, withFiles = false) { const query: IFindOptions = { offset: start, limit: count, @@ -653,7 +658,7 @@ export class VideoModel extends Model { { model: AccountModel, where: { - userId + id: accountId }, required: true } @@ -669,6 +674,12 @@ export class VideoModel extends Model { }) } + if (hideNSFW === true) { + query.where = { + nsfw: false + } + } + return VideoModel.findAndCountAll(query).then(({ rows, count }) => { return { data: rows, @@ -677,7 +688,7 @@ export class VideoModel extends Model { }) } - static async listForApi (start: number, count: number, sort: string, filter?: VideoFilter, withFiles = false) { + static async listForApi (start: number, count: number, sort: string, hideNSFW: boolean, filter?: VideoFilter, withFiles = false) { const query = { offset: start, limit: count, @@ -685,8 +696,7 @@ export class VideoModel extends Model { } const serverActor = await getServerActor() - - return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, filter, withFiles ] }) + return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles ] }) .findAndCountAll(query) .then(({ rows, count }) => { return { @@ -696,7 +706,7 @@ export class VideoModel extends Model { }) } - static async searchAndPopulateAccountAndServerAndTags (value: string, start: number, count: number, sort: string) { + static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string, hideNSFW: boolean) { const query: IFindOptions = { offset: start, limit: count, @@ -724,7 +734,7 @@ export class VideoModel extends Model { const serverActor = await getServerActor() - return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id ] }) + return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW ] }) .findAndCountAll(query) .then(({ rows, count }) => { return { @@ -867,13 +877,22 @@ export class VideoModel extends Model { return licenceLabel } - private static getLanguageLabel (id: number) { + private static getLanguageLabel (id: string) { let languageLabel = VIDEO_LANGUAGES[id] + console.log(VIDEO_LANGUAGES) + console.log(id) if (!languageLabel) languageLabel = 'Unknown' return languageLabel } + private static getPrivacyLabel (id: number) { + let privacyLabel = VIDEO_PRIVACIES[id] + if (!privacyLabel) privacyLabel = 'Unknown' + + return privacyLabel + } + getOriginalFile () { if (Array.isArray(this.VideoFiles) === false) return undefined @@ -927,8 +946,11 @@ export class VideoModel extends Model { return join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile)) } - createTorrentAndSetInfoHash = async function (videoFile: VideoFileModel) { + async createTorrentAndSetInfoHash (videoFile: VideoFileModel) { const options = { + // Keep the extname, it's used by the client to stream the file inside a web browser + name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, + createdBy: 'PeerTube', announceList: [ [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ], [ CONFIG.WEBSERVER.URL + '/tracker/announce' ] @@ -980,6 +1002,10 @@ export class VideoModel extends Model { id: this.language, label: VideoModel.getLanguageLabel(this.language) }, + privacy: { + id: this.privacy, + label: VideoModel.getPrivacyLabel(this.privacy) + }, nsfw: this.nsfw, description: this.getTruncatedDescription(), isLocal: this.isOwned(), @@ -1006,15 +1032,7 @@ export class VideoModel extends Model { toFormattedDetailsJSON (): VideoDetails { const formattedJson = this.toFormattedJSON() - // Maybe our server is not up to date and there are new privacy settings since our version - let privacyLabel = VIDEO_PRIVACIES[this.privacy] - if (!privacyLabel) privacyLabel = 'Unknown' - const detailsJson = { - privacy: { - id: this.privacy, - label: privacyLabel - }, support: this.support, descriptionPath: this.getDescriptionPath(), channel: this.VideoChannel.toFormattedJSON(), @@ -1067,7 +1085,7 @@ export class VideoModel extends Model { let language if (this.language) { language = { - identifier: this.language + '', + identifier: this.language, name: VideoModel.getLanguageLabel(this.language) } } @@ -1227,7 +1245,7 @@ export class VideoModel extends Model { return peertubeTruncate(this.description, maxLength) } - optimizeOriginalVideofile = async function () { + async optimizeOriginalVideofile () { const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR const newExtname = '.mp4' const inputVideoFile = this.getOriginalFile() @@ -1264,7 +1282,7 @@ export class VideoModel extends Model { } } - transcodeOriginalVideofile = async function (resolution: VideoResolution, isPortraitMode: boolean) { + async transcodeOriginalVideofile (resolution: VideoResolution, isPortraitMode: boolean) { const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR const extname = '.mp4'