mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
Randomize the image name when it's dropped
This commit is contained in:
@@ -19,10 +19,12 @@ function copyImage (filePath, storageKey) {
|
|||||||
const targetStorage = storage
|
const targetStorage = storage
|
||||||
|
|
||||||
const inputImage = fs.createReadStream(filePath)
|
const inputImage = fs.createReadStream(filePath)
|
||||||
const imageName = path.basename(filePath)
|
const imageExt = path.extname(filePath)
|
||||||
const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', imageName))
|
const imageName = Math.random().toString(36).slice(-16)
|
||||||
|
const basename = `${imageName}${imageExt}`
|
||||||
|
const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', basename))
|
||||||
inputImage.pipe(outputImage)
|
inputImage.pipe(outputImage)
|
||||||
resolve(`${encodeURI(targetStorage.path)}/images/${encodeURI(imageName)}`)
|
resolve(`${encodeURI(targetStorage.path)}/images/${encodeURI(basename)}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return reject(e)
|
return reject(e)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user