-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: Allow disabling file name sanitization #1586
base: master
Are you sure you want to change the base?
fix: Allow disabling file name sanitization #1586
Conversation
409dce9
to
194c053
Compare
Some clients, like Cozy Desktop, do their own file name sanitization and don't expect `cozy-client` to do it for them. In fact, this sanitization would lead to issues down the road. To prevent these, we add a `sanitizeName` option to `FileCollection`'s methods to disable `cozy-client`'s sanitization. The option's value will be `true` by default so other clients don't have anything to do.
194c053
to
c35efeb
Compare
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.
👍
* @returns {Promise} - Resolves when references have been removed | ||
* and file has been sent to trash | ||
*/ | ||
async destroy(file, { ifMatch = '' } = {}) { | ||
const { _id, relationships } = file | ||
const fileId = file.id || file._id |
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.
quite a nit, but _id
is the preferred format, so I would reverse: file._id || file.id
, so file._id
is evaluated first (and skip file._id
if it's true)
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.
Good catch. I can't remember why this change is part of this PR. It doesn't seem necessary.
I'll see if I can remove it otherwise I'll make the change you suggested.
? undefined | ||
: sanitizeName | ||
? sanitizeAndValidateFileName(name) | ||
: name, |
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 highly convinced that nested ternaries are a reading and understanding hell 😄
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.
Ah. I quite like them as you can see 😅. I'll go with 2 assignments then.
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.
We all have deviant sides, who am I to judge...
* @returns {Promise<object>} - A promise that returns the copied file if resolved. | ||
* @throws {FetchError} | ||
* | ||
*/ | ||
async copy(id, name, dirId) { | ||
async copy(id, name, dirId, { sanitizeName = true } = {}) { |
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.
An alternative would have been to pass a function rather than a bool, like:
{ sanitizeFct = sanitizeAndValidateFileName } = {}
And then:
if (sanitizeFct) { sanitizeFct(name) }
Not a big deal but I find it a bit more elegant than using a boolean
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.
It would open up some use cases but I don't find copy(id, name, dirId, { sanitizeFct: undefined })
that elegant.
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.
Maybe sanitizeFct: () => {}
would be better ? 😄
Anyways, I'm ok with both solutions, it's a matter of preference, so not a requirement to me
Some clients, like Cozy Desktop, do their own file name sanitization
and don't expect
cozy-client
to do it for them. In fact, thissanitization would lead to issues down the road.
To prevent these, we add a
sanitizeName
option toFileCollection
'smethods to disable
cozy-client
's sanitization.The option's value will be
true
by default so other clients don'thave anything to do.