mapFileToObject maps a Google Drive file to APIObject
(file *gdrive.File)
| 431 | |
| 432 | // mapFileToObject maps a Google Drive file to APIObject |
| 433 | func (d *Client) mapFileToObject(file *gdrive.File) (*APIObject, error) { |
| 434 | Log.Tracef("Converting Google Drive file: %v", file) |
| 435 | |
| 436 | var err error |
| 437 | targetFile := file |
| 438 | if file.MimeType == shortcutMimeType && file.ShortcutDetails != nil { |
| 439 | targetFile, err = d.GetFileById(file.ShortcutDetails.TargetId) |
| 440 | if err != nil { |
| 441 | return nil, err |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | lastModified, err := time.Parse(time.RFC3339, targetFile.ModifiedTime) |
| 446 | if nil != err { |
| 447 | Log.Debugf("%v", err) |
| 448 | Log.Warningf("Could not parse last modified date for object %v (%v)", file.Id, file.Name) |
| 449 | lastModified = time.Now() |
| 450 | } |
| 451 | |
| 452 | var downloadURL string |
| 453 | if "" != targetFile.HeadRevisionId { |
| 454 | downloadURL = fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%v/revisions/%v?alt=media", targetFile.Id, targetFile.HeadRevisionId) |
| 455 | } else { |
| 456 | downloadURL = fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%v?alt=media", targetFile.Id) |
| 457 | } |
| 458 | |
| 459 | return &APIObject{ |
| 460 | ObjectID: file.Id, |
| 461 | Name: file.Name, |
| 462 | IsDir: targetFile.MimeType == folderMimeType, |
| 463 | LastModified: lastModified, |
| 464 | Size: uint64(targetFile.Size), |
| 465 | DownloadURL: downloadURL, |
| 466 | Parents: file.Parents, |
| 467 | CanTrash: file.Capabilities.CanTrash, |
| 468 | MD5Checksum: targetFile.Md5Checksum, |
| 469 | RevisionID: targetFile.HeadRevisionId, |
| 470 | }, err |
| 471 | } |
no test coverage detected