-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
413 lines (374 loc) · 18.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>D-File</title>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/1.1.3/axios.min.js"></script>
<script src="https://unpkg.com/js-base64"></script>
<link rel="shortcut icon" type="image/x-icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAMxJREFUOE+t06FuAkEQxvH/FxpegUoeovXUoOobJLapRDaw2T1b21qwoNGUB8BW45jwDmQJENIj3F2vd0wyZjL7m2QmK2qGar7nCLSGsadIF2hfgOLTvGZFQ47A/Xt0iFFG45jI5Kp+x9acfg71v4Dc4YKHTdDqDHSAQ2ZFzKkvLdH3LyDegGYqixcsvHkt0sDiXxcRz+Y1rw7AiwVN6wB9CxpXB8SreX1VByIDS/RRBxhaonACXGyzYwo8lrzEmgZP5rS+zWcqOTWzbQ96PEURUT++WAAAAABJRU5ErkJggg==">
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/dayjs/1.11.7/dayjs.min.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/js-base64@3.7.5/base64.min.js"></script> -->
<style>
* {margin: 0; padding:0; box-sizing: border-box;}
html {
padding:20px 0 10px;
}
body { font-size: 16px;max-width: 80%; margin: 0 auto; }
h2 {margin-bottom: 10px;}
.back {display: inline-block;border: 1px solid #ddd; padding: 4px 8px;font-size: 15px; font-weight: normal; cursor: pointer; margin-left: 20px; margin-top: 0;}
input.back { cursor: auto; }
.ftr {float: right;}
.file_list li { line-height:40px;border-bottom: 1px solid #ddd;display: flex; align-items: center;padding: 6px 0;}
.w50 .file_list li { float: left;width: 31%;margin-right:2%;}
.w50 .file_list li span.sha { display: none;}
.file_list li:before { content: '其他'; background: #999; color: #fff; min-width: 40px; padding: 0 10px; line-height: 26px; height: 26px; font-size: 13px; margin-right: 8px; text-align: center; }
.file_list li.dir:before { content: '文件夹'; background: #f1c951; background: #ffbf00; }
.file_list li.img:before { content: '图片'; background: #b5c327; }
.file_list li.video:before { content: '视频'; background: #3369e7; }
.file_list li.music:before { content: '音频'; background: #00a98f; }
.file_list li.code:before { content: '代码'; background: #222; }
.file_list li.zip:before { content: '压缩包'; background: #8e43e7; }
.file_list li.doc:before { content: 'Word'; background: #00a1f1; }
.file_list li.xls:before { content: 'Excel'; background: #7cbb00; }
.file_list li.ppt:before { content: 'PPT'; background: #f65314; }
.file_list li.pdf:before { content: 'PDF'; background: #ea3e23; }
.file_list li.txt:before { content: '文本'; background: #999; }
.file_list li img { margin-right: 6px;display: inline-block;vertical-align: middle;}
.file_list li a { color: #333; text-decoration: none;flex: 1;width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}
.file_list li.dir a { text-decoration: underline; color: #1769ff ; font-weight: bold; }
.file_list li.dir .del { visibility: hidden; pointer-events: none; }
.file_list li span {color: #666; font-size:14px;}
.file_list li span.sha {min-width: 350px; display:inline-block;}
.file_list li span.size {width: 80px; display:inline-block;}
.file_list li i {border: 1px solid #ddd; padding: 4px 8px;font-size: 14px; font-style: normal; cursor: pointer; margin-left: 10px; line-height: 20px;}
.file-img {width: 60px; max-height: 60px;}
li{ list-style-type:none; }
@media screen and (max-width:700px){
.file_list li span {display:none !important;}
.back.ftr { display: none; }
input#search { display: inline-block; margin: 10px 0 0; }
button { margin-top: 6px; }
}
input { background: #fff; outline: none; line-height: 26px; border: 1px solid #ccc; padding: 0 10px; display: inline-block; min-width: 280px; margin-top: 6px;}
button{ outline: none; background: none; border: 1px solid #ccc; display: inline-block; margin-left: 10px; line-height: 18px; padding: 4px 10px; cursor: pointer;}
button span{ color: #f33; display: block;}
#file{ display: none;}
h4 { overflow: hidden; margin-bottom: 20px;}
h2 { padding: 10px 0; margin-bottom: 10px; border-bottom: 1px solid #ccc; overflow: hidden; }
.tip {color: #999; font-size: 12px; margin-left: 20px;}
i {
font-style: normal;
}
.hide { display: none !important; }
#loading { position: fixed; width: 100vw; height: 100vh; left: 0; top: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; color: #fff; z-index: 9; }
</style>
</head>
<body>
<p style="margin: 0;">版本号: 20230627-1 <span class="tip">测试延迟请在根目录上传<b>init.jpg</b>(50kb以内)</span></p>
<h4>根域名: <input type="text" value="" id="rootdm">
<div style="display: inline-block;" id="btn-wrap"></div>
</h4>
<input type="file" id="file" class="filepond" name="filepond" />
<h2>当前目录:<i id="repo"></i>
<span onclick="addDir()" class="back">新建目录</span>
<span onclick="document.getElementById('file').click()" class="back">上传文件</span>
<span onclick="dirBack()" class="back">←返回</span>
<span onclick="refresh()" class="back ftr">刷新</span>
<span onclick="toggleWrap()" class="back ftr">分列</span>
<span onclick="updateToken()" class="back ftr">设置Token</span>
<span onclick="updateRepo()" class="back ftr">设置Repo</span>
<input type="text" class="back ftr" id="search" placeholder="关键词搜索, 回车确认" onkeyup="search(event)">
<!-- <span onclick="history.go(-1)" class="back">返回</span> -->
</h2>
<div id="file_wrap">
<ul class="file_list" id="file_list">
加载中...
</ul>
</div>
<div id="loading" class="hide">处理中...</div>
<script>
window.baseRepo = localStorage.getItem('GIT_REPO') || 'dhjz/file'
window.baseToken = localStorage.getItem('GIT_TOKEN') || ''
if (!baseToken) alert('请先设置仓库和token')
function toggleWrap() {
var wrap = document.getElementById("file_wrap")
wrap.className = wrap.className ? '' : 'w50'
}
let urls = [
{ name: '本站', url: location.href },
{ name: 'staticaly加速', url: `https://cdn.staticaly.com/gh/${baseRepo}/master/` },
{ name: 'gitmirror加速', url: `https://raw.gitmirror.com/${baseRepo}/master/` },
{ name: 'jsdelivr加速', url: `https://gcore.jsdelivr.net/gh/${baseRepo}@master/` },
{ name: 'jsdelivr1加速', url: `https://cdn.jsdelivr.net/gh/${baseRepo}/` },
{ name: 'kgithub加速', url: `https://raw.kgh.neting.cc/${baseRepo}/master/` },
{ name: 'fastgit加速', url: `https://raw.fastgit.org/${baseRepo}/master/` },
]
function initBtn() {
let btnEl = document.getElementById('btn-wrap')
for (let j = 0; j < urls.length; j++) {
const temp = urls[j]
const btn = document.createElement('button')
btn.innerHTML = temp.name + `<span id="btn${j}"></span>`
let ig = new Image()
ig.src = temp.url + 'init.jpg?t=' + new Date().getTime()
let start = new Date().getTime()
ig.onload = function() {
document.getElementById(`btn${j}`).innerHTML = new Date().getTime() - start + 'ms'
}
ig.onerror = function() {
document.getElementById(`btn${j}`).innerHTML = '延迟过高'
}
btn.onclick = function () {
document.getElementById('rootdm').value = temp.url
initFileList()
}
btnEl.append(btn)
}
}
initBtn()
window.request = axios.create({
baseURL: 'https://api.github.com/',
timeout: 10000,
headers: {
'Authorization': 'Bearer ' + baseToken,
'Accept': 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28'
}
});
request.interceptors.response.use(function (response) {
console.log('请求成功', response);
hideLoading()
return response;
}, function (error) {
hideLoading()
return Promise.reject(error);
});
window.paths = []
window.en = Base64.encode
window.de = Base64.decode
window.fileList = []
function initFileList(searchVal) {
let rootdm = document.getElementById('rootdm').value || ''
let tempList = window.fileList
if (searchVal && searchVal.trim()) {
tempList = window.fileList.filter(item => item.name.includes(searchVal.trim()))
}
if (window.fileList.length) document.getElementById('file_list').innerHTML = tempList.map(item => {
return `<li class="file ${item.ftype}">
<a target="_blank" href="${rootdm}${item.path}" onclick="getDir('${item.type == 'dir' ? item.path : ''}', false, event)">${item.name}</a><span class='sha'>${item.sha}</span><span class="size">${getUnit(item.size)}</span>
<i onclick="delOne('${item.path}', '${item.sha}')" class="del">删除</i>
</li>`
}).join('')
document.getElementById('repo').innerHTML = baseRepo + '/' + (paths.length ? paths[paths.length - 1] : '')
}
// 初始化根目录
if (baseToken) getDir('', true)
function getDir(path, isRoot, event, isBack) {
if (!path && !isRoot) return
if (event) event.preventDefault()
showLoading()
getContent(path + '?t=' + new Date().getTime()).then(data => {
console.log(data);
window.fileList = (data || []).filter(d => d.name != 'init.jpg').map(item => {
item.ftype = getType(item.name)
if (item.type == 'dir') item.ftype = 'dir'
return item
})
window.fileList.sort((a, b) => a.type < b.type ? -1 : 1)
if (path && !isBack) paths.push(path)
initFileList()
})
}
function addDir() {
const val = prompt('请输入新建目录名称, 基于根目录, 不以/开头', '')
if (val) {
putDir(val)
}
}
function dirBack() {
if (!paths.length) return alert('已经是根目录了!')
paths.pop()
if (paths.length) {
getDir(paths[paths.length - 1], false, null, true)
} else {
getDir('', true, null, true)
}
}
function refresh() {
if (paths.length) {
getDir(paths[paths.length - 1], false, null, true)
} else {
getDir('', true, null, true)
}
}
function search(e) {
if (e.keyCode == 13) {
initFileList(document.getElementById('search').value)
}
}
function delOne(path, sha) {
if (path == 'index.html') return alert('主页index.html不能被删除!')
if (window.confirm("是否确认删除改文件: " + path)){
delFile(path, sha, true)
}
}
// putContent('ip.txt', base64Str)
document.getElementById('file').addEventListener('input', (e) => {
const file = e.target.files[0]
if (file) putFile(paths.length ? (paths[paths.length - 1] + '/' + file.name) : file.name, file)
document.getElementById('file').value = ''
})
function updateRepo() {
const val = prompt('请输入仓库 {owner}/{repo}', localStorage.getItem('GIT_REPO') || 'dhjz/file')
if(val) localStorage.setItem('GIT_REPO', val) || location.reload()
}
function updateToken() {
const val = prompt('请输入token', localStorage.getItem('GIT_TOKEN') || '')
if(val) localStorage.setItem('GIT_TOKEN', val) || location.reload()
}
function getSha(path) {
return new Promise((reso, rej) => {
request.get(`/repos/${baseRepo}/contents/${path}`).then(res => reso(res.data.sha)).catch(() => reso(null))
})
}
function getContent(path, isFull) {
if (isFull) return request.get(`/repos/${baseRepo}/contents/${path}`)
return new Promise((reso, rej) => {
request.get(`/repos/${baseRepo}/contents/${path}`).then(res => {
if (Array.isArray(res.data)) return reso(res.data)
reso(Base64.decode(res.data.content))
}).catch(() => {
console.log('not exit file: ' + path)
reso(null)
})
})
}
function putContent(path, content) {
const data = {
message: now() + ' update ' + path,
content: Base64.encode(content),
}
getSha(path).then(sha => {
if (sha) data.sha = sha
request.put(`/repos/${baseRepo}/contents/${path}`, data)
})
}
function putDir(path) {
const data = {
message: now() + ' create dir ' + path,
content: '',
}
getContent(path).then(res => {
if (Array.isArray(res)) return alert('该目录已存在')
request.put(`/repos/${baseRepo}/contents/${path}${path.endsWith('/') ? '' : '/'}.init`, data).then(() => {
alert('新建目录成功: ' + path)
refresh()
})
})
}
function delFile(path, sha, isTip) {
// getSha(path).then((sha) => {
// }).catch((e) => console.log('not exit file: ' + path))
request.delete(`/repos/${baseRepo}/contents/${path}`, {
params: {
message: now() + ' del ' + path,
sha
}
}).then(() => {
if (isTip) alert('删除文件成功:' + path)
refresh()
})
}
function putFile(path, file) {
console.log('upload file:', file)
getSha(path).then(sha => {
if (sha && !window.confirm('已存在改文件, 是否覆盖?')) return
// if (sha && window.confirm('是否自动重命名?')) path = (new Date().getTime() + '').substr(0, 10) + '_' + path
showLoading()
const reader = new FileReader()
reader.readAsArrayBuffer(file)
reader.onload = async () => {
const arrayBuffer = reader.result;
const blob = new Blob([arrayBuffer], { type: file.type });
const content = await blob.arrayBuffer();
const data = {
message: now() + ' update ' + path,
path: path,
content: btoa(chunkChar(new Uint8Array(content))),
sha,
}
request.put(`/repos/${baseRepo}/contents/${path}`, data, {
headers: {
'Content-Type': file.type,
}
}).then(() => {
alert('上传成功:' + path + ', 大小:' + getUnit(file.size))
refresh()
})
}
})
}
function chunkChar(arr) {
// content: btoa(String.fromCharCode(...new TextEncoder().encode(content))) 不太行
// String.fromCharCode()方法最多可以接受65535个参数
const chunkSize = 10000
const chunks = []
for (let i = 0; i < arr.length; i += chunkSize) {
chunks.push(arr.slice(i, i + chunkSize))
}
const strings = chunks.map(chunk => String.fromCharCode(...chunk))
return strings.join('')
}
function now() {
return new Date(new Date().getTime() + 8 * 60 * 60 * 1000).toISOString().replace('T', ' ').substring(0,19)
}
function getType(val) {
if (/\.(jpg|jpeg|png|gif)$/i.test(val)) return 'img'
if (/\.(mp4|avi|mov|wmv|flv)$/i.test(val)) return 'video'
if (/\.(mp3|wav|wma|aac)$/i.test(val)) return 'music'
if (/\.(doc|docx|odt)$/i.test(val)) return 'doc'
if (/\.(xls|xlsx)$/i.test(val)) return 'xls'
if (/\.(ppt|pptx)$/i.test(val)) return 'ppt'
if (/\.(pdf)$/i.test(val)) return 'pdf'
if (/\.(txt|ini|properties|yml|json|md)$/i.test(val)) return 'txt'
if (/\.(java|html|htm|css|js|php|h|go|)$/i.test(val)) return 'code'
if (/\.(zip|rar|7z|tar\.gz|tar\.bz2)$/i.test(val)) return 'zip'
return 'other'
}
function getUnit(bytes, decimals = 2) {
if (bytes === 0) return '0B';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + '' + sizes[i];
}
function showLoading(val) {
document.getElementById('loading').innerHTML = val || '处理中...'
document.getElementById('loading').className = ''
}
function hideLoading() {
document.getElementById('loading').className = 'hide'
}
</script>
<style>
.gg-folder{ transform: scale(var(--ggs,1))}
.gg-folder, .gg-folder::after{ box-sizing: border-box; position: relative; display: block; width: 22px; height: 16px; border: 2px solid; border-radius: 3px}
.gg-folder::after{ content: ""; position: absolute; width: 10px; height: 4px; border-bottom: 0; border-top-left-radius: 2px; border-top-right-radius: 4px; border-bottom-left-radius: 0; border-bottom-right-radius: 0; top: -5px}
.gg-file{ box-sizing: border-box; position: relative; display: block; transform: scale(var(--ggs,1)); width: 14px; height: 16px; border: 2px solid transparent; border-right: 0; border-top: 0; box-shadow: 0 0 0 2px; border-radius: 1px; border-top-right-radius: 4px; overflow: hidden}
.gg-file::after{ content: ""; display: block; box-sizing: border-box; position: absolute; width: 6px; height: 6px; border-left: 2px solid; border-bottom: 2px solid; right: -1px; top: -1px}
.gg-image{ box-sizing: border-box; position: relative; display: block; transform: scale(var(--ggs,1)); width: 20px; height: 16px; overflow: hidden; box-shadow: 0 0 0 2px; border-radius: 2px}
.gg-image::after,.gg-image::before{ content: ""; display: block; box-sizing: border-box; position: absolute; border: 2px solid}
.gg-image::after{ transform: rotate(45deg); border-radius: 3px; width: 16px; height: 16px; top: 9px; left: 6px}
.gg-image::before{ width: 6px; height: 6px; border-radius: 100%; top: 2px; left: 2px}
.gg-camera{ box-sizing: border-box; position: relative; display: block; transform: scale(var(--ggs,1)); border: 2px solid; border-radius: 3px; width: 18px; height: 12px; perspective: 24px}
.gg-camera::after,
.gg-camera::before{ content: ""; display: block; box-sizing: border-box; position: absolute}
.gg-camera::before{ border: 2px solid; border-left-color: transparent; transform: rotateY(-70deg); width: 8px; height: 8px; right: -7px; top: 0}
.gg-camera::after{ width: 10px; height: 5px; border-top: 2px solid; border-right: 2px solid; top: -5px; right: 2px; border-top-right-radius: 2px}
.gg-file.pdf:before{ content: 'pdf'; font-size: 15px; position: absolute; bottom: -46%; font-style: normal; transform: scale(0.5) translateX(-54%)}
.gg-file.doc:before{ content: 'doc'; font-size: 15px; position: absolute; bottom: -46%; font-style: normal; transform: scale(0.5) translateX(-54%)}
</style>
</body>
</html>