Skip to content

basalt / drives-google/src / toDriveItem

Function: toDriveItem() ​

> toDriveItem(file): DriveItem

Defined in: drives-google/src/metadata.ts:101

Maps one file.

Four decisions, each a place a vendor difference could have been flattened:

  • version is headRevisionId, not Google's version field. Drive's version is a monotonic counter that moves on any change, a rename included; headRevisionId moves only when the bytes do. Since contentVersion() prefers version over the checksum, using Drive's counter would re-download a file every time someone renamed it. A file with no headRevisionId (a native Doc, a folder) falls through to the checksum, which is content-exact, and then to updatedAt.
  • checksum is labelled md5, honestly. Google publishes an MD5 of the stored bytes for binary files, and only for those. It is comparable with anyone else's MD5 of the same bytes, which is exactly why it must not be labelled anything else.
  • A native Doc is exportOnly. Docs, Sheets, Slides and friends have no md5Checksum, no size and no downloadable bytes at all: files.get ?alt=media answers 403 fileNotDownloadable. They are surfaced with exportOnly: true and their mime type in raw, so an app can decide to run files.export itself. Silently exporting them to some format the app never asked for would be the framework inventing a business decision.
  • There is no path. Drive is a graph, not a tree: a file can have several parents, and a "path" is a display convention the API does not publish. parentId carries the first parent; anything path-shaped would be a fabrication, and the removal-by-path shape Dropbox needs is therefore not used here.

Parameters ​

file ​

GoogleFile

Returns ​

DriveItem

Released under the MIT License.