Refactored media file import path calculation

refs https://github.com/TryGhost/Toolbox/issues/523

- The naming was referring to "image", which is a leftover from a copy-paste.
- It's much nicer to read a skimmable, columnar urlJoin method parameters instead of one long line
This commit is contained in:
Naz 2023-03-02 13:59:09 +08:00
parent 2361669bb6
commit 0c111cfe6b
No known key found for this signature in database

View File

@ -51,12 +51,16 @@ class ImporterMediaHandler {
}); });
const self = this; const self = this;
return Promise.all(files.map(function (image) { return Promise.all(files.map(function (contentFile) {
return self.storage.getUniqueFileName(image, image.targetDir).then(function (targetFilename) { return self.storage.getUniqueFileName(contentFile, contentFile.targetDir).then(function (targetFilename) {
image.newPath = self.urlUtils.urlJoin('/', self.urlUtils.getSubdir(), self.storage.staticFileURLPrefix, contentFile.newPath = self.urlUtils.urlJoin(
path.relative(self.config.getContentPath('media'), targetFilename)); '/',
self.urlUtils.getSubdir(),
self.storage.staticFileURLPrefix,
path.relative(mediaContentPath, targetFilename)
);
return image; return contentFile;
}); });
})); }));
} }