get personal drive space size

pull/276/head
qkqpttgf 2021-03-15 21:16:21 +08:00 committed by GitHub
parent d5c456bc0b
commit 0f5c7587d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -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 = '')