Skip to content
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

Checks on resourceid (Public Links) #2494

Merged
merged 4 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files/src/components/FileLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default {

$_links () {
return this.links.filter(link => {
return parseInt(link.itemSource) === parseInt(this.highlightedFile.id)
return this.compareIds(link.itemSource, this.highlightedFile.id)
})
},

Expand Down
10 changes: 10 additions & 0 deletions apps/files/src/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ export default {
})
})
},
compareIds (x, y) {
if (!isNaN(x)) { // OC10 autoincrement id
return parseInt(x) === parseInt(y)
Copy link
Contributor

@PVince81 PVince81 Nov 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt(x, 10) === parseInt(y, 10). without this leading zeroes would cause Javascript to parse numbers as octal...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was was aware of the radix problem but was blatantly relying on ES5 definition:

If radix is undefined or 0, it is assumed to be 10 except when the number begins with the character pairs 0x or 0X, in which case a radix of 16 is assumed. If radix is 16, the number may also optionally begin with the character pairs 0x or 0X.

the definition applies also on Number ES6:

This method has the same functionality as the global parseInt() function:

Number.parseInt === parseInt; // true

and is part of ECMAScript 2015 (its purpose is modularization of globals). Please see parseInt() for more detail and examples.

In any case, a check for hex would make it less error prone, but octal should not be a concern, unless someone's using a version older than ES5... .

In any case, to make things clear I'd add the radix 💃

} else if (atob(y).split(':').length === 2) { // OC10: https://github.com/cs3org/reva/blob/e7830e2f752a05a081178ed26c384ced983b8fde/internal/http/services/owncloud/ocdav/ocdav.go#L169-L175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is something we'll do more in the future for extracting the id, maybe we need a separate function for just extraction ?

something like {x, y, z, ...} = extractCS3IdParts(id) (not sure how many parts it has)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now thinking, maybe this should me done on SDK level. The SDK is here to abstract away whether Webdav, OCS or CS3 is being used to avoid having API-specific logic in the frontend code.

@DeepDiver1975 thoughts ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure this is going to stay this way, perhaps @butonic can shed a bit more light, as the only place I found this requirement is alone in the reva code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@butonic any comments here ?

if we don't know let's add a "TODO: move to common location or library" then

const opaqueid = atob(y).split(':')[1] // https://cs3org.github.io/cs3apis/#cs3.storageproviderv0alpha.ResourceId
return x === opaqueid
}

return false
},
async $_ocUpload_addDropToQue (e) {
const items = e.dataTransfer.items || e.dataTransfer.files

Expand Down