From 7b51e773f3ac2b17cdb0ea560942b13db3426ac3 Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Sun, 14 Mar 2021 17:00:39 +0800 Subject: [PATCH] get disk space size --- disk/Onedrive.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/disk/Onedrive.php b/disk/Onedrive.php index d464d82..578b80b 100644 --- a/disk/Onedrive.php +++ b/disk/Onedrive.php @@ -851,7 +851,7 @@ class Onedrive { if (substr($url,-1)=='/') $url=substr($url,0,-1); } $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'])) { savecache('thumb_' . $path, $files['url'], $this->disktag); $thumb_url = $files['url']; @@ -901,6 +901,19 @@ class Onedrive { } 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 = '') {