get disk space size

pull/276/head
qkqpttgf 2021-03-14 17:00:39 +08:00 committed by GitHub
parent 82e8d5d0e7
commit 7b51e773f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -851,7 +851,7 @@ class Onedrive {
if (substr($url,-1)=='/') $url=substr($url,0,-1); if (substr($url,-1)=='/') $url=substr($url,0,-1);
} }
$url .= ':/thumbnails/0/medium'; $url .= ':/thumbnails/0/medium';
$files = json_decode(curl('GET', $url, false, ['Authorization' => 'Bearer ' . $this->access_token])['body'], true); $files = json_decode($this->MSAPI('GET', $url)['body'], true);
if (isset($files['url'])) { if (isset($files['url'])) {
savecache('thumb_' . $path, $files['url'], $this->disktag); savecache('thumb_' . $path, $files['url'], $this->disktag);
$thumb_url = $files['url']; $thumb_url = $files['url'];
@ -901,6 +901,19 @@ class Onedrive {
} }
return output($response['body'], $response['stat']); return output($response['body'], $response['stat']);
} }
public function getDiskSpace() {
if (!($diskSpace = getcache('diskSpace', $this->disktag))) {
$url = $this->api_url . $this->ext_api_url;
if (substr($url, -5)=='/root') $url = substr($url, 0, -5);
else return $url;
$response = json_decode($this->MSAPI('GET', $url)['body'], true)['quota'];
$used = size_format($response['used']);
$total = size_format($response['total']);
$diskSpace = $used . ' / ' . $total;
savecache('diskSpace', $diskSpace, $this->disktag);
}
return $diskSpace;
}
protected function MSAPI($method, $path, $data = '') protected function MSAPI($method, $path, $data = '')
{ {