Fix watching video in development (#1668)

* Fix watching watched video in development

* Fix removing a file even when it does not exist (and would raise error)

* Fix infinite reload in video watching

File updates (e.g. dashFiles) in static folder triggers app reload (web-dev-server)
But the a file is created/updated/deleted on before playing any video
So it goes into a loop of loading a video
This commit is contained in:
PikachuEXE 2021-09-23 15:04:00 +08:00 committed by GitHub
parent b1a310ef09
commit 07fd93d3aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -116,7 +116,12 @@ function startRenderer(callback) {
})
const server = new WebpackDevServer(compiler, {
static: path.join(process.cwd(), 'static'),
static: {
directory: path.join(process.cwd(), 'static'),
watch: {
ignored: /(dashFiles|storyboards)\/*/
}
},
port
})

View File

@ -960,13 +960,13 @@ export default Vue.extend({
if (this.removeVideoMetaFiles) {
const userData = await this.getUserDataPath()
if (this.isDev) {
const dashFileLocation = `dashFiles/${this.videoId}.xml`
const vttFileLocation = `storyboards/${this.videoId}.vtt`
const dashFileLocation = `static/dashFiles/${this.videoId}.xml`
const vttFileLocation = `static/storyboards/${this.videoId}.vtt`
// only delete the file it actually exists
if (fs.existsSync('dashFiles/') && fs.existsSync(dashFileLocation)) {
if (fs.existsSync('static/dashFiles/') && fs.existsSync(dashFileLocation)) {
fs.rmSync(dashFileLocation)
}
if (fs.existsSync('storyboards/') && fs.existsSync(vttFileLocation)) {
if (fs.existsSync('static/storyboards/') && fs.existsSync(vttFileLocation)) {
fs.rmSync(vttFileLocation)
}
} else {
@ -1014,9 +1014,10 @@ export default Vue.extend({
fs.mkdirSync('static/dashFiles/')
}
fs.rm(fileLocation, () => {
fs.writeFileSync(fileLocation, xmlData)
})
if (fs.existsSync(fileLocation)) {
fs.rmSync(fileLocation)
}
fs.writeFileSync(fileLocation, xmlData)
} else {
fileLocation = `${userData}/dashFiles/${this.videoId}.xml`
uriSchema = `file://${fileLocation}`