return json with content-type

pull/188/head
qkqpttgf 2021-01-16 12:27:41 +08:00 committed by GitHub
parent 66238a6d54
commit 01e094d95d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -191,7 +191,6 @@ function main($path)
// echo 'count$disk:'.count($disktags); // echo 'count$disk:'.count($disktags);
if (count($disktags)>1) { if (count($disktags)>1) {
if ($path=='/'||$path=='') { if ($path=='/'||$path=='') {
if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
$files['type'] = 'folder'; $files['type'] = 'folder';
$files['childcount'] = count($disktags); $files['childcount'] = count($disktags);
$files['showname'] = 'root'; $files['showname'] = 'root';
@ -202,8 +201,9 @@ function main($path)
} }
if ($_GET['json']) { if ($_GET['json']) {
// return a json // return a json
return output(json_encode($files)); return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
} }
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, '/');
@ -331,7 +331,7 @@ function main($path)
if ($_GET['json']) { if ($_GET['json']) {
// return a json // return a json
return output(json_encode($files)); return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
} }
// random file // random file
if (isset($_GET['random'])&&$_GET['random']!=='') { if (isset($_GET['random'])&&$_GET['random']!=='') {