reduce logging and send HTTP 202 early rather than expecting the caller to wait

This commit is contained in:
Ladd Hoffman 2024-04-20 21:50:02 -05:00
parent 819b7180ed
commit b4da0ec6e5
2 changed files with 13 additions and 12 deletions

View File

@ -35,7 +35,6 @@ const getContract = (name) => new ethers.Contract(
const fetchPaperInfo = async (paperId, retryDelay = 5000) => {
const url = `https://api.semanticscholar.org/graph/v1/paper/${paperId}?fields=title,url,authors,references`;
console.log('url:', url);
let retry = false;
let paper;
const response = await axios.get(url, {
@ -120,9 +119,6 @@ HREF ${paper.url}`;
contentToSign += `\n\n${JSON.stringify(embeddedData, null, 2)}`;
}
const signature = firstAuthorWallet.signMessageSync(contentToSign);
console.log({
authors, content, signature, embeddedData,
});
const verified = verifySignature({
authors, content, signature, embeddedData,
});
@ -149,6 +145,10 @@ module.exports = async (req, res) => {
// Read the paper info from SS
const paper = await fetchPaperInfo(paperId);
// Send HTTP code 202 - Accepted
res.status(202).end();
console.log('references count:', paper.references.length);
const eachCitationWeightPercent = Math.floor(30 / paper.references.length);
@ -176,19 +176,21 @@ module.exports = async (req, res) => {
hash, authors, content, signature, embeddedData,
} = await generatePost(paper);
console.log({
hash, authors, content, signature, embeddedData, citations,
});
// Write the new post to our database
await forum.put(hash, {
authors, content, signature, embeddedData, citations,
});
// Add the post to the form (on-chain)
await dao.addPost(authors, hash, citations);
try {
await dao.addPost(authors, hash, citations);
} catch (e) {
if (e.reason === 'A post with this contentId already exists') {
console.log(`Post already added for paper ${paperId}`);
return;
}
throw e;
}
console.log(`Added post to blockchain for paper ${paperId}`);
res.end();
};

View File

@ -9,7 +9,6 @@ const verifySignature = ({
}
try {
const account = recoverPersonalSignature({ data: contentToVerify, signature });
console.log(`recovered account: ${account}`);
const authorAddresses = authors.map((author) => author.authorAddress.toLowerCase());
if (!authorAddresses.includes(account.toLowerCase())) {
console.log('error: signer is not among the authors');