Accept both v1 and v2 spec for editcharacterattributes endpoint
This commit is contained in:
parent
42d838a0b3
commit
c584da2ea9
|
@ -81,7 +81,7 @@ class CharacterContextMenu {
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (response.ok) toggleFavoriteHighlight(characterId)
|
if (response.ok) toggleFavoriteHighlight(characterId)
|
||||||
else toastr.error('Character not saved. Error: ' + response.json()?.message)
|
else response.json().then(json => toastr.error('Character not saved. Error: ' + json.message + '. Field: ' + json.error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1189,7 +1189,8 @@ app.post("/v2/editcharacterattribute", jsonParser, async function (request, resp
|
||||||
|
|
||||||
const validator = new TavernCardValidator(character);
|
const validator = new TavernCardValidator(character);
|
||||||
|
|
||||||
if (true === validator.validateV2()) {
|
//Accept either V1 or V2.
|
||||||
|
if (validator.validate()) {
|
||||||
await charaWrite(
|
await charaWrite(
|
||||||
avatarPath,
|
avatarPath,
|
||||||
JSON.stringify(character),
|
JSON.stringify(character),
|
||||||
|
@ -1198,7 +1199,8 @@ app.post("/v2/editcharacterattribute", jsonParser, async function (request, resp
|
||||||
'Character saved'
|
'Character saved'
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
response.status(400).send({message: `Validation failed for card ${character.name}`, field: validator.lastValidationError});
|
console.log(validator.lastValidationError)
|
||||||
|
response.status(400).send({message: `Validation failed for ${character.name}`, error: validator.lastValidationError});
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
response.status(500).send({message: 'Unexpected error while saving character.', error: exception.toString()});
|
response.status(500).send({message: 'Unexpected error while saving character.', error: exception.toString()});
|
||||||
|
|
|
@ -88,7 +88,7 @@ class TavernCardValidator {
|
||||||
const data = this.card.data;
|
const data = this.card.data;
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
this.#lastValidationError = 'data';
|
this.#lastValidationError = 'No tavern card data found';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue