You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
All: Fixes #491: Handle non-standard ports and better handling of fetchBlob errors
This commit is contained in:
@ -184,7 +184,7 @@ function shimInit() {
|
||||
|
||||
const requestOptions = {
|
||||
protocol: url.protocol,
|
||||
host: url.host,
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
method: method,
|
||||
path: url.path + (url.query ? '?' + url.query : ''),
|
||||
@ -193,9 +193,29 @@ function shimInit() {
|
||||
|
||||
const doFetchOperation = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let file = null;
|
||||
|
||||
const cleanUpOnError = (error) => {
|
||||
// We ignore any unlink error as we only want to report on the main error
|
||||
fs.unlink(filePath).catch(() => {}).then(() => {
|
||||
if (file) {
|
||||
file.close(() => {
|
||||
file = null;
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
// Note: relative paths aren't supported
|
||||
const file = fs.createWriteStream(filePath);
|
||||
file = fs.createWriteStream(filePath);
|
||||
|
||||
file.on('error', function(error) {
|
||||
cleanUpOnError(error);
|
||||
});
|
||||
|
||||
const request = http.request(requestOptions, function(response) {
|
||||
response.pipe(file);
|
||||
@ -208,14 +228,12 @@ function shimInit() {
|
||||
})
|
||||
|
||||
request.on('error', function(error) {
|
||||
fs.unlink(filePath);
|
||||
reject(error);
|
||||
cleanUpOnError(error);
|
||||
});
|
||||
|
||||
request.end();
|
||||
} catch(error) {
|
||||
fs.unlink(filePath);
|
||||
reject(error);
|
||||
} catch (error) {
|
||||
cleanUpOnError(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user