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;
return Promise.all(files.map(function (image) {
return self.storage.getUniqueFileName(image, image.targetDir).then(function (targetFilename) {
image.newPath = self.urlUtils.urlJoin('/', self.urlUtils.getSubdir(), self.storage.staticFileURLPrefix,
path.relative(self.config.getContentPath('media'), targetFilename));
return Promise.all(files.map(function (contentFile) {
return self.storage.getUniqueFileName(contentFile, contentFile.targetDir).then(function (targetFilename) {
contentFile.newPath = self.urlUtils.urlJoin(
'/',
self.urlUtils.getSubdir(),
self.storage.staticFileURLPrefix,
path.relative(mediaContentPath, targetFilename)
);
return image;
return contentFile;
});
}));
}