From 0f5c7587d5885226533892ea97d36de264579d8f Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Mon, 15 Mar 2021 21:16:21 +0800 Subject: [PATCH] get personal drive space size --- disk/Googledrive.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/disk/Googledrive.php b/disk/Googledrive.php index 0a59198..491c316 100644 --- a/disk/Googledrive.php +++ b/disk/Googledrive.php @@ -769,7 +769,19 @@ class Googledrive { return true; } public function getDiskSpace() { - return ''; + if ($this->driveId!='root') return '0 / 0'; + if (!($diskSpace = getcache('diskSpace', $this->disktag))) { + $url = $this->api_url . '/about?fields=storageQuota'; + $response = $this->GDAPI('GET', $url); + if ($response['stat']==200) { + $res = json_decode($response['body'], true)['storageQuota']; + $used = size_format($res['usage']); + $total = size_format($res['limit']); + $diskSpace = $used . ' / ' . $total; + savecache('diskSpace', $diskSpace, $this->disktag); + } else return json_encode($res); + } + return $diskSpace; } protected function GDAPI($method, $url, $data = '')