diff --git a/app/components/Settings/SettingsSheet.vue b/app/components/Settings/SettingsSheet.vue index da330d8..1928415 100644 --- a/app/components/Settings/SettingsSheet.vue +++ b/app/components/Settings/SettingsSheet.vue @@ -1,104 +1,104 @@ - - - - - {{ t("login") }} - - + + + + + {{ t("login") }} + + - - {{ t("languages") }} - + {{ t("languages") }} + - - {{ t(`languageNames.${lang.code}`) }} - - - + > + + {{ t(`languageNames.${lang.code}`) }} + + + - - {{ t("push") }} - - {{ t("push") }} - - + + {{ t("push") }} + + {{ t("push") }} + + - - {{ t("insertionPoint") }} - - {{ t(`top`) }} - {{ t(`bottom`) }} - - - - - - - - + + {{ t("insertionPoint") }} + + {{ t(`top`) }} + {{ t(`bottom`) }} + + + + + + + + diff --git a/i18n/locales/de.json b/i18n/locales/de.json index d5bb6cd..0305638 100644 --- a/i18n/locales/de.json +++ b/i18n/locales/de.json @@ -34,6 +34,5 @@ "tagSelect": { "notUsedYet": "Nicht verwendet" }, - "recurring-weekly": "Wöchentlich", "push": "Webpush" } diff --git a/i18n/locales/en.json b/i18n/locales/en.json index d642731..afa47ec 100644 --- a/i18n/locales/en.json +++ b/i18n/locales/en.json @@ -32,7 +32,6 @@ "recurring-daily": "Daily", "recurring-weekly": "Weekly", "push": "Webpush", - "recurring-weekly": "Weekly", "tagSelect": { "notUsedYet": "Not used yet" } diff --git a/server/tasks/notify/push.ts b/server/tasks/notify/push.ts index a93f93d..e90ce1e 100644 --- a/server/tasks/notify/push.ts +++ b/server/tasks/notify/push.ts @@ -1,4 +1,4 @@ -import {sendMsg} from "#server/utils/subscriptions"; +import { sendMsg } from "#server/utils/subscriptions"; export default defineTask({ async run(_event) { diff --git a/server/utils/db/subscription.ts b/server/utils/db/subscription.ts index 7502616..6f4d0fb 100644 --- a/server/utils/db/subscription.ts +++ b/server/utils/db/subscription.ts @@ -1,46 +1,46 @@ -import type {NuxtError} from "nuxt/app"; +import type { NuxtError } from "nuxt/app"; import webpush from "web-push"; -import type {PushSubscriptionJSON} from "~~/shared/types"; +import type { PushSubscriptionJSON } from "~~/shared/types"; function getKey(userId: string): string { - return `subscriptions:${userId}`; + return `subscriptions:${userId}`; } webpush.setVapidDetails( - process.env.SUBSCRIPTIONS_MAIL!, - process.env.NUXT_PUBLIC_SUBSCRIPTIONS_PUBLIC_KEY!, - process.env.SUBSCRIPTIONS_PRIVATE_KEY!, + process.env.SUBSCRIPTIONS_MAIL!, + process.env.NUXT_PUBLIC_SUBSCRIPTIONS_PUBLIC_KEY!, + process.env.SUBSCRIPTIONS_PRIVATE_KEY!, ); export const Subscriptions = { - async getAll(userId: string): Promise { - const storage = useStorage(); - return (await storage.get(getKey(userId))) ?? []; - }, - async updateOrAdd( - userId: string, - subscription: PushSubscriptionJSON, - ): Promise { - const storage = useStorage(); - const subscriptions = await Subscriptions.getAll(userId); + async getAll(userId: string): Promise { + const storage = useStorage(); + return (await storage.get(getKey(userId))) ?? []; + }, + async updateOrAdd( + userId: string, + subscription: PushSubscriptionJSON, + ): Promise { + const storage = useStorage(); + const subscriptions = await Subscriptions.getAll(userId); - const exists = subscriptions.find( - (s) => - s.endpoint === subscription.endpoint || - (s.keys.p256dh === subscription.keys.p256dh && - s.keys.auth === subscription.keys.auth), - ); + const exists = subscriptions.find( + (s) => + s.endpoint === subscription.endpoint || + (s.keys.p256dh === subscription.keys.p256dh && + s.keys.auth === subscription.keys.auth), + ); - if (!exists) { - subscriptions.push(subscription); - await storage.set(getKey(userId), subscriptions); - return subscription; - } + if (!exists) { + subscriptions.push(subscription); + await storage.set(getKey(userId), subscriptions); + return subscription; + } - return createError({ - status: 201, - statusMessage: "Already subscribed", - message: `Subscription already exists`, - }); - } + return createError({ + status: 201, + statusMessage: "Already subscribed", + message: `Subscription already exists`, + }); + }, }; diff --git a/server/utils/subscriptions.ts b/server/utils/subscriptions.ts index 11b0657..5e353bb 100644 --- a/server/utils/subscriptions.ts +++ b/server/utils/subscriptions.ts @@ -1,50 +1,46 @@ -import type {Todo} from "#shared/types"; import webpush from "web-push"; +import type { Todo } from "#shared/types"; export async function sendMsg(): Promise { - const keys = await useStorage().getKeys(); - const filteredKeys = keys.filter((key) => key.startsWith("todos:")); - - for (const key of filteredKeys) { - const todos = await useStorage().get(key); - - for (const todo of todos!) { - if (todo.time?.type === "point") { - const date = new Date(todo.time.time); - const now = new Date(); - - const sameMinute = - date.getUTCFullYear() === now.getUTCFullYear() && - date.getUTCMonth() === now.getUTCMonth() && - date.getUTCDate() === now.getUTCDate() && - date.getUTCHours() === now.getUTCHours() && - date.getUTCMinutes() === now.getUTCMinutes(); - - if (sameMinute) { - await sendNotification( - key.substring(6), - todo.title, - todo.note, - ); - } - } - } - } + const keys = await useStorage().getKeys(); + const filteredKeys = keys.filter((key) => key.startsWith("todos:")); + + for (const key of filteredKeys) { + const todos = await useStorage().get(key); + + for (const todo of todos!) { + if (todo.time?.type === "point") { + const date = new Date(todo.time.time); + const now = new Date(); + + const sameMinute = + date.getUTCFullYear() === now.getUTCFullYear() && + date.getUTCMonth() === now.getUTCMonth() && + date.getUTCDate() === now.getUTCDate() && + date.getUTCHours() === now.getUTCHours() && + date.getUTCMinutes() === now.getUTCMinutes(); + + if (sameMinute) { + await sendNotification(key.substring(6), todo.title, todo.note); + } + } + } + } } async function sendNotification(userId: string, title: string, body: string) { - const subscriptions = await Subscriptions.getAll(userId); - - const payload = JSON.stringify({ - title: title, - body: body, - }); - - for (const sub of subscriptions) { - try { - await webpush.sendNotification(sub, payload); - } catch (err) { - console.error("Push failed", err); - } - } -} \ No newline at end of file + const subscriptions = await Subscriptions.getAll(userId); + + const payload = JSON.stringify({ + title: title, + body: body, + }); + + for (const sub of subscriptions) { + try { + await webpush.sendNotification(sub, payload); + } catch (err) { + console.error("Push failed", err); + } + } +}