rapid upload (need bcmath)

pull/574/head
qkqpttgf 2022-03-09 14:11:41 +08:00 committed by GitHub
parent 64096211e2
commit ed631d958d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 2 deletions

View File

@ -93,9 +93,10 @@ class Aliyundrive {
if (!($files = getcache('path_' . $path, $this->disktag))) {
if ($path == '/' || $path == '') {
$files = $this->fileList('root');
//error_log1('root_id' . $files['id']);
//error_log1('root_id' . $files['file_id']);
$files['file_id'] = 'root';
$files['type'] = 'folder';
//error_log1(json_encode($files, JSON_PRETTY_PRINT));
} else {
$tmp = splitlast($path, '/');
$parent_path = $tmp[0];
@ -490,6 +491,31 @@ class Aliyundrive {
return curl('POST', $url, json_encode($data), $header);
}
protected function fileCreate1($parentId, $fileName, $sha1, $proof_code, $size, $part_number) {
//$url = $this->api_url . '/file/create';
$url = 'https://api.aliyundrive.com/adrive/v2/file/createWithFolders';
$header["content-type"] = "application/json; charset=utf-8";
$header['authorization'] = 'Bearer ' . $this->access_token;
$data['check_name_mode'] = 'refuse'; // ignore, auto_rename, refuse.
$data['content_hash'] = $sha1;
$data['content_hash_name'] = 'sha1';
//$data['content_type'] = '';
$data['drive_id'] = $this->driveId;
//$data['ignoreError'] = false;
$data['name'] = $fileName;
$data['parent_file_id'] = $parentId;
for ($i=0;$i<$part_number;$i++) {
$data['part_info_list'][$i]['part_number'] = $i+1;
}
$data['proof_code'] = $proof_code;
$data['proof_version'] = 'v1';
$data['size'] = (int)$size;
$data['type'] = 'file';
return curl('POST', $url, json_encode($data), $header);
}
protected function tmpfileCreate($parentId, $tmpFilePath, $tofileName = '') {
$sha1 = sha1_file($tmpFilePath);
if ($tofileName == '') $tofileName = splitlast($tmpFilePath, '/')[1];
@ -545,6 +571,20 @@ class Aliyundrive {
$result = $this->fileComplete($_POST['fileid'], $_POST['uploadid'], json_decode($_POST['etag'], true));
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
} else {
if (isset($_POST['CalcProof'])&&is_numeric($_POST['filesize'])) {
// Calc proof code
if (!function_exists('hexdec')) {
// no php-bcmath
return output(0, 200);
} else {
$r = bchexdec( substr(md5($this->access_token), 0, 16) );
$i = $_POST['filesize'];
//$o = $i ? bcmod($r, $i) : 0;
$o = bcmod($r, $i);
//return output(hexdec( substr(md5($this->access_token), 0, 16) ) . ' , ' . $r . ' / ' . $i . ' = ' . $o, 200);
return output($o, 200);
}
}
if ($_POST['upbigfilename']=='') return output('error: no file name', 400);
if (!is_numeric($_POST['filesize'])) return output('error: no file size', 400);
if (!isset($_POST['filesha1'])) return output('error: no file sha1', 400);
@ -574,7 +614,8 @@ class Aliyundrive {
//error_log1($res['body']);
$parent_file_id = json_decode($res['body'], true)['file_id'];
}
$response = $this->fileCreate($parent_file_id, $filename, $_POST['filesha1'], $fileinfo['size'], ceil($fileinfo['size']/$_POST['chunksize']));
//$response = $this->fileCreate($parent_file_id, $filename, $_POST['filesha1'], $fileinfo['size'], ceil($fileinfo['size']/$_POST['chunksize']));
$response = $this->fileCreate1($parent_file_id, $filename, $_POST['filesha1'], $_POST['proof_code'], $fileinfo['size'], ceil($fileinfo['size']/$_POST['chunksize']));
$res = json_decode($response['body'], true);
if (isset($res['exist'])) {
// 已经有