halfwhole / luminus-downloader

Downloads files and folders from LumiNUS
MIT License
11 stars 4 forks source link

Luminus Folder Names With Slashes #16

Open parth-io opened 2 years ago

parth-io commented 2 years ago

My friend came across this rare problem where if the folder name contains forward slashes, the code breaks (on MacOS and Linux, not sure for Windows).

For example, a path on Luminus can look like this: My Modules > PS2240 > Files > Tutorial Readings > Tutorial 1-Admin affairs/grouping/case discussion > Tutorial.pdf 'Tutorial 1-Admin affairs/grouping/case discussion' is a permissible folder name on Luminus.

However, when fs parses the path, the path looks like this: 'PS2240/Tutorial Readings/Tutorial 1-Admin affairs/grouping/case discussion', so the program thinks that 'grouping' and 'case discussion' are additional folders to be created.

More specifically, the code stops working at line 68 in downloader.js, when writeFile() call is made in downloadFolder().

Possible solutions:

  1. Creating the folders locally, even though they don't exist on Luminus - possibly a hacky solution
  2. Adding an additional check in parent folder 'Tutorial Readings' to check if sub-folders have slashes, and if they do, to replace them with some other character for Unix systems

Any ideas on how to resolve this?

parth-io commented 2 years ago

2

Possibly related to this?

halfwhole commented 2 years ago

Thanks for pointing this out, it does sound like a tricky problem.

As far as I can tell, the forward slash is a reserved character in Unix systems, so it looks forbidden to have a directory called 'Tutorial 1-Admin affairs/grouping/case discussion'.

The issue you mentioned in line 68 can be fixed (we can actually change folder_name to any random name and it'll work normally, the exact name is not important). But what's more tricky is that the contents of the original downloaded zip file will likely still have '/'s in them, and it'll be hard to disambiguate between legitimate forward slashes and 'fake' ones. Because of that, I have a suspicion that this problem can't be fixed on our end alone and might require some help on LumiNUS's end as well (like #2).

Screenshot 2022-03-08 at 12 39 38 AM

Could I trouble your friend to download the folder as a zip file directly from LumiNUS, extract it locally on their OS (Mac/Linux), and see what happens as a result? I'm guessing it'll produce the additional nested folders, but would like to make sure. Thanks!