-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Fixed uppercase file extensions ignored in content import #14268
🐛 Fixed uppercase file extensions ignored in content import #14268
Conversation
Codecov Report
@@ Coverage Diff @@
## main #14268 +/- ##
==========================================
+ Coverage 55.45% 55.64% +0.18%
==========================================
Files 565 565
Lines 46883 46931 +48
Branches 3898 3906 +8
==========================================
+ Hits 26001 26115 +114
+ Misses 20843 20777 -66
Partials 39 39
Continue to review full report at Codecov.
|
b0d7388
to
38f3e84
Compare
Unit Tests are currently failing only in Node 12 due to a weird coverage bug in that Node version. refs https://ghost.slack.com/archives/C02G9E68C/p1646402101912059 |
db7f14d
to
71f11e7
Compare
Coverage issue is solved with the tests. This is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes are great. Really like the "boyscout" cleanup and the async/await rewrites. Makes future maintenance much more pleasant!
Something I'm also guilty of and wanted to point out here - would be awesome to remember to make the change that fixes the actual problem as atomic as possible. For example, in this PR would make the change adding nocase: true
as a one-liner with a minimal test case showing the root problem in one short commit. Going minimal allows the reviewer to see clearer the exact problem and would allow to merge/cherry-pick that changes into main waaaay faster 😜
}); | ||
async preProcess(importData) { | ||
for (const importer of this.importers) { | ||
importData = importer.preProcess(importData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm slightly confused by this substitution. It seems like we used to return a result of pipeline(ops)
which is Promise<[any, any...]>
(reference)
With just an assignment operation here we loose the "array" and resolve with a single object.
What I suspect has been misleading here from the very beginning is the * @returns {Promise<ImportData>}
signature. It should've been * @returns {Promise<ImportData[]>}
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yes indeed! Something is wrong here. But if you look at the implementation of importFromFile
, you can see that the output of preProcess
is passed to doImport
, where it certainly is not expecting an array (is is being used inside it as importData[importer.type]
).
If you look at the implementation of pipeline, there is a Promise.reduce
also at the end. I don't think it returns an array, but the type checker of my IDE (vscode) is showing the wrong return type (might be worth adding some JSDocs). I think it returns the last return value from all the tasks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naz Can you check this again? I do think that the change is okay here. Also note that importer.preProcess never returns a promise (that is why I also removed that async behaviour).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Just checked and the preProcess does return a single object. This piece of code is confusing! Let's get the PR going 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good. Let's get it out there!
refs https://github.com/TryGhost/Team/issues/1363 - When uploading a zip of images in Settings > Labs > [Import], it will skip images that have an uppercase extension, citing an 'unsupported file type' error. - Glob ignored those files when matching extensions in ImportManager - Added nocase option where needed - Extended tests to also test the processZip method of ImportManager with getFilesFromZip - Added isValidZip for zip with uppercase image - Cleaned up JSDoc a tiny bit in ImportManager
no issue Reason: lots of type errors in this file - Added JSDocs - Removed bluebird - Replaced some hard to follow code to make it easier to understand - importer.preProcess doesn't return promises -> removed pipeline - Replaced some older JS syntax Found an issue with getContentTypes returning the same content type twice - Fixed the issue - Updated wrong test for this method
no issue Because of the new JSDocs in ImportManager, some errors came up in the type checks
no issue When doing some refactoring on the processZip method of ImportManager in an effort to increase the test branches coverage. I discovered this bug when rewriting the older JS syntax. - The promise error was only returned in an _.each loop, but never thrown - Previously when combining images and data in a zip file, no error got thrown - Added a test for this error - Also added a test for noContentToImport error
ae18773
to
66acfc3
Compare
refs https://github.com/TryGhost/Team/issues/1363
Fixed zipContainsMultipleDataFormats error never thrown:
When doing some refactoring on the processZip method of ImportManager in an effort to increase the test branches coverage, I discovered that the zipContainsMultipleDataFormats error is never thrown.
Other errors and fixes: