Add generate API, Prototype for developer, Clean data
Some checks failed
Deploy eCourt Note Web to Server / Validate Database Schema (Drizzle) (push) Successful in 5s
Deploy eCourt Note Web to Server / Build Web Docker Image (push) Failing after 1m11s
Deploy eCourt Note Web to Server / Deploy eCourt Note Web to Server (push) Has been skipped
Deploy eCourt Note Web to Server / Notify Deployment Status (push) Failing after 0s
Some checks failed
Deploy eCourt Note Web to Server / Validate Database Schema (Drizzle) (push) Successful in 5s
Deploy eCourt Note Web to Server / Build Web Docker Image (push) Failing after 1m11s
Deploy eCourt Note Web to Server / Deploy eCourt Note Web to Server (push) Has been skipped
Deploy eCourt Note Web to Server / Notify Deployment Status (push) Failing after 0s
This commit is contained in:
parent
6ce071ee14
commit
a3d14fd58d
26 changed files with 911 additions and 1267 deletions
|
|
@ -1,8 +1,7 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import { extractContentControls, extractBookmark, templateContentControls, setCustomDocProps, getDocProps,templateDynamicContents } from "@/lib/lib-tmpl";
|
||||
import { verifyDataEd25519, verifyHmacSha256 } from "@/lib/lib-utils";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
import { verifyEd25519, verifyHmacSha256 } from "@/lib/lib-utils";
|
||||
// export const runtime = "nodejs";
|
||||
|
||||
const DOCX_CONTENT_TYPE =
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||
|
|
@ -15,27 +14,14 @@ export async function POST(request: Request) {
|
|||
try {
|
||||
const formData = await request.formData();
|
||||
const file = formData.get("file");
|
||||
const TEST_SECRET = String(formData.get("secret"))??"";
|
||||
const TEST_PUBLIC_KEY_HEX = String(formData.get("public_key"))??"";
|
||||
const TEST_SECRET = String(formData.get("secret") ?? "");
|
||||
const TEST_PUBLIC_KEY_HEX = String(formData.get("public_key") ?? "");
|
||||
|
||||
|
||||
if (!(file instanceof File)) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Missing DOCX file in field "file".',
|
||||
},
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
file.type !== DOCX_CONTENT_TYPE &&
|
||||
!file.name.toLowerCase().endsWith(".docx")
|
||||
if (!(file instanceof File) ||
|
||||
(file.type !== DOCX_CONTENT_TYPE && !file.name.toLowerCase().endsWith(".docx") )
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Field "file" must be a .docx file.',
|
||||
},
|
||||
{ status: 400 },
|
||||
|
|
@ -45,7 +31,6 @@ export async function POST(request: Request) {
|
|||
if (file.size > MAX_UPLOAD_BYTES) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Field "file" exceeds the 100MB size limit.',
|
||||
},
|
||||
{ status: 400 },
|
||||
|
|
@ -62,35 +47,30 @@ export async function POST(request: Request) {
|
|||
const bookmark = extractBookmark(buffer)
|
||||
const properties = getDocProps(buffer)
|
||||
let verify: Record<string, unknown> ={}
|
||||
const ticket_data = String(properties?.custom?.ticket_data)
|
||||
const ticket_data = properties?.custom?.ticket_data
|
||||
const HmacSha256 = String(properties?.custom?.HmacSha256)
|
||||
const Ed25519 = String(properties?.custom?.Ed25519)
|
||||
|
||||
if(ticket_data){
|
||||
|
||||
if(ticket_data && typeof ticket_data === 'string'){
|
||||
const ticketDataObj= JSON.parse(ticket_data)
|
||||
const unix_timestamp = Number(ticketDataObj.exp)*1000
|
||||
if(unix_timestamp){
|
||||
verify['exp'] = new Date(unix_timestamp).toLocaleString("th-TH", { timeZone: "Asia/Bangkok" })
|
||||
}
|
||||
if(TEST_SECRET && HmacSha256){
|
||||
verify['verifyHmacSha256'] = verifyHmacSha256(ticket_data,TEST_SECRET,HmacSha256)
|
||||
verify['HmacSha256'] = verifyHmacSha256(ticket_data,TEST_SECRET,HmacSha256)
|
||||
}
|
||||
if(TEST_PUBLIC_KEY_HEX&& Ed25519){
|
||||
verify["Ed25519"]=verifyDataEd25519(ticket_data,Ed25519,TEST_PUBLIC_KEY_HEX)
|
||||
verify["Ed25519"]=verifyEd25519(ticket_data,Ed25519,TEST_PUBLIC_KEY_HEX)
|
||||
}
|
||||
}
|
||||
let returnData : Record<string, unknown> = {
|
||||
success: true,
|
||||
cc,bookmark,properties,verify
|
||||
}
|
||||
|
||||
|
||||
let returnData : Record<string, unknown> = {cc,bookmark,properties,verify}
|
||||
return NextResponse.json(returnData);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue