operate by id

pull/440/merge
qkqpttgf 2021-10-06 19:28:05 +08:00 committed by GitHub
parent 0a0162abe2
commit cb478ccf66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,7 @@
<?php <?php
// https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0
// https://docs.microsoft.com/zh-cn/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http
// https://developer.microsoft.com/zh-cn/graph/graph-explorer
class Onedrive { class Onedrive {
protected $access_token; protected $access_token;
@ -46,9 +49,6 @@ class Onedrive {
{ {
global $exts; global $exts;
if (!($files = getcache('path_' . $path, $this->disktag))) { if (!($files = getcache('path_' . $path, $this->disktag))) {
// https://docs.microsoft.com/en-us/graph/api/driveitem-get?view=graph-rest-1.0
// https://docs.microsoft.com/zh-cn/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http
// https://developer.microsoft.com/zh-cn/graph/graph-explorer
$pos = splitlast($path, '/'); $pos = splitlast($path, '/');
$parentpath = $pos[0]; $parentpath = $pos[0];
if ($parentpath=='') $parentpath = '/'; if ($parentpath=='') $parentpath = '/';
@ -350,7 +350,8 @@ class Onedrive {
$filename = spurlencode($file['name']); $filename = spurlencode($file['name']);
$filename = path_format($file['path'] . '/' . $filename); $filename = path_format($file['path'] . '/' . $filename);
//echo $filename; //echo $filename;
$result = $this->MSAPI('DELETE', $filename); if ($file['id']) $result = $this->MSAPI('DELETE', "/items/" . $file['id']);
else $result = $this->MSAPI('DELETE', $filename);
if ($result['stat']!=204) $r_body = json_encode($this->files_format(json_decode($result['body'], true))); if ($result['stat']!=204) $r_body = json_encode($this->files_format(json_decode($result['body'], true)));
return output($r_body, $result['stat']); return output($r_body, $result['stat']);
//return output($result['body'], $result['stat']); //return output($result['body'], $result['stat']);
@ -358,7 +359,7 @@ class Onedrive {
public function Encrypt($folder, $passfilename, $pass) { public function Encrypt($folder, $passfilename, $pass) {
$filename = path_format($folder['path'] . '/' . urlencode($passfilename)); $filename = path_format($folder['path'] . '/' . urlencode($passfilename));
if ($pass==='') { if ($pass==='') {
$result = $this->MSAPI('DELETE', $filename, ''); $result = $this->MSAPI('DELETE', $filename);
} else { } else {
$result = $this->MSAPI('PUT', $filename, $pass); $result = $this->MSAPI('PUT', $filename, $pass);
} }
@ -372,7 +373,8 @@ class Onedrive {
$filename = spurlencode($file['name']); $filename = spurlencode($file['name']);
$filename = path_format($file['path'] . '/' . $filename); $filename = path_format($file['path'] . '/' . $filename);
$data = '{"parentReference":{"path": "/drive/root:' . $folder['path'] . '"}}'; $data = '{"parentReference":{"path": "/drive/root:' . $folder['path'] . '"}}';
$result = $this->MSAPI('PATCH', $filename, $data); if ($file['id']) $result = $this->MSAPI('PATCH', "/items/" . $file['id'], $data);
else $result = $this->MSAPI('PATCH', $filename, $data);
$path2 = spurlencode($folder['path'], '/'); $path2 = spurlencode($folder['path'], '/');
if ($path2!='/'&&substr($path2, -1)=='/') $path2 = substr($path2, 0, -1); if ($path2!='/'&&substr($path2, -1)=='/') $path2 = substr($path2, 0, -1);
savecache('path_' . $path2, json_decode('{}', true), $this->disktag, 1); savecache('path_' . $path2, json_decode('{}', true), $this->disktag, 1);
@ -391,7 +393,8 @@ class Onedrive {
$newname = '.' . $namearr[1] . ' (' . date("Ymd\THis\Z") . ')'; $newname = '.' . $namearr[1] . ' (' . date("Ymd\THis\Z") . ')';
} }
$data = '{ "name": "' . $newname . '" }'; $data = '{ "name": "' . $newname . '" }';
$result = $this->MSAPI('copy', $filename, $data); if ($file['id']) $result = $this->MSAPI('copy', "/items/" . $file['id'], $data);
else $result = $this->MSAPI('copy', $filename, $data);
/*$num = 0; /*$num = 0;
while ($result['stat']==409 && json_decode($result['body'], true)['error']['code']=='nameAlreadyExists') { while ($result['stat']==409 && json_decode($result['body'], true)['error']['code']=='nameAlreadyExists') {
$num++; $num++;
@ -1008,7 +1011,7 @@ class Onedrive {
if ($path=='' or $path=='/') { if ($path=='' or $path=='/') {
$url .= $method; $url .= $method;
} else { } else {
$url .= ':/' . $method; $url .= '/' . $method;
} }
$method='POST'; $method='POST';
$headers['Content-Type'] = 'application/json'; $headers['Content-Type'] = 'application/json';