Fixed dynamic operator loading not finishing for some operators.

This commit is contained in:
Felix Kaspar 2024-05-16 19:25:54 +02:00
parent efd4bdc493
commit b1bb8e0f02
2 changed files with 17 additions and 14 deletions

View File

@ -15,7 +15,7 @@ function Dynamic() {
const operators = listOperatorNames();
const activeOperator = useRef<typeof Operator>();
function selectionChanged(s: BaseSyntheticEvent) {
async function selectionChanged(s: BaseSyntheticEvent) {
const selectedValue = s.target.value;
console.log("Selection changed to", selectedValue);
if(selectedValue == "none") {
@ -23,20 +23,23 @@ function Dynamic() {
return;
}
i18next.loadNamespaces(selectedValue, (err, t) => {
console.log("Loading namespaces for", selectedValue);
await i18next.loadNamespaces(selectedValue, (err, t) => {
if (err) throw err;
});
console.log("Loading namespaces done");
const LoadingModule = import(`@stirling-pdf/shared-operations/src/functions/${selectedValue}`) as Promise<{ [key: string]: typeof Operator }>;
LoadingModule.then((Module) => {
const Operator = Module[capitalizeFirstLetter(selectedValue)];
const description = Operator.schema.describe();
console.log(Operator.schema);
console.log(description);
console.log("Loading modules for", selectedValue);
const LoadingModule = import(`@stirling-pdf/shared-operations/src/functions/${selectedValue}`) as Promise<{ [key: string]: typeof Operator }>;
LoadingModule.then((Module) => {
const Operator = Module[capitalizeFirstLetter(selectedValue)];
const description = Operator.schema.describe();
console.log(Operator.schema);
console.log(description);
activeOperator.current = Operator;
// This will update children
setSchemaDescription(description);
});
activeOperator.current = Operator;
// This will update children
setSchemaDescription(description);
});
}
@ -75,7 +78,7 @@ function Dynamic() {
const validationResults = activeOperator.current.schema.validate({input: inputs, values: action.values});
if(validationResults.error) {
console.log({error: "Validation failed", details: validationResults.error.message});
console.error({error: "Validation failed", details: validationResults.error.message}, validationResults.error.stack);
}
else {
action.values = validationResults.value.values;

View File

@ -8,7 +8,7 @@ export const JoiPDFFileSchema = Joi.custom((value: Express.Multer.File[] /* <- a
else { // File(s)
const firstWrongFile = value.find(f => f.mimetype != "application/pdf")
if(firstWrongFile)
throw new Error(`at least one of the files provided doesn't seem to be a PDF. Got ${firstWrongFile.mimetype} instead.`);
throw new Error(`at least one of the files provided doesn't seem to be a PDF. Got the file ${JSON.stringify(firstWrongFile)} instead.`);
return PdfFile.fromMulterFiles(value);
}