Fix avoiding crash if URL is invalid

Signed-off-by: toshi0123 <7948737+toshi0123@users.noreply.github.com>
This commit is contained in:
toshi0123 2019-04-18 19:10:46 +09:00 committed by GitHub
parent 4e596d724d
commit eff6e04e2b
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 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)
} }