peerdavid / remapy

An open source explorer for your remarkable tablet to show, upload or delete files via the remarkable cloud.
Apache License 2.0
174 stars 19 forks source link

Upload files with space in filename on Linux w/ Nautilus #21

Closed wimpomp closed 3 years ago

wimpomp commented 3 years ago

When trying to upload Nautilus copied a space in a filename as %20, and remapy didn't like that.

This fixed it for me: in btn_paste_async_click in file_explorer.py

replace paths = [path.replace("file://", "") for path in paths] with paths = [path.replace("file://", "").replace("%20", " ") for path in paths]

peerdavid commented 3 years ago

Thanks for your input! Also, your fix should be compatible to other versions so I will add this soon. I also use nautilus but I can not reproduce this (the file "Test File With Space" is exactly uploaded as provided). Can I ask which version you use? And what do you mean with "remapy didn't like that" - it crashed? Thanks a lot!

wimpomp commented 3 years ago

When I tried to upload u file with a space in its path remapy shows a popup with this message:

The given clipboard is invalid. Only .pdf, .epub and urls are supported.

x-special/nautilus-clipboard
copy
file:///home/wim/Documents/folder%20withspace/article.pdf

After clicking the ok button remapy works fine, it just didn't upload the pdf. Incidentally, it doesn't seem to matter where in the path the space occurs, it fails when the space is in the folder part as well as when the space is in the file part.

I'm using GNOME nautilus 3.38.1 on Ubuntu 20.10

frederik-elwert commented 3 years ago

I had the same issue as @wimpomp. I then noticed that the actual issue is the spaces, as remapy does in fact filter out the x-special entries.

I think the file and URL detection is a bit fragile. Without changing too much, I’d suggest performing proper parsing and unquoting on file URLs. Here’s a simple patch:

diff --git a/gui/file_explorer.py b/gui/file_explorer.py
index 0702802..d40d460 100644
--- a/gui/file_explorer.py
+++ b/gui/file_explorer.py
@@ -702,11 +702,19 @@ class FileExplorer(object):
         def is_url(url):
             return url.startswith("http")

+        def file_url_to_path(url):
+            from urllib.parse import urlparse, unquote
+            parts = urlparse(url)
+            if parts.scheme == 'file':
+                return unquote(parts.path)
+            return url
+
         # Some versions of nautilus include "x-special/nautilus-clipboard file://..." 
         # Or dolphin simple adds "file://..."
         # See also issue #11
         paths = self.root.clipboard_get().split("\n")
-        paths = [path.replace("file://", "") for path in paths]
+        paths = [file_url_to_path(path) for path in paths]
         paths = list(filter(lambda path: is_file(path) != None or is_url(path), paths))

         if len(paths) <= 0:

If you think something like this would work, I could prepare a pull request.

peerdavid commented 3 years ago

@frederik-elwert That would be great thank you very much as I cannot reproduce the problem on my machine. I think I'm using a different nautilus version...

Btw. Sry for being currently slow with the development of RemaPy but I'm currently busy with many other things...