add a undefined JSON replacer for diff
This commit is contained in:
parent
bcaa64bda1
commit
6228671048
|
@ -2,7 +2,7 @@ const superagent = require("superagent");
|
|||
const hash = require("object-hash");
|
||||
const { detailedDiff } = require("deep-object-diff");
|
||||
const { isEqual } = require("lodash");
|
||||
const { calculateElapsedTime, getResponseContent } = require("../utils");
|
||||
const { calculateElapsedTime, ensureValidJSON, getResponseContent } = require("../utils");
|
||||
|
||||
// audioExampleCheck returns the result of trying to download the skylink
|
||||
// for the Example audio file on siasky.net
|
||||
|
@ -918,7 +918,7 @@ function skylinkVerification(done, { name, skylink, bodyHash, metadata }) {
|
|||
if (!isEqual(currentMetadata, metadata)) {
|
||||
entry.up = false;
|
||||
|
||||
info.metadata = detailedDiff(metadata, currentMetadata);
|
||||
info.metadata = ensureValidJSON(detailedDiff(metadata, currentMetadata));
|
||||
}
|
||||
|
||||
if (Object.keys(info).length) entry.info = info; // add info only if it exists
|
||||
|
|
|
@ -29,8 +29,19 @@ function getResponseContent(response) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the object serializes to JSON properly
|
||||
*/
|
||||
function ensureValidJSON(object) {
|
||||
const replacer = (key, value) => (value === undefined ? "--undefined--" : value);
|
||||
const stringified = JSON.stringify(object, replacer);
|
||||
|
||||
return JSON.parse(stringified);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
calculateElapsedTime,
|
||||
getYesterdayISOString,
|
||||
getResponseContent,
|
||||
ensureValidJSON,
|
||||
};
|
||||
|
|
Reference in New Issue