|
|
@ -15,18 +15,17 @@
|
|
|
|
<script setup>
|
|
|
|
<script setup>
|
|
|
|
|
|
|
|
|
|
|
|
import {ref, computed} from 'vue'
|
|
|
|
import {ref, computed} from 'vue'
|
|
|
|
const emit = defineEmits(['upload', 'filename'])
|
|
|
|
const emit = defineEmits(['upload', 'file'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dropFile = ref([])
|
|
|
|
const file = ref([])
|
|
|
|
|
|
|
|
const fileType = ref("")
|
|
|
|
const fileType = ref("")
|
|
|
|
const thumb = ref(null)
|
|
|
|
const thumb = ref(null)
|
|
|
|
const loading = ref(false)
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dragFile = (e) => {
|
|
|
|
const dragFile = (e) => {
|
|
|
|
file.value = e.dataTransfer.files[0]
|
|
|
|
dropFile.value = e.dataTransfer.files[0]
|
|
|
|
createPreview(file.value)
|
|
|
|
createPreview(dropFile.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const container = computed(()=>{
|
|
|
|
const container = computed(()=>{
|
|
|
@ -39,9 +38,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
loading.value = true
|
|
|
|
loading.value = true
|
|
|
|
|
|
|
|
|
|
|
|
const fileName = file.name
|
|
|
|
|
|
|
|
emit('filename', fileName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get file type
|
|
|
|
// get file type
|
|
|
|
fileType.value = file.type.toLowerCase().substr(0, file.type.indexOf("/"))
|
|
|
|
fileType.value = file.type.toLowerCase().substr(0, file.type.indexOf("/"))
|
|
|
|
|
|
|
|
|
|
|
@ -55,6 +51,8 @@
|
|
|
|
fileToRead = await videoSnapshot(filePath)
|
|
|
|
fileToRead = await videoSnapshot(filePath)
|
|
|
|
filePath = (window.URL || window.webkitURL).createObjectURL(fileToRead)
|
|
|
|
filePath = (window.URL || window.webkitURL).createObjectURL(fileToRead)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit('file', fileToRead)
|
|
|
|
|
|
|
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
const reader = new FileReader()
|
|
|
|
reader.readAsDataURL(fileToRead)
|
|
|
|
reader.readAsDataURL(fileToRead)
|
|
|
@ -65,6 +63,7 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: scale image to thumb size
|
|
|
|
const imageSnapshot = (url) => {
|
|
|
|
const imageSnapshot = (url) => {
|
|
|
|
thumb.value.src = url
|
|
|
|
thumb.value.src = url
|
|
|
|
emit('upload', url)
|
|
|
|
emit('upload', url)
|
|
|
@ -80,12 +79,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
const snapshot = async () => {
|
|
|
|
const snapshot = async () => {
|
|
|
|
let canvas = document.createElement('canvas')
|
|
|
|
let canvas = document.createElement('canvas')
|
|
|
|
canvas.width = 1280
|
|
|
|
canvas.width = 640
|
|
|
|
canvas.height = 720
|
|
|
|
canvas.height = 360
|
|
|
|
let ctx = canvas.getContext('2d')
|
|
|
|
let ctx = canvas.getContext('2d')
|
|
|
|
|
|
|
|
|
|
|
|
ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
|
|
|
|
ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
|
|
|
|
thumb.value.src = canvas.toDataURL('image/png')
|
|
|
|
thumb.value.src = canvas.toDataURL('image/jpeg')
|
|
|
|
loading.value = false
|
|
|
|
loading.value = false
|
|
|
|
video.removeEventListener('canplay', snapshot)
|
|
|
|
video.removeEventListener('canplay', snapshot)
|
|
|
|
let file = await dataUrlToFile(thumb.value.src, 'snapshot')
|
|
|
|
let file = await dataUrlToFile(thumb.value.src, 'snapshot')
|
|
|
@ -101,7 +100,7 @@
|
|
|
|
// in order not to have super long src urls for snapshot in the DOM
|
|
|
|
// in order not to have super long src urls for snapshot in the DOM
|
|
|
|
const res = await fetch(dataUrl);
|
|
|
|
const res = await fetch(dataUrl);
|
|
|
|
const blob = await res.blob();
|
|
|
|
const blob = await res.blob();
|
|
|
|
return new File([blob], fileName, { type: 'image/png' });
|
|
|
|
return new File([blob], fileName, { type: 'image/jpeg' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|