fix: 改用 better-sqlite3 兼容 GLIBC 环境

This commit is contained in:
Cuishibing
2026-04-26 10:00:42 +08:00
parent fdae636637
commit b885dbac0f
3 changed files with 55 additions and 14 deletions

View File

@@ -100,13 +100,30 @@
}
async function setup() {
// 检查是否已有 key
const savedKey = localStorage.getItem('myoss_api_key');
if (savedKey) {
apiKey = savedKey;
location.reload();
return;
}
const name = document.getElementById('setup-name').value;
const res = await fetch(API_BASE + '/api/keys/bootstrap', {
const res = await fetch('/api/keys/bootstrap', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name })
});
const data = await res.json();
if (data.error) {
// 已初始化过,提示用户输入已有 key
const key = prompt('服务已初始化,请输入已有的 API Key:');
if (key) {
localStorage.setItem('myoss_api_key', key);
location.reload();
}
return;
}
apiKey = data.key;
localStorage.setItem('myoss_api_key', apiKey);
location.reload();
@@ -143,10 +160,14 @@
for (const file of files) {
const formData = new FormData();
formData.append('file', file);
await request('/api/files', {
const data = await request('/api/files', {
method: 'POST',
body: formData
});
if (data.error) {
alert(data.error);
return;
}
}
alert('上传成功');
loadFiles();
@@ -154,6 +175,10 @@
async function loadFiles() {
const files = await request('/api/files');
renderFiles(files);
}
function renderFiles(files) {
const tbody = document.getElementById('files-tbody');
if (!files || !files.length) {
tbody.innerHTML = '<tr><td colspan="3" class="empty">暂无文件</td></tr>';
@@ -167,7 +192,7 @@
</td>
<td>${formatSize(f.size)}</td>
<td class="actions">
<a href="${API_BASE}/api/files/${f.fileKey}/download" target="_blank">下载</a>
<a href="/api/files/${f.fileKey}/download?key=${apiKey}" target="_blank">下载</a>
<button class="danger" onclick="deleteFile('${f.fileKey}')">删除</button>
</td>
</tr>
@@ -189,20 +214,34 @@
async function init() {
if (!apiKey) {
// 先检查是否已有 bootstrap key
try {
const res = await fetch('/api/files', {
headers: { 'X-API-Key': 'check' }
});
if (res.status === 401 || res.status === 404) {
document.getElementById('setup-card').classList.remove('hidden');
return;
}
} catch (e) {}
document.getElementById('setup-card').classList.remove('hidden');
return;
}
const res = await fetch(API_BASE + '/api/files', {
headers: { 'X-API-Key': apiKey }
});
document.getElementById('main-card').classList.remove('hidden');
document.getElementById('upload-card').classList.remove('hidden');
document.getElementById('files-card').classList.remove('hidden');
document.getElementById('current-key').textContent = apiKey;
loadFiles();
try {
const files = await request('/api/files');
if (!files) {
document.getElementById('setup-card').classList.remove('hidden');
return;
}
document.getElementById('main-card').classList.remove('hidden');
document.getElementById('upload-card').classList.remove('hidden');
document.getElementById('files-card').classList.remove('hidden');
document.getElementById('current-key').textContent = apiKey;
renderFiles(files);
} catch (e) {
document.getElementById('setup-card').classList.remove('hidden');
}
}
init();