2019-01-26 16:45:03 +01:00
|
|
|
// TODO this func might as well take the entire file and use its mimetype
|
|
|
|
// or the entire service could be just mimetype service that only operates
|
|
|
|
// on mimetypes and not files. Currently the naming is confusing.
|
|
|
|
const fileType = mimetype => {
|
2021-04-09 18:09:22 +02:00
|
|
|
if (mimetype.match(/flash/)) {
|
|
|
|
return 'flash'
|
|
|
|
}
|
|
|
|
|
2019-01-26 16:45:03 +01:00
|
|
|
if (mimetype.match(/text\/html/)) {
|
|
|
|
return 'html'
|
2016-11-25 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:45:03 +01:00
|
|
|
if (mimetype.match(/image/)) {
|
|
|
|
return 'image'
|
2016-11-25 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:45:03 +01:00
|
|
|
if (mimetype.match(/video/)) {
|
|
|
|
return 'video'
|
2016-11-25 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:45:03 +01:00
|
|
|
if (mimetype.match(/audio/)) {
|
|
|
|
return 'audio'
|
2016-11-25 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:45:03 +01:00
|
|
|
return 'unknown'
|
2016-11-25 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:45:03 +01:00
|
|
|
const fileMatchesSomeType = (types, file) =>
|
|
|
|
types.some(type => fileType(file.mimetype) === type)
|
|
|
|
|
2016-11-25 18:21:25 +01:00
|
|
|
const fileTypeService = {
|
2019-01-26 16:45:03 +01:00
|
|
|
fileType,
|
|
|
|
fileMatchesSomeType
|
2016-11-25 18:21:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default fileTypeService
|