onedrive-cli icon indicating copy to clipboard operation
onedrive-cli copied to clipboard

Question about "Ability to get the link for a file"

Open Dark4Codrutz opened this issue 5 years ago • 6 comments

Really looking forward to "Ability to get the link for a file"

Glad you started this project as I just came across an issue of mine that requires such ability to overcome it. I would love to help but I'm afraid I'm not that well versed in JS

My question is how you envision such capability ? Will it just give the file's URL starting from a relative path to that file as input and it looks it up on the OneDrive cloud storage, OR could it compute such path starting from a local file saved on the computer inside the OneDrive sync folder.

My doubt is on the second part as I don't know how NodeJS can access local system files.

Dark4Codrutz avatar Dec 11 '20 15:12 Dark4Codrutz

Actually, you can already do this by using onedrive stat FILENAME (replace FILENAME with the name of the file in your OneDrive). This will dump a JSON file with different properties of that file, and the property "@content.downloadUrl" has the download URL for that file.

lionello avatar Dec 11 '20 16:12 lionello

Thank you for replying so promptly .

The downloadurl is not quite what I'm looking for. What I want to achieve is basically emulate the "View Online" context menu option you get in Windows which opens the OneDrive webpage to that file, with eventually a Preview frame if the file type is supported or even opens it in Online Office editors for office files.

One can do that easily by right-clicking and selecting View Online but I want to simplify this (for someone) and add that behaviour to double-clicking the file by associating the file type (lets say .docx) with some program that handles the operation and opens the file link in a browser. (let's say only with the Preview panel for simplicity)

Dark4Codrutz avatar Dec 11 '20 16:12 Dark4Codrutz

The url query is composed of cid , id and partId , then finally a &o=OneUp which represents the Preview frame. Here id is composed of repeating cid then a % separator after which there is some 7digits file identification number . For partId similarly cid gets repeated except you get a 6digit identification number for the folder/path. (except for root, where it's simply partId=root

Dark4Codrutz avatar Dec 11 '20 16:12 Dark4Codrutz

Question is if onedrive-cli is able to link the local file inside OneDrive sync folder to its corresponding id for the file and parId for the container folder/path in the cloud.

Dark4Codrutz avatar Dec 11 '20 16:12 Dark4Codrutz

Actually, you can already do this by using onedrive stat FILENAME (replace FILENAME with the name of the file in your OneDrive). This will dump a JSON file with different properties of that file, and the property "@content.downloadUrl" has the download URL for that file.

Thanks for suggesting. I still have to try it. Can you elaborate more on which properties the JSON contain ? Anything related to id and parId I mentioned before ?

Dark4Codrutz avatar Dec 11 '20 16:12 Dark4Codrutz

Hi, @Dark4Codrutz Not sure if you solved this? I had a quick look at the view file link and broke it up into 3 parts that are required via its API URL. If you pipe the JSON date info a JSON file, using onedrive stat PATH_TO_FILE > info.json you can view the JSON file, the below keys would allow you to extract what you need so you can programmatically give it any file and reconstruct the View URL?

cid = $.createdBy.user.id resid = $.id parId : $.parentReference.id

For Ref, View File URL Structure https://onedrive.live.com/edit.aspx?cid=xxx&page=view&resid=xxx!xxx&parId=xxx!xxx (not I dropped "&app=Word" from the URL as Onedrive adds it based on the file type when you open it).

Tested this and confirmed working. Now can easily write a bash script to do as required (when I get the time). My plan is to upload my bills via a script and create an alert once processed allowing me to use the URL in the alert (using pushover)

mgguinne avatar Apr 11 '21 10:04 mgguinne