use '?random=jpg' to get an URL of a random file

pull/31/head
qkqpttgf 2020-03-09 18:55:17 +08:00 committed by GitHub
parent 3b1de93cc4
commit 46714bff6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -614,7 +614,20 @@ function main($path)
} else return output(json_encode($exts['img']),400);
} else return output('',401);
}
$files = list_files($path);
//echo json_encode(array_keys($files['children']), JSON_PRETTY_PRINT);
if ($_GET['random']!=='') {
if ($_SERVER['ishidden']<4) {
$tmp = [];
foreach (array_keys($files['children']) as $filename) {
if (strtolower(splitlast($filename,'.')[1])==strtolower($_GET['random'])) $tmp[$filename] = $files['children'][$filename]['@microsoft.graph.downloadUrl'];
}
$tmp = array_values($tmp);
if (count($tmp)>0) return output($tmp[rand(0,count($tmp)-1)],200);
else return output('',404);
} else return output('',401);
}
if (isset($files['file']) && !$_GET['preview']) {
// is file && not preview mode
if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt')&&$files['name']!=getConfig('passfile')) ) return output('', 302, [ 'Location' => $files['@microsoft.graph.downloadUrl'] ]);
@ -927,6 +940,13 @@ function fetch_files($path = '/')
$files=fetch_files_children($files, $path1, $page);
} else {
// files num < 200 , then cache
if (isset($files['children'])) {
$tmp = [];
foreach ($files['children'] as $file) {
$tmp[$file['name']] = $file;
}
$files['children'] = $tmp;
}
savecache('path_' . $path, $files);
}
}
@ -938,6 +958,7 @@ function fetch_files($path = '/')
$files = json_decode( '{"unknownError":{ "stat":'.$arr['stat'].',"message":"'.$arr['body'].'"}}', true);
}
}
return $files;
}