add rapid copy, add smallfileupload
parent
54a997acbb
commit
e87b00a242
|
@ -321,7 +321,6 @@ class Aliyundrive {
|
||||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||||
}
|
}
|
||||||
public function Copy($file) {
|
public function Copy($file) {
|
||||||
return output('NO copy', 415);
|
|
||||||
if (!$file['id']) {
|
if (!$file['id']) {
|
||||||
$oldfile = $this->list_path($file['path'] . '/' . $file['name']);
|
$oldfile = $this->list_path($file['path'] . '/' . $file['name']);
|
||||||
//error_log1('res:' . json_encode($res));
|
//error_log1('res:' . json_encode($res));
|
||||||
|
@ -329,47 +328,60 @@ class Aliyundrive {
|
||||||
} else {
|
} else {
|
||||||
$oldfile = $this->fileGet($file['id']);
|
$oldfile = $this->fileGet($file['id']);
|
||||||
}
|
}
|
||||||
|
if ($oldfile['type']=='folder') return output('Can not copy folder', 415);
|
||||||
$url = $this->api_url . '/file/create';
|
if (!function_exists('bcadd')) {
|
||||||
|
// no php-bcmath
|
||||||
|
if ($bcmathurl = getConfig('bcmathUrl', $this->disktag)) {
|
||||||
|
if (strpos($bcmathurl, '?')) {
|
||||||
|
$bcmathurl .= '÷nd=0x' . substr(md5($this->access_token), 0, 16) . '&divisor=' . $oldfile['size'];
|
||||||
|
} else {
|
||||||
|
$bcmathurl .= '?dividend=0x' . substr(md5($this->access_token), 0, 16) . '&divisor=' . $oldfile['size'];
|
||||||
|
}
|
||||||
|
$o = curl('GET', $bcmathurl)['body'];
|
||||||
|
} else {
|
||||||
|
return output('No bcmath module, can not copy', 415);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$r = bchexdec( substr(md5($this->access_token), 0, 16) );
|
||||||
|
$o = bcmod($r, $oldfile['size']);
|
||||||
|
}
|
||||||
|
$res = curl('GET', $oldfile['download_url'], '', [
|
||||||
|
'Referer' => ''
|
||||||
|
, 'Range' => 'bytes=' . $o . '-' . ($o+7)
|
||||||
|
]);
|
||||||
|
if ($res['stat']==206) {
|
||||||
|
$proof_code = base64_encode($res['body']);
|
||||||
|
$url = 'https://api.aliyundrive.com/adrive/v2/file/createWithFolders';
|
||||||
$header["content-type"] = "application/json; charset=utf-8";
|
$header["content-type"] = "application/json; charset=utf-8";
|
||||||
$header['authorization'] = 'Bearer ' . $this->access_token;
|
$header['authorization'] = 'Bearer ' . $this->access_token;
|
||||||
|
|
||||||
$data['check_name_mode'] = 'auto_rename'; // ignore, auto_rename, refuse.
|
$data['check_name_mode'] = 'auto_rename'; // ignore, auto_rename, refuse.
|
||||||
$data['content_hash'] = $oldfile['content_hash'];
|
$data['content_hash'] = $oldfile['content_hash'];
|
||||||
$data['content_hash_name'] = 'sha1';
|
$data['content_hash_name'] = 'sha1';
|
||||||
$data['content_type'] = $oldfile['content_type'];
|
|
||||||
$data['drive_id'] = $this->driveId;
|
$data['drive_id'] = $this->driveId;
|
||||||
$data['ignoreError'] = false;
|
|
||||||
$data['name'] = $oldfile['name'];
|
$data['name'] = $oldfile['name'];
|
||||||
$data['parent_file_id'] = $oldfile['parent_file_id'];
|
$data['parent_file_id'] = $oldfile['parent_file_id'];
|
||||||
$data['part_info_list'][0]['part_number'] = 1;
|
$data['part_info_list'][0]['part_number'] = 1;
|
||||||
|
$data['proof_code'] = $proof_code;
|
||||||
|
$data['proof_version'] = 'v1';
|
||||||
$data['size'] = $oldfile['size'];
|
$data['size'] = $oldfile['size'];
|
||||||
$data['type'] = 'file';
|
$data['type'] = 'file';
|
||||||
|
|
||||||
$result = curl('POST', $url, json_encode($data), $header);
|
$result = curl('POST', $url, json_encode($data), $header);
|
||||||
|
/*if ($result['stat']==201) {
|
||||||
if ($result['stat']==201) {
|
|
||||||
//error_log1('1,url:' . $url .' res:' . json_encode($result));
|
|
||||||
$res = json_decode($result['body'], true);
|
$res = json_decode($result['body'], true);
|
||||||
|
if ($res['rapid_upload']) return output('rapid upload', 200);
|
||||||
$url = $res['part_info_list'][0]['upload_url'];
|
$url = $res['part_info_list'][0]['upload_url'];
|
||||||
if (!$url) { // 无url,应该算秒传
|
if (!$url) { // 无url,应该算秒传
|
||||||
return output('no up url', 200);
|
return output('no up url', 200);
|
||||||
} else {
|
} else {
|
||||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||||
}
|
}
|
||||||
/*$file_id = $res['file_id'];
|
|
||||||
$upload_id = $res['upload_id'];
|
|
||||||
$result = curl('PUT', $url, $content, [], 1);
|
|
||||||
if ($result['stat']==200) { // 块1传好
|
|
||||||
$etag = $result['returnhead']['ETag'];
|
|
||||||
$result = $this->fileComplete($file_id, $upload_id, [ $etag ]);
|
|
||||||
if ($result['stat']!=200) return output($result['body'], $result['stat']);
|
|
||||||
else return output('success', 0);
|
|
||||||
}*/
|
}*/
|
||||||
}
|
|
||||||
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||||
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||||
|
} else {
|
||||||
|
return output("Get proof error\n" . json_encode($res), 415);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public function Edit($file, $content) {
|
public function Edit($file, $content) {
|
||||||
$tmp = splitlast($file['path'], '/');
|
$tmp = splitlast($file['path'], '/');
|
||||||
|
@ -564,6 +576,60 @@ class Aliyundrive {
|
||||||
$thumb_url = $res['thumbnail'];
|
$thumb_url = $res['thumbnail'];
|
||||||
return $thumb_url;
|
return $thumb_url;
|
||||||
}
|
}
|
||||||
|
public function smallfileupload($path, $tmpfile) {
|
||||||
|
if (!$_SERVER['admin']) {
|
||||||
|
$tmp1 = splitlast($tmpfile['name'], '.');
|
||||||
|
if ($tmp1[0]==''||$tmp1[1]=='') $filename = sha1_file($tmpfile['tmp_name']);
|
||||||
|
else $filename = sha1_file($tmpfile['tmp_name']) . '.' . $tmp1[1];
|
||||||
|
} else {
|
||||||
|
$filename = $tmpfile['name'];
|
||||||
|
}
|
||||||
|
//$content = file_get_contents($tmpfile['tmp_name']);
|
||||||
|
$result = $this->tmpfileCreate($this->list_path($_SERVER['list_path'] . '/' . $path . '/')['file_id'], $tmpfile['tmp_name'], $filename);
|
||||||
|
//error_log1('1,url:' . $url .' res:' . json_encode($result));
|
||||||
|
if ($result['stat']==201) {
|
||||||
|
$res = json_decode($result['body'], true);
|
||||||
|
$url = $res['part_info_list'][0]['upload_url'];
|
||||||
|
if (!$url) { // 无url,应该算秒传
|
||||||
|
//return output('no up url', 0);
|
||||||
|
$a = 1;
|
||||||
|
} else {
|
||||||
|
$file_id = $res['file_id'];
|
||||||
|
$upload_id = $res['upload_id'];
|
||||||
|
//$result = curl('PUT', $url, $content, [], 1);
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_PUT, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||||
|
$fh_res = fopen($tmpfile['tmp_name'], 'r');
|
||||||
|
curl_setopt($ch, CURLOPT_INFILE, $fh_res);
|
||||||
|
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($tmpfile['tmp_name']));
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$tmpres = splitlast(curl_exec($ch), "\r\n\r\n");
|
||||||
|
$result['body'] = $tmpres[1];
|
||||||
|
$returnhead = $tmpres[0];
|
||||||
|
foreach (explode("\r\n", $returnhead) as $head) {
|
||||||
|
$tmp = explode(': ', $head);
|
||||||
|
$heads[$tmp[0]] = $tmp[1];
|
||||||
|
}
|
||||||
|
$result['returnhead'] = $heads;
|
||||||
|
$result['stat'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
fclose($fh_res);
|
||||||
|
curl_close($ch);
|
||||||
|
//error_log1('2,url:' . $url .' res:' . json_encode($result));
|
||||||
|
if ($result['stat']==200) { // 块1传好
|
||||||
|
$result = $this->fileComplete($file_id, $upload_id, [ $result['returnhead']['ETag'] ]);
|
||||||
|
//error_log1('3, res:' . json_encode($result));
|
||||||
|
//if ($result['stat']!=200) return output(json_encode($this->files_format(json_decode($result['body'], true))), $result['stat']);
|
||||||
|
//else return output('success', 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res = json_decode($result['body'], true);
|
||||||
|
//if (isset($res['url']))
|
||||||
|
$res['download_url'] = $_SERVER['host'] . path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . $filename);
|
||||||
|
}
|
||||||
|
return output(json_encode($this->files_format($res), JSON_UNESCAPED_SLASHES), $result['stat']);
|
||||||
|
}
|
||||||
public function bigfileupload($path)
|
public function bigfileupload($path)
|
||||||
{
|
{
|
||||||
if (isset($_POST['uploadid'])) {
|
if (isset($_POST['uploadid'])) {
|
||||||
|
@ -582,7 +648,6 @@ class Aliyundrive {
|
||||||
$i = $_POST['filesize'];
|
$i = $_POST['filesize'];
|
||||||
//$o = $i ? bcmod($r, $i) : 0;
|
//$o = $i ? bcmod($r, $i) : 0;
|
||||||
$o = bcmod($r, $i);
|
$o = bcmod($r, $i);
|
||||||
//return output(hexdec( substr(md5($this->access_token), 0, 16) ) . ' , ' . $r . ' / ' . $i . ' = ' . $o, 200);
|
|
||||||
return output($o, 200);
|
return output($o, 200);
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue