mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-24 00:01:03 +08:00
Compare commits
No commits in common. "3ebaff521866faf50e8aa60b3d3d26e054e69328" and "5392974261f9902fd0d7eb89859e17e76c178d34" have entirely different histories.
3ebaff5218
...
5392974261
@ -34,7 +34,6 @@ const switchTabs = ref(false);
|
|||||||
const tabs = ref([]);
|
const tabs = ref([]);
|
||||||
const primary = ref<string>("top"); // Hard code value fn
|
const primary = ref<string>("top"); // Hard code value fn
|
||||||
const canNotLoadTabUI = ref(false);
|
const canNotLoadTabUI = ref(false);
|
||||||
const isDataCached = ref(false);
|
|
||||||
const pullTabsData = async () => {
|
const pullTabsData = async () => {
|
||||||
try {
|
try {
|
||||||
const req = await fetch("/api/tabs");
|
const req = await fetch("/api/tabs");
|
||||||
@ -61,7 +60,6 @@ const updateContent = async (url: string, tabAction: boolean) => {
|
|||||||
if (data) {
|
if (data) {
|
||||||
contentArray.value = [...data.uuidData, ...(data.nuuiddata?.items || [])];
|
contentArray.value = [...data.uuidData, ...(data.nuuiddata?.items || [])];
|
||||||
switchTabs.value = false;
|
switchTabs.value = false;
|
||||||
isDataCached.value = data.cached || false;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -1,81 +1,28 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { BadgeCheckIcon, OctagonAlertIcon } from "lucide-vue-next";
|
|
||||||
import { Input } from "~/components/ui/input";
|
|
||||||
const { t, locale } = useI18n();
|
|
||||||
const user = ref();
|
const user = ref();
|
||||||
|
const userToken = localStorage.getItem("token");
|
||||||
|
const { t, locale } = useI18n();
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const req = await fetch("/api/user/validateUserToken");
|
const req = await fetch("/api/user/validateUserToken", {
|
||||||
const res = await req.json();
|
|
||||||
user.value = res;
|
|
||||||
});
|
|
||||||
|
|
||||||
const logoutAction = () => {};
|
|
||||||
const groqApiKeyRegex = /^gsk_[a-zA-Z0-9]{52}$/;
|
|
||||||
const customApiKey = ref();
|
|
||||||
const isCorrect = ref(false);
|
|
||||||
const submitCustomApiKey = async () => {
|
|
||||||
if (!isCorrect.value) {
|
|
||||||
checkValidApiKey();
|
|
||||||
if (!isCorrect.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const apiKey = customApiKey.value;
|
|
||||||
try {
|
|
||||||
const sendApi = await fetch("/api/ai/loadCustomGroqApi", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
apiKey: apiKey,
|
token: userToken,
|
||||||
|
lang: locale,
|
||||||
|
page: "settings",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
const data = await sendApi.json();
|
const res = req.json();
|
||||||
if (data.error) {
|
user.value = res;
|
||||||
}
|
});
|
||||||
} catch (e) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
const checkValidApiKey = () => {
|
const logoutAction = () => {};
|
||||||
const apiKey = customApiKey.value;
|
|
||||||
if (!apiKey) {
|
|
||||||
isCorrect.value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
isCorrect.value = groqApiKeyRegex.test(apiKey);
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="justify-center align-center text-center">
|
<div class="justify-center align-center text-center">
|
||||||
<div class="">Greetings, {{ user }}</div>
|
<div class="">Greetings, {{ user }}</div>
|
||||||
<div class="flex flex-row text-center align-center justify-center">
|
|
||||||
<span class="text-md p-1 text-nowrap">Your Groq API: </span>
|
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
class="h-6 m-1 py-3 rounded"
|
|
||||||
v-model="customApiKey"
|
|
||||||
placeholder="gsk_..."
|
|
||||||
v-on:mouseover="checkValidApiKey"
|
|
||||||
v-on:keypress="checkValidApiKey"
|
|
||||||
v-on:mouseleave="checkValidApiKey"
|
|
||||||
/>
|
|
||||||
<!--If it is a valid api key or not.-->
|
|
||||||
<BadgeCheckIcon
|
|
||||||
v-if="isCorrect"
|
|
||||||
class="w-8 h-8 p-1/2 mr-1 text-green-700"
|
|
||||||
/>
|
|
||||||
<OctagonAlertIcon
|
|
||||||
v-if="!isCorrect"
|
|
||||||
class="w-8 h-8 p-1/2 mr-1 text-red-700"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="p-1 text-sm bg-gray-400/60 rounded"
|
|
||||||
@click="submitCustomApiKey"
|
|
||||||
>
|
|
||||||
Submit
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="bg-gray-200/70 p-2 m-2 w-full">
|
<div class="bg-gray-200/70 p-2 m-2 w-full">
|
||||||
<button @click="logoutAction">Logout</button>
|
<button @click="logoutAction">Logout</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,6 +29,7 @@ const submitUserPassword = async () => {
|
|||||||
|
|
||||||
if (!res.error) {
|
if (!res.error) {
|
||||||
error.value = false;
|
error.value = false;
|
||||||
|
localStorage.setItem("token", res.token);
|
||||||
success.value = true;
|
success.value = true;
|
||||||
console.log(res);
|
console.log(res);
|
||||||
userAccount.value = "";
|
userAccount.value = "";
|
||||||
|
@ -9,8 +9,20 @@ const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// 喔 我沒有加 await :( 難怪有問題
|
// 喔 我沒有加 await :( 難怪有問題
|
||||||
|
const token = localStorage.getItem("token");
|
||||||
const { data, error: sendError } = await useFetch(
|
const { data, error: sendError } = await useFetch(
|
||||||
"/api/user/validateUserToken",
|
"/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) {
|
if (sendError.value) {
|
||||||
error.value = true;
|
error.value = true;
|
||||||
|
@ -269,6 +269,7 @@ const navBarDisplayText = (text: string) => {
|
|||||||
}
|
}
|
||||||
const trimSpaces = text.trim();
|
const trimSpaces = text.trim();
|
||||||
const regex = /.{0,7}/;
|
const regex = /.{0,7}/;
|
||||||
|
console.log("asdasda");
|
||||||
if (trimSpaces.length <= 7) {
|
if (trimSpaces.length <= 7) {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
import sql from "~/server/components/postgres";
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
if (event.method !== "POST") {
|
|
||||||
return {
|
|
||||||
error: "ERR_METHOD_NOT_ALLOWED",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const body = readBody(event);
|
|
||||||
if (!body.apiKey) {
|
|
||||||
return {
|
|
||||||
error: "ERR_API_KEY_REQUIRED",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const readUserToken = getCookie(event, "token");
|
|
||||||
if (!readUserToken) {
|
|
||||||
return {
|
|
||||||
error: "ERR_NOT_USER_LOGIN",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const checkUser = await sql``;
|
|
||||||
});
|
|
@ -28,30 +28,16 @@ export default defineEventHandler(async (event) => {
|
|||||||
html("div.editor div figure img").attr("srcset") ||
|
html("div.editor div figure img").attr("srcset") ||
|
||||||
html("div.editor div figure img").attr("src") ||
|
html("div.editor div figure img").attr("src") ||
|
||||||
"";
|
"";
|
||||||
const bgImage = html("figure.keyVisual img").attr("srcset") || "";
|
|
||||||
const articles = [];
|
const articles = [];
|
||||||
const regexArticleLinks = /[a-zA-Z0-9]{7}/g
|
const otherArticles = html("section.moduleContainer div");
|
||||||
const otherArticles = <any[]>[];
|
for (const item in otherArticles) {
|
||||||
html("a.ltcp-link")
|
|
||||||
.each((i, element) => {
|
|
||||||
const articleLink = html(element).attr("href");
|
|
||||||
const articleTitle = html(element).find("h3.header").text();
|
|
||||||
const date = html(element).find("div._articleCard div.css-wqleh6 span").text();
|
|
||||||
if (articleLink && articleTitle) {
|
|
||||||
const articleSlug = articleLink.matchAll(regexArticleLinks);
|
|
||||||
otherArticles.push({
|
|
||||||
index: i,
|
|
||||||
title: articleTitle,
|
|
||||||
link: articleSlug,
|
|
||||||
date: date,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
name: newsOrgName,
|
name: newsOrgName,
|
||||||
description: description,
|
description: description,
|
||||||
logo: logo,
|
logo: logo,
|
||||||
articles: otherArticles,
|
articles: []
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -68,9 +68,9 @@ export default defineEventHandler(async (event) => {
|
|||||||
INSERT INTO usertokens (user, token)
|
INSERT INTO usertokens (user, token)
|
||||||
VALUES ('${fetchUserInfo[0].username}', '${newToken}')
|
VALUES ('${fetchUserInfo[0].username}', '${newToken}')
|
||||||
`;
|
`;
|
||||||
setCookie(event, "token", newToken);
|
|
||||||
return {
|
return {
|
||||||
user: fetchUserInfoAgain,
|
user: fetchUserInfoAgain,
|
||||||
|
token: newToken,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -4,7 +4,12 @@ export default defineEventHandler(async (event) => {
|
|||||||
const nowDate = new Date().toLocaleString();
|
const nowDate = new Date().toLocaleString();
|
||||||
try {
|
try {
|
||||||
if (loginCookie) {
|
if (loginCookie) {
|
||||||
deleteCookie(event, "token");
|
deleteCookie(event, "session");
|
||||||
|
setCookie(event, "lastCheckCookie", nowDate, {
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
path: "/",
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
error: null,
|
error: null,
|
||||||
|
@ -2,11 +2,11 @@ import sql from "~/server/components/postgres";
|
|||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
const token = getCookie(event, "token");
|
const token = body.token;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return {
|
return {
|
||||||
error: "INVALID_TOKEN",
|
error: "NO_TOKEN_GIVEN",
|
||||||
requested_action: "LOGOUT_USER",
|
requested_action: "SHOW_WARNING",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const checkIsUUIDRegex =
|
const checkIsUUIDRegex =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user