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

@uppy/companion: add parent folder path in onedrive provider #4486

Closed

Conversation

JammingBen
Copy link

Adds the parent folder path to the OneDrive provider. This can be used to determine and distinguish different source locations of files.

Relates to #4034 (although it doesn't fix it completely because other providers are still missing).

@arturi
Copy link
Contributor

arturi commented Jun 6, 2023

Thank you! Note that we have relativePath meta data key in Uppy, I wonder if it should be used here instead of parentPath.

meta: {
// path of the file relative to the ancestor directory the user selected.
// e.g. 'docs/Old Prague/airbnb.pdf'
relativePath: file.relativePath || file.webkitRelativePath || null,
},

@arturi arturi requested a review from mifi June 6, 2023 17:46
@JammingBen
Copy link
Author

Thank you! Note that we have relativePath meta data key in Uppy, I wonder if it should be used here instead of parentPath.

That would be fine as well, although the property is a little bit different: relativePath is null for flat files while it would be /drive/root: here. Eventually you decide though, just let me know 🙂

Copy link
Contributor

@mifi mifi left a comment

Choose a reason for hiding this comment

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

what's a 'flat' file? and what does relativePath mean in the context of onedrive? I believe relativePath is only set for local files in Uppy? (not remote/provider files).

Also I'm not sure what's the difference between a file's relativePath and a file's path - what is a path relative to? should it instead be called path?

The way I understand it, parentPath in OneDrive is the whole absolute path to a file excluding the file name, kind of like dirname() in node.js, am i right?

@JammingBen
Copy link
Author

what's a 'flat' file?

By that I meant files that are not located inside another directory but in the root directory.

The way I understand it, parentPath in OneDrive is the whole absolute path to a file excluding the file name, kind of like dirname() in node.js, am i right?

Yes, that's my understanding as well. Hence I figured parentPath would be a fitting name. Something like directoryPath would work as well I guess.

Also I'm not sure what's the difference between a file's relativePath and a file's path - what is a path relative to? should it instead be called path?

In that specific case there is no difference I believe. relativePath makes sense for local files as it's the path relative to the folder the file is located in on the OS. However, here, all paths are always relative to the OneDrive root = the file path.

@mifi
Copy link
Contributor

mifi commented Jun 10, 2023

Ok, I believe relativePath is something completely different than this then (it also includes the file's name), so we shouldn't mix the two together.

IMO something like directoryPath is a better name than parentPath, but we can let others weigh in too. @arturi ?

I find the root path /drive/root: a bit odd with the trailing colon. Am I right that if someone selects a file that has the (unix equivalent) path /mydir/myfile.pdf, then item.parentReference?.path would become /drive/root:/mydir ?

@mifi
Copy link
Contributor

mifi commented Jun 10, 2023

related? #4423

@arturi
Copy link
Contributor

arturi commented Jun 13, 2023

Also related: #4034?

@arturi
Copy link
Contributor

arturi commented Jun 13, 2023

Also thinking that /root: is a bit weird, especially if only GoogleDrive-specific, so maybe the path should be /googledrive/myfolder/file.txt or /googledrive/file.txt.

@Murderlon
Copy link
Member

Murderlon commented Jun 15, 2023

My two cents:

  • Name it directoryPath
  • Make the difference clear between requestPath and directoryPath. Comment could be enough.
  • Align how we treat paths locally and remote. Is local absolute path? Perhaps not possible then. Otherwise we may want to remove /drive/root:?

@arturi
Copy link
Contributor

arturi commented Jun 15, 2023

Note: we add relativePath to file.id, so that two identical files from different folders are allowed in Uppy. Maybe we should account for that too with the new property.

@JammingBen JammingBen force-pushed the feat-onedrive-parent-path branch from 20714d1 to 1c4e35e Compare June 21, 2023 09:49
@JammingBen
Copy link
Author

Okay so I renamed the property to directoryPath, added comments and strip /drive/root: (which sounds reasonable to me).

It relates to #4423 and #4034 although it does not fix them because this is for OneDrive only.

Copy link
Contributor

@mifi mifi left a comment

Choose a reason for hiding this comment

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

I think the root path should be /. also there's a bug where it doesn't match from the start of the string

packages/@uppy/companion/test/fixtures/onedrive.js Outdated Show resolved Hide resolved
@Murderlon Murderlon changed the title feat: parent folder path in onedrive provider @uppy/companion: add parent folder path in onedrive provider Jun 21, 2023
Adds the parent folder path to the OneDrive provider. This can be used to determine and distinguish different source locations of files.
@JammingBen JammingBen force-pushed the feat-onedrive-parent-path branch from 1c4e35e to 7180cb9 Compare June 21, 2023 11:55
mifi
mifi previously approved these changes Jun 21, 2023
@dschmidt
Copy link
Contributor

dschmidt commented Jun 21, 2023

I've been playing around further with this with @JammingBen and we realized that this is not all we need.

Basically we want to achieve that recursive cloud uploads work - relative to the selected folder, just like local folders
The second change we would like to make is to add a relativePath property to the file via the ProviderView as the server has no knowledge about the selection:

const onFiles = (files) => {
for (const newFile of files) {
const tagFile = this.getTagFile(newFile)
const id = getSafeFileId(tagFile)
// If the same folder is added again, we don't want to send
// X amount of duplicate file notifications, we want to say
// the folder was already added. This checks if all files are duplicate,
// if that's the case, we don't add the files.
if (!this.plugin.uppy.checkIfFileAlreadyExists(id)) {
newFiles.push(newFile)
numNewFiles++
this.setLoading(this.plugin.uppy.i18n('addedNumFiles', { numFiles: numNewFiles }))
}
isEmpty = false
}
}

We might as well just build the full path including the filename in the server and name the property absolutePath instead of directoryPath.

To me that seems a tad more consistent and feels a little less awkward than directoryPath - what do you think?

Also it would make the code a little easier as we don't need to add the item.name in several places. We could do something along these lines:

              if(newFile.absolutePath?.startsWith(file.absolutePath)) {
                newFile.relativePath = newFile.absolutePath.slice(file.absolutePath.length - 1)
              }

This handles the relativePath completely analogue to the local file upload case:

  • we set it only on files that are inside a selected folder and not for single files
  • we have a leading /
  • it contains the filename

The absolutePath would be analogue to the relativePath, it would just always be available and not only for files in selected folders.

Would you like a separate PR for the ProviderView change or would you prefer us to add it to this one?

@dschmidt
Copy link
Contributor

When we agree on something, we should add it to the documentation here: https://github.com/transloadit/uppy.io/blob/4bc81c342bdf48fd9083c6b8975f1f3b078d4580/docs/companion.md?plain=1#L818

@mifi mifi dismissed their stale review June 21, 2023 21:51

changed mind

@mifi
Copy link
Contributor

mifi commented Jun 21, 2023

I've been doing some more thinking around this, and I'm not sure if this is the way to do it, because not all providers support returning the path to Companion in their APIs, so it would't be consistent between providers. We probably want to implement a solution that work across all (most) providers.

Will continue the discussion here for now: #4034 (because it is not onedrive specific)

mifi added a commit that referenced this pull request Jun 29, 2023
@mifi mifi mentioned this pull request Jun 29, 2023
@dschmidt
Copy link
Contributor

@JammingBen I guess you can close this one, as a different solution is being worked on and we use the same approach in our fork already

@Murderlon
Copy link
Member

Superseded by #4537

@Murderlon Murderlon closed this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants