plokmii commited on
Commit
d8b3b7f
·
verified ·
1 Parent(s): eab885c

Upload templates/admin.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. templates/admin.html +53 -35
templates/admin.html CHANGED
@@ -58,46 +58,64 @@
58
  </div>
59
 
60
  <!-- ============ Storage ============ -->
61
- <h5 class="mt-4">檔案儲存空間</h5>
62
- <div class="card mb-4">
63
- <div class="card-body">
64
- <div class="d-flex justify-content-between align-items-center mb-2">
65
- <div>
66
- <strong>{{ storage.count }}</strong>檔案,共 <strong>{{ storage.size_mb }} MB</strong>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  </div>
68
- <div>
69
- <a href="/admin/download_all_uploads" class="btn btn-sm btn-outline-primary me-1">一鍵下載全部</a>
70
- <button class="btn btn-sm btn-outline-danger" onclick="cleanupUploads()">清理舊檔案</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  </div>
72
  </div>
73
- {% if uploads %}
74
- <div style="max-height: 360px; overflow-y: auto;">
75
- <table class="table table-sm table-bordered mb-0" style="font-size:.85rem;">
76
- <thead class="table-light" style="position:sticky; top:0;">
77
- <tr><th>檔名</th><th style="width:90px;">大小</th><th style="width:140px;">上傳時間</th><th style="width:130px;">操作</th></tr>
78
- </thead>
79
- <tbody>
80
- {% for u in uploads %}
81
- <tr id="upload-row-{{ loop.index }}">
82
- <td class="small">{{ u.name }}</td>
83
- <td class="text-end">{{ u.size_kb }} KB</td>
84
- <td class="small">{{ u.mtime }}</td>
85
- <td class="text-nowrap">
86
- <a href="/download_upload/{{ u.name }}" class="btn btn-sm btn-outline-primary py-0 px-2">下載</a>
87
- <button class="btn btn-sm btn-outline-danger py-0 px-2" onclick="deleteUpload('{{ u.name }}', {{ loop.index }})">刪除</button>
88
- </td>
89
- </tr>
90
- {% endfor %}
91
- </tbody>
92
- </table>
93
- </div>
94
- {% else %}
95
- <div class="text-muted small mt-2">無上傳檔案</div>
96
- {% endif %}
97
  </div>
 
98
  </div>
99
  <script>
100
- function deleteUpload(name, idx) {
101
  if (!confirm('確定刪除 ' + name + '?')) return;
102
  fetch('/admin/delete_upload', {
103
  method: 'POST',
@@ -105,7 +123,7 @@
105
  body: JSON.stringify({ filename: name })
106
  }).then(r => r.json()).then(d => {
107
  if (d.ok) {
108
- const row = document.getElementById('upload-row-' + idx);
109
  if (row) row.remove();
110
  } else {
111
  alert('刪除失敗:' + (d.error || ''));
 
58
  </div>
59
 
60
  <!-- ============ Storage ============ -->
61
+ {% set pra_uploads = uploads | selectattr('source', 'equalto', 'PRA') | list %}
62
+ {% set dsa_uploads = uploads | selectattr('source', 'equalto', 'DSA') | list %}
63
+ {% set pra_size = (pra_uploads | sum(attribute='size_kb') / 1024) | round(2) %}
64
+ {% set dsa_size = (dsa_uploads | sum(attribute='size_kb') / 1024) | round(2) %}
65
+ <div class="d-flex justify-content-between align-items-center mt-4 mb-2">
66
+ <h5 class="mb-0">檔案儲存空間
67
+ <small class="text-muted">總計 {{ storage.count }} 個檔案,{{ storage.size_mb }} MB</small>
68
+ </h5>
69
+ <button class="btn btn-sm btn-outline-danger" onclick="cleanupUploads()">清理舊檔案</button>
70
+ </div>
71
+ <div class="row g-3 mb-4">
72
+ {% for grp in [
73
+ {'label': 'PRA', 'badge': 'bg-primary', 'list': pra_uploads, 'size': pra_size, 'idprefix': 'pra'},
74
+ {'label': 'DSA', 'badge': 'bg-danger', 'list': dsa_uploads, 'size': dsa_size, 'idprefix': 'dsa'}
75
+ ] %}
76
+ <div class="col-md-6">
77
+ <div class="card h-100">
78
+ <div class="card-header d-flex justify-content-between align-items-center py-2">
79
+ <div>
80
+ <span class="badge {{ grp.badge }} me-1">{{ grp.label }}</span>
81
+ <strong>{{ grp.list | length }}</strong> 個檔案,共 <strong>{{ grp.size }} MB</strong>
82
+ </div>
83
+ {% if grp.list %}
84
+ <a href="/admin/download_all_uploads?source={{ grp.label }}" class="btn btn-sm btn-outline-primary">下載 {{ grp.label }} 全部</a>
85
+ {% endif %}
86
  </div>
87
+ <div class="card-body p-2">
88
+ {% if grp.list %}
89
+ <div style="max-height: 360px; overflow-y: auto;">
90
+ <table class="table table-sm table-bordered mb-0" style="font-size:.82rem;">
91
+ <thead class="table-light" style="position:sticky; top:0;">
92
+ <tr><th>檔名</th><th style="width:80px;">大小</th><th style="width:130px;">上傳時間</th><th style="width:120px;">操作</th></tr>
93
+ </thead>
94
+ <tbody>
95
+ {% for u in grp.list %}
96
+ <tr id="upload-row-{{ grp.idprefix }}-{{ loop.index }}">
97
+ <td class="small">{{ u.name }}</td>
98
+ <td class="text-end">{{ u.size_kb }} KB</td>
99
+ <td class="small">{{ u.mtime }}</td>
100
+ <td class="text-nowrap">
101
+ <a href="/download_upload/{{ u.name }}" class="btn btn-sm btn-outline-primary py-0 px-2">下載</a>
102
+ <button class="btn btn-sm btn-outline-danger py-0 px-2" onclick="deleteUpload('{{ u.name }}', '{{ grp.idprefix }}-{{ loop.index }}')">刪除</button>
103
+ </td>
104
+ </tr>
105
+ {% endfor %}
106
+ </tbody>
107
+ </table>
108
+ </div>
109
+ {% else %}
110
+ <div class="text-muted small">無 {{ grp.label }} 上傳檔案</div>
111
+ {% endif %}
112
  </div>
113
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  </div>
115
+ {% endfor %}
116
  </div>
117
  <script>
118
+ function deleteUpload(name, rowKey) {
119
  if (!confirm('確定刪除 ' + name + '?')) return;
120
  fetch('/admin/delete_upload', {
121
  method: 'POST',
 
123
  body: JSON.stringify({ filename: name })
124
  }).then(r => r.json()).then(d => {
125
  if (d.ok) {
126
+ const row = document.getElementById('upload-row-' + rowKey);
127
  if (row) row.remove();
128
  } else {
129
  alert('刪除失敗:' + (d.error || ''));