}
@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<VideoModel> = {
where: {
id: {
})
}
+ // Hide nsfw videos?
+ if (hideNSFW === true) {
+ query.where['nsfw'] = false
+ }
+
return query
},
[ScopeNames.WITH_ACCOUNT_DETAILS]: {
@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'))
})
}
- 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<VideoModel> = {
offset: start,
limit: count,
{
model: AccountModel,
where: {
- userId
+ id: accountId
},
required: true
}
})
}
+ if (hideNSFW === true) {
+ query.where = {
+ nsfw: false
+ }
+ }
+
return VideoModel.findAndCountAll(query).then(({ rows, count }) => {
return {
data: rows,
})
}
- 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,
}
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 {
})
}
- 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<VideoModel> = {
offset: start,
limit: count,
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 {
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
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' ]
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(),
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(),
let language
if (this.language) {
language = {
- identifier: this.language + '',
+ identifier: this.language,
name: VideoModel.getLanguageLabel(this.language)
}
}
return peertubeTruncate(this.description, maxLength)
}
- optimizeOriginalVideofile = async function () {
+ async optimizeOriginalVideofile () {
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
const newExtname = '.mp4'
const inputVideoFile = this.getOriginalFile()
}
}
- transcodeOriginalVideofile = async function (resolution: VideoResolution, isPortraitMode: boolean) {
+ async transcodeOriginalVideofile (resolution: VideoResolution, isPortraitMode: boolean) {
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
const extname = '.mp4'