mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Add news article archiving & Add user favs.
This commit is contained in:
parent
2527056e85
commit
25760cf0d1
4 changed files with 48 additions and 7 deletions
|
@ -33,6 +33,13 @@ if (error === null) {
|
||||||
errorMsg.value = error.value;
|
errorMsg.value = error.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (data.length === 0) {
|
||||||
|
eerrrroorr.value = true;
|
||||||
|
errorMsg.value = "No data returned.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function getImageSource(image: string) {
|
async function getImageSource(image: string) {
|
||||||
console.log(image);
|
console.log(image);
|
||||||
if (!image || image === "#") {
|
if (!image || image === "#") {
|
||||||
|
|
|
@ -51,6 +51,15 @@ const createSources = await sql`
|
||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const createArticlesArchive = await sql`
|
||||||
|
create table if not exists news_articles (
|
||||||
|
uuid text primary key,
|
||||||
|
article_id text primary key,
|
||||||
|
jsondata json not null,
|
||||||
|
archive_timestamp timestamp default CURRENT_TIMESTAMP,
|
||||||
|
)
|
||||||
|
`;
|
||||||
|
|
||||||
console.log("Creation Complete");
|
console.log("Creation Complete");
|
||||||
console.log(
|
console.log(
|
||||||
"If the script still does not quit after 2 seconds after the 'Creation Complete' message, please stop it by using Ctrl + C or on mac Control + C",
|
"If the script still does not quit after 2 seconds after the 'Creation Complete' message, please stop it by using Ctrl + C or on mac Control + C",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import lineToday from "~/server/scrape/line_today";
|
import lineToday from "~/server/scrape/line_today";
|
||||||
import sql from "~/server/components/postgres";
|
import sql from "~/server/components/postgres";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
interface CacheItems {
|
interface CacheItems {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -36,6 +37,23 @@ function cleanUpSlug(orgslug: string) {
|
||||||
return slug;
|
return slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Archive articles. For future use?
|
||||||
|
async function storeArticlesIfItDoesNotExists(data, RequestId) {
|
||||||
|
const checkDataIsInDatabase = await sql`
|
||||||
|
SELECT * FROM news_articles
|
||||||
|
WHERE jsondata = ${data}
|
||||||
|
`;
|
||||||
|
if (checkDataIsInDatabase.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const storeData = await sql`
|
||||||
|
INSERT INTO news_articles (uuid, article_id, jsondata)
|
||||||
|
VALUES (${uuidv4()}, ${RequestId}, ${data})
|
||||||
|
`;
|
||||||
|
console.log(storeData);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const translateQuery = getQuery(event).translate;
|
const translateQuery = getQuery(event).translate;
|
||||||
const translate = translateQuery === "true" ? true : false;
|
const translate = translateQuery === "true" ? true : false;
|
||||||
|
@ -54,6 +72,7 @@ export default defineEventHandler(async (event) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await lineToday(cleanSlug);
|
const data = await lineToday(cleanSlug);
|
||||||
|
storeArticlesIfItDoesNotExists(data, cleanSlug);
|
||||||
cache[cleanSlug] = {
|
cache[cleanSlug] = {
|
||||||
...data,
|
...data,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
|
import getUserTokenMinusSQLInjection from "~/server/components/getUserToken";
|
||||||
|
import sql from "~/server/components/postgres";
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
|
const userToken = await getUserTokenMinusSQLInjection(event);
|
||||||
|
if (userToken.error.length !== 0) {
|
||||||
|
return {
|
||||||
|
error: userToken.error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const getData = await sql`
|
||||||
|
SELECT * FROM user_other_data
|
||||||
|
WHERE username = ${userToken.user}
|
||||||
|
`;
|
||||||
return {
|
return {
|
||||||
items: [
|
items: getData[0].starred_news,
|
||||||
{
|
|
||||||
name: "dfasdfa",
|
|
||||||
article_link: "49redjvicjwsd",
|
|
||||||
favTime: "2024-12-12",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue