more smoothly in Adding Onedrive disk

pull/525/head
qkqpttgf 2022-01-14 10:29:29 +08:00 committed by GitHub
parent f2d53d45af
commit 1b8287062d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 87 additions and 47 deletions

View File

@ -446,7 +446,7 @@ class Onedrive {
$envs = '';
foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', ';
$url = path_format($_SERVER['PHP_SELF'] . '/');
$url = path_format($_SERVER['base_path'] . '/');
//$this->api_url = splitfirst($_SERVER['api_url'], '/v1.0')[0] . '/v1.0';
if (isset($_GET['Finish'])) {
@ -478,8 +478,8 @@ class Onedrive {
} else {
return message($arr['stat'] . $arr['body'], 'Get User ID', $arr['stat']);
}*/
if (get_class($this)=='Sharepoint') $tmp['Driver'] = 'Onedrive';
elseif (get_class($this)=='SharepointCN') $tmp['Driver'] = 'OnedriveCN';
if ($tmp['Driver']=='Sharepoint') $tmp['Driver'] = 'Onedrive';
elseif ($tmp['Driver']=='SharepointCN') $tmp['Driver'] = 'OnedriveCN';
$tmp['sharepointSite'] = '';
$tmp['siteid'] = '';
} elseif ($_POST['DriveType']=='Custom') {
@ -492,14 +492,14 @@ class Onedrive {
//if ($arr['stat']!=200) return message($arr['stat'] . $arr['body'], 'Get Sharepoint Drive ID ' . $_POST['DriveType'], $arr['stat']);
$tmp['siteid'] = $siteid;
$tmp['sharepointSite'] = $_POST['sharepointSite'];
if (get_class($this)=='Onedrive') $tmp['Driver'] = 'Sharepoint';
elseif (get_class($this)=='OnedriveCN') $tmp['Driver'] = 'SharepointCN';
if ($tmp['Driver']=='Onedrive') $tmp['Driver'] = 'Sharepoint';
elseif ($tmp['Driver']=='OnedriveCN') $tmp['Driver'] = 'SharepointCN';
} else {
// 直接是siteid
$tmp['siteid'] = $_POST['DriveType'];
$tmp['sharepointSite'] = $_POST['sharepointSiteUrl'];
if (get_class($this)=='Onedrive') $tmp['Driver'] = 'Sharepoint';
elseif (get_class($this)=='OnedriveCN') $tmp['Driver'] = 'SharepointCN';
if ($tmp['Driver']=='Onedrive') $tmp['Driver'] = 'Sharepoint';
elseif ($tmp['Driver']=='OnedriveCN') $tmp['Driver'] = 'SharepointCN';
}
$response = setConfigResponse( setConfig($tmp, $this->disktag) );
@ -520,11 +520,11 @@ class Onedrive {
console.log(i++);
} else {
clearInterval(uploadList);
location.href = "' . $url . '";
location.href = "' . $url . '?setup&disktag=' . $_GET['disktag'] . '";
}
}, 1000);
</script>';
return message($html, getconstStr('WaitJumpIndex'), 201, 1);
return message($html, getconstStr('Wait'), 201, 1);
}
}
@ -554,12 +554,13 @@ class Onedrive {
$title = 'Select Driver';
$html = '
<div>
<form action="?Finish&disktag=' . $_GET['disktag'] . '&AddDisk=' . get_class($this) . '" method="post" onsubmit="return notnull(this);">
<label><input type="radio" name="DriveType" value="Onedrive" checked>' . 'Use Onedrive ' . getconstStr(' ') . '</label><br>';
<form name="form1" action="?Finish&disktag=' . $_GET['disktag'] . '&AddDisk=' . get_class($this) . '" method="post" onsubmit="return notnull(this);">
<label><input type="radio" name="DriveType" value="Onedrive">' . 'Use Onedrive ' . getconstStr(' ') . '</label><br>';
if ($sites[0]!='') foreach ($sites as $k => $v) {
$html .= '
<label>
<input type="radio" name="DriveType" value="' . $v['id'] . '" onclick="document.getElementById(\'sharepointSiteUrl\').value=\'' . $v['webUrl'] . '\';">' . 'Use Sharepoint: <br><div style="width:100%;margin:0px 35px">webUrl: ' . $v['webUrl'] . '<br>siteid: ' . $v['id'] . '</div>
<input type="hidden" id="' . $v['id'] . '" name="' . $v['id'] . '" value="' . $v['webUrl'] . '">
</label>';
}
$html .= '
@ -576,6 +577,26 @@ class Onedrive {
</form>
</div>
<script>
var driver = "' . $_GET['AddDisk'] . '";
if (driver=="Onedrive"||driver=="OnedriveCN") {
document.form1.DriveType[0].checked = true;
} else {
var siteid = "' . getConfig('siteid', $this->disktag) . '";
if (siteid==="") {
document.form1.DriveType[document.form1.DriveType.length-1].checked = true;
} else {
for (i=0; i<document.form1.DriveType.length; i++) {
if (document.form1.DriveType[i].value==siteid) {
document.form1.DriveType[i].checked = true;
document.getElementById(\'sharepointSiteUrl\').value = document.getElementById(siteid).value;
}
}
if (document.getElementById(\'sharepointSiteUrl\').value=="") {
document.form1.DriveType[document.form1.DriveType.length-1].checked = true;
document.getElementById(\'sharepointSite\').value = "' . getConfig('sharepointSite', $this->disktag) . '";
}
}
}
function notnull(t)
{
if (t.DriveType.value==\'\') {
@ -590,8 +611,8 @@ class Onedrive {
}
return true;
}
</script>
';
</script>
';
return message($html, $title, 201);
}
@ -611,7 +632,7 @@ class Onedrive {
texta[i].style.height = texta[i].scrollHeight + \'px\';
}
</script>';
$tmptoken['Driver'] = get_class($this);
$tmptoken['Driver'] = $_GET['AddDisk'];
$tmptoken['refresh_token'] = $refresh_token;
$tmptoken['token_expires'] = time()+7*24*60*60;
$response = setConfigResponse( setConfig($tmptoken, $this->disktag) );
@ -629,7 +650,7 @@ class Onedrive {
console.log(i++);
} else {
clearInterval(uploadList);
location.href = "' . $url . '?AddDisk=' . get_class($this) . '&disktag=' . $_GET['disktag'] . '&SelectDrive";
location.href = "' . $url . '?AddDisk=' . $_GET['AddDisk'] . '&disktag=' . $_GET['disktag'] . '&SelectDrive";
}
}, 1000);
</script>';
@ -641,7 +662,7 @@ class Onedrive {
}
if (isset($_GET['install1'])) {
if (get_class($this)=='Onedrive' || get_class($this)=='OnedriveCN') {
//if (get_class($this)=='Onedrive' || get_class($this)=='OnedriveCN') {
return message('
<a href="" id="a1">' . getconstStr('JumptoOffice') . '</a>
<script>
@ -652,9 +673,9 @@ class Onedrive {
location.href = url;
</script>
', getconstStr('Wait') . ' 1s', 201);
} else {
return message('Something error, retry after a few seconds.', 'Retry', 201);
}
//} else {
// return message('Something error, retry after a few seconds.', 'Retry', 201);
//}
}
if (isset($_GET['install0'])) {
@ -681,7 +702,8 @@ class Onedrive {
//$this->disktag = $_POST['disktag_add'];
$tmp['disktag_add'] = $_POST['disktag_add'];
$tmp['diskname'] = $_POST['diskname'];
$tmp['Driver'] = $_POST['Drive_ver'];
//$tmp['Driver'] = $_POST['Drive_ver'];
$tmp['Driver'] = $_GET['AddDisk'];
if ($_POST['Drive_ver']=='Sharelink') {
$tmp['shareurl'] = $_POST['shareurl'];
} else {
@ -701,7 +723,7 @@ class Onedrive {
} else {
$title = getconstStr('MayinEnv');
$html = getconstStr('Wait');
if ($_POST['Drive_ver']!='Sharelink') $url .= '?install1&disktag=' . $_GET['disktag'] . '&AddDisk=' . $_POST['Drive_ver'];
if ($_POST['Drive_ver']!='Sharelink') $url .= '?install1&disktag=' . $_GET['disktag'] . '&AddDisk=' . $_GET['AddDisk'];
$html .= '<script>
var i = 0;
var status = "' . $response['DplStatus'] . '";
@ -722,7 +744,7 @@ class Onedrive {
$html = '
<div>
<form id="form1" action="" method="post" onsubmit="return notnull(this);">
<form id="form1" name="form1" action="" method="post" onsubmit="return notnull(this);">
' . getconstStr('DiskTag') . ': (' . getConfig('disktag') . ')
<input type="text" name="disktag_add" placeholder="' . getconstStr('EnvironmentsDescription')['disktag'] . '" style="width:100%"><br>
' . getconstStr('DiskName') . ':
@ -762,6 +784,21 @@ class Onedrive {
</form>
</div>
<script>
var driver = "' . get_class($this) . '";
if (driver=="Onedrive" || driver=="Sharepoint") {
document.form1.Drive_ver[0].checked = true;
document.getElementById(\'NT_custom\').style.display=\'\';
//document.getElementById(\'CN_custom\').style.display=\'\';
//document.getElementById(\'inputshareurl\').style.display=\'none\';
}
if (driver=="OnedriveCN" || driver=="SharepointCN") {
document.form1.Drive_ver[1].checked = true;
document.getElementById(\'CN_custom\').style.display=\'\';
}
if (driver=="Sharelink") {
document.form1.Drive_ver[2].checked = true;
document.getElementById(\'inputshareurl\').style.display=\'\';
}
function notnull(t)
{
if (t.disktag_add.value==\'\') {
@ -770,7 +807,7 @@ class Onedrive {
}
envs = [' . $envs . '];
if (envs.indexOf(t.disktag_add.value)>-1) {
alert("Do not input ' . $envs . '");
alert("Do not input \"" + t.disktag_add.value + "\" in ' . getconstStr('DiskTag') . '");
return false;
}
var reg = /^[a-zA-Z]([_a-zA-Z0-9]{1,20})$/;
@ -787,25 +824,28 @@ class Onedrive {
alert(\'shareurl\');
return false;
}
driver = \'Sharelink\';
} else {
if ((t.Drive_ver.value==\'Onedrive\') && t.NT_Drive_custom.checked==true) {
if (t.Drive_ver.value==\'Onedrive\') {
if (t.NT_Drive_custom.checked==true) {
if (t.NT_client_secret.value==\'\'||t.NT_client_id.value==\'\') {
alert(\'client_id & client_secret\');
return false;
}
}
if ((t.Drive_ver.value==\'OnedriveCN\') && t.CN_Drive_custom.checked==true) {
if (driver!="Onedrive" && driver!="Sharepoint") driver = "Onedrive";
}
if (t.Drive_ver.value==\'OnedriveCN\') {
if (t.CN_Drive_custom.checked==true) {
if (t.CN_client_secret.value==\'\'||t.CN_client_id.value==\'\') {
alert(\'client_id & client_secret\');
return false;
}
}
if (driver!="OnedriveCN" && driver!="SharepointCN") driver = "OnedriveCN";
}
document.getElementById("form1").action="?install0&disktag=" + t.disktag_add.value + "&AddDisk=" + t.Drive_ver.value;
//var expd = new Date();
//expd.setTime(expd.getTime()+(2*60*60*1000));
//var expires = "expires="+expd.toGMTString();
//document.cookie=\'disktag=\'+t.disktag_add.value+\'; path=/; \'+expires;
}
document.getElementById("form1").action="?install0&disktag=" + t.disktag_add.value + "&AddDisk=" + driver;
return true;
}
</script>';