forked from prasmussen/gdrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
68 lines (58 loc) · 1.5 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package drive
import (
"fmt"
"google.golang.org/api/drive/v3"
"io"
)
type FileInfoArgs struct {
Out io.Writer
Id string
SizeInBytes bool
}
func (self *Drive) Info(args FileInfoArgs) error {
f, err := self.service.Files.Get(args.Id).Fields("id", "name", "size", "createdTime", "modifiedTime", "md5Checksum", "mimeType", "parents", "shared", "description", "webContentLink", "webViewLink").Do()
if err != nil {
return fmt.Errorf("Failed to get file: %s", err)
}
pathfinder := self.newPathfinder()
absPath, err := pathfinder.absPath(f)
if err != nil {
return err
}
PrintFileInfo(PrintFileInfoArgs{
Out: args.Out,
File: f,
Path: absPath,
SizeInBytes: args.SizeInBytes,
})
return nil
}
type PrintFileInfoArgs struct {
Out io.Writer
File *drive.File
Path string
SizeInBytes bool
}
func PrintFileInfo(args PrintFileInfoArgs) {
f := args.File
items := []kv{
kv{"Id", f.Id},
kv{"Name", f.Name},
kv{"Path", args.Path},
kv{"Description", f.Description},
kv{"Mime", f.MimeType},
kv{"Size", formatSize(f.Size, args.SizeInBytes)},
kv{"Created", formatDatetime(f.CreatedTime)},
kv{"Modified", formatDatetime(f.ModifiedTime)},
kv{"Md5sum", f.Md5Checksum},
kv{"Shared", formatBool(f.Shared)},
kv{"Parents", formatList(f.Parents)},
kv{"ViewUrl", f.WebViewLink},
kv{"DownloadUrl", f.WebContentLink},
}
for _, item := range items {
if item.value != "" {
fmt.Fprintf(args.Out, "%s: %s\n", item.key, item.value)
}
}
}