Skip to content

Commit f5c3b8e

Browse files
committed
bug fix
1 parent 6a6895d commit f5c3b8e

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

β€Žadmin/panel.htmlβ€Ž

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5882,7 +5882,7 @@
58825882
async function deletePhd(idx) {
58835883
const entry = phdState.entries[idx];
58845884
const updated = phdState.entries.filter((_, i) => i !== idx);
5885-
await savePhdToGitHub(updated, `Remove PhD thesis: ${entry.author}`);
5885+
await savePhdToGitHub(updated, `Remove PhD thesis: ${entry.author}`, { deletePdf: entry.pdf });
58865886
}
58875887

58885888
// ── Toggle pending ────────────────────────────────────────────────────────────
@@ -5937,7 +5937,7 @@
59375937
await savePhdToGitHub(updated, commitMsg);
59385938
}
59395939

5940-
async function savePhdToGitHub(entries, commitMsg) {
5940+
async function savePhdToGitHub(entries, commitMsg, opts = {}) {
59415941
if (!phdState.loaded) return;
59425942
const content = serializePhdYaml(entries);
59435943
progressStart();
@@ -5958,6 +5958,20 @@
59585958
body: JSON.stringify({ ref: `refs/heads/${branch}`, sha: baseSha }) });
59595959
if (!branchRes.ok) await parseGhError(branchRes, 'Failed to create branch');
59605960

5961+
// Delete PDF if requested (on delete thesis)
5962+
if (opts.deletePdf) {
5963+
const delPath = `phd_thesis/${opts.deletePdf}`;
5964+
try {
5965+
const chk = await fetch(`${GH}/contents/${delPath}`, { headers: ghH() });
5966+
if (chk.ok) {
5967+
const { sha: delSha } = await chk.json();
5968+
const delRes = await fetch(`${GH}/contents/${delPath}`, { method: 'DELETE', headers: ghH(),
5969+
body: JSON.stringify({ message: `Remove PDF: ${opts.deletePdf}`, sha: delSha, branch }) });
5970+
if (!delRes.ok) await parseGhError(delRes, 'Failed to delete PDF');
5971+
}
5972+
} catch(e) { /* PDF not found – ignore */ }
5973+
}
5974+
59615975
// Upload PDF if a new file was selected
59625976
if (phdPdfFile) {
59635977
const pdfFilename = document.getElementById('phd-pdf').value.trim().replace(/^.*[\/\\]/, '');

0 commit comments

Comments
Β (0)