Merge pull request #1 from kkren/patch-1

add random disk
pull/276/head
madoka 2021-03-18 16:19:12 +08:00 committed by GitHub
commit daff2a6e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 36 deletions

View File

@ -192,42 +192,43 @@ function main($path)
$_SERVER['base_disk_path'] = $_SERVER['base_path']; $_SERVER['base_disk_path'] = $_SERVER['base_path'];
$disktags = explode("|", getConfig('disktag')); $disktags = explode("|", getConfig('disktag'));
// echo 'count$disk:'.count($disktags); // echo 'count$disk:'.count($disktags);
if (count($disktags)>1) { // if (count($disktags)>1) {
if ($path=='/'||$path=='') { // if ($path=='/'||$path=='') {
$files['type'] = 'folder'; // $files['type'] = 'folder';
$files['childcount'] = count($disktags); // $files['childcount'] = count($disktags);
$files['showname'] = 'root'; // $files['showname'] = 'root';
foreach ($disktags as $disktag) { // foreach ($disktags as $disktag) {
$files['list'][$disktag]['type'] = 'folder'; // $files['list'][$disktag]['type'] = 'folder';
$files['list'][$disktag]['name'] = $disktag; // $files['list'][$disktag]['name'] = $disktag;
$files['list'][$disktag]['showname'] = getConfig('diskname', $disktag); // $files['list'][$disktag]['showname'] = getConfig('diskname', $disktag);
} // }
if ($_GET['json']) { // if ($_GET['json']) {
// return a json // // return a json
return output(json_encode($files), 200, ['Content-Type' => 'application/json']); // return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
} // }
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]); // if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
} else { // } else {
$_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0]; // $_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
//$pos = strpos($path, '/'); // //$pos = strpos($path, '/');
//if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos); // //if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
if (!in_array($_SERVER['disktag'], $disktags)) { // if (!in_array($_SERVER['disktag'], $disktags)) {
$tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path); // $tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path);
if (!!$_GET) { // if (!!$_GET) {
$tmp .= '?'; // $tmp .= '?';
foreach ($_GET as $k => $v) { // foreach ($_GET as $k => $v) {
if ($v === true) $tmp .= $k . '&'; // if ($v === true) $tmp .= $k . '&';
else $tmp .= $k . '=' . $v . '&'; // else $tmp .= $k . '=' . $v . '&';
} // }
$tmp = substr($tmp, 0, -1); // $tmp = substr($tmp, 0, -1);
} // }
return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 302, [ 'Location' => $tmp ]); // return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 302, [ 'Location' => $tmp ]);
//return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404); // //return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404);
} // }
$path = substr($path, strlen('/' . $_SERVER['disktag'])); // $path = substr($path, strlen('/' . $_SERVER['disktag']));
if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/'); // if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
} // }
} else $_SERVER['disktag'] = $disktags[0]; // } else
$_SERVER['disktag'] = $disktags[rand(0,count($disktags)-1)];
// echo 'main.disktag:'.$_SERVER['disktag'].'path:'.$path.''; // echo 'main.disktag:'.$_SERVER['disktag'].'path:'.$path.'';
$_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']); $_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/'; if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';