aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drive/url.go26
-rw-r--r--gdrive.go2
-rw-r--r--handlers.go9
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)
+}
diff --git a/gdrive.go b/gdrive.go
index 3f9ec90..c2f2fba 100644
--- a/gdrive.go
+++ b/gdrive.go
@@ -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...")
}