Skip to content

Commit

Permalink
[Bug]: OneDrive URLs - Properly Handle Type Codes
Browse files Browse the repository at this point in the history
Some of the path segments describe the file type and permissions
  • Loading branch information
seandenigris committed Aug 16, 2024
1 parent 60e5328 commit d44add3
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/LivingLibrary/LlOneDriveFile.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ Class {
#superclass : #LlWebResource,
#instVars : [
'owner',
'file'
'file',
'typeCodes'
],
#category : #'LivingLibrary-Core'
}

{ #category : #'instance creation' }
LlOneDriveFile class >> fromString: aString [

| aUrl filePath |
| aUrl filePath owner typeCodes |
(aString beginsWith: self urlBase printString) ifFalse: [ self error: 'invalid one drive URL' ].

aUrl := aString asUrl.
typeCodes := RelativePath withAll: (aUrl pathSegments first: 3).
owner := aUrl pathSegments fourth.
filePath := RelativePath withAll: (aUrl pathSegments allButFirst: 4).

^ self new
owner: aUrl pathSegments fourth;
owner: owner;
typeCodes: typeCodes;
file: filePath;
yourself
]
Expand All @@ -32,13 +36,13 @@ LlOneDriveFile class >> peCanHandleFromString: aString [
{ #category : #accessing }
LlOneDriveFile class >> urlBase [

^ 'https://nrny-my.sharepoint.com/:x:/r/personal' asUrl
^ 'https://nrny-my.sharepoint.com/' asUrl
]

{ #category : #accessing }
LlOneDriveFile >> downloadUrl [

^ self class urlBase withPathSegments: (self file segments copyWithFirst: self owner)
^ self class urlBase withPathSegments: (self typeCodes / self owner resolvePath: self file)
]

{ #category : #accessing }
Expand Down Expand Up @@ -74,6 +78,29 @@ LlOneDriveFile >> printOn: aStream [
print: self url
]

{ #category : #accessing }
LlOneDriveFile >> typeCodes [
^ typeCodes

"
Apparently the first code is related to file type and the second to permissions/visibility
Characters right after the main URL: https://companyname.sharepoint.com change depending on what you are sharing:
“:f” means Folder sharing
“:w” means Word document sharing
“:x” means Excel document sharing
“:p” means PowerPoint document sharing
“:b” means PDF document sharing (https://sharepointmaven.com/the-anatomy-of-a-sharepoint-url/)
/:r - indicates a read-only link
/:e - edit link (https://sharepoint.stackexchange.com/a/270230)"
]

{ #category : #accessing }
LlOneDriveFile >> typeCodes: anObject [
typeCodes := anObject
]

{ #category : #accessing }
LlOneDriveFile >> url [

Expand Down

0 comments on commit d44add3

Please sign in to comment.