aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorshpuld <shp@cock.li>2019-01-26 17:45:03 +0200
committershpuld <shp@cock.li>2019-01-26 17:45:03 +0200
commit3978aaef84cc023908155343af76983f2715cf90 (patch)
tree0776b181029151d45450e472d1540715040bcab0 /src/services
parent8761e039d04ff26944c87339ef55d2951a42696c (diff)
Redo everything in the MR
Diffstat (limited to 'src/services')
-rw-r--r--src/services/file_type/file_type.service.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/services/file_type/file_type.service.js b/src/services/file_type/file_type.service.js
index f543ec79..2a046bec 100644
--- a/src/services/file_type/file_type.service.js
+++ b/src/services/file_type/file_type.service.js
@@ -1,27 +1,32 @@
-const fileType = (typeString) => {
- let type = 'unknown'
-
- if (typeString.match(/text\/html/)) {
- type = 'html'
+// 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 => {
+ if (mimetype.match(/text\/html/)) {
+ return 'html'
}
- if (typeString.match(/image/)) {
- type = 'image'
+ if (mimetype.match(/image/)) {
+ return 'image'
}
- if (typeString.match(/video/)) {
- type = 'video'
+ if (mimetype.match(/video/)) {
+ return 'video'
}
- if (typeString.match(/audio/)) {
- type = 'audio'
+ if (mimetype.match(/audio/)) {
+ return 'audio'
}
- return type
+ return 'unknown'
}
+const fileMatchesSomeType = (types, file) =>
+ types.some(type => fileType(file.mimetype) === type)
+
const fileTypeService = {
- fileType
+ fileType,
+ fileMatchesSomeType
}
export default fileTypeService