(Add archive system) Merge pull request #10 from hpware/beta

This commit is contained in:
元皓 2025-06-18 21:40:01 +08:00 committed by GitHub
commit dfd9bb274d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 78 additions and 13 deletions

View File

@ -0,0 +1,14 @@
import currentVersion from "~/versionTag";
export default async function newestVersion() {
export default async function newestVersion() {
const current = currentVersion();
const req = await fetch("/api/version");
if (!req.ok) {
console.error("Version check failed:", req.statusText);
return true; // fail-closed → pretend we are up-to-date
}
const { version: latest } = await req.json();
return current === latest; // `true` ➜ up-to-date
}
}

View File

@ -47,6 +47,9 @@ import { gsap } from "gsap";
import confetti from "js-confetti";
import translate from "translate";
// Import Scripts
import checkAppVersion from "~/components/checkAppVersion";
// Import Windows
import UserWindow from "~/components/app/windows/user.vue";
import SourcesWindow from "~/components/app/windows/sources.vue";
@ -99,6 +102,7 @@ const applyForTranslation = ref(false);
const langPrefDifferent = ref(false);
const notLoggedInState = ref(false);
const translateProvider = ref("");
const newUpdate = ref(false);
// Key Data
const menuItems = [
@ -620,6 +624,12 @@ onMounted(async () => {
translateProvider.value = loadUserInfoData.translate.provider || "google";
console.log(langPrefDifferent);
});*/
// Get ghe newest update
const newUpdateTimer = 1000 * 60 * 3; // Check for thime every 3 min.
setInterval(async () => {
newUpdate.value = await checkAppVersion();
}, newUpdateTimer);
</script>
<template>
<div v-if="changeLangAnimation">
@ -745,6 +755,35 @@ onMounted(async () => {
</DialogFooter>
</DialogContent>
</Dialog>
<!--New Update-->
<Dialog v-model:open="langPrefDifferent">
<DialogContent class="!border-0 !bg-black !rounded">
<DialogHeader>
<DialogTitle>There is a new Update!</DialogTitle>
<DialogDescription>
Click notify later to save your current tasks & update the page.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button
@click="
() => {
newUpdate.value = false;
}
"
variant="outline"
>
Notify later
</Button>
<Button
@click="() => window.location.reload('/desktop')"
variant="outline"
>
Update
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<!--Window system-->
<Transition>
<div>

View File

@ -38,20 +38,32 @@ function cleanUpSlug(orgslug: string) {
}
// Archive articles. For future use?
async function storeArticlesIfItDoesNotExists(data, RequestId) {
const checkDataIsInDatabase = await sql`
SELECT * FROM news_articles
WHERE jsondata = ${data}
`;
if (checkDataIsInDatabase.length > 0) {
return;
function storeArticlesIfItDoesNotExists(data, RequestId) {
try {
setImmediate(async () => {
try {
const checkDataIsInDatabase = await sql`
SELECT uuid FROM news_articles
WHERE article_id = ${RequestId}
LIMIT 1
`;
if (checkDataIsInDatabase.length > 0) {
console.log(`Article ${RequestId} already exists in database`);
return;
}
const jsonData = JSON.stringify(data);
await sql`
INSERT INTO news_articles (uuid, article_id, jsondata)
VALUES (${uuidv4()}, ${RequestId}, ${jsonData}::JSON)
`;
console.log(`Successfully archived article ${RequestId} in background`);
} catch (error) {
console.error("Failed to archive article in background:", error);
}
});
} catch (error) {
console.error("Failed to initiate background archiving:", error);
}
const storeData = await sql`
INSERT INTO news_articles (uuid, article_id, jsondata)
VALUES (${uuidv4()}, ${RequestId}, ${data}::JSON)
`;
console.log(storeData);
return;
}
export default defineEventHandler(async (event) => {