Ultimate fix and tested ! You can download contract now.
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user