github.com/artpar/rclone@v1.67.3/backend/onedrive/api/types.go (about)

     1  // Package api provides types used by the OneDrive API.
     2  package api
     3  
     4  import (
     5  	"strings"
     6  	"time"
     7  )
     8  
     9  const (
    10  	timeFormat = `"` + "2006-01-02T15:04:05.999Z" + `"`
    11  
    12  	// PackageTypeOneNote is the package type value for OneNote files
    13  	PackageTypeOneNote = "oneNote"
    14  )
    15  
    16  // Error is returned from OneDrive when things go wrong
    17  type Error struct {
    18  	ErrorInfo struct {
    19  		Code       string `json:"code"`
    20  		Message    string `json:"message"`
    21  		InnerError struct {
    22  			Code string `json:"code"`
    23  		} `json:"innererror"`
    24  	} `json:"error"`
    25  }
    26  
    27  // Error returns a string for the error and satisfies the error interface
    28  func (e *Error) Error() string {
    29  	out := e.ErrorInfo.Code
    30  	if e.ErrorInfo.InnerError.Code != "" {
    31  		out += ": " + e.ErrorInfo.InnerError.Code
    32  	}
    33  	out += ": " + e.ErrorInfo.Message
    34  	return out
    35  }
    36  
    37  // Check Error satisfies the error interface
    38  var _ error = (*Error)(nil)
    39  
    40  // Identity represents an identity of an actor. For example, and actor
    41  // can be a user, device, or application.
    42  type Identity struct {
    43  	DisplayName string `json:"displayName,omitempty"`
    44  	ID          string `json:"id,omitempty"`
    45  }
    46  
    47  // IdentitySet is a keyed collection of Identity objects. It is used
    48  // to represent a set of identities associated with various events for
    49  // an item, such as created by or last modified by.
    50  type IdentitySet struct {
    51  	User        Identity `json:"user,omitempty"`
    52  	Application Identity `json:"application,omitempty"`
    53  	Device      Identity `json:"device,omitempty"`
    54  }
    55  
    56  // Quota groups storage space quota-related information on OneDrive into a single structure.
    57  type Quota struct {
    58  	Total     int64  `json:"total"`
    59  	Used      int64  `json:"used"`
    60  	Remaining int64  `json:"remaining"`
    61  	Deleted   int64  `json:"deleted"`
    62  	State     string `json:"state"` // normal | nearing | critical | exceeded
    63  }
    64  
    65  // Drive is a representation of a drive resource
    66  type Drive struct {
    67  	ID        string      `json:"id"`
    68  	DriveType string      `json:"driveType"`
    69  	Owner     IdentitySet `json:"owner"`
    70  	Quota     Quota       `json:"quota"`
    71  }
    72  
    73  // Timestamp represents date and time information for the
    74  // OneDrive API, by using ISO 8601 and is always in UTC time.
    75  type Timestamp time.Time
    76  
    77  // MarshalJSON turns a Timestamp into JSON (in UTC)
    78  func (t *Timestamp) MarshalJSON() (out []byte, err error) {
    79  	timeString := (*time.Time)(t).UTC().Format(timeFormat)
    80  	return []byte(timeString), nil
    81  }
    82  
    83  // UnmarshalJSON turns JSON into a Timestamp
    84  func (t *Timestamp) UnmarshalJSON(data []byte) error {
    85  	newT, err := time.Parse(timeFormat, string(data))
    86  	if err != nil {
    87  		return err
    88  	}
    89  	*t = Timestamp(newT)
    90  	return nil
    91  }
    92  
    93  // ItemReference groups data needed to reference a OneDrive item
    94  // across the service into a single structure.
    95  type ItemReference struct {
    96  	DriveID   string `json:"driveId"`   // Unique identifier for the Drive that contains the item.	Read-only.
    97  	ID        string `json:"id"`        // Unique identifier for the item.	Read/Write.
    98  	Path      string `json:"path"`      // Path that used to navigate to the item.	Read/Write.
    99  	DriveType string `json:"driveType"` // Type of the drive,	Read-Only
   100  }
   101  
   102  // GetID returns a normalized ID of the item
   103  // If DriveID is known it will be prefixed to the ID with # separator
   104  // Can be parsed using onedrive.parseNormalizedID(normalizedID)
   105  func (i *ItemReference) GetID() string {
   106  	if !strings.Contains(i.ID, "#") {
   107  		return i.DriveID + "#" + i.ID
   108  	}
   109  	return i.ID
   110  }
   111  
   112  // RemoteItemFacet groups data needed to reference a OneDrive remote item
   113  type RemoteItemFacet struct {
   114  	ID                   string               `json:"id"`                   // The unique identifier of the item within the remote Drive. Read-only.
   115  	Name                 string               `json:"name"`                 // The name of the item (filename and extension). Read-write.
   116  	CreatedBy            IdentitySet          `json:"createdBy"`            // Identity of the user, device, and application which created the item. Read-only.
   117  	LastModifiedBy       IdentitySet          `json:"lastModifiedBy"`       // Identity of the user, device, and application which last modified the item. Read-only.
   118  	CreatedDateTime      Timestamp            `json:"createdDateTime"`      // Date and time of item creation. Read-only.
   119  	LastModifiedDateTime Timestamp            `json:"lastModifiedDateTime"` // Date and time the item was last modified. Read-only.
   120  	Folder               *FolderFacet         `json:"folder"`               // Folder metadata, if the item is a folder. Read-only.
   121  	File                 *FileFacet           `json:"file"`                 // File metadata, if the item is a file. Read-only.
   122  	Package              *PackageFacet        `json:"package"`              // If present, indicates that this item is a package instead of a folder or file. Packages are treated like files in some contexts and folders in others. Read-only.
   123  	FileSystemInfo       *FileSystemInfoFacet `json:"fileSystemInfo"`       // File system information on client. Read-write.
   124  	ParentReference      *ItemReference       `json:"parentReference"`      // Parent information, if the item has a parent. Read-write.
   125  	Size                 int64                `json:"size"`                 // Size of the item in bytes. Read-only.
   126  	WebURL               string               `json:"webUrl"`               // URL that displays the resource in the browser. Read-only.
   127  }
   128  
   129  // FolderFacet groups folder-related data on OneDrive into a single structure
   130  type FolderFacet struct {
   131  	ChildCount int64 `json:"childCount"` // Number of children contained immediately within this container.
   132  }
   133  
   134  // HashesType groups different types of hashes into a single structure, for an item on OneDrive.
   135  type HashesType struct {
   136  	Sha1Hash     string `json:"sha1Hash"`     // hex encoded SHA1 hash for the contents of the file (if available)
   137  	Crc32Hash    string `json:"crc32Hash"`    // hex encoded CRC32 value of the file (if available)
   138  	QuickXorHash string `json:"quickXorHash"` // base64 encoded QuickXorHash value of the file (if available)
   139  	Sha256Hash   string `json:"sha256Hash"`   // hex encoded SHA256 value of the file (if available)
   140  }
   141  
   142  // FileFacet groups file-related data on OneDrive into a single structure.
   143  type FileFacet struct {
   144  	MimeType string     `json:"mimeType"` // The MIME type for the file. This is determined by logic on the server and might not be the value provided when the file was uploaded.
   145  	Hashes   HashesType `json:"hashes"`   // Hashes of the file's binary content, if available.
   146  }
   147  
   148  // FileSystemInfoFacet contains properties that are reported by the
   149  // device's local file system for the local version of an item. This
   150  // facet can be used to specify the last modified date or created date
   151  // of the item as it was on the local device.
   152  type FileSystemInfoFacet struct {
   153  	CreatedDateTime      Timestamp `json:"createdDateTime,omitempty"`      // The UTC date and time the file was created on a client.
   154  	LastModifiedDateTime Timestamp `json:"lastModifiedDateTime,omitempty"` // The UTC date and time the file was last modified on a client.
   155  }
   156  
   157  // DeletedFacet indicates that the item on OneDrive has been
   158  // deleted. In this version of the API, the presence (non-null) of the
   159  // facet value indicates that the file was deleted. A null (or
   160  // missing) value indicates that the file is not deleted.
   161  type DeletedFacet struct{}
   162  
   163  // PackageFacet indicates that a DriveItem is the top level item
   164  // in a "package" or a collection of items that should be treated as a collection instead of individual items.
   165  // `oneNote` is the only currently defined value.
   166  type PackageFacet struct {
   167  	Type string `json:"type"`
   168  }
   169  
   170  // SharedType indicates a DriveItem has been shared with others. The resource includes information about how the item is shared.
   171  // If a Driveitem has a non-null shared facet, the item has been shared.
   172  type SharedType struct {
   173  	Owner          IdentitySet `json:"owner,omitempty"`          // The identity of the owner of the shared item. Read-only.
   174  	Scope          string      `json:"scope,omitempty"`          // Indicates the scope of how the item is shared: anonymous, organization, or users. Read-only.
   175  	SharedBy       IdentitySet `json:"sharedBy,omitempty"`       // The identity of the user who shared the item. Read-only.
   176  	SharedDateTime Timestamp   `json:"sharedDateTime,omitempty"` // The UTC date and time when the item was shared. Read-only.
   177  }
   178  
   179  // SharingInvitationType groups invitation-related data items into a single structure.
   180  type SharingInvitationType struct {
   181  	Email          string       `json:"email,omitempty"`          // The email address provided for the recipient of the sharing invitation. Read-only.
   182  	InvitedBy      *IdentitySet `json:"invitedBy,omitempty"`      // Provides information about who sent the invitation that created this permission, if that information is available. Read-only.
   183  	SignInRequired bool         `json:"signInRequired,omitempty"` // If true the recipient of the invitation needs to sign in in order to access the shared item. Read-only.
   184  }
   185  
   186  // SharingLinkType groups link-related data items into a single structure.
   187  // If a Permission resource has a non-null sharingLink facet, the permission represents a sharing link (as opposed to permissions granted to a person or group).
   188  type SharingLinkType struct {
   189  	Application *Identity `json:"application,omitempty"` // The app the link is associated with.
   190  	Type        LinkType  `json:"type,omitempty"`        // The type of the link created.
   191  	Scope       LinkScope `json:"scope,omitempty"`       // The scope of the link represented by this permission. Value anonymous indicates the link is usable by anyone, organization indicates the link is only usable for users signed into the same tenant.
   192  	WebHTML     string    `json:"webHtml,omitempty"`     // For embed links, this property contains the HTML code for an <iframe> element that will embed the item in a webpage.
   193  	WebURL      string    `json:"webUrl,omitempty"`      // A URL that opens the item in the browser on the OneDrive website.
   194  }
   195  
   196  // LinkType represents the type of SharingLinkType created.
   197  type LinkType string
   198  
   199  const (
   200  	ViewLinkType  LinkType = "view"  // ViewLinkType (role: read) A view-only sharing link, allowing read-only access.
   201  	EditLinkType  LinkType = "edit"  // EditLinkType (role: write) An edit sharing link, allowing read-write access.
   202  	EmbedLinkType LinkType = "embed" // EmbedLinkType (role: read) A view-only sharing link that can be used to embed content into a host webpage. Embed links are not available for OneDrive for Business or SharePoint.
   203  )
   204  
   205  // LinkScope represents the scope of the link represented by this permission.
   206  // Value anonymous indicates the link is usable by anyone, organization indicates the link is only usable for users signed into the same tenant.
   207  type LinkScope string
   208  
   209  const (
   210  	AnonymousScope    LinkScope = "anonymous"    // AnonymousScope = Anyone with the link has access, without needing to sign in. This may include people outside of your organization.
   211  	OrganizationScope LinkScope = "organization" // OrganizationScope = Anyone signed into your organization (tenant) can use the link to get access. Only available in OneDrive for Business and SharePoint.
   212  
   213  )
   214  
   215  // PermissionsType provides information about a sharing permission granted for a DriveItem resource.
   216  // Sharing permissions have a number of different forms. The Permission resource represents these different forms through facets on the resource.
   217  type PermissionsType struct {
   218  	ID                  string                 `json:"id"`                            // The unique identifier of the permission among all permissions on the item. Read-only.
   219  	GrantedTo           *IdentitySet           `json:"grantedTo,omitempty"`           // For user type permissions, the details of the users & applications for this permission. Read-only.
   220  	GrantedToIdentities []*IdentitySet         `json:"grantedToIdentities,omitempty"` // For link type permissions, the details of the users to whom permission was granted. Read-only.
   221  	Invitation          *SharingInvitationType `json:"invitation,omitempty"`          // Details of any associated sharing invitation for this permission. Read-only.
   222  	InheritedFrom       *ItemReference         `json:"inheritedFrom,omitempty"`       // Provides a reference to the ancestor of the current permission, if it is inherited from an ancestor. Read-only.
   223  	Link                *SharingLinkType       `json:"link,omitempty"`                // Provides the link details of the current permission, if it is a link type permissions. Read-only.
   224  	Roles               []Role                 `json:"roles,omitempty"`               // The type of permission (read, write, owner, member). Read-only.
   225  	ShareID             string                 `json:"shareId,omitempty"`             // A unique token that can be used to access this shared item via the shares API. Read-only.
   226  }
   227  
   228  // Role represents the type of permission (read, write, owner, member)
   229  type Role string
   230  
   231  const (
   232  	ReadRole   Role = "read"   // ReadRole provides the ability to read the metadata and contents of the item.
   233  	WriteRole  Role = "write"  // WriteRole provides the ability to read and modify the metadata and contents of the item.
   234  	OwnerRole  Role = "owner"  // OwnerRole represents the owner role for SharePoint and OneDrive for Business.
   235  	MemberRole Role = "member" // MemberRole represents the member role for SharePoint and OneDrive for Business.
   236  )
   237  
   238  // PermissionsResponse is the response to the list permissions method
   239  type PermissionsResponse struct {
   240  	Value []*PermissionsType `json:"value"` // An array of Item objects
   241  }
   242  
   243  // AddPermissionsRequest is the request for the add permissions method
   244  type AddPermissionsRequest struct {
   245  	Recipients                 []DriveRecipient `json:"recipients,omitempty"`                 // A collection of recipients who will receive access and the sharing invitation.
   246  	Message                    string           `json:"message,omitempty"`                    // A plain text formatted message that is included in the sharing invitation. Maximum length 2000 characters.
   247  	RequireSignIn              bool             `json:"requireSignIn,omitempty"`              // Specifies whether the recipient of the invitation is required to sign-in to view the shared item.
   248  	SendInvitation             bool             `json:"sendInvitation,omitempty"`             // If true, a sharing link is sent to the recipient. Otherwise, a permission is granted directly without sending a notification.
   249  	Roles                      []Role           `json:"roles,omitempty"`                      // Specify the roles that are to be granted to the recipients of the sharing invitation.
   250  	RetainInheritedPermissions bool             `json:"retainInheritedPermissions,omitempty"` // Optional. If true (default), any existing inherited permissions are retained on the shared item when sharing this item for the first time. If false, all existing permissions are removed when sharing for the first time. OneDrive Business Only.
   251  }
   252  
   253  // UpdatePermissionsRequest is the request for the update permissions method
   254  type UpdatePermissionsRequest struct {
   255  	Roles []Role `json:"roles,omitempty"` // Specify the roles that are to be granted to the recipients of the sharing invitation.
   256  }
   257  
   258  // DriveRecipient represents a person, group, or other recipient to share with using the invite action.
   259  type DriveRecipient struct {
   260  	Email    string `json:"email,omitempty"`    // The email address for the recipient, if the recipient has an associated email address.
   261  	Alias    string `json:"alias,omitempty"`    // The alias of the domain object, for cases where an email address is unavailable (e.g. security groups).
   262  	ObjectID string `json:"objectId,omitempty"` // The unique identifier for the recipient in the directory.
   263  }
   264  
   265  // Item represents metadata for an item in OneDrive
   266  type Item struct {
   267  	ID                   string               `json:"id"`                    // The unique identifier of the item within the Drive. Read-only.
   268  	Name                 string               `json:"name"`                  // The name of the item (filename and extension). Read-write.
   269  	ETag                 string               `json:"eTag"`                  // eTag for the entire item (metadata + content). Read-only.
   270  	CTag                 string               `json:"cTag"`                  // An eTag for the content of the item. This eTag is not changed if only the metadata is changed. Read-only.
   271  	CreatedBy            IdentitySet          `json:"createdBy"`             // Identity of the user, device, and application which created the item. Read-only.
   272  	LastModifiedBy       IdentitySet          `json:"lastModifiedBy"`        // Identity of the user, device, and application which last modified the item. Read-only.
   273  	CreatedDateTime      Timestamp            `json:"createdDateTime"`       // Date and time of item creation. Read-only.
   274  	LastModifiedDateTime Timestamp            `json:"lastModifiedDateTime"`  // Date and time the item was last modified. Read-only.
   275  	Size                 int64                `json:"size"`                  // Size of the item in bytes. Read-only.
   276  	ParentReference      *ItemReference       `json:"parentReference"`       // Parent information, if the item has a parent. Read-write.
   277  	WebURL               string               `json:"webUrl"`                // URL that displays the resource in the browser. Read-only.
   278  	Description          string               `json:"description,omitempty"` // Provides a user-visible description of the item. Read-write. Only on OneDrive Personal. Undocumented limit of 1024 characters.
   279  	Folder               *FolderFacet         `json:"folder"`                // Folder metadata, if the item is a folder. Read-only.
   280  	File                 *FileFacet           `json:"file"`                  // File metadata, if the item is a file. Read-only.
   281  	RemoteItem           *RemoteItemFacet     `json:"remoteItem"`            // Remote Item metadata, if the item is a remote shared item. Read-only.
   282  	FileSystemInfo       *FileSystemInfoFacet `json:"fileSystemInfo"`        // File system information on client. Read-write.
   283  	//	Image                *ImageFacet          `json:"image"`                // Image metadata, if the item is an image. Read-only.
   284  	//	Photo                *PhotoFacet          `json:"photo"`                // Photo metadata, if the item is a photo. Read-only.
   285  	//	Audio                *AudioFacet          `json:"audio"`                // Audio metadata, if the item is an audio file. Read-only.
   286  	//	Video                *VideoFacet          `json:"video"`                // Video metadata, if the item is a video. Read-only.
   287  	//	Location             *LocationFacet       `json:"location"`             // Location metadata, if the item has location data. Read-only.
   288  	Package *PackageFacet `json:"package"`           // If present, indicates that this item is a package instead of a folder or file. Packages are treated like files in some contexts and folders in others. Read-only.
   289  	Deleted *DeletedFacet `json:"deleted"`           // Information about the deleted state of the item. Read-only.
   290  	Malware *struct{}     `json:"malware,omitempty"` // Malware metadata, if the item was detected to contain malware. Read-only. (Currently has no properties.)
   291  	Shared  *SharedType   `json:"shared,omitempty"`  // Indicates that the item has been shared with others and provides information about the shared state of the item. Read-only.
   292  }
   293  
   294  // Metadata represents a request to update Metadata.
   295  // It includes only the writeable properties.
   296  // omitempty is intentionally included for all, per https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_update?view=odsp-graph-online#request-body
   297  type Metadata struct {
   298  	Description    string               `json:"description,omitempty"`    // Provides a user-visible description of the item. Read-write. Only on OneDrive Personal. Undocumented limit of 1024 characters.
   299  	FileSystemInfo *FileSystemInfoFacet `json:"fileSystemInfo,omitempty"` // File system information on client. Read-write.
   300  }
   301  
   302  // IsEmpty returns true if the metadata is empty (there is nothing to set)
   303  func (m Metadata) IsEmpty() bool {
   304  	return m.Description == "" && m.FileSystemInfo == &FileSystemInfoFacet{}
   305  }
   306  
   307  // DeltaResponse is the response to the view delta method
   308  type DeltaResponse struct {
   309  	Value      []Item `json:"value"`            // An array of Item objects which have been created, modified, or deleted.
   310  	NextLink   string `json:"@odata.nextLink"`  // A URL to retrieve the next available page of changes.
   311  	DeltaLink  string `json:"@odata.deltaLink"` // A URL returned instead of @odata.nextLink after all current changes have been returned. Used to read the next set of changes in the future.
   312  	DeltaToken string `json:"@delta.token"`     // A token value that can be used in the query string on manually-crafted calls to view.delta. Not needed if you're using nextLink and deltaLink.
   313  }
   314  
   315  // ListChildrenResponse is the response to the list children method
   316  type ListChildrenResponse struct {
   317  	Value    []Item `json:"value"`           // An array of Item objects
   318  	NextLink string `json:"@odata.nextLink"` // A URL to retrieve the next available page of items.
   319  }
   320  
   321  // CreateItemRequest is the request to create an item object
   322  type CreateItemRequest struct {
   323  	Name             string      `json:"name"`                   // Name of the folder to be created.
   324  	Folder           FolderFacet `json:"folder"`                 // Empty Folder facet to indicate that folder is the type of resource to be created.
   325  	ConflictBehavior string      `json:"@name.conflictBehavior"` // Determines what to do if an item with a matching name already exists in this folder. Accepted values are: rename, replace, and fail (the default).
   326  }
   327  
   328  // CreateItemWithMetadataRequest is like CreateItemRequest but also allows setting Metadata
   329  type CreateItemWithMetadataRequest struct {
   330  	CreateItemRequest
   331  	Metadata
   332  }
   333  
   334  // SetFileSystemInfo is used to Update an object's FileSystemInfo.
   335  type SetFileSystemInfo struct {
   336  	FileSystemInfo FileSystemInfoFacet `json:"fileSystemInfo"` // File system information on client. Read-write.
   337  }
   338  
   339  // CreateUploadRequest is used by CreateUploadSession to set the dates correctly
   340  type CreateUploadRequest struct {
   341  	Item Metadata `json:"item"`
   342  }
   343  
   344  // CreateUploadResponse is the response from creating an upload session
   345  type CreateUploadResponse struct {
   346  	UploadURL          string    `json:"uploadUrl"`          // "https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337",
   347  	ExpirationDateTime Timestamp `json:"expirationDateTime"` // "2015-01-29T09:21:55.523Z",
   348  	NextExpectedRanges []string  `json:"nextExpectedRanges"` // ["0-"]
   349  }
   350  
   351  // UploadFragmentResponse is the response from uploading a fragment
   352  type UploadFragmentResponse struct {
   353  	ExpirationDateTime Timestamp `json:"expirationDateTime"` // "2015-01-29T09:21:55.523Z",
   354  	NextExpectedRanges []string  `json:"nextExpectedRanges"` // ["0-"]
   355  }
   356  
   357  // CopyItemRequest is the request to copy an item object
   358  //
   359  // Note: The parentReference should include either an id or path but
   360  // not both. If both are included, they need to reference the same
   361  // item or an error will occur.
   362  type CopyItemRequest struct {
   363  	ParentReference ItemReference `json:"parentReference"` // Reference to the parent item the copy will be created in.
   364  	Name            *string       `json:"name"`            // Optional The new name for the copy. If this isn't provided, the same name will be used as the original.
   365  }
   366  
   367  // MoveItemRequest is the request to copy an item object
   368  //
   369  // Note: The parentReference should include either an id or path but
   370  // not both. If both are included, they need to reference the same
   371  // item or an error will occur.
   372  type MoveItemRequest struct {
   373  	ParentReference *ItemReference       `json:"parentReference,omitempty"` // Reference to the destination parent directory
   374  	Name            string               `json:"name,omitempty"`            // Optional The new name for the file. If this isn't provided, the same name will be used as the original.
   375  	FileSystemInfo  *FileSystemInfoFacet `json:"fileSystemInfo,omitempty"`  // File system information on client. Read-write.
   376  }
   377  
   378  // CreateShareLinkRequest is the request to create a sharing link
   379  // Always Type:view and Scope:anonymous for public sharing
   380  type CreateShareLinkRequest struct {
   381  	Type     string     `json:"type"`                         // Link type in View, Edit or Embed
   382  	Scope    string     `json:"scope,omitempty"`              // Scope in anonymous, organization
   383  	Password string     `json:"password,omitempty"`           // The password of the sharing link that is set by the creator. Optional and OneDrive Personal only.
   384  	Expiry   *time.Time `json:"expirationDateTime,omitempty"` // A String with format of yyyy-MM-ddTHH:mm:ssZ of DateTime indicates the expiration time of the permission.
   385  }
   386  
   387  // CreateShareLinkResponse is the response from CreateShareLinkRequest
   388  type CreateShareLinkResponse struct {
   389  	ID    string   `json:"id"`
   390  	Roles []string `json:"roles"`
   391  	Link  struct {
   392  		Type        string `json:"type"`
   393  		Scope       string `json:"scope"`
   394  		WebURL      string `json:"webUrl"`
   395  		Application struct {
   396  			ID          string `json:"id"`
   397  			DisplayName string `json:"displayName"`
   398  		} `json:"application"`
   399  	} `json:"link"`
   400  }
   401  
   402  // AsyncOperationStatus provides information on the status of an asynchronous job progress.
   403  //
   404  // The following API calls return AsyncOperationStatus resources:
   405  //
   406  // Copy Item
   407  // Upload From URL
   408  type AsyncOperationStatus struct {
   409  	PercentageComplete float64 `json:"percentageComplete"` // A float value between 0 and 100 that indicates the percentage complete.
   410  	Status             string  `json:"status"`             // A string value that maps to an enumeration of possible values about the status of the job. "notStarted | inProgress | completed | updating | failed | deletePending | deleteFailed | waiting"
   411  	ErrorCode          string  `json:"errorCode"`          // Not officially documented :(
   412  }
   413  
   414  // GetID returns a normalized ID of the item
   415  // If DriveID is known it will be prefixed to the ID with # separator
   416  // Can be parsed using onedrive.parseNormalizedID(normalizedID)
   417  func (i *Item) GetID() string {
   418  	if i.IsRemote() && i.RemoteItem.ID != "" {
   419  		return i.RemoteItem.ParentReference.DriveID + "#" + i.RemoteItem.ID
   420  	} else if i.ParentReference != nil && !strings.Contains(i.ID, "#") {
   421  		return i.ParentReference.DriveID + "#" + i.ID
   422  	}
   423  	return i.ID
   424  }
   425  
   426  // GetDriveID returns a normalized ParentReference of the item
   427  func (i *Item) GetDriveID() string {
   428  	return i.GetParentReference().DriveID
   429  }
   430  
   431  // GetName returns a normalized Name of the item
   432  func (i *Item) GetName() string {
   433  	if i.IsRemote() && i.RemoteItem.Name != "" {
   434  		return i.RemoteItem.Name
   435  	}
   436  	return i.Name
   437  }
   438  
   439  // GetFolder returns a normalized Folder of the item
   440  func (i *Item) GetFolder() *FolderFacet {
   441  	if i.IsRemote() && i.RemoteItem.Folder != nil {
   442  		return i.RemoteItem.Folder
   443  	}
   444  	return i.Folder
   445  }
   446  
   447  // GetPackage returns a normalized Package of the item
   448  func (i *Item) GetPackage() *PackageFacet {
   449  	if i.IsRemote() && i.RemoteItem.Package != nil {
   450  		return i.RemoteItem.Package
   451  	}
   452  	return i.Package
   453  }
   454  
   455  // GetPackageType returns the package type of the item if available,
   456  // otherwise ""
   457  func (i *Item) GetPackageType() string {
   458  	pack := i.GetPackage()
   459  	if pack == nil {
   460  		return ""
   461  	}
   462  	return pack.Type
   463  }
   464  
   465  // GetFile returns a normalized File of the item
   466  func (i *Item) GetFile() *FileFacet {
   467  	if i.IsRemote() && i.RemoteItem.File != nil {
   468  		return i.RemoteItem.File
   469  	}
   470  	return i.File
   471  }
   472  
   473  // GetFileSystemInfo returns a normalized FileSystemInfo of the item
   474  func (i *Item) GetFileSystemInfo() *FileSystemInfoFacet {
   475  	if i.IsRemote() && i.RemoteItem.FileSystemInfo != nil {
   476  		return i.RemoteItem.FileSystemInfo
   477  	}
   478  	return i.FileSystemInfo
   479  }
   480  
   481  // GetSize returns a normalized Size of the item
   482  func (i *Item) GetSize() int64 {
   483  	if i.IsRemote() && i.RemoteItem.Size != 0 {
   484  		return i.RemoteItem.Size
   485  	}
   486  	return i.Size
   487  }
   488  
   489  // GetWebURL returns a normalized WebURL of the item
   490  func (i *Item) GetWebURL() string {
   491  	if i.IsRemote() && i.RemoteItem.WebURL != "" {
   492  		return i.RemoteItem.WebURL
   493  	}
   494  	return i.WebURL
   495  }
   496  
   497  // GetCreatedBy returns a normalized CreatedBy of the item
   498  func (i *Item) GetCreatedBy() IdentitySet {
   499  	if i.IsRemote() && i.RemoteItem.CreatedBy != (IdentitySet{}) {
   500  		return i.RemoteItem.CreatedBy
   501  	}
   502  	return i.CreatedBy
   503  }
   504  
   505  // GetLastModifiedBy returns a normalized LastModifiedBy of the item
   506  func (i *Item) GetLastModifiedBy() IdentitySet {
   507  	if i.IsRemote() && i.RemoteItem.LastModifiedBy != (IdentitySet{}) {
   508  		return i.RemoteItem.LastModifiedBy
   509  	}
   510  	return i.LastModifiedBy
   511  }
   512  
   513  // GetCreatedDateTime returns a normalized CreatedDateTime of the item
   514  func (i *Item) GetCreatedDateTime() Timestamp {
   515  	if i.IsRemote() && i.RemoteItem.CreatedDateTime != (Timestamp{}) {
   516  		return i.RemoteItem.CreatedDateTime
   517  	}
   518  	return i.CreatedDateTime
   519  }
   520  
   521  // GetLastModifiedDateTime returns a normalized LastModifiedDateTime of the item
   522  func (i *Item) GetLastModifiedDateTime() Timestamp {
   523  	if i.IsRemote() && i.RemoteItem.LastModifiedDateTime != (Timestamp{}) {
   524  		return i.RemoteItem.LastModifiedDateTime
   525  	}
   526  	return i.LastModifiedDateTime
   527  }
   528  
   529  // GetParentReference returns a normalized ParentReference of the item
   530  func (i *Item) GetParentReference() *ItemReference {
   531  	if i.IsRemote() && i.ParentReference == nil {
   532  		return i.RemoteItem.ParentReference
   533  	}
   534  	return i.ParentReference
   535  }
   536  
   537  // MalwareDetected returns true if OneDrive has detected that this item contains malware.
   538  func (i *Item) MalwareDetected() bool {
   539  	return i.Malware != nil
   540  }
   541  
   542  // IsRemote checks if item is a remote item
   543  func (i *Item) IsRemote() bool {
   544  	return i.RemoteItem != nil
   545  }
   546  
   547  // User details for each version
   548  type User struct {
   549  	Email       string `json:"email"`
   550  	ID          string `json:"id"`
   551  	DisplayName string `json:"displayName"`
   552  }
   553  
   554  // LastModifiedBy for each version
   555  type LastModifiedBy struct {
   556  	User User `json:"user"`
   557  }
   558  
   559  // Version info
   560  type Version struct {
   561  	ID                   string         `json:"id"`
   562  	LastModifiedDateTime time.Time      `json:"lastModifiedDateTime"`
   563  	Size                 int            `json:"size"`
   564  	LastModifiedBy       LastModifiedBy `json:"lastModifiedBy"`
   565  }
   566  
   567  // VersionsResponse is returned from /versions
   568  type VersionsResponse struct {
   569  	Versions []Version `json:"value"`
   570  }
   571  
   572  // DriveResource is returned from /me/drive
   573  type DriveResource struct {
   574  	DriveID   string `json:"id"`
   575  	DriveName string `json:"name"`
   576  	DriveType string `json:"driveType"`
   577  }
   578  
   579  // DrivesResponse is returned from /sites/{siteID}/drives",
   580  type DrivesResponse struct {
   581  	Drives []DriveResource `json:"value"`
   582  }
   583  
   584  // SiteResource is part of the response from "/sites/root:"
   585  type SiteResource struct {
   586  	SiteID   string `json:"id"`
   587  	SiteName string `json:"displayName"`
   588  	SiteURL  string `json:"webUrl"`
   589  }
   590  
   591  // SiteResponse is returned from "/sites/root:"
   592  type SiteResponse struct {
   593  	Sites []SiteResource `json:"value"`
   594  }