Improve SOC for Upload component
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
73e51ef1b9
commit
c25301b3d2
|
@ -1,45 +1,46 @@
|
||||||
<template>
|
<template>
|
||||||
<Card class="upload" v-cloak @drop.prevent="fileDropped" @dragover.prevent>
|
<Card class="dropZone" @dragover.prevent @drop.prevent @drop="selected" @click="$refs.fileInput.click()">
|
||||||
<template #content>
|
<template #content>
|
||||||
<div class="p-text-center">
|
<div class="p-text-center">
|
||||||
<i class="pi pi-upload"></i>
|
<i class="pi pi-upload"></i>
|
||||||
<h2>Drag a H.264 encoded MP4 here to start a screen.</h2>
|
<h2>{{ message }}</h2>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Card>
|
</Card>
|
||||||
|
<input type="file" hidden="true" ref="fileInput" @change="selected" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { useToast } from 'primevue/usetoast'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup () {
|
emits: [
|
||||||
const toast = useToast()
|
'selected'
|
||||||
function fileDropped (e) {
|
],
|
||||||
if (e.dataTransfer.files.length !== 1) {
|
props: [
|
||||||
toast.add({ severity: 'error', summary: 'Bad file', detail: 'Please select only a single file.', life: 3000 })
|
'message'
|
||||||
return
|
],
|
||||||
}
|
setup (props, context) {
|
||||||
|
const selected = (event) => {
|
||||||
const file = e.dataTransfer.files[0]
|
const files = event.dataTransfer ? event.dataTransfer.files : event.target.files
|
||||||
if (!file.name.endsWith('.mp4') || !file.type === 'video/mp4') {
|
context.emit('selected', files)
|
||||||
toast.add({ severity: 'error', summary: 'Bad file', detail: 'File must be a H.264 encoded MP4.', life: 3000 })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fileDropped
|
selected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style lang="scss">
|
||||||
.upload {
|
.dropZone {
|
||||||
color: rgba(0,0,0,0.4)
|
cursor: pointer;
|
||||||
|
|
||||||
|
i, h2 {
|
||||||
|
color: #aaaaaa
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i.pi.pi-upload {
|
i.pi.pi-upload {
|
||||||
font-size: 5em;
|
font-size: 5em
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,14 +1,38 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="p-p-6">
|
<div class="p-p-6">
|
||||||
<h1 class="p-my-0">Host</h1>
|
<h1 class="p-my-0">Host</h1>
|
||||||
<Upload />
|
<Upload v-if="!file" message="Drag a H.264 encoded MP4 here to start a screen." @selected="filesSelected" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { useToast } from 'primevue/usetoast'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup () {
|
setup () {
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
|
const file = ref()
|
||||||
|
|
||||||
|
const filesSelected = (files) => {
|
||||||
|
if (files?.length !== 1) {
|
||||||
|
toast.add({ severity: 'error', summary: 'Bad file input', detail: 'You must select only one file.', life: 3000 })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!files[0].name.endsWith('.mp4') || files[0].type !== 'video/mp4') {
|
||||||
|
toast.add({ severity: 'error', summary: 'Bad file input', detail: 'Only H.264 encoded MP4s are supported.', life: 3000 })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file.value = files[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
filesSelected,
|
||||||
|
file
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue