Merge pull request #1196 from toshi0123/fix_avoiding_crash

Fix avoiding crash if URL is invalid
This commit is contained in:
Raccoon 2019-04-30 18:40:18 +08:00 committed by GitHub
commit 440661f1ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -16,5 +16,12 @@ exports.uploadImage = function (imagePath, callback) {
return
}
callback(null, (new URL(path.basename(imagePath), config.serverURL + '/uploads/')).href)
let url
try {
url = (new URL(path.basename(imagePath), config.serverURL + '/uploads/')).href
} catch (e) {
url = config.serverURL + '/uploads/' + path.basename(imagePath)
}
callback(null, url)
}