diff options
| -rw-r--r-- | drive/url.go | 26 | ||||
| -rw-r--r-- | gdrive.go | 2 | ||||
| -rw-r--r-- | handlers.go | 9 | 
3 files changed, 36 insertions, 1 deletions
| diff --git a/drive/url.go b/drive/url.go new file mode 100644 index 0000000..2dc429d --- /dev/null +++ b/drive/url.go @@ -0,0 +1,26 @@ +package drive + +import ( +    "fmt" +) + +type UrlArgs struct { +    FileId string     +    DownloadUrl bool     +} + +func (self *Drive) Url(args UrlArgs) { +    if args.DownloadUrl { +        fmt.Println(downloadUrl(args.FileId)) +        return +    } +    fmt.Println(previewUrl(args.FileId)) +} + +func previewUrl(id string) string { +    return fmt.Sprintf("https://drive.google.com/uc?id=%s", id) +} + +func downloadUrl(id string) string { +    return fmt.Sprintf("https://drive.google.com/uc?id=%s&export=download", id) +} @@ -224,7 +224,7 @@ func main() {          &cli.Handler{              Pattern: "[global options] url [options] <id>",              Description: "Get url to file or directory", -            Callback: handler, +            Callback: urlHandler,              Flags: cli.Flags{                  "global options": globalFlags,                  "options": []cli.Flag{ diff --git a/handlers.go b/handlers.go index 3d90dc7..d74eb1a 100644 --- a/handlers.go +++ b/handlers.go @@ -82,6 +82,15 @@ func shareHandler(ctx cli.Context) {      })  } +func urlHandler(ctx cli.Context) { +    args := ctx.Args() + +    newDrive(args).Url(drive.UrlArgs{ +        FileId: args.String("id"), +        DownloadUrl: args.Bool("download"), +    }) +} +  func deleteHandler(ctx cli.Context) {      fmt.Println("Deleting...")  } | 
