Skip to content

Commit

Permalink
优化报错跳转显示
Browse files Browse the repository at this point in the history
  • Loading branch information
WangNingkai committed Dec 15, 2018
1 parent 3b0e7a1 commit 2f112a5
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ function () use ($graphPath) {
}
);
if (is_null($item)) {
abort(404);
Tool::showMessage('获取目录失败,请检查路径或稍后重试', false);

return view(config('olaindex.theme').'message');
}
if (array_has($item, '@microsoft.graph.downloadUrl')) {
return redirect()->away($item['@microsoft.graph.downloadUrl']);
Expand Down Expand Up @@ -131,35 +133,36 @@ function () use ($graphPath) {
if (!empty($origin_items['.password'])) {
$pass_id = $origin_items['.password']['id'];
$pass_url
= $origin_items['.password']['@microsoft.graph.downloadUrl'];
= $origin_items['.password']['@microsoft.graph.downloadUrl'];
$key = 'password:'.$origin_path;
if (Session::has($key)) {
$data = Session::get($key);
$password = Tool::getFileContent($pass_url, false);
if (strcmp($password, decrypt($data['password'])) !== 0
|| time() > $data['expires']
) {
|| time() > $data['expires']
) {
Session::forget($key);
Tool::showMessage('密码已过期', false);

return view(
config('olaindex.theme').'password',
compact('origin_path', 'pass_id')
);
config('olaindex.theme').'password',
compact('origin_path', 'pass_id')
);
}
} else {
return view(
config('olaindex.theme').'password',
compact('origin_path', 'pass_id')
);
config('olaindex.theme').'password',
compact('origin_path', 'pass_id')
);
}
}
}
// 过滤受限隐藏目录
if (!empty($origin_items['.deny'])) {
if (!Session::has('LogInfo')) {
Tool::showMessage('目录访问受限,仅管理员可以访问!', false);
abort(403);

return view(config('olaindex.theme').'message');
}
}
// 处理 head/readme
Expand Down Expand Up @@ -244,11 +247,13 @@ public function show(Request $request)
{
$realPath = $request->route()->parameter('query') ?? '/';
if ($realPath === '/') {
abort(404);
return redirect()->route('home');
}
$file = $this->getFileOrCache($realPath);
if (is_null($file) || array_has($file, 'folder')) {
abort(404);
Tool::showMessage('获取文件失败,请检查路径或稍后重试', false);

return view(config('olaindex.theme').'message');
}
$file['download'] = $file['@microsoft.graph.downloadUrl'];
foreach ($this->show as $key => $suffix) {
Expand All @@ -261,8 +266,10 @@ public function show(Request $request)

return redirect()->back();
} else {
$file['content']
= Tool::getFileContent($file['@microsoft.graph.downloadUrl'], false);
$file['content'] = Tool::getFileContent(
$file['@microsoft.graph.downloadUrl'],
false
);
}
}
// 处理缩略图
Expand Down Expand Up @@ -320,11 +327,15 @@ public function download(Request $request)
{
$realPath = $request->route()->parameter('query') ?? '/';
if ($realPath === '/') {
abort(404);
Tool::showMessage('下载失败,请检查路径或稍后重试', false);

return view(config('olaindex.theme').'message');
}
$file = $this->getFileOrCache($realPath);
if (is_null($file) || array_has($file, 'folder')) {
abort(404);
Tool::showMessage('下载失败,请检查路径或稍后重试', false);

return view(config('olaindex.theme').'message');
}
$url = $file['@microsoft.graph.downloadUrl'];

Expand Down Expand Up @@ -382,11 +393,15 @@ public function view(Request $request)
{
$realPath = $request->route()->parameter('query') ?? '/';
if ($realPath === '/') {
abort(404);
Tool::showMessage('获取失败,请检查路径或稍后重试', false);

return view(config('olaindex.theme').'message');
}
$file = $this->getFileOrCache($realPath);
if (is_null($file) || array_has($file, 'folder')) {
abort(404);
Tool::showMessage('获取失败,请检查路径或稍后重试', false);

return view(config('olaindex.theme').'message');
}
$download = $file['@microsoft.graph.downloadUrl'];

Expand Down

0 comments on commit 2f112a5

Please sign in to comment.