fix(core): encode URLs to files to handle special characters

Fixes #229
pull/224/head^2
Romain 3 years ago
parent 590b14079f
commit c3ca18d97e

@ -24,7 +24,7 @@ class File {
this.type = mediaType(dbEntry)
this.isVideo = (this.type === 'video')
this.output = output.paths(this.path, this.type, opts || {})
this.urls = _.mapValues(this.output, o => o.path.replace('\\', '/'))
this.urls = _.mapValues(this.output, o => pathToUrl(o.path))
this.meta = meta
}
}
@ -40,4 +40,8 @@ function mediaType (dbEntry) {
return 'unknown'
}
function pathToUrl (filepath) {
return encodeURI(filepath.replace('\\', '/'))
}
module.exports = File

@ -51,6 +51,22 @@ describe('File', function () {
const video = new File(dbFile({ File: { MIMEType: 'video/quicktime' } }))
should(video.isVideo).eql(true)
})
it('exposes the URL for each output file', function () {
const file = new File(dbFile({ File: { MIMEType: 'image/jpeg' } }))
should(file.urls.thumbnail).eql('media/thumbs/photo.jpg')
should(file.urls.small).eql('media/small/photo.jpg')
should(file.urls.large).eql('media/large/photo.jpg')
should(file.urls.download).eql('media/large/photo.jpg')
})
it('encodes the URLs to cater for special characters', function () {
const file = new File(dbFile({
SourceFile: 'test%22folder/photo.jpg',
File: { MIMEType: 'image/jpeg' }
}))
should(file.urls.small).eql('media/small/test%2522folder/photo.jpg')
})
})
function dbFile (data) {

Loading…
Cancel
Save