Use ISO 639 for languages

This commit is contained in:
Chocobozzz 2018-04-23 14:39:52 +02:00
parent 2a2c19dfef
commit 9d3ef9fe05
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
25 changed files with 292 additions and 109 deletions

View File

@ -6,6 +6,7 @@ import { ReplaySubject } from 'rxjs/ReplaySubject'
import { ServerConfig } from '../../../../../shared' import { ServerConfig } from '../../../../../shared'
import { About } from '../../../../../shared/models/server/about.model' import { About } from '../../../../../shared/models/server/about.model'
import { environment } from '../../../environments/environment' import { environment } from '../../../environments/environment'
import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
@Injectable() @Injectable()
export class ServerService { export class ServerService {
@ -57,10 +58,10 @@ export class ServerService {
videoQuota: -1 videoQuota: -1
} }
} }
private videoCategories: Array<{ id: number, label: string }> = [] private videoCategories: Array<VideoConstant<number>> = []
private videoLicences: Array<{ id: number, label: string }> = [] private videoLicences: Array<VideoConstant<number>> = []
private videoLanguages: Array<{ id: number, label: string }> = [] private videoLanguages: Array<VideoConstant<string>> = []
private videoPrivacies: Array<{ id: number, label: string }> = [] private videoPrivacies: Array<VideoConstant<VideoPrivacy>> = []
constructor (private http: HttpClient) { constructor (private http: HttpClient) {
this.loadConfigLocally() this.loadConfigLocally()
@ -118,7 +119,7 @@ export class ServerService {
private loadVideoAttributeEnum ( private loadVideoAttributeEnum (
attributeName: 'categories' | 'licences' | 'languages' | 'privacies', attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
hashToPopulate: { id: number, label: string }[], hashToPopulate: VideoConstant<number | string>[],
notifier: ReplaySubject<boolean>, notifier: ReplaySubject<boolean>,
sort = false sort = false
) { ) {
@ -127,7 +128,7 @@ export class ServerService {
Object.keys(data) Object.keys(data)
.forEach(dataKey => { .forEach(dataKey => {
hashToPopulate.push({ hashToPopulate.push({
id: parseInt(dataKey, 10), id: dataKey,
label: data[dataKey] label: data[dataKey]
}) })
}) })

View File

@ -4,7 +4,7 @@ import { VideoPrivacy } from '../../../../../shared/models/videos/video-privacy.
export class VideoEdit { export class VideoEdit {
category: number category: number
licence: number licence: number
language: number language: string
description: string description: string
name: string name: string
tags: string[] tags: string[]

View File

@ -13,7 +13,7 @@ export class Video implements VideoServerModel {
publishedAt: Date publishedAt: Date
category: VideoConstant<number> category: VideoConstant<number>
licence: VideoConstant<number> licence: VideoConstant<number>
language: VideoConstant<number> language: VideoConstant<string>
privacy: VideoConstant<VideoPrivacy> privacy: VideoConstant<VideoPrivacy>
description: string description: string
duration: number duration: number

View File

@ -69,6 +69,7 @@
"express-rate-limit": "^2.11.0", "express-rate-limit": "^2.11.0",
"express-validator": "^5.0.0", "express-validator": "^5.0.0",
"fluent-ffmpeg": "^2.1.0", "fluent-ffmpeg": "^2.1.0",
"iso-639-3": "^1.0.1",
"js-yaml": "^3.5.4", "js-yaml": "^3.5.4",
"jsonld": "^1.0.1", "jsonld": "^1.0.1",
"jsonld-signatures": "https://github.com/Chocobozzz/jsonld-signatures#rsa2017", "jsonld-signatures": "https://github.com/Chocobozzz/jsonld-signatures#rsa2017",

View File

@ -49,9 +49,9 @@ function isVideoTorrentObjectValid (video: any) {
isActivityPubVideoDurationValid(video.duration) && isActivityPubVideoDurationValid(video.duration) &&
isUUIDValid(video.uuid) && isUUIDValid(video.uuid) &&
setValidRemoteTags(video) && setValidRemoteTags(video) &&
(!video.category || isRemoteIdentifierValid(video.category)) && (!video.category || isRemoteNumberIdentifierValid(video.category)) &&
(!video.licence || isRemoteIdentifierValid(video.licence)) && (!video.licence || isRemoteNumberIdentifierValid(video.licence)) &&
(!video.language || isRemoteIdentifierValid(video.language)) && (!video.language || isRemoteStringIdentifierValid(video.language)) &&
isVideoViewsValid(video.views) && isVideoViewsValid(video.views) &&
isBooleanValid(video.sensitive) && isBooleanValid(video.sensitive) &&
isBooleanValid(video.commentsEnabled) && isBooleanValid(video.commentsEnabled) &&
@ -72,6 +72,7 @@ export {
isVideoTorrentCreateActivityValid, isVideoTorrentCreateActivityValid,
isVideoTorrentUpdateActivityValid, isVideoTorrentUpdateActivityValid,
isVideoTorrentDeleteActivityValid, isVideoTorrentDeleteActivityValid,
isRemoteStringIdentifierValid,
isVideoFlagValid, isVideoFlagValid,
isVideoTorrentObjectValid isVideoTorrentObjectValid
} }
@ -89,10 +90,14 @@ function setValidRemoteTags (video: any) {
return true return true
} }
function isRemoteIdentifierValid (data: any) { function isRemoteNumberIdentifierValid (data: any) {
return validator.isInt(data.identifier, { min: 0 }) return validator.isInt(data.identifier, { min: 0 })
} }
function isRemoteStringIdentifierValid (data: any) {
return typeof data.identifier === 'string'
}
function isRemoteVideoContentValid (mediaType: string, content: string) { function isRemoteVideoContentValid (mediaType: string, content: string) {
return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content) return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content)
} }

View File

@ -18,16 +18,17 @@ import { exists, isArray, isFileValid } from './misc'
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
function isVideoCategoryValid (value: number) { function isVideoCategoryValid (value: any) {
return value === null || VIDEO_CATEGORIES[value] !== undefined return value === null || VIDEO_CATEGORIES[value] !== undefined
} }
function isVideoLicenceValid (value: number) { function isVideoLicenceValid (value: any) {
return value === null || VIDEO_LICENCES[value] !== undefined return value === null || VIDEO_LICENCES[value] !== undefined
} }
function isVideoLanguageValid (value: number) { function isVideoLanguageValid (value: any) {
return value === null || VIDEO_LANGUAGES[value] !== undefined return value === null ||
(typeof value === 'string' && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.LANGUAGE))
} }
function isVideoDurationValid (value: string) { function isVideoDurationValid (value: string) {

View File

@ -28,7 +28,7 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
errorFilter: err => { errorFilter: err => {
const willRetry = (err.name === 'SequelizeDatabaseError') const willRetry = (err.name === 'SequelizeDatabaseError')
logger.debug('Maybe retrying the transaction function.', { willRetry }) logger.debug('Maybe retrying the transaction function.', { willRetry, err })
return willRetry return willRetry
} }
}, func, (err, data) => err ? rej(err) : res(data)) }, func, (err, data) => err ? rej(err) : res(data))

View File

@ -13,7 +13,7 @@ let config: IConfig = require('config')
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 205 const LAST_MIGRATION_VERSION = 210
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -196,6 +196,7 @@ const CONSTRAINTS_FIELDS = {
}, },
VIDEOS: { VIDEOS: {
NAME: { min: 3, max: 120 }, // Length NAME: { min: 3, max: 120 }, // Length
LANGUAGE: { min: 1, max: 10 }, // Length
TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length
DESCRIPTION: { min: 3, max: 10000 }, // Length DESCRIPTION: { min: 3, max: 10000 }, // Length
SUPPORT: { min: 3, max: 300 }, // Length SUPPORT: { min: 3, max: 300 }, // Length
@ -291,38 +292,7 @@ const VIDEO_LICENCES = {
7: 'Public Domain Dedication' 7: 'Public Domain Dedication'
} }
// See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin const VIDEO_LANGUAGES = buildLanguages()
const VIDEO_LANGUAGES = {
1: 'English',
2: 'Spanish',
3: 'Mandarin',
4: 'Hindi',
5: 'Arabic',
6: 'Portuguese',
7: 'Bengali',
8: 'Russian',
9: 'Japanese',
10: 'Punjabi',
11: 'German',
12: 'Korean',
13: 'French',
14: 'Italian',
1000: 'Sign Language',
1001: 'American Sign Language',
1002: 'Arab Sign Language',
1003: 'British Sign Language',
1004: 'Brazilian Sign Language',
1005: 'Chinese Sign Language',
1006: 'Czech Sign Language',
1007: 'Danish Sign Language',
1008: 'French Sign Language',
1009: 'German Sign Language',
1010: 'Indo-Pakistani Sign Language',
1011: 'Japanese Sign Language',
1012: 'South African Sign Language',
1013: 'Swedish Sign Language',
1014: 'Russian Sign Language'
}
const VIDEO_PRIVACIES = { const VIDEO_PRIVACIES = {
[VideoPrivacy.PUBLIC]: 'Public', [VideoPrivacy.PUBLIC]: 'Public',
@ -521,6 +491,40 @@ function updateWebserverConfig () {
CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
} }
function buildLanguages () {
const iso639 = require('iso-639-3')
const languages: { [ id: string ]: string } = {}
const signLanguages = [
'sgn', // Sign languages (macro language)
'ase', // American
'sdl', // Arabian
'bfi', // British
'bzs', // Brazilian
'csl', // Chinese
'cse', // Czech
'dsl', // Danish
'fsl', // French
'gsg', // German
'pks', // Pakistan
'jsl', // Japanese
'sfs', // South African
'swl', // Swedish
'rsl' // Russian
]
// Only add ISO639-1 languages and some sign languages (ISO639-3)
iso639
.filter(l => {
return (l.iso6391 !== null && l.type === 'living') ||
signLanguages.indexOf(l.iso6393) !== -1
})
.forEach(l => languages[l.iso6391 || l.iso6393] = l.name)
return languages
}
export function reloadConfig () { export function reloadConfig () {
function directory () { function directory () {

View File

@ -0,0 +1,162 @@
import * as Sequelize from 'sequelize'
import { CONSTRAINTS_FIELDS } from '../index'
async function up (utils: {
transaction: Sequelize.Transaction,
queryInterface: Sequelize.QueryInterface,
sequelize: Sequelize.Sequelize
}): Promise<void> {
{
await utils.queryInterface.renameColumn('video', 'language', 'oldLanguage')
}
{
const data = {
type: Sequelize.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max),
allowNull: true,
defaultValue: null
}
await utils.queryInterface.addColumn('video', 'language', data)
}
{
const languages = [
{
oldLanguage: 1,
newLanguage: 'en'
},
{
oldLanguage: 2,
newLanguage: 'es'
},
{
oldLanguage: 3,
newLanguage: 'zh'
},
{
oldLanguage: 4,
newLanguage: 'hi'
},
{
oldLanguage: 5,
newLanguage: 'ar'
},
{
oldLanguage: 6,
newLanguage: 'pt'
},
{
oldLanguage: 7,
newLanguage: 'bn'
},
{
oldLanguage: 8,
newLanguage: 'ru'
},
{
oldLanguage: 9,
newLanguage: 'ja'
},
{
oldLanguage: 10,
newLanguage: 'pa'
},
{
oldLanguage: 11,
newLanguage: 'de'
},
{
oldLanguage: 12,
newLanguage: 'ko'
},
{
oldLanguage: 13,
newLanguage: 'fr'
},
{
oldLanguage: 14,
newLanguage: 'it'
},
{
oldLanguage: 1000,
newLanguage: 'sgn'
},
{
oldLanguage: 1001,
newLanguage: 'ase'
},
{
oldLanguage: 1002,
newLanguage: 'sdl'
},
{
oldLanguage: 1003,
newLanguage: 'bfi'
},
{
oldLanguage: 1004,
newLanguage: 'bzs'
},
{
oldLanguage: 1005,
newLanguage: 'csl'
},
{
oldLanguage: 1006,
newLanguage: 'cse'
},
{
oldLanguage: 1007,
newLanguage: 'dsl'
},
{
oldLanguage: 1008,
newLanguage: 'fsl'
},
{
oldLanguage: 1009,
newLanguage: 'gsg'
},
{
oldLanguage: 1010,
newLanguage: 'pks'
},
{
oldLanguage: 1011,
newLanguage: 'jsl'
},
{
oldLanguage: 1012,
newLanguage: 'sfs'
},
{
oldLanguage: 1013,
newLanguage: 'swl'
},
{
oldLanguage: 1014,
newLanguage: 'rsl'
}
]
for (const language of languages) {
const query = 'UPDATE "video" SET "language" = \'' + language.newLanguage + '\' WHERE "oldLanguage" = ' + language.oldLanguage
await utils.sequelize.query(query)
}
}
{
await utils.queryInterface.removeColumn('video', 'oldLanguage')
}
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}

View File

@ -58,19 +58,19 @@ async function videoActivityObjectToDBAttributes (videoChannel: VideoChannelMode
videoObject: VideoTorrentObject, videoObject: VideoTorrentObject,
to: string[] = []) { to: string[] = []) {
const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED
const duration = videoObject.duration.replace(/[^\d]+/, '') const duration = videoObject.duration.replace(/[^\d]+/, '')
let language = null
let language: string = null
if (videoObject.language) { if (videoObject.language) {
language = parseInt(videoObject.language.identifier, 10) language = videoObject.language.identifier
} }
let category = null let category: number = null
if (videoObject.category) { if (videoObject.category) {
category = parseInt(videoObject.category.identifier, 10) category = parseInt(videoObject.category.identifier, 10)
} }
let licence = null let licence: number = null
if (videoObject.licence) { if (videoObject.licence) {
licence = parseInt(videoObject.licence.identifier, 10) licence = parseInt(videoObject.licence.identifier, 10)
} }

View File

@ -322,8 +322,8 @@ export class VideoModel extends Model<VideoModel> {
@AllowNull(true) @AllowNull(true)
@Default(null) @Default(null)
@Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language')) @Is('VideoLanguage', value => throwIfNotValid(value, isVideoLanguageValid, 'language'))
@Column @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max))
language: number language: string
@AllowNull(false) @AllowNull(false)
@Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy')) @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
@ -877,8 +877,10 @@ export class VideoModel extends Model<VideoModel> {
return licenceLabel return licenceLabel
} }
private static getLanguageLabel (id: number) { private static getLanguageLabel (id: string) {
let languageLabel = VIDEO_LANGUAGES[id] let languageLabel = VIDEO_LANGUAGES[id]
console.log(VIDEO_LANGUAGES)
console.log(id)
if (!languageLabel) languageLabel = 'Unknown' if (!languageLabel) languageLabel = 'Unknown'
return languageLabel return languageLabel
@ -1083,7 +1085,7 @@ export class VideoModel extends Model<VideoModel> {
let language let language
if (this.language) { if (this.language) {
language = { language = {
identifier: this.language + '', identifier: this.language,
name: VideoModel.getLanguageLabel(this.language) name: VideoModel.getLanguageLabel(this.language)
} }
} }

View File

@ -105,7 +105,7 @@ describe('Test videos API validator', function () {
name: 'my super name', name: 'my super name',
category: 5, category: 5,
licence: 1, licence: 1,
language: 6, language: 'pt',
nsfw: false, nsfw: false,
commentsEnabled: true, commentsEnabled: true,
description: 'my super description', description: 'my super description',
@ -151,7 +151,7 @@ describe('Test videos API validator', function () {
}) })
it('Should fail with a bad language', async function () { it('Should fail with a bad language', async function () {
const fields = immutableAssign(baseCorrectParams, { language: 125 }) const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
const attaches = baseCorrectAttaches const attaches = baseCorrectAttaches
await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@ -359,7 +359,7 @@ describe('Test videos API validator', function () {
name: 'my super name', name: 'my super name',
category: 5, category: 5,
licence: 2, licence: 2,
language: 6, language: 'pt',
nsfw: false, nsfw: false,
commentsEnabled: false, commentsEnabled: false,
description: 'my super description', description: 'my super description',
@ -413,7 +413,7 @@ describe('Test videos API validator', function () {
}) })
it('Should fail with a bad language', async function () { it('Should fail with a bad language', async function () {
const fields = immutableAssign(baseCorrectParams, { language: 125 }) const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
}) })

View File

@ -277,7 +277,7 @@ describe('Test follows', function () {
name: 'server3-4', name: 'server3-4',
category: 2, category: 2,
licence: 6, licence: 6,
language: 3, language: 'zh',
nsfw: true, nsfw: true,
description: 'my super description', description: 'my super description',
support: 'my super support text', support: 'my super support text',

View File

@ -32,7 +32,7 @@ describe('Test handle downs', function () {
name: 'my super name for server 1', name: 'my super name for server 1',
category: 5, category: 5,
licence: 4, licence: 4,
language: 9, language: 'ja',
nsfw: true, nsfw: true,
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
description: 'my super description for server 1', description: 'my super description for server 1',
@ -49,7 +49,7 @@ describe('Test handle downs', function () {
name: 'my super name for server 1', name: 'my super name for server 1',
category: 5, category: 5,
licence: 4, licence: 4,
language: 9, language: 'ja',
nsfw: true, nsfw: true,
description: 'my super description for server 1', description: 'my super description for server 1',
support: 'my super support text for server 1', support: 'my super support text for server 1',

View File

@ -89,7 +89,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 1', name: 'my super name for server 1',
category: 5, category: 5,
licence: 4, licence: 4,
language: 9, language: 'ja',
nsfw: true, nsfw: true,
description: 'my super description for server 1', description: 'my super description for server 1',
support: 'my super support text for server 1', support: 'my super support text for server 1',
@ -108,7 +108,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 1', name: 'my super name for server 1',
category: 5, category: 5,
licence: 4, licence: 4,
language: 9, language: 'ja',
nsfw: true, nsfw: true,
description: 'my super description for server 1', description: 'my super description for server 1',
support: 'my super support text for server 1', support: 'my super support text for server 1',
@ -159,7 +159,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 2', name: 'my super name for server 2',
category: 4, category: 4,
licence: 3, licence: 3,
language: 11, language: 'de',
nsfw: true, nsfw: true,
description: 'my super description for server 2', description: 'my super description for server 2',
support: 'my super support text for server 2', support: 'my super support text for server 2',
@ -180,7 +180,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 2', name: 'my super name for server 2',
category: 4, category: 4,
licence: 3, licence: 3,
language: 11, language: 'de',
nsfw: true, nsfw: true,
description: 'my super description for server 2', description: 'my super description for server 2',
support: 'my super support text for server 2', support: 'my super support text for server 2',
@ -238,7 +238,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 3', name: 'my super name for server 3',
category: 6, category: 6,
licence: 5, licence: 5,
language: 11, language: 'de',
nsfw: true, nsfw: true,
description: 'my super description for server 3', description: 'my super description for server 3',
support: 'my super support text for server 3', support: 'my super support text for server 3',
@ -251,7 +251,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 3-2', name: 'my super name for server 3-2',
category: 7, category: 7,
licence: 6, licence: 6,
language: 12, language: 'ko',
nsfw: false, nsfw: false,
description: 'my super description for server 3-2', description: 'my super description for server 3-2',
support: 'my super support text for server 3-2', support: 'my super support text for server 3-2',
@ -286,7 +286,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 3', name: 'my super name for server 3',
category: 6, category: 6,
licence: 5, licence: 5,
language: 11, language: 'de',
nsfw: true, nsfw: true,
description: 'my super description for server 3', description: 'my super description for server 3',
support: 'my super support text for server 3', support: 'my super support text for server 3',
@ -318,7 +318,7 @@ describe('Test multiple servers', function () {
name: 'my super name for server 3-2', name: 'my super name for server 3-2',
category: 7, category: 7,
licence: 6, licence: 6,
language: 12, language: 'ko',
nsfw: false, nsfw: false,
description: 'my super description for server 3-2', description: 'my super description for server 3-2',
support: 'my super support text for server 3-2', support: 'my super support text for server 3-2',
@ -597,7 +597,7 @@ describe('Test multiple servers', function () {
name: 'my super video updated', name: 'my super video updated',
category: 10, category: 10,
licence: 7, licence: 7,
language: 13, language: 'fr',
nsfw: true, nsfw: true,
description: 'my super description updated', description: 'my super description updated',
support: 'my super support text updated', support: 'my super support text updated',
@ -626,7 +626,7 @@ describe('Test multiple servers', function () {
name: 'my super video updated', name: 'my super video updated',
category: 10, category: 10,
licence: 7, licence: 7,
language: 13, language: 'fr',
nsfw: true, nsfw: true,
description: 'my super description updated', description: 'my super description updated',
support: 'my super support text updated', support: 'my super support text updated',

View File

@ -23,7 +23,7 @@ describe('Test a single server', function () {
name: 'my super name', name: 'my super name',
category: 2, category: 2,
licence: 6, licence: 6,
language: 3, language: 'zh',
nsfw: true, nsfw: true,
description: 'my super description', description: 'my super description',
support: 'my super support text', support: 'my super support text',
@ -54,7 +54,7 @@ describe('Test a single server', function () {
name: 'my super video updated', name: 'my super video updated',
category: 4, category: 4,
licence: 2, licence: 2,
language: 5, language: 'ar',
nsfw: false, nsfw: false,
description: 'my super description updated', description: 'my super description updated',
support: 'my super support text updated', support: 'my super support text updated',
@ -115,7 +115,7 @@ describe('Test a single server', function () {
const languages = res.body const languages = res.body
expect(Object.keys(languages)).to.have.length.above(5) expect(Object.keys(languages)).to.have.length.above(5)
expect(languages[3]).to.equal('Mandarin') expect(languages['ru']).to.equal('Russian')
}) })
it('Should list video privacies', async function () { it('Should list video privacies', async function () {
@ -222,8 +222,8 @@ describe('Test a single server', function () {
// expect(video.categoryLabel).to.equal('Films') // expect(video.categoryLabel).to.equal('Films')
// expect(video.licence).to.equal(6) // expect(video.licence).to.equal(6)
// expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
// expect(video.language).to.equal(3) // expect(video.language).to.equal('zh')
// expect(video.languageLabel).to.equal('Mandarin') // expect(video.languageLabel).to.equal('Chinese')
// expect(video.nsfw).to.be.ok // expect(video.nsfw).to.be.ok
// expect(video.description).to.equal('my super description') // expect(video.description).to.equal('my super description')
// expect(video.account.name).to.equal('root') // expect(video.account.name).to.equal('root')
@ -292,7 +292,7 @@ describe('Test a single server', function () {
description: video + ' description', description: video + ' description',
category: 2, category: 2,
licence: 1, licence: 1,
language: 1, language: 'en',
nsfw: true, nsfw: true,
tags: [ 'tag1', 'tag2', 'tag3' ], tags: [ 'tag1', 'tag2', 'tag3' ],
fixture: video fixture: video
@ -458,7 +458,7 @@ describe('Test a single server', function () {
name: 'my super video updated', name: 'my super video updated',
category: 4, category: 4,
licence: 2, licence: 2,
language: 5, language: 'ar',
nsfw: false, nsfw: false,
description: 'my super description updated', description: 'my super description updated',
commentsEnabled: false, commentsEnabled: false,

View File

@ -182,7 +182,7 @@ function upload (servers: ServerInfo[], numServer: number) {
category: 4, category: 4,
nsfw: false, nsfw: false,
licence: 2, licence: 2,
language: 1, language: 'en',
description: Date.now() + ' description', description: Date.now() + ' description',
tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ], tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
fixture: 'video_short1.webm' fixture: 'video_short1.webm'

View File

@ -24,7 +24,7 @@ type VideoAttributes = {
name?: string name?: string
category?: number category?: number
licence?: number licence?: number
language?: number language?: string
nsfw?: boolean nsfw?: boolean
commentsEnabled?: boolean commentsEnabled?: boolean
description?: string description?: string
@ -284,7 +284,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
name: 'my super video', name: 'my super video',
category: 5, category: 5,
licence: 4, licence: 4,
language: 3, language: 'zh',
channelId: defaultChannelId, channelId: defaultChannelId,
nsfw: true, nsfw: true,
description: 'my super description', description: 'my super description',
@ -403,7 +403,7 @@ async function completeVideoCheck (
name: string name: string
category: number category: number
licence: number licence: number
language: number language: string
nsfw: boolean nsfw: boolean
commentsEnabled: boolean commentsEnabled: boolean
description: string description: string
@ -437,11 +437,11 @@ async function completeVideoCheck (
expect(video.name).to.equal(attributes.name) expect(video.name).to.equal(attributes.name)
expect(video.category.id).to.equal(attributes.category) expect(video.category.id).to.equal(attributes.category)
expect(video.category.label).to.equal(VIDEO_CATEGORIES[attributes.category] || 'Misc') expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc')
expect(video.licence.id).to.equal(attributes.licence) expect(video.licence.id).to.equal(attributes.licence)
expect(video.licence.label).to.equal(VIDEO_LICENCES[attributes.licence] || 'Unknown') expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown')
expect(video.language.id).to.equal(attributes.language) expect(video.language.id).to.equal(attributes.language)
expect(video.language.label).to.equal(VIDEO_LANGUAGES[attributes.language] || 'Unknown') expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown')
expect(video.privacy.id).to.deep.equal(attributes.privacy) expect(video.privacy.id).to.deep.equal(attributes.privacy)
expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
expect(video.nsfw).to.equal(attributes.nsfw) expect(video.nsfw).to.equal(attributes.nsfw)

View File

@ -16,7 +16,7 @@ program
.option('-U, --username <username>', 'Username') .option('-U, --username <username>', 'Username')
.option('-p, --password <token>', 'Password') .option('-p, --password <token>', 'Password')
.option('-t, --target-url <targetUrl>', 'Video target URL') .option('-t, --target-url <targetUrl>', 'Video target URL')
.option('-l, --language <languageCode>', 'Language code') .option('-l, --language <languageCode>', 'Language ISO 639 code (fr or en...)')
.option('-v, --verbose', 'Verbose mode') .option('-v, --verbose', 'Verbose mode')
.parse(process.argv) .parse(process.argv)
@ -82,7 +82,7 @@ async function run () {
}) })
} }
function processVideo (info: any, languageCode: number) { function processVideo (info: any, languageCode: string) {
return new Promise(async res => { return new Promise(async res => {
if (program['verbose']) console.log('Fetching object.', info) if (program['verbose']) console.log('Fetching object.', info)
@ -121,7 +121,7 @@ function processVideo (info: any, languageCode: number) {
}) })
} }
async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, language?: number) { async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, language?: string) {
const category = await getCategory(videoInfo.categories) const category = await getCategory(videoInfo.categories)
const licence = getLicence(videoInfo.license) const licence = getLicence(videoInfo.license)
let tags = [] let tags = []

View File

@ -18,7 +18,7 @@ program
.option('-c, --category <category number>', 'Category number') .option('-c, --category <category number>', 'Category number')
.option('-m, --comments-enabled', 'Enable comments') .option('-m, --comments-enabled', 'Enable comments')
.option('-l, --licence <licence number>', 'Licence number') .option('-l, --licence <licence number>', 'Licence number')
.option('-L, --language <language number>', 'Language number') .option('-L, --language <language code>', 'Language ISO 639 code (fr or en...)')
.option('-d, --video-description <description>', 'Video description') .option('-d, --video-description <description>', 'Video description')
.option('-t, --tags <tags>', 'Video tags', list) .option('-t, --tags <tags>', 'Video tags', list)
.option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path') .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')

View File

@ -3,7 +3,7 @@ import { VideoPrivacy } from './video-privacy.enum'
export interface VideoCreate { export interface VideoCreate {
category?: number category?: number
licence?: number licence?: number
language?: number language?: string
description?: string description?: string
support?: string support?: string
channelId: number channelId: number

View File

@ -4,7 +4,7 @@ export interface VideoUpdate {
name?: string name?: string
category?: number category?: number
licence?: number licence?: number
language?: number language?: string
description?: string description?: string
support?: string support?: string
privacy?: VideoPrivacy privacy?: VideoPrivacy

View File

@ -5,7 +5,7 @@ import { VideoChannel } from './video-channel.model'
import { VideoPrivacy } from './video-privacy.enum' import { VideoPrivacy } from './video-privacy.enum'
export interface VideoConstant <T> { export interface VideoConstant <T> {
id: number id: T
label: string label: string
} }
@ -25,7 +25,7 @@ export interface Video {
publishedAt: Date | string publishedAt: Date | string
category: VideoConstant<number> category: VideoConstant<number>
licence: VideoConstant<number> licence: VideoConstant<number>
language: VideoConstant<number> language: VideoConstant<string>
privacy: VideoConstant<VideoPrivacy> privacy: VideoConstant<VideoPrivacy>
description: string description: string
duration: number duration: number

View File

@ -82,9 +82,9 @@ paths:
get: get:
tags: tags:
- Feeds - Feeds
consumes:
- application/json
produces: produces:
- application/atom+xml
- application/rss+xml
- application/json - application/json
parameters: parameters:
- name: format - name: format
@ -107,9 +107,6 @@ paths:
responses: responses:
'200': '200':
description: successful operation description: successful operation
content:
application/json:
application/xml:
/jobs: /jobs:
get: get:
security: security:
@ -660,7 +657,7 @@ paths:
description: 'Video licence' description: 'Video licence'
- name: language - name: language
in: formData in: formData
type: number type: string
description: 'Video language' description: 'Video language'
- name: description - name: description
in: formData in: formData
@ -804,7 +801,7 @@ paths:
description: 'Video licence' description: 'Video licence'
- name: language - name: language
in: formData in: formData
type: number type: string
description: 'Video language' description: 'Video language'
- name: description - name: description
in: formData in: formData
@ -1245,12 +1242,18 @@ paths:
'204': '204':
description: successful operation description: successful operation
definitions: definitions:
VideoConstant: VideoConstantNumber:
properties: properties:
id: id:
type: number type: number
label: label:
type: string type: string
VideoConstantString:
properties:
id:
type: string
label:
type: string
VideoPrivacy: VideoPrivacy:
type: string type: string
enum: [Public, Unlisted, Private] enum: [Public, Unlisted, Private]
@ -1267,11 +1270,11 @@ definitions:
updatedAt: updatedAt:
type: string type: string
category: category:
$ref: "#/definitions/VideoConstant" $ref: "#/definitions/VideoConstantNumber"
licence: licence:
$ref: "#/definitions/VideoConstant" $ref: "#/definitions/VideoConstantNumber"
language: language:
$ref: "#/definitions/VideoConstant" $ref: "#/definitions/VideoConstantString"
privacy: privacy:
$ref: "#/definitions/VideoPrivacy" $ref: "#/definitions/VideoPrivacy"
description: description:

View File

@ -3239,6 +3239,10 @@ isexe@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
iso-639-3@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/iso-639-3/-/iso-639-3-1.0.1.tgz#ebdf945e1e691bc8225e41e4520fe6a51083e647"
isobject@^2.0.0: isobject@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89" resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89"