2021-01-15 03:10:08 +00:00
|
|
|
<?php
|
|
|
|
if (!class_exists('Onedrive')) require 'Onedrive.php';
|
|
|
|
|
|
|
|
class Sharelink extends Onedrive {
|
|
|
|
|
|
|
|
function __construct($tag) {
|
|
|
|
$this->disktag = $tag;
|
|
|
|
$this->redirect_uri = 'https://scfonedrive.github.io';
|
|
|
|
$this->api_url = getConfig('shareapiurl', $tag);
|
2021-01-15 11:27:36 +00:00
|
|
|
$res = $this->get_access_token(1);
|
2021-01-15 03:10:08 +00:00
|
|
|
//$this->ext_api_url = '/me/drive/root';
|
|
|
|
$this->DownurlStrName = '@content.downloadUrl';
|
|
|
|
}
|
|
|
|
|
2021-01-17 11:01:07 +00:00
|
|
|
public function ext_show_innerenv()
|
|
|
|
{
|
|
|
|
return [ 'shareurl' ];
|
|
|
|
}
|
|
|
|
|
2021-01-15 03:10:08 +00:00
|
|
|
protected function get_access_token($refresh_token) {
|
|
|
|
if (!($this->access_token = getcache('access_token', $this->disktag))) {
|
|
|
|
$shareurl = getConfig('shareurl', $this->disktag);
|
|
|
|
if (!($this->sharecookie = getcache('sharecookie', $this->disktag))) {
|
2021-03-30 08:16:07 +00:00
|
|
|
$res = curl('GET', $shareurl, '', [], 1);
|
|
|
|
error_log1(json_encode($res, JSON_PRETTY_PRINT));
|
|
|
|
if (isset($res['returnhead']['Set-Cookie'])) $this->sharecookie = $res['returnhead']['Set-Cookie'];
|
|
|
|
if (isset($res['returnhead']['set-cookie'])) $this->sharecookie = $res['returnhead']['set-cookie'];
|
|
|
|
if ($this->sharecookie=='') {
|
|
|
|
$this->error = $res;
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-15 03:10:08 +00:00
|
|
|
savecache('sharecookie', $this->sharecookie, $this->disktag);
|
|
|
|
}
|
|
|
|
$tmp1 = splitlast($shareurl, '/')[0];
|
|
|
|
$account = splitlast($tmp1, '/')[1];
|
|
|
|
$domain = splitlast($shareurl, '/:')[0];
|
|
|
|
$response = curl('POST',
|
|
|
|
$domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE",
|
|
|
|
'{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}',
|
|
|
|
[ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'origin' => $domain, 'Cookie' => $this->sharecookie ]
|
|
|
|
);
|
|
|
|
if ($response['stat']==200) $ret = json_decode($response['body'], true);
|
|
|
|
$this->access_token = splitlast($ret['ListSchema']['.driveAccessToken'],'=')[1];
|
|
|
|
$this->api_url = $ret['ListSchema']['.driveUrl'].'/root';
|
|
|
|
if (!$this->access_token) {
|
2021-01-16 09:12:03 +00:00
|
|
|
error_log1($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE");
|
|
|
|
error_log1('failed to get share access_token. response' . json_encode($ret));
|
2021-03-30 08:16:07 +00:00
|
|
|
//$response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT);
|
|
|
|
$response['body'] .= '<br>' .json_decode($response['body'], true)['error']['message']['value'];
|
|
|
|
$response['body'] .= '<br>failed to get shareurl access_token.';
|
|
|
|
$this->error = $response;
|
|
|
|
return false;
|
2021-01-15 03:10:08 +00:00
|
|
|
//throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']);
|
|
|
|
}
|
|
|
|
//$tmp = $ret;
|
|
|
|
//$tmp['access_token'] = '******';
|
2021-01-16 09:12:03 +00:00
|
|
|
//error_log1('['.$this->disktag.'] Get access token:'.json_encode($tmp, JSON_PRETTY_PRINT));
|
2021-01-15 03:10:08 +00:00
|
|
|
savecache('access_token', $this->access_token, $this->disktag);
|
|
|
|
$tmp1 = null;
|
|
|
|
if (getConfig('shareapiurl', $this->disktag)!=$this->api_url) $tmp1['shareapiurl'] = $this->api_url;
|
|
|
|
//if (getConfig('sharecookie', $this->disktag)!=$this->sharecookie) $tmp1['sharecookie'] = $this->sharecookie;
|
2021-03-30 08:16:07 +00:00
|
|
|
if (!!$tmp1) setConfig($tmp1, $this->disktag);
|
2021-01-16 03:28:19 +00:00
|
|
|
return true;
|
2021-01-15 03:10:08 +00:00
|
|
|
}
|
2021-01-15 11:27:36 +00:00
|
|
|
return true;
|
2021-01-15 03:10:08 +00:00
|
|
|
}
|
2021-01-17 11:01:07 +00:00
|
|
|
}
|