|
5882 | 5882 | async function deletePhd(idx) { |
5883 | 5883 | const entry = phdState.entries[idx]; |
5884 | 5884 | 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 }); |
5886 | 5886 | } |
5887 | 5887 |
|
5888 | 5888 | // ββ Toggle pending ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
|
5937 | 5937 | await savePhdToGitHub(updated, commitMsg); |
5938 | 5938 | } |
5939 | 5939 |
|
5940 | | -async function savePhdToGitHub(entries, commitMsg) { |
| 5940 | +async function savePhdToGitHub(entries, commitMsg, opts = {}) { |
5941 | 5941 | if (!phdState.loaded) return; |
5942 | 5942 | const content = serializePhdYaml(entries); |
5943 | 5943 | progressStart(); |
|
5958 | 5958 | body: JSON.stringify({ ref: `refs/heads/${branch}`, sha: baseSha }) }); |
5959 | 5959 | if (!branchRes.ok) await parseGhError(branchRes, 'Failed to create branch'); |
5960 | 5960 |
|
| 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 | + |
5961 | 5975 | // Upload PDF if a new file was selected |
5962 | 5976 | if (phdPdfFile) { |
5963 | 5977 | const pdfFilename = document.getElementById('phd-pdf').value.trim().replace(/^.*[\/\\]/, ''); |
|
0 commit comments