aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordtluna <dtluna@openmailbox.org>2016-11-25 20:21:25 +0300
committerdtluna <dtluna@openmailbox.org>2016-11-25 20:21:25 +0300
commit4f8d476a2b5ff9bb75f8300665e2c18aa96fecfd (patch)
tree96141e9f35c4597f30e843e6874f9867b49a420e
parent96b4997492a5d784bc318524ed86cc414ca74720 (diff)
Add fileTypeService
-rw-r--r--src/components/attachment/attachment.js17
-rw-r--r--src/components/post_status_form/post_status_form.js4
-rw-r--r--src/components/post_status_form/post_status_form.vue2
-rw-r--r--src/services/file_type/file_type.service.js27
-rw-r--r--src/services/status_poster/status_poster.service.js3
5 files changed, 36 insertions, 17 deletions
diff --git a/src/components/attachment/attachment.js b/src/components/attachment/attachment.js
index 99958589..fa43c12f 100644
--- a/src/components/attachment/attachment.js
+++ b/src/components/attachment/attachment.js
@@ -1,4 +1,5 @@
import nsfwImage from '../../assets/nsfw.jpg'
+import fileTypeService from '../../services/file_type/file_type.service.js'
const Attachment = {
props: [
@@ -9,21 +10,7 @@ const Attachment = {
data: () => ({ nsfwImage }),
computed: {
type () {
- let type = 'unknown'
-
- if (this.attachment.mimetype.match(/text\/html/)) {
- type = 'html'
- }
-
- if (this.attachment.mimetype.match(/image/)) {
- type = 'image'
- }
-
- if (this.attachment.mimetype.match(/video\/(webm|mp4)/)) {
- type = 'video'
- };
-
- return type
+ return fileTypeService.fileType(this.attachment.mimetype)
}
},
methods: {
diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js
index 58c11fb9..60698e6e 100644
--- a/src/components/post_status_form/post_status_form.js
+++ b/src/components/post_status_form/post_status_form.js
@@ -1,5 +1,6 @@
import statusPoster from '../../services/status_poster/status_poster.service.js'
import MediaUpload from '../media_upload/media_upload.vue'
+import fileTypeService from '../../services/file_type/file_type.service.js'
import { reject, map, uniqBy } from 'lodash'
@@ -67,6 +68,9 @@ const PostStatusForm = {
},
enableSubmit () {
this.submitDisabled = false
+ },
+ type (fileInfo) {
+ return fileTypeService.fileType(fileInfo.mimetype)
}
}
}
diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue
index 3709a6f6..a935a984 100644
--- a/src/components/post_status_form/post_status_form.vue
+++ b/src/components/post_status_form/post_status_form.vue
@@ -6,7 +6,7 @@
</div>
<div class="attachments">
<div class="attachment" v-for="file in newStatus.files">
- <img class="thumbnail media-upload" :src="file.image"></img>
+ <img class="thumbnail media-upload" :src="file.image" v-if="type(file) === 'image'"></img>
</div>
</div>
<div class='form-bottom'>
diff --git a/src/services/file_type/file_type.service.js b/src/services/file_type/file_type.service.js
new file mode 100644
index 00000000..f9d3b466
--- /dev/null
+++ b/src/services/file_type/file_type.service.js
@@ -0,0 +1,27 @@
+const fileType = (typeString) => {
+ let type = 'unknown'
+
+ if (typeString.match(/text\/html/)) {
+ type = 'html'
+ }
+
+ if (typeString.match(/image/)) {
+ type = 'image'
+ }
+
+ if (typeString.match(/video\/(webm|mp4)/)) {
+ type = 'video'
+ }
+
+ if (typeString.match(/audio|ogg/)) {
+ type = 'audio'
+ }
+
+ return type
+}
+
+const fileTypeService = {
+ fileType
+}
+
+export default fileTypeService
diff --git a/src/services/status_poster/status_poster.service.js b/src/services/status_poster/status_poster.service.js
index 1cc97c7a..5b50231a 100644
--- a/src/services/status_poster/status_poster.service.js
+++ b/src/services/status_poster/status_poster.service.js
@@ -19,7 +19,8 @@ const uploadMedia = ({ store, formData }) => {
return {
id: xml.getElementsByTagName('media_id')[0].textContent,
url: xml.getElementsByTagName('media_url')[0].textContent,
- image: xml.getElementsByTagName('atom:link')[0].getAttribute('href')
+ image: xml.getElementsByTagName('atom:link')[0].getAttribute('href'),
+ mimetype: xml.getElementsByTagName('atom:link')[0].getAttribute('type')
}
})
}