Skip to content

Commit

Permalink
added opendrive as provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mschneider82 committed Jan 4, 2023
1 parent c830543 commit cb8130d
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 10 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Share your files with your friends using Cloudproviders with just one command.
# Supported Cloud Providers:

* Dropbox
* Google Drive
* Google Drive (currently not working)
* OpenDrive
* Seafile (also private hosted)
* Nextcloud / Owncloud
* Any missing? Create an Issue or PR!
Expand Down Expand Up @@ -66,6 +67,9 @@ It uploads all files to /Apps/sharecmd (folder auto generated)
## Googledrive:
It uploads all files to /sharecmd (folder auto generated)

## Opendrive
It uploads all files to /sharecmd (folder auto generated)

## Seafile:
It creates a new Library called sharecmd on setup

Expand Down
28 changes: 26 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"schneider.vip/share/urlshortener"
)

var providers = []string{"dropbox", "googledrive", "seafile", "nextcloud"}
var providers = []string{"dropbox", "opendrive", "seafile", "nextcloud"}

// Config File Structure
type Config struct {
Expand All @@ -45,7 +45,7 @@ func UserHomeDir() string {

// Write config to disk
func (c Config) Write() error {
err := os.MkdirAll(path.Dir(UserHomeDir()+"/.config/sharecmd/config.json"), 0700)
err := os.MkdirAll(path.Dir(UserHomeDir()+"/.config/sharecmd/config.json"), 0o700)
if err != nil {
return err
}
Expand Down Expand Up @@ -287,6 +287,30 @@ func Setup(configfilepath string) error {
return err
}
config.ProviderSettings["token"] = token.AccessToken
case "opendrive":
var user, password string
userPrompt := promptui.Prompt{
Label: "Username",
Default: "",
}
user, err = userPrompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return err
}

passwordPrompt := promptui.Prompt{
Label: "Password",
Default: "",
Mask: '*',
}
password, err = passwordPrompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return err
}
config.ProviderSettings["user"] = user
config.ProviderSettings["pass"] = password
}
u, settings := urlshortener.Questions()
config.URLShortenerProvider = u
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"schneider.vip/share/config"
"schneider.vip/share/provider"
"schneider.vip/share/provider/dropbox"
"schneider.vip/share/provider/googledrive"
"schneider.vip/share/provider/nextcloud"
"schneider.vip/share/provider/opendrive"
"schneider.vip/share/provider/seafile"
"schneider.vip/share/urlshortener"
"schneider.vip/share/urlshortener/biturl"
Expand Down Expand Up @@ -58,8 +58,9 @@ func main() {
switch sharecmd.config.Provider {
case "seafile":
sharecmd.provider = seafile.NewProvider(sharecmd.config.ProviderSettings["url"], sharecmd.config.ProviderSettings["token"], sharecmd.config.ProviderSettings["repoid"])
case "googledrive":
sharecmd.provider = googledrive.NewProvider(sharecmd.config.ProviderSettings["googletoken"])
case "opendrive":
sharecmd.provider = opendrive.NewProvider(sharecmd.config.ProviderSettings["user"],
sharecmd.config.ProviderSettings["pass"])
case "dropbox":
sharecmd.provider = dropbox.NewProvider(cfg.ProviderSettings["token"])
case "nextcloud":
Expand Down
9 changes: 5 additions & 4 deletions provider/googledrive/googledrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
drive "google.golang.org/api/drive/v3"
"google.golang.org/api/option"
)

//https://developers.google.com/drive/api/v3/quickstart/go
// https://developers.google.com/drive/api/v3/quickstart/go

// Provider implements a provider
type Provider struct {
Expand Down Expand Up @@ -55,6 +56,7 @@ var mimeExtentions = map[string]string{
".txt": "text/plain",
".tsv": "text/tab-separated-values",
}

var (
ob = "ufsdii23n452u32iXXi8231aso0i1"
y = "MmciVUipVqmm4Chej+dVMxwUumsQDTq3G6Qkv7lhR366CaVac3eD1w=="
Expand All @@ -68,7 +70,7 @@ func OAuth2GoogleDriveConfig() *oauth2.Config {
k := obf{jkoq: []byte(ab)}
x := k.de(y)
b := []byte(`{"installed":{"client_id":"26115953275-7971erj532s8d98vlso25467iudikbvf.apps.googleusercontent.com","project_id":"sharecmd-223413","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://www.googleapis.com/oauth2/v3/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"` + x + `","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}`)
//config, err := google.ConfigFromJSON(b, drive.DriveMetadataScope)
// config, err := google.ConfigFromJSON(b, drive.DriveMetadataScope)
config, err := google.ConfigFromJSON(b, drive.DriveScope)
if err != nil {
log.Fatalf("Unable to parse client secret file to config: %v", err)
Expand All @@ -93,14 +95,13 @@ func (c *Provider) getClient() *http.Client {

// Upload the file
func (c *Provider) Upload(file *os.File, path string) (fileID string, err error) {

fileInfo, err := file.Stat()
if err != nil {
return "", err
}

client := c.getClient()
srv, err := drive.New(client)
srv, err := drive.NewService(context.Background(), option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve Drive client: %v", err)
}
Expand Down
Loading

0 comments on commit cb8130d

Please sign in to comment.