mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Add a few more database tables & made the api pull from the database
when then article exists & not ddos line today, Also made a basic newsView with the api & the scraping script now scraps more stuff! :D
This commit is contained in:
parent
fe5e2d996e
commit
b62a3cda3d
6 changed files with 84 additions and 40 deletions
|
@ -1,6 +1,28 @@
|
|||
import lineToday from "~/server/scrape/line_today";
|
||||
import sql from "~/server/components/postgres";
|
||||
import saveDataToSql from "~/server/scrape/save_scrape_data";
|
||||
|
||||
function cleanUpSlug(orgslug: string) {
|
||||
let slug = dirtySlug.trim();
|
||||
const validSlugRegex = /^[a-zA-Z0-9-]+$/;
|
||||
if (!validSlugRegex.test(slug)) {
|
||||
throw new Error("Invalid slug format");
|
||||
}
|
||||
return slug;
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, "slug");
|
||||
const data = await lineToday(slug);
|
||||
return data;
|
||||
const cleanSlug = await cleanUpSlug(slug);
|
||||
const result = await sql`
|
||||
select * from articles_lt
|
||||
where slug = ${cleanSlug}
|
||||
`;
|
||||
if (result) {
|
||||
return result;
|
||||
} else {
|
||||
const data = await lineToday(slug);
|
||||
saveDataToSql(data, slug);
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue