|
7 | 7 |
|
8 | 8 | class Files extends MsGraph
|
9 | 9 | {
|
10 |
| - public function getFiles($path = null, $order = 'asc') |
| 10 | + public function getFiles($path = null, $type = 'me') |
11 | 11 | {
|
12 |
| - $path = $path === null ? "me/drive/root/children?\$orderby=name%20$order" : "me/drive/root:".$this->forceStartingSlash($path).':/children?\$orderby=name%20$order'; |
| 12 | + $path = $path === null ? $type.'/drive/root/children?$orderby=name%20asc' : $type.'/drive/root:'.$this->forceStartingSlash($path).':/children'; |
13 | 13 | return MsGraph::get($path);
|
14 | 14 | }
|
15 | 15 |
|
16 |
| - public function getDrive() |
| 16 | + public function getDrive($type = 'me') |
17 | 17 | {
|
18 |
| - return MsGraph::get('me/drive'); |
| 18 | + return MsGraph::get($type.'/drive'); |
19 | 19 | }
|
20 | 20 |
|
21 |
| - public function getDrives() |
| 21 | + public function getDrives($type = 'me') |
22 | 22 | {
|
23 |
| - return MsGraph::get('me/drives'); |
| 23 | + return MsGraph::get($type.'/drives'); |
24 | 24 | }
|
25 | 25 |
|
26 |
| - public function search($term) |
| 26 | + public function search($term, $type = 'me') |
27 | 27 | {
|
28 |
| - return MsGraph::get("me/drive/root/search(q='$term')"); |
| 28 | + return MsGraph::get($type."/drive/root/search(q='$term')"); |
29 | 29 | }
|
30 | 30 |
|
31 |
| - public function downloadFile($id) |
| 31 | + public function downloadFile($id, $type = 'me') |
32 | 32 | {
|
33 |
| - $id = MsGraph::get("me/drive/items/$id"); |
| 33 | + $id = MsGraph::get($type."/drive/items/$id"); |
34 | 34 |
|
35 | 35 | return redirect()->away($id['@microsoft.graph.downloadUrl']);
|
36 | 36 | }
|
37 | 37 |
|
38 |
| - public function deleteFile($id) |
| 38 | + public function deleteFile($id, $type = 'me') |
39 | 39 | {
|
40 |
| - return MsGraph::delete("me/drive/items/$id"); |
| 40 | + return MsGraph::delete($type."/drive/items/$id"); |
41 | 41 | }
|
42 | 42 |
|
43 |
| - public function createFolder($name, $path = null) |
| 43 | + public function createFolder($name, $path, $type = 'me') |
44 | 44 | {
|
45 |
| - $path = $path === null ? 'me/drive/root/children' : 'me/drive/root:'.$this->forceStartingSlash($path).':/children'; |
| 45 | + $path = $path === null ? $type.'/drive/root/children' : $type.'/drive/root:'.$this->forceStartingSlash($path).':/children'; |
46 | 46 | return MsGraph::post($path, [
|
47 | 47 | 'name' => $name,
|
48 | 48 | 'folder' => new \stdClass(),
|
49 | 49 | "@microsoft.graph.conflictBehavior" => "rename"
|
50 | 50 | ]);
|
51 | 51 | }
|
52 | 52 |
|
53 |
| - public function getItem($id) |
| 53 | + public function getItem($id, $type = 'me') |
54 | 54 | {
|
55 |
| - return MsGraph::get("me/drive/items/$id"); |
| 55 | + return MsGraph::get($type."/drive/items/$id"); |
56 | 56 | }
|
57 | 57 |
|
58 |
| - public function rename($name, $id) |
| 58 | + public function rename($name, $id, $type = 'me') |
59 | 59 | {
|
60 |
| - $path = "me/drive/items/$id"; |
| 60 | + $path = $type."/drive/items/$id"; |
61 | 61 | return MsGraph::patch($path, [
|
62 | 62 | 'name' => $name
|
63 | 63 | ]);
|
64 | 64 | }
|
65 | 65 |
|
66 |
| - public function upload($name, $uploadPath, $path = null) |
| 66 | + public function upload($name, $uploadPath, $path = null, $type = 'me') |
67 | 67 | {
|
68 |
| - $uploadSession = $this->createUploadSession($name, $path); |
| 68 | + $uploadSession = $this->createUploadSession($name, $path, $type); |
69 | 69 | $uploadUrl = $uploadSession['uploadUrl'];
|
70 | 70 |
|
71 | 71 | $fragSize = 320 * 1024;
|
@@ -97,19 +97,20 @@ public function upload($name, $uploadPath, $path = null)
|
97 | 97 | ];
|
98 | 98 |
|
99 | 99 | $client = new Client;
|
100 |
| - $client->put($uploadUrl, [ |
| 100 | + $response = $client->put($uploadUrl, [ |
101 | 101 | 'headers' => $headers,
|
102 | 102 | 'body' => $data,
|
103 | 103 | ]);
|
104 | 104 |
|
105 | 105 | $bytesRemaining = $bytesRemaining - $chunkSize;
|
106 | 106 | $i++;
|
107 | 107 | }
|
| 108 | + |
108 | 109 | }
|
109 | 110 |
|
110 |
| - protected function createUploadSession($name, $path = null) |
| 111 | + protected function createUploadSession($name, $path = null, $type = 'me') |
111 | 112 | {
|
112 |
| - $path = $path === null ? "me/drive/root:/$name:/createUploadSession" : "me/drive/root:".$this->forceStartingSlash($path)."/$name:/createUploadSession"; |
| 113 | + $path = $path === null ? $type."/drive/root:/$name:/createUploadSession" : $type."/drive/root:".$this->forceStartingSlash($path)."/$name:/createUploadSession"; |
113 | 114 |
|
114 | 115 | return MsGraph::post($path, [
|
115 | 116 | 'item' => [
|
|
0 commit comments