validate json before processing it (fixes #247)

This commit is contained in:
teddit 2021-10-06 17:38:08 +02:00
parent d475407061
commit c4d167c787
1 changed files with 32 additions and 0 deletions

View File

@ -14,6 +14,38 @@ async function processJsonUser(
json = JSON.parse(json);
}
function validateJson(json) {
const empty = {
username: '',
icon_img: '',
created: '',
verified: '',
link_karma: '',
comment_karma: '',
view_more_posts: '',
user_front: '',
post_type:'',
before: '',
after: '',
posts: [],
};
if (!json.overview) {
return { error: true, data: empty };
}
if (!json.overview.data) {
return { error: true, data: empty };
}
return true;
}
const validJson = validateJson(json);
if (validJson.error) {
return validJson.data
}
let about = json.about.data;
let posts = [];
let view_more_posts = false;