types.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package google_drive
  2. import (
  3. "strconv"
  4. "time"
  5. "github.com/IceWhaleTech/CasaOS/model"
  6. log "github.com/sirupsen/logrus"
  7. )
  8. type TokenError struct {
  9. Error string `json:"error"`
  10. ErrorDescription string `json:"error_description"`
  11. }
  12. type Files struct {
  13. NextPageToken string `json:"nextPageToken"`
  14. Files []File `json:"files"`
  15. }
  16. type File struct {
  17. Id string `json:"id"`
  18. Name string `json:"name"`
  19. MimeType string `json:"mimeType"`
  20. ModifiedTime time.Time `json:"modifiedTime"`
  21. Size string `json:"size"`
  22. ThumbnailLink string `json:"thumbnailLink"`
  23. ShortcutDetails struct {
  24. TargetId string `json:"targetId"`
  25. TargetMimeType string `json:"targetMimeType"`
  26. } `json:"shortcutDetails"`
  27. }
  28. func fileToObj(f File) *model.ObjThumb {
  29. log.Debugf("google file: %+v", f)
  30. size, _ := strconv.ParseInt(f.Size, 10, 64)
  31. obj := &model.ObjThumb{
  32. Object: model.Object{
  33. ID: f.Id,
  34. Name: f.Name,
  35. Size: size,
  36. Modified: f.ModifiedTime,
  37. IsFolder: f.MimeType == "application/vnd.google-apps.folder",
  38. },
  39. Thumbnail: model.Thumbnail{},
  40. }
  41. if f.MimeType == "application/vnd.google-apps.shortcut" {
  42. obj.ID = f.ShortcutDetails.TargetId
  43. obj.IsFolder = f.ShortcutDetails.TargetMimeType == "application/vnd.google-apps.folder"
  44. }
  45. return obj
  46. }
  47. type Error struct {
  48. Error struct {
  49. Errors []struct {
  50. Domain string `json:"domain"`
  51. Reason string `json:"reason"`
  52. Message string `json:"message"`
  53. LocationType string `json:"location_type"`
  54. Location string `json:"location"`
  55. }
  56. Code int `json:"code"`
  57. Message string `json:"message"`
  58. } `json:"error"`
  59. }