Certificates react work

- renewal and download
- table columns rendering
- searching
- deleting
This commit is contained in:
Jamie Curnow
2025-10-27 18:08:37 +10:00
parent 7b5c70ed35
commit 0de26f2950
16 changed files with 381 additions and 86 deletions

View File

@@ -80,8 +80,16 @@ export async function get(args: GetArgs, abortController?: AbortController) {
return processResponse(await baseGet(args, abortController));
}
export async function download(args: GetArgs, abortController?: AbortController) {
return (await baseGet(args, abortController)).text();
export async function download({ url, params }: GetArgs, filename = "download.file") {
const headers = buildAuthHeader();
const res = await fetch(buildUrl({ url, params }), { headers });
const bl = await res.blob();
const u = window.URL.createObjectURL(bl);
const a = document.createElement("a");
a.href = u;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
}
interface PostArgs {

View File

@@ -1,8 +1,10 @@
import * as api from "./base";
import type { Binary } from "./responseTypes";
export async function downloadCertificate(id: number): Promise<Binary> {
return await api.get({
url: `/nginx/certificates/${id}/download`,
});
export async function downloadCertificate(id: number): Promise<void> {
await api.download(
{
url: `/nginx/certificates/${id}/download`,
},
`certificate-${id}.zip`,
);
}

View File

@@ -15,5 +15,3 @@ export interface ValidatedCertificateResponse {
certificate: Record<string, any>;
certificateKey: boolean;
}
export type Binary = number & { readonly __brand: unique symbol };