mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 21:02:43 +00:00
Split version from hash checks
This commit is contained in:
@@ -339,17 +339,22 @@ const api = {
|
|||||||
// Initialize brew from request and body, destructure query params, and set the initial value for the after-save method
|
// Initialize brew from request and body, destructure query params, and set the initial value for the after-save method
|
||||||
const brewFromClient = api.excludePropsFromUpdate(req.body);
|
const brewFromClient = api.excludePropsFromUpdate(req.body);
|
||||||
const brewFromServer = req.brew;
|
const brewFromServer = req.brew;
|
||||||
|
|
||||||
|
if(brewFromServer?.version !== brewFromClient?.version){
|
||||||
|
console.log(`Version mismatch on brew ${brewFromClient.editId}`);
|
||||||
|
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
return res.status(409).send(JSON.stringify({ message: `The server version is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.` }));
|
||||||
|
}
|
||||||
|
|
||||||
splitTextStyleAndMetadata(brewFromServer);
|
splitTextStyleAndMetadata(brewFromServer);
|
||||||
|
|
||||||
brewFromServer.text = brewFromServer.text.normalize();
|
brewFromServer.text = brewFromServer.text.normalize();
|
||||||
brewFromServer.hash = await md5(brewFromServer.text);
|
brewFromServer.hash = await md5(brewFromServer.text);
|
||||||
|
|
||||||
if((brewFromServer?.version !== brewFromClient?.version) || (brewFromServer?.hash !== brewFromClient?.hash)) {
|
if(brewFromServer?.hash !== brewFromClient?.hash) {
|
||||||
if(brewFromClient?.version !== brewFromClient?.version)
|
console.log(`Hash mismatch on brew ${brewFromClient.editId}`);
|
||||||
console.log(`Version mismatch on brew ${brewFromClient.editId}`);
|
|
||||||
if(brewFromServer?.hash !== brewFromClient?.hash) {
|
|
||||||
console.log(`Hash mismatch on brew ${brewFromClient.editId}`);
|
|
||||||
}
|
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
return res.status(409).send(JSON.stringify({ message: `The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.` }));
|
return res.status(409).send(JSON.stringify({ message: `The server copy is out of sync with the saved brew. Please save your changes elsewhere, refresh, and try again.` }));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user