-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add support for downloading public files #24
base: master
Are you sure you want to change the base?
Conversation
This method is rather hacked together from code found elsewhere in go-mega. It works fine, but probably needs a bit of tidying up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
Where are you using the API?
It looks like this API could be used from rclone too as a backend command.
Where do you get the hash and the key from a shared file? From the URL?
Maybe we should parse the URL for the user.
@@ -1037,6 +1037,112 @@ func (m *Mega) NewDownload(src *Node) (*Download, error) { | |||
return d, nil | |||
} | |||
|
|||
// Create a new public Download from the hash and key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you get the hash for a public file? From the URL?
What about directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you get the hash for a public file? From the URL?
https://mega.nz/file/hash#key
Maybe hash isn't the best name... ID might be better?
What about directories?
I've not actually tested this with directories, but I'd guess that they work completely differently (looking at the URLs at least).
var msg [1]DownloadMsg | ||
var res [1]DownloadResp | ||
|
||
// XXX: Do we need this mutex here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the mutex is required
// Call Chunks to find out how many chunks there are, then for id = | ||
// 0..chunks-1 call DownloadChunk. Finally call Finish() to receive | ||
// the error status. | ||
func (m *Mega) NewPublicDownload(hash, key string) (*Download, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure on using the existing Download
type for this, as we end up faking a Node
instance which technically doesn't exist in the user's filesystem.
A nicer option may be a whole new PublicDownload
type, but that would be a lot more code (primarily duplicated from the existing Download
type). I'm open to suggestions here on how this can be improved.
return nil, err | ||
} | ||
|
||
aes_key, err := a32_to_bytes([]uint32{compkey[0] ^ compkey[4], compkey[1] ^ compkey[5], compkey[2] ^ compkey[6], compkey[3] ^ compkey[7]}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been copied from addFSNode
(as has some of the other logic in this function), which I'm not too happy about. Open to suggestions on how we can remove some of the duplicate code here.
Thanks for the feedback @ncw - I'll look at implementing it shortly. I've just noticed that I had 2 pending comments of my own on here, which I've now posted. |
This PR is a bit hacked together right now - I'm hoping to get around to tidying it up sooner or later but I thought I'd open up this PR for discussion anyway.