From 92b3518c78848d454a7352707fa7c849fd93403a Mon Sep 17 00:00:00 2001 From: Florian Penzkofer Date: Sun, 16 May 2021 16:28:18 -0500 Subject: [PATCH] fichier: support downloading password protected files and folders --- backend/fichier/api.go | 16 ++++++++++++---- backend/fichier/fichier.go | 20 +++++++++++++++++--- backend/fichier/structs.go | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/backend/fichier/api.go b/backend/fichier/api.go index 991ad621a..3558e5661 100644 --- a/backend/fichier/api.go +++ b/backend/fichier/api.go @@ -4,6 +4,7 @@ import ( "context" "io" "net/http" + "net/url" "regexp" "strconv" "strings" @@ -90,6 +91,7 @@ func (f *Fs) getDownloadToken(ctx context.Context, url string) (*GetTokenRespons request := DownloadRequest{ URL: url, Single: 1, + Pass: f.opt.FilePassword, } opts := rest.Opts{ Method: "POST", @@ -118,10 +120,16 @@ func fileFromSharedFile(file *SharedFile) File { func (f *Fs) listSharedFiles(ctx context.Context, id string) (entries fs.DirEntries, err error) { opts := rest.Opts{ - Method: "GET", - RootURL: "https://1fichier.com/dir/", - Path: id, - Parameters: map[string][]string{"json": {"1"}}, + Method: "GET", + RootURL: "https://1fichier.com/dir/", + Path: id, + Parameters: map[string][]string{"json": {"1"}}, + ContentType: "application/x-www-form-urlencoded", + } + if f.opt.FolderPassword != "" { + opts.Method = "POST" + opts.Parameters = nil + opts.Body = strings.NewReader("json=1&pass=" + url.QueryEscape(f.opt.FolderPassword)) } var sharedFiles SharedFolderResponse diff --git a/backend/fichier/fichier.go b/backend/fichier/fichier.go index 5a5800b90..c46f45c24 100644 --- a/backend/fichier/fichier.go +++ b/backend/fichier/fichier.go @@ -44,6 +44,18 @@ func init() { Name: "shared_folder", Required: false, Advanced: true, + }, { + Help: "If you want to download a shared file that is password protected, add this parameter", + Name: "file_password", + Required: false, + Advanced: true, + IsPassword: true, + }, { + Help: "If you want to list the files in a shared folder that is password protected, add this parameter", + Name: "folder_password", + Required: false, + Advanced: true, + IsPassword: true, }, { Name: config.ConfigEncoding, Help: config.ConfigEncodingHelp, @@ -75,9 +87,11 @@ func init() { // Options defines the configuration for this backend type Options struct { - APIKey string `config:"api_key"` - SharedFolder string `config:"shared_folder"` - Enc encoder.MultiEncoder `config:"encoding"` + APIKey string `config:"api_key"` + SharedFolder string `config:"shared_folder"` + FilePassword string `config:"file_password"` + FolderPassword string `config:"folder_password"` + Enc encoder.MultiEncoder `config:"encoding"` } // Fs is the interface a cloud storage system must provide diff --git a/backend/fichier/structs.go b/backend/fichier/structs.go index c20e459f1..40efd0032 100644 --- a/backend/fichier/structs.go +++ b/backend/fichier/structs.go @@ -19,6 +19,7 @@ type ListFilesRequest struct { type DownloadRequest struct { URL string `json:"url"` Single int `json:"single"` + Pass string `json:"pass,omitempty"` } // RemoveFolderRequest is the request structure of the corresponding request