mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
🐛 Fixed uploading images with custom storage adapters
fixes https://github.com/TryGhost/Ghost/issues/16278 `urlToPath` is not a method that is defined on the StorageBase, and thus is not implemented on any custom storage adapter. We need this method to prevent uploading a file in two different directories. Currently this is an edge case: - If you upload a file at midnight between a month shift, it is possible that we upload one file at `/2023/02/file.png` and the original at `/2023/03/file_o.png` - To make sure we upload the second at the same directory, we need the `urlToPath` implementation. The save method sadly only returns the URL, which could be different than the stored file path, so we cannot use that return value. This fix only uses `urlToPath` if available, to prevent above issue.
This commit is contained in:
parent
8dfa490638
commit
f8e77ad012
@ -37,13 +37,20 @@ module.exports = {
|
|||||||
...frame.file,
|
...frame.file,
|
||||||
path: out
|
path: out
|
||||||
});
|
});
|
||||||
const processedImagePath = store.urlToPath(processedImageUrl);
|
|
||||||
|
|
||||||
// Get the path and name of the processed image
|
let processedImageName = path.basename(processedImageUrl);
|
||||||
// We want to store the original image on the same name + _o
|
let processedImageDir = undefined;
|
||||||
// So we need to wait for the first store to finish before generating the name of the original image
|
|
||||||
const processedImageName = path.basename(processedImagePath);
|
if (store.urlToPath) {
|
||||||
const processedImageDir = path.dirname(processedImagePath);
|
// Currently urlToPath is not part of StorageBase, so not all storage provider have implemented it
|
||||||
|
const processedImagePath = store.urlToPath(processedImageUrl);
|
||||||
|
|
||||||
|
// Get the path and name of the processed image
|
||||||
|
// We want to store the original image on the same name + _o
|
||||||
|
// So we need to wait for the first store to finish before generating the name of the original image
|
||||||
|
processedImageName = path.basename(processedImagePath);
|
||||||
|
processedImageDir = path.dirname(processedImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
// Store the original image
|
// Store the original image
|
||||||
await store.save({
|
await store.save({
|
||||||
|
Loading…
Reference in New Issue
Block a user