Made the line_today.py kinda work ig. But I have no idea how can I run

this without issues in prod tho. and the "BlurPageBeforeLogin" thing
works just file, oh and checkCookie is now working (but without the
database part just yet)
This commit is contained in:
yuanhau 2025-05-17 23:31:55 +08:00
parent 0e26a23261
commit 81012f5061
6 changed files with 91 additions and 36 deletions

View file

@ -0,0 +1,20 @@
export default defineEventHandler(async (event) => {
const slug = getRouterParam(event, "slug");
return new Promise((resolve, reject) => {
const pythonProcess = spawn("python3", ["scraping/hot_articles.py"]);
let dataString = "";
pythonProcess.stdout.on("data", (data) => {
dataString += data.toString();
});
pythonProcess.stderr.on("data", (data) => {
console.error(`Error: ${data}`);
});
pythonProcess.on("close", (code) => {
resolve({ status: "completed", output: dataString });
});
});
});

View file

@ -1,23 +1,45 @@
// This should be hooked up to a database soon.
import postgres from "~/server/components/postgres";
// Parse Date Function
function checkDate(dateString: string) {
const now = new Date();
const parsed = new Date(dateString);
const timer = 60 * 60 * 1;
return now.getTime() - parsed.getTime() > timer;
}
export default defineEventHandler(async (event) => {
const loginCookie = getCookie(event, "session");
const lastCheckCookie = getCookie(event, "last_check");
const nowDate = new Date().toLocaleString();
console.log(nowDate);
if (!lastCheckCookie && loginCookie) {
deleteCookie(event, "session");
deleteCookie(event, "lastCheckCookie");
setCookie(event, "lastCheckCookie", nowDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
return {
auth: false,
user: null,
};
}
const checkDate = new Date().toLocaleString();
console.log(checkDate);
setCookie(event, "lastCheckCookie", checkDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
if (!lastCheckCookie) {
setCookie(event, "lastCheckCookie", nowDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
}
if (checkDate(String(lastCheckCookie))) {
setCookie(event, "lastCheckCookie", nowDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
}
return {
auth: true,
user: "testing",