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