mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 07:41:02 +08:00
I mean this should work now? (Like the archiving feat.
This commit is contained in:
parent
804694f74c
commit
a032abbc9b
@ -38,20 +38,32 @@ function cleanUpSlug(orgslug: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Archive articles. For future use?
|
// Archive articles. For future use?
|
||||||
async function storeArticlesIfItDoesNotExists(data, RequestId) {
|
function storeArticlesIfItDoesNotExists(data, RequestId) {
|
||||||
const checkDataIsInDatabase = await sql`
|
try {
|
||||||
SELECT * FROM news_articles
|
setImmediate(async () => {
|
||||||
WHERE jsondata = ${data}
|
try {
|
||||||
`;
|
const checkDataIsInDatabase = await sql`
|
||||||
if (checkDataIsInDatabase.length > 0) {
|
SELECT uuid FROM news_articles
|
||||||
return;
|
WHERE article_id = ${RequestId}
|
||||||
|
LIMIT 1
|
||||||
|
`;
|
||||||
|
if (checkDataIsInDatabase.length > 0) {
|
||||||
|
console.log(`Article ${RequestId} already exists in database`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const jsonData = JSON.stringify(data);
|
||||||
|
await sql`
|
||||||
|
INSERT INTO news_articles (uuid, article_id, jsondata)
|
||||||
|
VALUES (${uuidv4()}, ${RequestId}, ${jsonData}::JSON)
|
||||||
|
`;
|
||||||
|
console.log(`Successfully archived article ${RequestId} in background`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to archive article in background:", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to initiate background archiving:", error);
|
||||||
}
|
}
|
||||||
const storeData = await sql`
|
|
||||||
INSERT INTO news_articles (uuid, article_id, jsondata)
|
|
||||||
VALUES (${uuidv4()}, ${RequestId}, ${data}::JSON)
|
|
||||||
`;
|
|
||||||
console.log(storeData);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user