Compare commits

...

4 Commits

Author SHA1 Message Date
200e89f066 **Maybe** fix the sources system & fix logout system. 2025-06-23 07:13:57 +08:00
bf4e695676 What is this? undefined:undefined? A recipe for debugging hell. (I used
GitHub Copilot for this debugging session.), Also changes some broken
stuff like const res = req.json() req.status === "success", what even is
that 🙃
2025-06-23 01:10:24 +08:00
87d5620e34 Forgot useFetch uses .value 🤦‍♂️💀🙄 2025-06-23 00:55:49 +08:00
5f37fb5049 Update news view to check if the user has faved a news article or not &
the star button finally do something for the two weeks that is there.
Also done SOME user auth logic (aka revert bac kthe changes)
2025-06-23 00:20:02 +08:00
4 changed files with 45 additions and 29 deletions

View File

@ -31,6 +31,7 @@ const isGenerating = ref(false);
const summaryText = ref(""); const summaryText = ref("");
const { locale } = useI18n(); const { locale } = useI18n();
const likeart = ref([]); const likeart = ref([]);
const staredStatus = ref(false);
// Translating logic // Translating logic
const translateText = ref(false); const translateText = ref(false);
const translatedBefore = ref(false); const translatedBefore = ref(false);
@ -105,6 +106,21 @@ const aiSummary = async () => {
isGenerating.value = false; isGenerating.value = false;
} }
}; };
const starArticle = async () => {
const buildUrl = `/user/${slug}/fav`;
const req = await fetch(buildUrl);
const res = await req.json();
if (res.status === "success") {
staredStatus.value = res.starred;
}
};
onMounted(async () => {
const req = await fetch(`/user/${slug}/star`);
const res = await req.json();
staredStatus.value = res;
});
</script> </script>
<template> <template>
<div <div
@ -173,17 +189,25 @@ const aiSummary = async () => {
<div v-else>{{ summaryText }}</div> <div v-else>{{ summaryText }}</div>
</div> </div>
</div> </div>
<div class="flex flex-col bg-gray-500"> <!--<div class="flex flex-col bg-gray-500">
<!--Similar articles--> <!--Similar articles-->
<div class="flex flex-row" v-for="item in likeart"> <!--<div class="flex flex-row" v-for="item in likeart">
<img /><!--Image--> <img /><!--Image-->
<div class="flex flex-col"> <!--<div class="flex flex-col">
<h2>title</h2> <h2>title</h2>
<span>description</span> <span>description</span>
</div> </div>
</div> </div>
</div> </div>-->
<button><StarIcon /></button> <button
@click="starArticle"
:class="[
'duration-300 transition-all',
{ 'fill-blue-500 text-blue-500': staredStatus },
]"
>
<StarIcon />
</button>
</div> </div>
</div> </div>
</template> </template>

View File

@ -11,8 +11,8 @@ const props = defineProps<{
}>(); }>();
const openNewWindow = (itemId: string) => { const openNewWindow = (itemId: string) => {
emit("windowopener", "aboutNewsOrg");
emit("loadValue", itemId); emit("loadValue", itemId);
emit("windowopener", "aboutNewsOrg");
}; };
const { const {
@ -78,9 +78,9 @@ onMounted(async () => {
{{ errorMsg }} {{ errorMsg }}
</div> </div>
</div> </div>
<div class="flex flex-row flexw-wrap justify-center gap-2"> <div class="flex flex-row flex-wrap justify-center gap-2">
<div <div
class="flex flex-col group bg-gray-900/30 rounded-xl p-3 transition-all duration-500 shadow-lg hover:translate-y-[-2px] ransition-all duration-700" class="flex flex-col group bg-gray-900/30 rounded-xl p-3 transition-all shadow-lg hover:translate-y-[-2px] ransition-all duration-500 max-w-1/2"
v-for="item in source?.data" v-for="item in source?.data"
:key="item.id" :key="item.id"
> >

View File

@ -7,16 +7,6 @@ const error = ref(false);
const errorMsg = ref(""); const errorMsg = ref("");
const emit = defineEmits(["windowopener", "error", "loadValue"]); const emit = defineEmits(["windowopener", "error", "loadValue"]);
/**
* return {
userAccount: fetchViaSQL[0].username,
firstName: fetchViaSQL[0].firstName,
requested_action: "CONTINUE",
current_spot: "KEEP_LOGIN",
email: fetchViaSQL[0].email,
avatarURL: fetchViaSQL[0].avatarurl,
};
*/
try { try {
// await :( // await :(
const { data, error: sendError } = await useFetch( const { data, error: sendError } = await useFetch(
@ -25,8 +15,8 @@ try {
if (sendError.value) { if (sendError.value) {
error.value = true; error.value = true;
} }
if (data.requested_action === "KEEP_LOGIN") { if (data.value.requested_action === "CONTINUE") {
if (data.userAccount && data.userAccount.length !== 0) { if (data.value.userAccount && data.value.userAccount.length !== 0) {
allowed.value = true; allowed.value = true;
} else { } else {
allowed.value = false; allowed.value = false;

View File

@ -1,16 +1,18 @@
import getUserTokenMinusSQLInjection from "~/server/components/getUserToken"; import getUserTokenMinusSQLInjection from "~/server/components/getUserToken";
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
const loginCookie = await getUserTokenMinusSQLInjection(event); const userToken = await getUserTokenMinusSQLInjection(event);
if (userToken.error.length !== 0) {
return {
error: userToken.error,
};
}
try { try {
if (false) { deleteCookie(event, "token");
deleteCookie(event, "token"); return {
return { success: true,
success: true, error: null,
error: null, };
};
}
return "testing";
} catch (e) { } catch (e) {
return { return {
success: false, success: false,