Skip to content

Commit

Permalink
🐛 build url outside worker
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZhang73 committed Nov 14, 2023
1 parent 8209f9a commit 65a838a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/VideoLoaderV2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { onMounted, watch } from 'vue'
import utils from '~/libs/utils.js'
import { useAnnotationStore } from '~/store/annotation.js'
import { usePreferenceStore } from '~/store/preference.js'
import VideoProcessWorker from '../worker/video-process-worker.js?worker'
import VideoProcessWorker from '~/worker/video-process-worker.js?worker'
const annotationStore = useAnnotationStore()
const preferenceStore = usePreferenceStore()
Expand All @@ -18,7 +18,9 @@ onMounted(() => {
}
if (newValue) {
worker = new VideoProcessWorker()
worker.postMessage({ src: newValue, defaultFps: preferenceStore.defaultFps })
// Parse the src into a ful URL (the worker does not know the current web root)
const srcURL = new URL(newValue, window.location.href).href
worker.postMessage({ src: srcURL, defaultFps: preferenceStore.defaultFps })
annotationStore.cachedFrameList = []
annotationStore.isCaching = true
worker.onmessage = event => {
Expand Down
4 changes: 2 additions & 2 deletions src/worker/video-process-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ onmessage = async (event) => {
headers['Range'] = `bytes=${leftOffset}-`
} else {
headers['Range'] = `bytes=${rightOffset}-${rightOffset + probeUnit -
1}`
1}`
}
const response = await fetch(
(new URL(event.data.src, new URL('..', event.target.location)).href),
event.data.src,
{
signal: abortController.signal,
headers,
Expand Down

0 comments on commit 65a838a

Please sign in to comment.