mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 07:41:02 +08:00
Remove legacy component & Update validating system using localstorage.
This commit is contained in:
parent
b716a0ed5c
commit
c5c614c75d
@ -23,7 +23,6 @@ const emit = defineEmits([
|
||||
"openNewsSourcePage",
|
||||
"windowopener",
|
||||
]);
|
||||
const staticid = computed(() => props.staticid);
|
||||
|
||||
const openNewWindow = (itemId: string) => {
|
||||
emit("windowopener", "aboutNewsOrg");
|
||||
@ -285,10 +284,7 @@ const openPublisher = (text: string) => {
|
||||
<div>
|
||||
<div>
|
||||
<h3 class="text-lg">類似文章</h3>
|
||||
<div
|
||||
|
||||
class="space-y-2"
|
||||
>
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="similar in useArgFindRel(item.title, item.publisher)"
|
||||
:key="similar.item.id"
|
||||
@ -302,8 +298,12 @@ const openPublisher = (text: string) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="checkIfEmpty(item.title)" class="text-gray-500 text-sm">找不到類似文章</div>
|
||||
|
||||
<div
|
||||
v-if="checkIfEmpty(item.title)"
|
||||
class="text-gray-500 text-sm"
|
||||
>
|
||||
找不到類似文章
|
||||
</div>
|
||||
</div>
|
||||
<!--<div v-for="item in findRel(item.title)">
|
||||
{{ item }}
|
||||
|
@ -1,13 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
const logoutAction = () => {
|
||||
const user = ref();
|
||||
const userToken = localStorage.getItem("token");
|
||||
const { t, locale } = useI18n();
|
||||
onMounted(async () => {
|
||||
const req = await fetch("/api/user/validateUserToken", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
token: userToken,
|
||||
lang: locale,
|
||||
page: "settings",
|
||||
}),
|
||||
});
|
||||
const res = req.json();
|
||||
user.value = res;
|
||||
});
|
||||
|
||||
}
|
||||
const logoutAction = () => {};
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<div class="bg-gray-400 p-2 m-2 w-full">
|
||||
<div class="justify-center align-center text-center">
|
||||
<div class="">Greetings, {{ user }}</div>
|
||||
<div class="bg-gray-200/70 p-2 m-2 w-full">
|
||||
<button @click="logoutAction">Logout</button>
|
||||
</div>
|
||||
<hr/>
|
||||
<hr />
|
||||
<div class="justiy-center align-center text-center">Settings v0.0.1</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
// Imports
|
||||
const { t } = useI18n();
|
||||
const { t, locale } = useI18n();
|
||||
// Values
|
||||
const allowed = ref(false);
|
||||
const error = ref(false);
|
||||
@ -9,7 +9,21 @@ const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
||||
|
||||
try {
|
||||
// 喔 我沒有加 await :( 難怪有問題
|
||||
const { data, error: sendError } = await useFetch("/api/user/checkcookie");
|
||||
const token = localStorage.getItem("token");
|
||||
const { data, error: sendError } = await useFetch(
|
||||
"/api/user/validateUserToken",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
token: token,
|
||||
lang: locale,
|
||||
page: "a_window_application_using_blurPageBeforeLogin_component",
|
||||
}),
|
||||
},
|
||||
);
|
||||
if (sendError.value) {
|
||||
error.value = true;
|
||||
}
|
||||
|
@ -1,10 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
const apis = [
|
||||
{
|
||||
apiroute: "/shortforward",
|
||||
name: "A Simple url forwarder.",
|
||||
content:
|
||||
"This is maly used for yhw.tw/news, which is a super simple redirection tool for easy redirecting.",
|
||||
caching: false,
|
||||
},
|
||||
{
|
||||
apiroute: "/api/tabs",
|
||||
name: "Get LINE Today Tabs",
|
||||
content: "Using LINE Today as a source for getting tabs & caching results.",
|
||||
caching: true,
|
||||
},
|
||||
{
|
||||
apiroute: "/api/home/lt",
|
||||
name: "Get the news feed of LINE Today",
|
||||
content:
|
||||
"This endpoint requires ?query=, and you can go the the /api/tabs to find the query.",
|
||||
caching: true,
|
||||
},
|
||||
{
|
||||
apiroute: "/api/news/get/lt/[slug]",
|
||||
name: "Get the news article using node-fetch & cheerio",
|
||||
content:
|
||||
"This endpoint requires the slug to be filled in, in order to get it to work.",
|
||||
caching: true,
|
||||
},
|
||||
{
|
||||
apiroute: "/api/ai/chat/[slug]",
|
||||
name: "",
|
||||
content: "",
|
||||
caching: false,
|
||||
},
|
||||
{
|
||||
apiroute: "/api/ai/summarize/[slug]",
|
||||
name: "",
|
||||
content: "",
|
||||
caching: false,
|
||||
},
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<div
|
||||
class="justify-center align-center text-center absolute inset-0 flex flex-col"
|
||||
>
|
||||
<h1 class="text-4xl text-bold">APIs</h1>
|
||||
<div class="items flex flex-row flex-wrap">
|
||||
<div class="item group"></div>
|
||||
<div class="item group" v-for="item in apis">
|
||||
{{ item.name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -472,12 +472,6 @@ const openNewsSourcePage = async (slug: string, titleName: string) => {
|
||||
passedValues.value = null;
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
// Not used?
|
||||
const getStaticArticleId = () => {
|
||||
storeStaticArticleId.value += 1;
|
||||
return storeStaticArticleId.value;
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<div v-if="changeLangAnimation">
|
||||
@ -597,7 +591,6 @@ const getStaticArticleId = () => {
|
||||
@loadValue=""
|
||||
@openArticles="openArticles"
|
||||
@openNewsSourcePage="openNewsSourcePage"
|
||||
:staticid="getStaticArticleId"
|
||||
:values="passedValues"
|
||||
/>
|
||||
</Suspense>
|
||||
|
@ -1,64 +0,0 @@
|
||||
// This should be hooked up to a database soon.
|
||||
import sql 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");
|
||||
setCookie(event, "lastCheckCookie", nowDate, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/",
|
||||
});
|
||||
return {
|
||||
auth: false,
|
||||
user: null,
|
||||
};
|
||||
}
|
||||
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: "/",
|
||||
});
|
||||
}
|
||||
if (!loginCookie) {
|
||||
setCookie(event, "lastCheckCookie", nowDate, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
path: "/",
|
||||
});
|
||||
return {
|
||||
auth: false,
|
||||
user: null,
|
||||
};
|
||||
}
|
||||
const loginCookieStore = atob(loginCookie);
|
||||
/*const findUser = sql`
|
||||
select * from userlogintokens
|
||||
where token = ${loginCookieStore}
|
||||
`;*/
|
||||
return {
|
||||
auth: true,
|
||||
user: "testing",
|
||||
loginCookie: loginCookieStore, // Debug
|
||||
};
|
||||
});
|
48
server/api/user/validateUserToken.post.ts
Normal file
48
server/api/user/validateUserToken.post.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import sql from "~/server/components/postgres";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event);
|
||||
const token = body.token;
|
||||
if (!token) {
|
||||
return {
|
||||
error: "NO_TOKEN_GIVEN",
|
||||
requested_action: "SHOW_WARNING",
|
||||
};
|
||||
}
|
||||
const checkIsUUIDRegex =
|
||||
/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/;
|
||||
if (!checkIsUUIDRegex.test(token)) {
|
||||
return {
|
||||
error: "NOT_A_UUID",
|
||||
requested_action: "LOGOUT_USER",
|
||||
};
|
||||
}
|
||||
const fetchViaSQL = await sql`
|
||||
SELECT * FROM usertokens
|
||||
where token=${token}
|
||||
`;
|
||||
if (!fetchViaSQL[0]) {
|
||||
return {
|
||||
error: "INVALID_TOKEN",
|
||||
requested_action: "LOGOUT_USER",
|
||||
};
|
||||
}
|
||||
|
||||
const tokenDate = new Date(fetchViaSQL[0].created_at);
|
||||
const now = new Date();
|
||||
const dayInMilliseconds = 24 * 60 * 60 * 1000;
|
||||
|
||||
if (now.getTime() - tokenDate.getTime() > dayInMilliseconds) {
|
||||
return {
|
||||
error: "TOKEN_EXPIRED",
|
||||
requested_action: "LOGOUT_USER",
|
||||
};
|
||||
}
|
||||
return {
|
||||
userAccount: fetchViaSQL[0].username,
|
||||
requested_action: "CONTINUE",
|
||||
email: fetchViaSQL[0].email,
|
||||
avatarURL: fetchViaSQL[0].avatarurl,
|
||||
firstName: fetchViaSQL[0].firstName,
|
||||
};
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user