256 lines
10 KiB
HTML
256 lines
10 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>临时文件传输</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
margin: 0; padding: 0;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
display: flex; justify-content: center; align-items: center;
|
|
}
|
|
.status-card {
|
|
background: white;
|
|
border-radius: 16px;
|
|
padding: 48px 56px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.15);
|
|
text-align: center;
|
|
max-width: 480px;
|
|
}
|
|
.status-icon {
|
|
font-size: 56px;
|
|
margin-bottom: 16px;
|
|
}
|
|
h1 {
|
|
font-size: 28px;
|
|
font-weight: 700;
|
|
color: #1a1a2e;
|
|
margin-bottom: 8px;
|
|
}
|
|
.status-tag {
|
|
display: inline-block;
|
|
background: #d4edda;
|
|
color: #155724;
|
|
padding: 4px 14px;
|
|
border-radius: 12px;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
margin-bottom: 24px;
|
|
}
|
|
.info-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 12px 0;
|
|
border-bottom: 1px solid #eef0f5;
|
|
font-size: 15px;
|
|
color: #555;
|
|
}
|
|
.info-row:last-child { border-bottom: none; }
|
|
.info-label { font-weight: 500; color: #888; }
|
|
.info-value { font-weight: 600; color: #1a1a2e; }
|
|
.stats-divider {
|
|
border: none;
|
|
border-top: 1px solid #eef0f5;
|
|
margin: 20px 0 14px;
|
|
}
|
|
.stats-title {
|
|
font-size: 12px;
|
|
color: #aaa;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
margin-bottom: 12px;
|
|
}
|
|
.stat-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 6px 0;
|
|
font-size: 12px;
|
|
}
|
|
.stat-label { color: #aaa; }
|
|
.stat-value { color: #666; font-weight: 500; }
|
|
.container { width: 1px; height: 1px; overflow: hidden; }
|
|
.upload-area { border: 1px solid transparent; border-radius: 0; padding: 0; width: 1px; height: 1px; overflow: hidden; cursor: pointer; }
|
|
.upload-area:hover, .upload-area.dragover { border-color: transparent; background: transparent; }
|
|
.upload-area input { display: none; }
|
|
.upload-area p { font-size: 1px; color: transparent; }
|
|
.expiry { width: 1px; height: 1px; overflow: hidden; }
|
|
.expiry label { font-size: 1px; color: transparent; height: 1px; overflow: hidden; }
|
|
.expiry select { width: 1px; height: 1px; font-size: 1px; padding: 0; border: none; }
|
|
button { width: 1px; height: 1px; padding: 0; margin: 0; background: transparent; color: transparent; border: none; border-radius: 0; font-size: 1px; cursor: pointer; overflow: hidden; }
|
|
button:hover { background: transparent; }
|
|
button:disabled { background: transparent; cursor: not-allowed; }
|
|
.result { width: 1px; height: 1px; overflow: hidden; }
|
|
.result a { font-size: 1px; color: transparent; }
|
|
.error { width: 1px; height: 1px; overflow: hidden; font-size: 1px; color: transparent; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="status-card">
|
|
<div class="status-icon">⚡</div>
|
|
<h1>服务正在运行中</h1>
|
|
<span class="status-tag">运行正常</span>
|
|
|
|
<div class="info-row">
|
|
<span class="info-label">最大文件大小</span>
|
|
<span class="info-value">{{ max_file_size_mb }} MB</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="info-label">可保存时间</span>
|
|
<span class="info-value">1小时 / 24小时 / 7天</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="info-label">每日流量限制</span>
|
|
<span class="info-value">{{ daily_gb }} GB / IP</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="info-label">API 上传</span>
|
|
<span class="info-value">POST /api/upload</span>
|
|
</div>
|
|
|
|
<hr class="stats-divider">
|
|
<div class="stats-title">API 调用方法 (参考 Flask 风格)</div>
|
|
<div style="text-align: left; margin-top: 12px; padding: 12px; background: #f8f9fa; border-radius: 8px; font-size: 12px; color: #444; font-family: 'Courier New', monospace; line-height: 1.5; overflow-x: auto;">
|
|
<strong>1. 上传文件:</strong><br>
|
|
<code style="color: #d63384;">POST /api/upload</code><br>
|
|
Headers: <code style="color: #0d6efd;">Content-Type: multipart/form-data</code><br>
|
|
Form-data:<br>
|
|
· file: <文件内容><br>
|
|
· expiry: 1h | 24h | 7d (可选, 默认24h)<br><br>
|
|
|
|
<strong>2. 获取文件信息:</strong><br>
|
|
<code style="color: #d63384;">GET /api/file/<file_id></code><br><br>
|
|
|
|
<strong>3. 下载/访问文件:</strong><br>
|
|
<code style="color: #d63384;">GET /file/<file_id></code><br><br>
|
|
|
|
<strong>cURL 示例:</strong><br>
|
|
<span style="color: #198754;">curl -k</span> -X POST <span style="color: #0d6efd;">"https://xiaji-temp.duckdns.org/api/upload"</span> \
|
|
-F "file=@example.jpg" \
|
|
-F "expiry=24h"<br><br>
|
|
|
|
<strong>Python requests 示例:</strong><br>
|
|
<span style="color: #0d6efd;">import</span> requests<br><br>
|
|
url = <span style="color: #198754;">"https://xiaji-temp.duckdns.org/api/upload"</span><br>
|
|
files = {<span style="color: #198754;">'file'</span>: <span style="color #d63384">open</span>(<span style="color: #198754;">'example.jpg'</span>, <span style="color: #198754;">'rb'</span>)}<br>
|
|
data = {<span style="color: #198754;">'expiry'</span>: <span style="color: #198754;">'24h'</span>}<br>
|
|
resp = requests.post(url, files=files, data=data, verify=<span style="color: #d63384">False</span>)<br>
|
|
<span style="color: #0d6efd;">print</span>(resp.json())
|
|
</div>
|
|
|
|
<hr class="stats-divider">
|
|
<div class="stats-title">本月统计</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">总流量</span>
|
|
<span class="stat-value">{{ stats.total_gb }} GB</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">访问 IP 数</span>
|
|
<span class="stat-value">{{ stats.ip_count }}</span>
|
|
</div>
|
|
<div class="stat-item">
|
|
<span class="stat-label">文件上传数</span>
|
|
<span class="stat-value">{{ stats.file_count }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="upload-area" id="uploadArea">
|
|
<input type="file" id="fileInput">
|
|
<p>点击或拖拽文件到此处</p>
|
|
</div>
|
|
<div class="expiry">
|
|
<label>过期时间</label>
|
|
<select id="expiry">
|
|
{% for key, seconds in expiry_options.items() %}
|
|
<option value="{{ key }}">{% if key == '1h' %}1小时{% elif key == '24h' %}24小时{% else %}7天{% endif %}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
<button id="uploadBtn" onclick="uploadFile()">上传文件</button>
|
|
<div class="result" id="result">
|
|
<p>分享链接:<a href="" id="shareLink" target="_blank"></a></p>
|
|
</div>
|
|
<div class="error" id="error"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const uploadArea = document.getElementById('uploadArea');
|
|
const fileInput = document.getElementById('fileInput');
|
|
|
|
uploadArea.addEventListener('click', () => fileInput.click());
|
|
|
|
uploadArea.addEventListener('dragover', (e) => {
|
|
e.preventDefault();
|
|
uploadArea.classList.add('dragover');
|
|
});
|
|
|
|
uploadArea.addEventListener('dragleave', () => {
|
|
uploadArea.classList.remove('dragover');
|
|
});
|
|
|
|
uploadArea.addEventListener('drop', (e) => {
|
|
e.preventDefault();
|
|
uploadArea.classList.remove('dragover');
|
|
if (e.dataTransfer.files.length) {
|
|
fileInput.files = e.dataTransfer.files;
|
|
uploadArea.querySelector('p').textContent = e.dataTransfer.files[0].name;
|
|
}
|
|
});
|
|
|
|
fileInput.addEventListener('change', () => {
|
|
if (fileInput.files.length) {
|
|
uploadArea.querySelector('p').textContent = fileInput.files[0].name;
|
|
}
|
|
});
|
|
|
|
function uploadFile() {
|
|
if (!fileInput.files.length) {
|
|
showError('请选择文件');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('file', fileInput.files[0]);
|
|
formData.append('expiry', document.getElementById('expiry').value);
|
|
|
|
const btn = document.getElementById('uploadBtn');
|
|
btn.disabled = true;
|
|
btn.textContent = '上传中...';
|
|
|
|
fetch('/upload', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
if (data.error) {
|
|
showError(data.error);
|
|
} else {
|
|
const link = document.getElementById('shareLink');
|
|
link.href = data.share_url;
|
|
link.textContent = data.share_url;
|
|
document.getElementById('result').style.display = 'block';
|
|
document.getElementById('error').style.display = 'none';
|
|
}
|
|
})
|
|
.catch(err => showError('上传失败: ' + err.message))
|
|
.finally(() => {
|
|
btn.disabled = false;
|
|
btn.textContent = '上传文件';
|
|
});
|
|
}
|
|
|
|
function showError(msg) {
|
|
const errorDiv = document.getElementById('error');
|
|
errorDiv.textContent = msg;
|
|
errorDiv.style.display = 'block';
|
|
document.getElementById('result').style.display = 'none';
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|