Add fileTypeService

This commit is contained in:
dtluna 2016-11-25 20:21:25 +03:00
parent 96b4997492
commit 4f8d476a2b
5 changed files with 36 additions and 17 deletions

View file

@ -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: {

View file

@ -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)
}
}
}

View file

@ -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'>