inline function immediately called lolwtf
This commit is contained in:
parent
4e78c3ec79
commit
3422b3e963
30
server.js
30
server.js
|
@ -5273,23 +5273,19 @@ app.post('/asset_download', jsonParser, async (request, response) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Download to temp
|
// Download to temp
|
||||||
const downloadFile = (async (url, temp_path) => {
|
const res = await fetch(url);
|
||||||
const res = await fetch(url);
|
if (!res.ok) {
|
||||||
if (!res.ok) {
|
throw new Error(`Unexpected response ${res.statusText}`);
|
||||||
throw new Error(`Unexpected response ${res.statusText}`);
|
}
|
||||||
}
|
const destination = path.resolve(temp_path);
|
||||||
const destination = path.resolve(temp_path);
|
// Delete if previous download failed
|
||||||
// Delete if previous download failed
|
if (fs.existsSync(temp_path)) {
|
||||||
if (fs.existsSync(temp_path)) {
|
fs.unlink(temp_path, (err) => {
|
||||||
fs.unlink(temp_path, (err) => {
|
if (err) throw err;
|
||||||
if (err) throw err;
|
});
|
||||||
});
|
}
|
||||||
}
|
const fileStream = fs.createWriteStream(destination, { flags: 'wx' });
|
||||||
const fileStream = fs.createWriteStream(destination, { flags: 'wx' });
|
await finished(Readable.fromWeb(res.body).pipe(fileStream));
|
||||||
await finished(Readable.fromWeb(res.body).pipe(fileStream));
|
|
||||||
});
|
|
||||||
|
|
||||||
await downloadFile(url, temp_path);
|
|
||||||
|
|
||||||
// Move into asset place
|
// Move into asset place
|
||||||
console.debug("Download finished, moving file from", temp_path, "to", file_path);
|
console.debug("Download finished, moving file from", temp_path, "to", file_path);
|
||||||
|
|
Loading…
Reference in New Issue