From 8c5c61508cd1a3c3bbfbff1e3ac0a14a73e21b59 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Sat, 6 Mar 2021 15:59:18 +0800
Subject: [PATCH] try to stop when activeLimit
---
disk/Onedrive.php | 88 ++++++++++++++++++++++++++---------------------
1 file changed, 49 insertions(+), 39 deletions(-)
diff --git a/disk/Onedrive.php b/disk/Onedrive.php
index dd33ddc..1128cb1 100644
--- a/disk/Onedrive.php
+++ b/disk/Onedrive.php
@@ -17,7 +17,6 @@ class Onedrive {
$this->oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/';
$this->api_url = 'https://graph.microsoft.com/v1.0';
$this->scope = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access';
-
$this->client_secret = urlencode($this->client_secret);
$this->scope = urlencode($this->scope);
$this->DownurlStrName = '@microsoft.graph.downloadUrl';
@@ -73,12 +72,7 @@ class Onedrive {
if (substr($url,-1)=='/') $url=substr($url,0,-1);
}
$url .= '?expand=children(select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$this->DownurlStrName.')';
- $retry = 0;
- $arr = [];
- while ($retry<3&&!$arr['stat']) {
- $arr = curl('GET', $url, '', ['Authorization' => 'Bearer ' . $this->access_token], 1);
- $retry++;
- }
+ $arr = $this->MSAPI('GET', $url);
//echo $url . '
' . json_encode($arr, JSON_PRETTY_PRINT) . ''; if ($arr['stat']<500) { $files = json_decode($arr['body'], true); @@ -187,7 +181,7 @@ class Onedrive { $url .= ':'; } $url .= '/children?$top=' . ($page-1)*200 . '&$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,' . $this->DownurlStrName; - $children_tmp = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + $children_tmp = json_decode($this->MSAPI('GET', $url)['body'], true); //echo $url . '
' . json_encode($children_tmp, JSON_PRETTY_PRINT) . ''; $p = 1; $i = 0; @@ -204,7 +198,7 @@ class Onedrive { } $url = $children_tmp['@odata.nextLink']; - $children_tmp = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + $children_tmp = json_decode($this->MSAPI('GET', $url)['body'], true); //echo $url . '
' . json_encode($children_tmp, JSON_PRETTY_PRINT) . ''; $p = $page; $i = 0; @@ -254,7 +248,7 @@ class Onedrive { $url .= ':'; } $url .= '/children?$select=id,name,size,file,folder,parentReference,lastModifiedDateTime,'.$this->DownurlStrName; - $children = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + $children = json_decode($this->MSAPI('GET', $url)['body'], true); // echo $url . '
' . json_encode($children, JSON_PRETTY_PRINT) . ''; savecache('files_' . $path . '_page_' . $page1, $children, $this->disktag); $nextlink=getcache('nextlink_' . $path . '_page_' . $page1, $this->disktag); @@ -267,7 +261,7 @@ class Onedrive { $url = $children['@odata.nextLink']; for ($page2=$page1+1;$page2<=$page;$page2++) { sleep(1); - $children = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + $children = json_decode($this->MSAPI('GET', $url)['body'], true); savecache('files_' . $path . '_page_' . $page2, $children, $this->disktag); $nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $this->disktag); if ($nextlink!=$children['@odata.nextLink']) { @@ -287,13 +281,13 @@ class Onedrive { $pageinfocache['dirsize'] = $files['size']; $pageinfocache['cachesize'] = $cachefile['size']; $pageinfocache['size'] = $files['size']-$cachefile['size']; - if ($pageinfochange == 1) $this->MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $this->access_token)['body']; + if ($pageinfochange == 1) $this->MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT))['body']; return $files;*/ } } else { for ($page2=$page3+1;$page2<=$page;$page2++) { sleep(1); - $children = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); + $children = json_decode($this->MSAPI('GET', $url)['body'], true); savecache('files_' . $path . '_page_' . $page2, $children, $this->disktag, 3300); $nextlink=getcache('nextlink_' . $path . '_page_' . $page2, $this->disktag); if ($nextlink!=$children['@odata.nextLink']) { @@ -313,7 +307,7 @@ class Onedrive { $pageinfocache['dirsize'] = $files['size']; $pageinfocache['cachesize'] = $cachefile['size']; $pageinfocache['size'] = $files['size']-$cachefile['size']; - if ($pageinfochange == 1) $this->MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT), $this->access_token)['body']; + if ($pageinfochange == 1) $this->MSAPI('PUT', path_format($path.'/'.$cachefilename), json_encode($pageinfocache, JSON_PRETTY_PRINT))['body']; return $files;*/ } } @@ -336,23 +330,23 @@ class Onedrive { $oldname = path_format($file['path'] . '/' . $oldname); $data = '{"name":"' . $newname . '"}'; //echo $oldname; - $result = $this->MSAPI('PATCH', $oldname, $data, $this->access_token); + $result = $this->MSAPI('PATCH', $oldname, $data); return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); } public function Delete($file) { $filename = spurlencode($file['name']); $filename = path_format($file['path'] . '/' . $filename); //echo $filename; - $result = $this->MSAPI('DELETE', $filename, '', $this->access_token); + $result = $this->MSAPI('DELETE', $filename, ''); return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); return output($result['body'], $result['stat']); } public function Encrypt($folder, $passfilename, $pass) { $filename = path_format($folder['path'] . '/' . urlencode($passfilename)); if ($pass==='') { - $result = $this->MSAPI('DELETE', $filename, '', $this->access_token); + $result = $this->MSAPI('DELETE', $filename, ''); } else { - $result = $this->MSAPI('PUT', $filename, $pass, $this->access_token); + $result = $this->MSAPI('PUT', $filename, $pass); } $path1 = $folder['path']; if ($path1!='/'&&substr($path1, -1)=='/') $path1 = substr($path1, 0, -1); @@ -364,7 +358,7 @@ class Onedrive { $filename = spurlencode($file['name']); $filename = path_format($file['path'] . '/' . $filename); $data = '{"parentReference":{"path": "/drive/root:' . $folder['path'] . '"}}'; - $result = $this->MSAPI('PATCH', $filename, $data, $this->access_token); + $result = $this->MSAPI('PATCH', $filename, $data); $path2 = spurlencode($folder['path'], '/'); if ($path2!='/'&&substr($path2, -1)=='/') $path2 = substr($path2, 0, -1); savecache('path_' . $path2, json_decode('{}', true), $this->disktag, 1); @@ -383,7 +377,7 @@ class Onedrive { $newname = '.' . $namearr[1] . ' (' . date("Ymd\THis\Z") . ')'; } $data = '{ "name": "' . $newname . '" }'; - $result = $this->MSAPI('copy', $filename, $data, $this->access_token); + $result = $this->MSAPI('copy', $filename, $data); /*$num = 0; while ($result['stat']==409 && json_decode($result['body'], true)['error']['code']=='nameAlreadyExists') { $num++; @@ -395,7 +389,7 @@ class Onedrive { } //$newname = spurlencode($newname); $data = '{ "name": "' . $newname . '" }'; - $result = $this->MSAPI('copy', $filename, $data, $this->access_token); + $result = $this->MSAPI('copy', $filename, $data); }*/ return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); return output($result['body'], $result['stat']); @@ -406,7 +400,7 @@ class Onedrive { $response=MSAPI('POST',$filename,'{"item": { "@microsoft.graph.conflictBehavior": "replace" }}',$_SERVER['access_token']); $uploadurl=json_decode($response,true)['uploadUrl']; echo MSAPI('PUT',$uploadurl,$data,$_SERVER['access_token']);*/ - $result = $this->MSAPI('PUT', $file['path'], $content, $this->access_token); + $result = $this->MSAPI('PUT', $file['path'], $content); //return output($result['body'], $result['stat']); //echo $result; $resultarry = json_decode($result['body'],true); @@ -417,11 +411,11 @@ class Onedrive { if ($type=='file') { $filename = spurlencode($name); $filename = path_format($parent['path'] . '/' . $filename); - $result = $this->MSAPI('PUT', $filename, $content, $this->access_token); + $result = $this->MSAPI('PUT', $filename, $content); } if ($type=='folder') { $data = '{ "name": "' . $name . '", "folder": { }, "@microsoft.graph.conflictBehavior": "rename" }'; - $result = $this->MSAPI('children', $parent['path'], $data, $this->access_token); + $result = $this->MSAPI('children', $parent['path'], $data); } //savecache('path_' . $path1, json_decode('{}',true), $_SERVER['disktag'], 1); return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']); @@ -446,7 +440,7 @@ class Onedrive { return message($html, $title, 201); } $response = $this->get_access_token($refresh_token); - if (!$response) return message($this->error['body'], 'Error', $this->error['stat']); + if (!$response) return message($this->error['body'], $this->error['stat'] . ' Error', $this->error['stat']); } $tmp = null; @@ -516,7 +510,7 @@ class Onedrive { return message($html, $title, 201); } $response = $this->get_access_token($refresh_token); - if (!$response) return message($this->error['body'], 'Error', $this->error['stat']); + if (!$response) return message($this->error['body'], $this->error['stat'] . ' Error', $this->error['stat']); } $api = $this->api_url . '/sites/root'; @@ -709,7 +703,7 @@ class Onedrive {