Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Fix problems such as leading to blank page
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeBottle committed Nov 11, 2021
1 parent e98617d commit 81f62f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ $config = array(
"api_url" => "https://graph.microsoft.com/v1.0",
"oauth_url" => "https://login.microsoftonline.com/common/oauth2/v2.0",
"redirect_uri" => "http://localhost",
'base' => '/',
'base' => '',
'data_path' => 'data',
'rewrite' => false,
'site_path' => '',
Expand Down
8 changes: 5 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"api_url" => "https://graph.microsoft.com/v1.0",
"oauth_url" => "https://login.microsoftonline.com/common/oauth2/v2.0",
"redirect_uri" => "http://localhost",
'base' => '/',
'base' => '',
'data_path' => 'data',
'rewrite' => false,
'site_path' => '',
Expand Down Expand Up @@ -337,8 +337,9 @@ function handleRequest($url, $returnUrl = false, $requestForFile = false)
} else {
handleFile($data["@microsoft.graph.downloadUrl"], $data);/*下载文件*/
}
} else if (isset($data['value'])) {/*返回的是目录*/
$render = renderFolderIndex($data['value'], parsePath($url));/*渲染目录*/
} else if (array_key_exists('value', $data)) {/*返回的是目录*/
/*渲染目录,2021.11.11修复空目录返回空白的bug*/
$render = renderFolderIndex(($data['value'] ? $data['value'] : []), parsePath($url));
return $render;
} else {
$resp = json_decode($resp, true);
Expand All @@ -349,6 +350,7 @@ function handleRequest($url, $returnUrl = false, $requestForFile = false)
} else if ($config['no_index']) {
return $config['no_index_print'];
} else {
http_response_code(404);/*找不到文件就返回404,以便处理2021.11.11*/
$jsonArr['msg'] = 'Not found: ' . urldecode($path);
echo ($config['list_as_json'] ? json_encode($jsonArr, true) : '<!--NotFound:' . urldecode($path) . '-->');
return '';/*当文件或目录不存在的时候返回空,以免缓存记录*/
Expand Down
81 changes: 39 additions & 42 deletions template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{Body}}

<head>
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Expand Down Expand Up @@ -31,10 +32,21 @@
<script src="https://cdn.jsdelivr.net/gh/SomeBottle/[email protected]/othumb.m.js"></script>
<script>
var readmefile = "{[ReadmeFile]}";

function fHook(resp) { /*用于判断fetch状态码的一个hook*/
let statusStart = Math.floor(resp.status / 100);
if ([2, 3].includes(statusStart)) {
return resp;
} else {
throw resp.status;
}
}
async function renderReadme() {
const resp = await fetch(readmefile)
if (!resp.ok) return
document.querySelector("#readme").innerHTML = window.markdownit().render(await resp.text());
document.querySelector("#readme").innerHTML = window.markdownit().render(await fHook(resp).text().catch(e => {
throw e;
}));
Prism.highlightAll()
}

Expand All @@ -45,9 +57,7 @@
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
var units = si ?
['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] :
['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var units = si ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
var u = -1;
do {
bytes /= thresh;
Expand All @@ -61,33 +71,26 @@
document.querySelectorAll("a.item").forEach(function(i) {
i.insertAdjacentHTML('beforeend',
'<div style="flex-grow:1"></div>' +
((i.hasAttribute("size")&&Number(i.getAttribute("size"))>0) ? '<span class="size">' + humanFileSize(i.getAttribute("size"), true) + '</span>' : '')
((i.hasAttribute("size") && Number(i.getAttribute("size")) > 0) ? '<span class="size">' + humanFileSize(i.getAttribute("size"), true) + '</span>' : '')
)
})

});

renderReadme().catch(console.error)
</script>
{{BodyEnd}}
{{PathSingle}}
<a href='{[FolderLink]}'>{[FolderName]}</a>
{{PathSingleEnd}}
{{ItemSingle}}
<a href="{[ItemLink]}" class="item" size="{[ItemSize]}" mimetype="{[MimeType]}" lastmodified="{[LastModifiedDateTime]}" created="{[CreatedDateTime]}"><i class="material-icons">{[MimeIcon]}</i>{[ItemName]}</a>
{{ItemSingleEnd}}
{{PaginationSingle}}
{{BodyEnd}} {{PathSingle}}
<a href='{[FolderLink]}'>{[FolderName]}</a> {{PathSingleEnd}} {{ItemSingle}}
<a href="{[ItemLink]}" class="item" size="{[ItemSize]}" mimetype="{[MimeType]}" lastmodified="{[LastModifiedDateTime]}" created="{[CreatedDateTime]}"><i class="material-icons">{[MimeIcon]}</i>{[ItemName]}</a> {{ItemSingleEnd}} {{PaginationSingle}}
<div class='pagination'>
{[Prev]}{[Next]}
</div>
{{PaginationSingleEnd}}
{{PaginationPrev}}
{{PaginationSingleEnd}} {{PaginationPrev}}
<input type='button' class='prevpage' value='' onclick="location.href='{[PrevLink]}'"></input>
{{PaginationPrevEnd}}
{{PaginationNext}}
{{PaginationPrevEnd}} {{PaginationNext}}
<input type='button' class='nextpage' value='' onclick="location.href='{[NextLink]}'"></input>
{{PaginationNextEnd}}
{{PreviewBody}}
{{PaginationNextEnd}} {{PreviewBody}}

<head>
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Expand All @@ -114,57 +117,52 @@
function jumpreview() {
window.open('{[PreviewUrl]}', '_blank');
}
var dl=location.href.split('?');
dl.pop();
dl=dl.join('?');
document.getElementById('du').value=dl;
function down() {
var dl = location.href.split('?');
dl.pop();
dl = dl.join('?');
document.getElementById('du').value = dl;

function down() {
window.open(dl, '_self');
}
</script>
</div>
</body>
{{PreviewBodyEnd}}
{{ImgPreview}}
{{PreviewBodyEnd}} {{ImgPreview}}
<div class='previewitems'>
<div style='min-width:300px'>
<img style='max-width:100%' src='{[FileRawUrl]}'></img>
</div>
</div>
{{ImgPreviewEnd}}
{{AudioPreview}}
{{ImgPreviewEnd}} {{AudioPreview}}
<div class='previewitems'>
<div style='min-width:300px'>
<audio style='width:80%;margin:10px 0;' src="{[FileRawUrl]}" controls="controls"></audio>
</div>
</div>
{{AudioPreviewEnd}}
{{VideoPreview}}
{{AudioPreviewEnd}} {{VideoPreview}}
<div class='previewitems'>
<div style='min-width:300px'>
<video style='max-width:100%' src='{[FileRawUrl]}' controls="controls"></video>
</div>
</div>
{{VideoPreviewEnd}}
{{TxtPreview}}
{{VideoPreviewEnd}} {{TxtPreview}}
<div class='previewitems'>
<div style='min-width:300px'>
<div class='previewtext markdown-body'><pre><code>{[FileContent]}</code></pre></div>
</div>
</div>
{{TxtPreviewEnd}}
{{MDPreview}}
{{TxtPreviewEnd}} {{MDPreview}}
<div class='previewitems'>
<div style='min-width:300px'>
<div class='previewtext markdown-body' id='md'>{[FileContent]}</div>
</div>
</div>
<script src='https://cdn.jsdelivr.net/npm/markdown-it@latest/dist/markdown-it.min.js'></script>
<script>
document.getElementById('md').innerHTML=window.markdownit().render(document.getElementById('md').innerHTML);
document.getElementById('md').innerHTML = window.markdownit().render(document.getElementById('md').innerHTML);
</script>
{{MDPreviewEnd}}
{{CodePreview}}
{{MDPreviewEnd}} {{CodePreview}}
<div class='previewitems'>
<div style='min-width:300px'>
<div class='previewtext markdown-body' id='codes'>
Expand All @@ -176,16 +174,15 @@
<script>
Prism.highlightAllUnder(document.getElementById('codes'));
</script>
{{CodePreviewEnd}}
{{OfficePreview}}
{{CodePreviewEnd}} {{OfficePreview}}
<div class='previewitems'>
<div style='min-width:300px;padding:10px 0;'>
<h2 style='margin-top:0;'>此预览需要前往Office</h2>
<input type='button' style='padding:10px 10px;' class='downbtn' value='点击跳转预览' onclick='jumpreview()'>
</div>
</div>
{{OfficePreviewEnd}}
{{PasswordPage}}
{{OfficePreviewEnd}} {{PasswordPage}}

<head>
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Expand All @@ -208,7 +205,7 @@ <h2 style='margin-top:0;'>此预览需要前往Office</h2>
<h2>输入密码以继续</h2>
<div class='passwordform'>
<form action="#" method="post" style="display: flex;flex: 1;">
<input class='passwordinput' type="password" name="password" placeholder="password"></input><input type="hidden" name="requestfolder" value="{[FolderMD5]}"/><input type='submit' class='submitbtn' value='Submit'></input>
<input class='passwordinput' type="password" name="password" placeholder="password"></input><input type="hidden" name="requestfolder" value="{[FolderMD5]}" /><input type='submit' class='submitbtn' value='Submit'></input>
</form>
</div>
</div>
Expand Down

0 comments on commit 81f62f5

Please sign in to comment.