2019-03-19 03:26:07 -05:00
|
|
|
<template>
|
|
|
|
<div class="zdjebgpv" :class="{ detail }" ref="thumbnail" :style="`background-color: ${ background }`">
|
|
|
|
<img
|
|
|
|
:src="file.url"
|
|
|
|
:alt="file.name"
|
|
|
|
:title="file.name"
|
2019-04-05 10:51:31 -05:00
|
|
|
@load="onThumbnailLoaded"
|
2019-03-19 03:26:07 -05:00
|
|
|
v-if="detail && is === 'image'"/>
|
|
|
|
<video
|
|
|
|
:src="file.url"
|
|
|
|
ref="volumectrl"
|
|
|
|
preload="metadata"
|
|
|
|
controls
|
|
|
|
v-else-if="detail && is === 'video'"/>
|
|
|
|
<img :src="file.thumbnailUrl" alt="" @load="onThumbnailLoaded" :style="`object-fit: ${ fit }`" v-else-if="isThumbnailAvailable"/>
|
|
|
|
<fa :icon="faFileImage" class="icon" v-else-if="is === 'image'"/>
|
|
|
|
<fa :icon="faFileVideo" class="icon" v-else-if="is === 'video'"/>
|
|
|
|
|
|
|
|
<audio
|
|
|
|
:src="file.url"
|
|
|
|
ref="volumectrl"
|
|
|
|
preload="metadata"
|
|
|
|
controls
|
|
|
|
v-else-if="detail && is === 'audio'"/>
|
|
|
|
<fa :icon="faMusic" class="icon" v-else-if="is === 'audio' || is === 'midi'"/>
|
|
|
|
|
|
|
|
<fa :icon="faFileCsv" class="icon" v-else-if="is === 'csv'"/>
|
|
|
|
<fa :icon="faFilePdf" class="icon" v-else-if="is === 'pdf'"/>
|
|
|
|
<fa :icon="faFileAlt" class="icon" v-else-if="is === 'textfile'"/>
|
|
|
|
<fa :icon="faFileArchive" class="icon" v-else-if="is === 'archive'"/>
|
|
|
|
<fa :icon="faFile" class="icon" v-else/>
|
|
|
|
|
|
|
|
<fa :icon="faFilm" class="icon-sub" v-if="!detail && isThumbnailAvailable && is === 'video'"/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import {
|
|
|
|
faFile,
|
|
|
|
faFileAlt,
|
|
|
|
faFileImage,
|
|
|
|
faMusic,
|
|
|
|
faFileVideo,
|
|
|
|
faFileCsv,
|
|
|
|
faFilePdf,
|
|
|
|
faFileArchive,
|
|
|
|
faFilm
|
|
|
|
} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
fit: {
|
|
|
|
type: String,
|
2019-09-01 15:42:30 -05:00
|
|
|
required: false,
|
|
|
|
default: 'cover'
|
2019-03-19 03:26:07 -05:00
|
|
|
},
|
|
|
|
detail: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isContextmenuShowing: false,
|
|
|
|
isDragging: false,
|
|
|
|
|
|
|
|
faFile,
|
|
|
|
faFileAlt,
|
|
|
|
faFileImage,
|
|
|
|
faMusic,
|
|
|
|
faFileVideo,
|
|
|
|
faFileCsv,
|
|
|
|
faFilePdf,
|
|
|
|
faFileArchive,
|
|
|
|
faFilm
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
is(): 'image' | 'video' | 'midi' | 'audio' | 'csv' | 'pdf' | 'textfile' | 'archive' | 'unknown' {
|
|
|
|
if (this.file.type.startsWith('image/')) return 'image';
|
|
|
|
if (this.file.type.startsWith('video/')) return 'video';
|
|
|
|
if (this.file.type === 'audio/midi') return 'midi';
|
|
|
|
if (this.file.type.startsWith('audio/')) return 'audio';
|
|
|
|
if (this.file.type.endsWith('/csv')) return 'csv';
|
|
|
|
if (this.file.type.endsWith('/pdf')) return 'pdf';
|
|
|
|
if (this.file.type.startsWith('text/')) return 'textfile';
|
|
|
|
if ([
|
|
|
|
"application/zip",
|
|
|
|
"application/x-cpio",
|
|
|
|
"application/x-bzip",
|
|
|
|
"application/x-bzip2",
|
|
|
|
"application/java-archive",
|
|
|
|
"application/x-rar-compressed",
|
|
|
|
"application/x-tar",
|
|
|
|
"application/gzip",
|
|
|
|
"application/x-7z-compressed"
|
|
|
|
].some(e => e === this.file.type)) return 'archive';
|
|
|
|
return 'unknown';
|
|
|
|
},
|
|
|
|
isThumbnailAvailable(): boolean {
|
2019-03-19 09:35:22 -05:00
|
|
|
return this.file.thumbnailUrl
|
2019-04-14 03:12:04 -05:00
|
|
|
? (this.is === 'image' || this.is === 'video')
|
2019-03-19 09:35:22 -05:00
|
|
|
: false;
|
2019-03-19 03:26:07 -05:00
|
|
|
},
|
|
|
|
background(): string {
|
2019-04-08 05:56:42 -05:00
|
|
|
return this.file.properties.avgColor || 'transparent';
|
2019-03-19 03:26:07 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
const audioTag = this.$refs.volumectrl as HTMLAudioElement;
|
|
|
|
if (audioTag) audioTag.volume = this.$store.state.device.mediaVolume;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onThumbnailLoaded() {
|
2019-04-08 05:56:42 -05:00
|
|
|
if (this.file.properties.avgColor) {
|
2020-01-29 13:37:25 -06:00
|
|
|
this.$refs.thumbnail.style.backgroundColor = 'transparent';
|
2019-03-19 03:26:07 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
volumechange() {
|
|
|
|
const audioTag = this.$refs.volumectrl as HTMLAudioElement;
|
|
|
|
this.$store.commit('device/set', { key: 'mediaVolume', value: audioTag.volume });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.zdjebgpv {
|
|
|
|
display: flex;
|
2019-03-19 03:26:07 -05:00
|
|
|
|
|
|
|
> img,
|
2020-01-29 13:37:25 -06:00
|
|
|
> .icon {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2019-03-19 03:26:07 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .icon-sub {
|
|
|
|
position: absolute;
|
|
|
|
width: 30%;
|
|
|
|
height: auto;
|
|
|
|
margin: 0;
|
|
|
|
right: 4%;
|
|
|
|
bottom: 4%;
|
|
|
|
}
|
2019-03-19 03:26:07 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> * {
|
|
|
|
margin: auto;
|
|
|
|
}
|
2019-04-05 10:51:31 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
&:not(.detail) {
|
|
|
|
> img {
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
object-fit: cover;
|
|
|
|
}
|
2019-04-05 10:51:31 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> .icon {
|
|
|
|
height: 65%;
|
|
|
|
width: 65%;
|
|
|
|
}
|
2019-04-05 10:51:31 -05:00
|
|
|
|
|
|
|
> video,
|
2020-01-29 13:37:25 -06:00
|
|
|
> audio {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 10:51:31 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
&.detail {
|
|
|
|
> .icon {
|
|
|
|
height: 100px;
|
|
|
|
width: 100px;
|
|
|
|
margin: 16px;
|
|
|
|
}
|
2019-03-19 03:26:07 -05:00
|
|
|
|
2020-01-29 13:37:25 -06:00
|
|
|
> *:not(.icon) {
|
|
|
|
max-height: 300px;
|
|
|
|
max-width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
object-fit: contain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-19 03:26:07 -05:00
|
|
|
</style>
|