Skip to content

Commit

Permalink
馃殤 attempt fix for #3167
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Feb 19, 2024
1 parent 4df62c4 commit 2531781
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/api/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1958,10 +1958,10 @@ public async testCallback(callbackToTest: SimpleListener, testData: any) : Prom
let thumb;
try {
linkData = (await axios.get(`${this._createConfig?.linkParser || "https://link.openwa.cloud/api"}?url=${url}`)).data;
log.info("Got link data", linkData)
log.info("Got link data")
if(!thumbnail) thumb = await getDUrl(linkData.image);
} catch (error) {
log.error(error)
console.error(error)
}
if(linkData && (thumbnail || thumb)) return await this.sendMessageWithThumb(thumbnail || thumb,url,linkData.title, linkData.description, text, to);
else return await this.pup(
Expand Down
25 changes: 23 additions & 2 deletions src/logging/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ const sensitiveKeys = [
/api[-._]?key/i,
];

const getCircularReplacer = () => {
const seen = new WeakSet();
return (_key: string, value: any) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return "[Circular]";
}
seen.add(value);
}
return value;
};
}

const k = (obj : any) => {
try {
return klona(obj)
} catch (error) {
return klona(JSON.parse(JSON.stringify(obj, getCircularReplacer())))
}
}

function isSensitiveKey(keyStr) {
if (keyStr && typeof keyStr == "string") {
return sensitiveKeys.some(regex => regex.test(keyStr));
Expand All @@ -39,7 +60,7 @@ function redactObject(obj) {
}

function redact(obj) {
const copy = klona(obj); // Making a deep copy to prevent side effects
const copy = k(obj); // Making a deep copy to prevent side effects
redactObject(copy);

const splat = copy[Symbol.for("splat")];
Expand All @@ -56,7 +77,7 @@ function truncate(str: string, n: number) {
const formatRedact = winston.format(redact);

const stringSaver = winston.format((info : any)=>{
const copy = klona(info);
const copy = k(info);
const splat = copy[Symbol.for("splat")];
if(splat) {
copy.message = `${copy.message} ${splat.filter((x:any)=>typeof x !== 'object').join(' ')}`
Expand Down

0 comments on commit 2531781

Please sign in to comment.