Improve SOC for Upload component
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jack Hadrill 2021-01-04 01:45:01 +00:00
parent 73e51ef1b9
commit c25301b3d2
2 changed files with 47 additions and 22 deletions

View File

@ -1,45 +1,46 @@
<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>
<div class="p-text-center">
<i class="pi pi-upload"></i>
<h2>Drag a H.264 encoded MP4 here to start a screen.</h2>
<h2>{{ message }}</h2>
</div>
</template>
</Card>
<input type="file" hidden="true" ref="fileInput" @change="selected" />
</template>
<script>
import { useToast } from 'primevue/usetoast'
export default {
setup () {
const toast = useToast()
function fileDropped (e) {
if (e.dataTransfer.files.length !== 1) {
toast.add({ severity: 'error', summary: 'Bad file', detail: 'Please select only a single file.', life: 3000 })
return
}
const file = e.dataTransfer.files[0]
if (!file.name.endsWith('.mp4') || !file.type === 'video/mp4') {
toast.add({ severity: 'error', summary: 'Bad file', detail: 'File must be a H.264 encoded MP4.', life: 3000 })
}
emits: [
'selected'
],
props: [
'message'
],
setup (props, context) {
const selected = (event) => {
const files = event.dataTransfer ? event.dataTransfer.files : event.target.files
context.emit('selected', files)
}
return {
fileDropped
selected
}
}
}
</script>
<style>
.upload {
color: rgba(0,0,0,0.4)
<style lang="scss">
.dropZone {
cursor: pointer;
i, h2 {
color: #aaaaaa
}
}
i.pi.pi-upload {
font-size: 5em;
font-size: 5em
}
</style>

View File

@ -1,14 +1,38 @@
<template>
<div class="p-p-6">
<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>
</template>
<script>
import { useToast } from 'primevue/usetoast'
import { ref } from 'vue'
export default {
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>