feat(ext/sw): GitHost.writeFileCreateOnly() refuses to overwrite

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
adlee-was-taken
2026-04-27 18:06:48 -04:00
parent 98c962796f
commit 86b5941875
4 changed files with 89 additions and 0 deletions

View File

@@ -82,6 +82,23 @@ export class GiteaHost implements GitHost {
}
}
async writeFileCreateOnly(path: string, content: Uint8Array, message: string): Promise<void> {
const existing = await fetch(`${this.baseUrl}/${path}`, { headers: this.headers });
if (existing.ok) {
throw new Error(`writeFileCreateOnly: ${path} already exists`);
}
const b64 = uint8ArrayToBase64(content);
const resp = await fetch(`${this.baseUrl}/${path}`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({ content: b64, message }),
});
if (!resp.ok) {
const text = await resp.text();
throw new Error(`Gitea writeFileCreateOnly ${path}: ${resp.status} ${text}`);
}
}
async deleteFile(path: string, message: string): Promise<void> {
// Need the current SHA to delete.
const existing = await fetch(`${this.baseUrl}/${path}`, {