Fix caption upload on Mac OS
This commit is contained in:
parent
9484e1f6fc
commit
2769e297ca
|
@ -167,7 +167,7 @@
|
||||||
"chai-json-schema": "^1.5.0",
|
"chai-json-schema": "^1.5.0",
|
||||||
"chai-xml": "^0.3.2",
|
"chai-xml": "^0.3.2",
|
||||||
"husky": "^1.0.0-rc.4",
|
"husky": "^1.0.0-rc.4",
|
||||||
"libxmljs": "0.19.1",
|
"libxmljs": "0.19.0",
|
||||||
"lint-staged": "^7.1.0",
|
"lint-staged": "^7.1.0",
|
||||||
"maildev": "^1.0.0-rc3",
|
"maildev": "^1.0.0-rc3",
|
||||||
"mocha": "^5.0.0",
|
"mocha": "^5.0.0",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES, VIDEO_MIMETYPE_EXT } from '../../initializers'
|
import { CONSTRAINTS_FIELDS, VIDEO_CAPTIONS_MIMETYPE_EXT, VIDEO_LANGUAGES } from '../../initializers'
|
||||||
import { exists, isFileValid } from './misc'
|
import { exists, isFileValid } from './misc'
|
||||||
import { Response } from 'express'
|
import { Response } from 'express'
|
||||||
import { VideoModel } from '../../models/video/video'
|
import { VideoModel } from '../../models/video/video'
|
||||||
|
@ -8,7 +8,9 @@ function isVideoCaptionLanguageValid (value: any) {
|
||||||
return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined
|
return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoCaptionTypes = Object.keys(VIDEO_CAPTIONS_MIMETYPE_EXT).map(m => `(${m})`)
|
const videoCaptionTypes = Object.keys(VIDEO_CAPTIONS_MIMETYPE_EXT)
|
||||||
|
.concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream ><
|
||||||
|
.map(m => `(${m})`)
|
||||||
const videoCaptionTypesRegex = videoCaptionTypes.join('|')
|
const videoCaptionTypesRegex = videoCaptionTypes.join('|')
|
||||||
function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
|
function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
|
||||||
return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
|
return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { CONFIG, REMOTE_SCHEME } from '../initializers'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { User } from '../../shared/models/users'
|
import { User } from '../../shared/models/users'
|
||||||
import { generateRandomString } from './utils'
|
import { generateRandomString } from './utils'
|
||||||
|
import { extname } from 'path'
|
||||||
|
|
||||||
function buildNSFWFilter (res: express.Response, paramNSFW?: string) {
|
function buildNSFWFilter (res: express.Response, paramNSFW?: string) {
|
||||||
if (paramNSFW === 'true') return true
|
if (paramNSFW === 'true') return true
|
||||||
|
@ -50,7 +51,7 @@ function createReqFiles (
|
||||||
},
|
},
|
||||||
|
|
||||||
filename: async (req, file, cb) => {
|
filename: async (req, file, cb) => {
|
||||||
const extension = mimeTypes[ file.mimetype ]
|
const extension = mimeTypes[ file.mimetype ] || extname(file.originalname)
|
||||||
let randomString = ''
|
let randomString = ''
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
userLogin
|
userLogin
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
import { createVideoCaption } from '../../utils/videos/video-captions'
|
||||||
|
|
||||||
describe('Test video captions API validator', function () {
|
describe('Test video captions API validator', function () {
|
||||||
const path = '/api/v1/videos/'
|
const path = '/api/v1/videos/'
|
||||||
|
@ -143,6 +144,31 @@ describe('Test video captions API validator', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// We don't check the extension yet
|
||||||
|
// it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
|
||||||
|
// await createVideoCaption({
|
||||||
|
// url: server.url,
|
||||||
|
// accessToken: server.accessToken,
|
||||||
|
// language: 'zh',
|
||||||
|
// videoId: videoUUID,
|
||||||
|
// fixture: 'subtitle-bad.txt',
|
||||||
|
// mimeType: 'application/octet-stream',
|
||||||
|
// statusCodeExpected: 400
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
|
||||||
|
it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
|
||||||
|
await createVideoCaption({
|
||||||
|
url: server.url,
|
||||||
|
accessToken: server.accessToken,
|
||||||
|
language: 'zh',
|
||||||
|
videoId: videoUUID,
|
||||||
|
fixture: 'subtitle-good.srt',
|
||||||
|
mimeType: 'application/octet-stream'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// We don't check the file validity yet
|
||||||
// it('Should fail with an invalid captionfile srt', async function () {
|
// it('Should fail with an invalid captionfile srt', async function () {
|
||||||
// const attaches = {
|
// const attaches = {
|
||||||
// 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
|
// 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
|
||||||
|
|
|
@ -56,7 +56,8 @@ describe('Test video captions', function () {
|
||||||
accessToken: servers[0].accessToken,
|
accessToken: servers[0].accessToken,
|
||||||
language: 'zh',
|
language: 'zh',
|
||||||
videoId: videoUUID,
|
videoId: videoUUID,
|
||||||
fixture: 'subtitle-good2.vtt'
|
fixture: 'subtitle-good2.vtt',
|
||||||
|
mimeType: 'application/octet-stream'
|
||||||
})
|
})
|
||||||
|
|
||||||
await waitJobs(servers)
|
await waitJobs(servers)
|
||||||
|
|
|
@ -48,7 +48,7 @@ function makeUploadRequest (options: {
|
||||||
path: string,
|
path: string,
|
||||||
token?: string,
|
token?: string,
|
||||||
fields: { [ fieldName: string ]: any },
|
fields: { [ fieldName: string ]: any },
|
||||||
attaches: { [ attachName: string ]: any },
|
attaches: { [ attachName: string ]: any | any[] },
|
||||||
statusCodeExpected?: number
|
statusCodeExpected?: number
|
||||||
}) {
|
}) {
|
||||||
if (!options.statusCodeExpected) options.statusCodeExpected = 400
|
if (!options.statusCodeExpected) options.statusCodeExpected = 400
|
||||||
|
@ -78,7 +78,11 @@ function makeUploadRequest (options: {
|
||||||
|
|
||||||
Object.keys(options.attaches).forEach(attach => {
|
Object.keys(options.attaches).forEach(attach => {
|
||||||
const value = options.attaches[attach]
|
const value = options.attaches[attach]
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1])
|
||||||
|
} else {
|
||||||
req.attach(attach, buildAbsoluteFixturePath(value))
|
req.attach(attach, buildAbsoluteFixturePath(value))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return req.expect(options.statusCodeExpected)
|
return req.expect(options.statusCodeExpected)
|
||||||
|
|
|
@ -10,10 +10,15 @@ function createVideoCaption (args: {
|
||||||
accessToken: string
|
accessToken: string
|
||||||
videoId: string | number
|
videoId: string | number
|
||||||
language: string
|
language: string
|
||||||
fixture: string
|
fixture: string,
|
||||||
|
mimeType?: string,
|
||||||
|
statusCodeExpected?: number
|
||||||
}) {
|
}) {
|
||||||
const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
|
const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
|
||||||
|
|
||||||
|
const captionfile = buildAbsoluteFixturePath(args.fixture)
|
||||||
|
const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
|
||||||
|
|
||||||
return makeUploadRequest({
|
return makeUploadRequest({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
url: args.url,
|
url: args.url,
|
||||||
|
@ -21,9 +26,9 @@ function createVideoCaption (args: {
|
||||||
token: args.accessToken,
|
token: args.accessToken,
|
||||||
fields: {},
|
fields: {},
|
||||||
attaches: {
|
attaches: {
|
||||||
captionfile: buildAbsoluteFixturePath(args.fixture)
|
captionfile: captionfileAttach
|
||||||
},
|
},
|
||||||
statusCodeExpected: 204
|
statusCodeExpected: args.statusCodeExpected || 204
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue