fix media downloading paths
This commit is contained in:
parent
bc93da2a31
commit
4edeaf45f9
2
app.js
2
app.js
|
@ -103,4 +103,4 @@ redis.on('error', (error) => {
|
||||||
if(config.https_enabled) {
|
if(config.https_enabled) {
|
||||||
https.listen(config.ssl_port, '::', () => console.log(`Teddit running on https://${config.domain}`))
|
https.listen(config.ssl_port, '::', () => console.log(`Teddit running on https://${config.domain}`))
|
||||||
}
|
}
|
||||||
http.listen(config.nonssl_port, '::', () => console.log(`Teddit running on http://${config.domain}:${config.nonssl_port}`))
|
http.listen(config.nonssl_port, '::', () => console.log(`Teddit running on http://${config.domain}`))
|
||||||
|
|
|
@ -49,8 +49,8 @@ module.exports = function(tools) {
|
||||||
resolve('')
|
resolve('')
|
||||||
} else {
|
} else {
|
||||||
let filename = `${temp_url.pathname.substr(1).split('/')[0]}.${file_ext}`
|
let filename = `${temp_url.pathname.substr(1).split('/')[0]}.${file_ext}`
|
||||||
let path = `${__dirname}/../dist/vids/${filename}`
|
let path = `./dist/vids/${filename}`
|
||||||
let temp_path = `${__dirname}/../dist/vids/temp_${filename}`
|
let temp_path = `./dist/vids/temp_${filename}`
|
||||||
if(!fs.existsSync(path)) {
|
if(!fs.existsSync(path)) {
|
||||||
const download = await downloadFile(cleanUrl(url))
|
const download = await downloadFile(cleanUrl(url))
|
||||||
if(download.success === true) {
|
if(download.success === true) {
|
||||||
|
@ -65,13 +65,13 @@ module.exports = function(tools) {
|
||||||
}
|
}
|
||||||
const download_audio = await downloadFile(cleanUrl(audio_url))
|
const download_audio = await downloadFile(cleanUrl(audio_url))
|
||||||
if(download_audio.success === true) {
|
if(download_audio.success === true) {
|
||||||
let audio_path = `${__dirname}/../dist/vids/temp_audio_${filename}`
|
let audio_path = `./dist/vids/temp_audio_${filename}`
|
||||||
const write_audio = await writeToDisk(download_audio.data, audio_path)
|
const write_audio = await writeToDisk(download_audio.data, audio_path)
|
||||||
if(write_audio.success === true) {
|
if(write_audio.success === true) {
|
||||||
let processVideo = spawn('ffmpeg', ['-y', '-i', temp_path, '-i', audio_path, '-c', 'copy', path])
|
let processVideo = spawn('ffmpeg', ['-y', '-i', temp_path, '-i', audio_path, '-c', 'copy', path])
|
||||||
processVideo.on('exit', (code) => {
|
processVideo.on('exit', (code) => {
|
||||||
if(code === 0) {
|
if(code === 0) {
|
||||||
let final_url = `${protocol}${config.domain}/vids/${filename}`
|
let final_url = `/vids/${filename}`
|
||||||
let temp_files = [temp_path, audio_path]
|
let temp_files = [temp_path, audio_path]
|
||||||
deleteFiles(temp_files, (error) => {
|
deleteFiles(temp_files, (error) => {
|
||||||
if(error) {
|
if(error) {
|
||||||
|
@ -97,7 +97,7 @@ module.exports = function(tools) {
|
||||||
if(error) {
|
if(error) {
|
||||||
console.log(`Error while renaming the temp video file: ${temp_path} => ${path}.`, error)
|
console.log(`Error while renaming the temp video file: ${temp_path} => ${path}.`, error)
|
||||||
} else {
|
} else {
|
||||||
let final_url = `${protocol}${config.domain}/vids/${filename}`
|
let final_url = `/vids/${filename}`
|
||||||
resolve(final_url)
|
resolve(final_url)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -111,7 +111,7 @@ module.exports = function(tools) {
|
||||||
resolve('')
|
resolve('')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(`${protocol}${config.domain}/vids/${filename}`)
|
resolve(`/vids/${filename}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,13 +126,13 @@ module.exports = function(tools) {
|
||||||
}
|
}
|
||||||
filename = `${file_prefix}w:${temp_url.searchParams.get('width')}_${temp_url.pathname.split('/').slice(-1)}`
|
filename = `${file_prefix}w:${temp_url.searchParams.get('width')}_${temp_url.pathname.split('/').slice(-1)}`
|
||||||
}
|
}
|
||||||
path = `${__dirname}/../dist/pics/${filename}`
|
path = `./dist/pics/${filename}`
|
||||||
if(!fs.existsSync(path)) {
|
if(!fs.existsSync(path)) {
|
||||||
const download = await downloadFile(cleanUrl(url))
|
const download = await downloadFile(cleanUrl(url))
|
||||||
if(download.success === true) {
|
if(download.success === true) {
|
||||||
const write = await writeToDisk(download.data, path)
|
const write = await writeToDisk(download.data, path)
|
||||||
if(write.success === true) {
|
if(write.success === true) {
|
||||||
let final_url = `${protocol}${config.domain}/pics/${filename}`
|
let final_url = `/pics/${filename}`
|
||||||
resolve(final_url)
|
resolve(final_url)
|
||||||
} else {
|
} else {
|
||||||
console.log(`Error while writing image file.`, write)
|
console.log(`Error while writing image file.`, write)
|
||||||
|
@ -143,7 +143,7 @@ module.exports = function(tools) {
|
||||||
resolve('')
|
resolve('')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(`${protocol}${config.domain}/pics/${filename}`)
|
resolve(`/pics/${filename}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue