Ultimate fix and tested ! You can download contract now.

This commit is contained in:
2026-01-06 23:43:09 -05:00
committed by Djalim Simaila
parent 7568afb888
commit aaa9d0812b
2 changed files with 46 additions and 2 deletions
@@ -0,0 +1,36 @@
import { Handlers } from "$fresh/server.ts";
import connect from "$root/databases/connect.ts";
export const handler: Handlers = {
async GET(_request, ctx) {
try {
const { id } = ctx.params;
if (!id) {
return new Response("Invalid request: Missing ID", { status: 400 });
}
using connection = connect("mobility");
const query = connection.database.prepare(
"SELECT attestationFile FROM mobility WHERE id = ?",
);
const result = query.get(id);
if (!result || !result.attestationFile) {
return new Response("No file found for the given ID", { status: 404 });
}
return new Response(result.attestationFile, {
status: 200,
headers: {
"Content-Type": "application/pdf",
"Content-Disposition": `attachment; filename="attestation_${id}.pdf"`,
},
});
} catch (error) {
console.error("Error fetching file:", error);
return new Response("Failed to fetch file", { status: 500 });
}
},
};