Skip to content
Snippets Groups Projects
Commit 36735c58 authored by Anthony's avatar Anthony
Browse files

WIP saving

parent 8a00a2e9
No related branches found
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1913 failed
...@@ -21,7 +21,7 @@ import { secondsToHMS } from './utils'; ...@@ -21,7 +21,7 @@ import { secondsToHMS } from './utils';
import AnnotationFormContent from './annotationForm/AnnotationFormContent'; import AnnotationFormContent from './annotationForm/AnnotationFormContent';
import AnnotationFormTime from './annotationForm/AnnotationFormTime'; import AnnotationFormTime from './annotationForm/AnnotationFormTime';
import { import {
geomFromAnnoTarget, getSvg, saveAnnotation, timeFromAnnoTarget, geomFromAnnoTarget, getJPG, getSvg, saveAnnotation, timeFromAnnoTarget,
} from './AnnotationCreationUtils'; } from './AnnotationCreationUtils';
import AnnotationFormOverlay from './annotationForm/AnnotationFormOverlay/AnnotationFormOverlay.js'; import AnnotationFormOverlay from './annotationForm/AnnotationFormOverlay/AnnotationFormOverlay.js';
...@@ -338,10 +338,12 @@ function AnnotationCreation(props) { ...@@ -338,10 +338,12 @@ function AnnotationCreation(props) {
} = state; } = state;
// TODO rename variable for better comprenhension // TODO rename variable for better comprenhension
const svg = await getSvg(props.windowId); const svg = await getSvg(props.windowId);
// const jpg = await getJPG(props.windowId);
const drawingImageExport = svg;
const t = (tstart && tend) ? `${tstart},${tend}` : null; const t = (tstart && tend) ? `${tstart},${tend}` : null;
const body = { value: (!textBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody }; const body = { value: (!textBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody };
saveAnnotation(canvases, config, receiveAnnotation, annotation, body, t, xywh, image, drawingStateSerialized, svg, tags); saveAnnotation(canvases, config, receiveAnnotation, annotation, body, t, xywh, image, drawingStateSerialized, drawingImageExport, tags);
props.closeCompanionWindow('annotationCreation', { props.closeCompanionWindow('annotationCreation', {
id, id,
......
...@@ -5,6 +5,7 @@ import WebAnnotation from './WebAnnotation'; ...@@ -5,6 +5,7 @@ import WebAnnotation from './WebAnnotation';
//const fileUploaderUrl = 'https://scene-uploads.tetras-libre.fr/upload'; //const fileUploaderUrl = 'https://scene-uploads.tetras-libre.fr/upload';
const fileUploaderUrl = 'http://localhost:3000/upload'; const fileUploaderUrl = 'http://localhost:3000/upload';
const fileReaderUrl = 'http://localhost:3000/static/';
/** Extract time information from annotation target */ /** Extract time information from annotation target */
export function timeFromAnnoTarget(annotarget) { export function timeFromAnnoTarget(annotarget) {
...@@ -61,32 +62,30 @@ export async function getSvg(windowId) { ...@@ -61,32 +62,30 @@ export async function getSvg(windowId) {
return svg; return svg;
} }
export function saveAnnotation(canvases, config, receiveAnnotation, annotation, body, t, xywh, image, drawingStateSerialized, svg, tags) { export async function getJPG(windowId) {
const dumbAnnotation = { const stage = window.Konva.stages.find((s) => s.attrs.id === windowId);
type: 'Annotation', const jpg = await stage.toImage({ mimeType: 'image/jpeg', quality: 1 });
motivation: 'commenting', console.log('JPG:', jpg);
body: { return jpg;
id: 'https://files.tetras-libre.fr/dev/Hakanai/media/02_HKN-couv.jpg', }
type: 'Image',
format: 'image/jpg', export async function saveAnnotation(canvases, config, receiveAnnotation, annotation, body, t, xywh, image, drawingStateSerialized, drawingImageExport, tags) {
}, console.log('Send file :', drawingImageExport);
target: 'https://preview.iiif.io/cookbook/master/recipe/0003-mvm-video/canvas#xywh=0,0,301,400&t=0,1000', const filename = await sendFile(drawingImageExport);
};
console.log('Send file :', svg);
const filename = sendFile(svg);
canvases.forEach(async (canvas) => { canvases.forEach(async (canvas) => {
const storageAdapter = config.annotation.adapter(canvas.id); const storageAdapter = config.annotation.adapter(canvas.id);
const anno = { const anno = {
body: { body: {
id: filename, id: fileReaderUrl + filename,
type: 'Image', type: 'Image',
format: 'image/jpg', format: 'image/svg+xml',
value: body.value, value: body.value,
}, },
drawingState: drawingStateSerialized, drawingState: drawingStateSerialized,
id: (annotation && annotation.id) || `${uuid()}`, id: (annotation && annotation.id) || `${uuid()}`,
motivation: 'commenting', motivation: 'painting',
target: `${canvas.id}#xywh=0,0,640,360&t=0,1000',`,
type: 'Annotation', type: 'Annotation',
}; };
...@@ -109,8 +108,6 @@ const sendFile = async (fileContent) => { ...@@ -109,8 +108,6 @@ const sendFile = async (fileContent) => {
const formData = new FormData(); const formData = new FormData();
formData.append('file', blob); formData.append('file', blob);
formData.append('filename', filename);
try { try {
...@@ -124,6 +121,7 @@ const sendFile = async (fileContent) => { ...@@ -124,6 +121,7 @@ const sendFile = async (fileContent) => {
console.log('File Uploaded', response.data); console.log('File Uploaded', response.data);
return response.data.file.filename; return response.data.file.filename;
} catch (error) { } catch (error) {
return '';
console.error('Error uploading file:', error); console.error('Error uploading file:', error);
} }
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment