save annotation data as json and sent to server

This commit is contained in:
Jonathan Jenne
2023-10-09 13:05:31 +02:00
parent 8c629691d9
commit dfadcff710
5 changed files with 75 additions and 22 deletions

View File

@@ -71,15 +71,21 @@ export class App {
}
public static async handleFinish(event: any) {
await App.Instance.save();
// Export annotation data and save to database
const json = await App.Instance.exportInstantJSON()
console.log(json);
console.log(JSON.stringify(json));
const result = await App.Network.postEnvelope(App.envelopeKey, App.currentDocument.id, JSON.stringify(json))
// Flatten the annotations and save the document to disk
/*
const buffer = await App.Instance.exportPDF({ flatten: true });
const result = await App.Network.postDocument(App.envelopeKey, App.currentDocument.id, buffer);
console.log(result)
*/
}
public static async handleReset(event: any) {
@@ -196,11 +202,18 @@ class Network {
.then(res => res.json());
}
public postEnvelope(envelopeKey: string, documentId: number, jsonString: string): Promise<any> {
const options: RequestInit = {
credentials: "include",
method: "POST",
body: jsonString
}
public postEnvelope(envelopeKey: string, documentId: number, buffer: ArrayBuffer): Promise<any> {
return fetch(`/api/envelope/${envelopeKey}/${documentId}`, { credentials: "include", method: "POST", body: buffer })
.then(res => res.json());
return fetch(`/api/envelope/${envelopeKey}?index=${documentId}`, options)
.then(res => {
console.log(res)
res.json()
});
}
}