diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index be18bd7f4..76095499b 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -42,19 +42,6 @@ declare const routes: hono_hono_base.HonoBase; diff --git a/src/renderer/src/queries/entries.ts b/src/renderer/src/queries/entries.ts index 4fa450b13..13366b019 100644 --- a/src/renderer/src/queries/entries.ts +++ b/src/renderer/src/queries/entries.ts @@ -1,5 +1,4 @@ import { - UnAuthorizedError, UnprocessableEntityError, } from "@renderer/biz/error" import { useBizInfiniteQuery } from "@renderer/hooks/useBizQuery" @@ -54,9 +53,7 @@ export const entries = { } const res = await apiClient.entries.$get({ query: { id } }) const json = await res.json() - if (json.code === 1) { - throw new UnAuthorizedError() - } + return json.data }, { diff --git a/src/renderer/src/queries/subscriptions.ts b/src/renderer/src/queries/subscriptions.ts index d5aca1c0d..a3a8213f1 100644 --- a/src/renderer/src/queries/subscriptions.ts +++ b/src/renderer/src/queries/subscriptions.ts @@ -1,4 +1,3 @@ -import { UnAuthorizedError } from "@renderer/biz/error" import { defineQuery } from "@renderer/lib/defineQuery" import type { SubscriptionResponse } from "@renderer/lib/types" import { apiClient } from "@renderer/queries/api-fetch" @@ -15,83 +14,85 @@ export type Response = { export const subscription = { byView: (view?: number) => - defineQuery(["subscriptions", view], async () => { - const res = await ( - await apiClient.subscriptions.$get({ query: { view: String(view) } }) - ).json() - if (res.code === 1) { - throw new UnAuthorizedError() - } - const subscriptions = res.data as SubscriptionResponse - const categories = { - list: {}, - unread: 0, - } as { - list: Record< - string, - { - list: SubscriptionResponse - unread: number - } - > - unread: number - } - const domains: Record = {} - if (subscriptions) { - for (const subscription of subscriptions) { - if (!subscription.category && subscription.feeds.siteUrl) { - const { domain } = parse(subscription.feeds.siteUrl) - if (domain) { - if (!domains[domain]) { - domains[domain] = 0 - } - domains[domain]++ + defineQuery( + ["subscriptions", view], + async () => { + const res = await ( + await apiClient.subscriptions.$get({ query: { view: String(view) } }) + ).json() + + const subscriptions = res.data as SubscriptionResponse + const categories = { + list: {}, + unread: 0, + } as { + list: Record< + string, + { + list: SubscriptionResponse + unread: number } - } + > + unread: number } - } - if (subscriptions) { - for (const subscription of subscriptions) { - if (!subscription.category) { - if (subscription.feeds.siteUrl) { + const domains: Record = {} + if (subscriptions) { + for (const subscription of subscriptions) { + if (!subscription.category && subscription.feeds.siteUrl) { const { domain } = parse(subscription.feeds.siteUrl) - if (domain && domains[domain] > 1) { - subscription.category = - domain.slice(0, 1).toUpperCase() + domain.slice(1) + if (domain) { + if (!domains[domain]) { + domains[domain] = 0 + } + domains[domain]++ } } - if (!subscription.category) { - subscription.category = "" - } } - if (!categories.list[subscription.category]) { - categories.list[subscription.category] = { - list: [], - unread: 0, - } - } - // const unread = counters.unreads[feed.id] || 0 - const unread = 0 - subscription.unread = unread - categories.list[subscription.category].list.push(subscription) - categories.list[subscription.category].unread += unread - categories.unread += unread } - } - const list = Object.entries(categories.list) - .map(([name, list]) => ({ - name, - list: list.list.sort((a, b) => (b.unread || 0) - (a.unread || 0)), - unread: list.unread, - })) - .sort((a, b) => b.unread - a.unread) - return { - list, - unread: categories.unread, - } as Response - }, { - rootKey: ["subscriptions"], - }), + if (subscriptions) { + for (const subscription of subscriptions) { + if (!subscription.category) { + if (subscription.feeds.siteUrl) { + const { domain } = parse(subscription.feeds.siteUrl) + if (domain && domains[domain] > 1) { + subscription.category = + domain.slice(0, 1).toUpperCase() + domain.slice(1) + } + } + if (!subscription.category) { + subscription.category = "" + } + } + if (!categories.list[subscription.category]) { + categories.list[subscription.category] = { + list: [], + unread: 0, + } + } + // const unread = counters.unreads[feed.id] || 0 + const unread = 0 + subscription.unread = unread + categories.list[subscription.category].list.push(subscription) + categories.list[subscription.category].unread += unread + categories.unread += unread + } + } + const list = Object.entries(categories.list) + .map(([name, list]) => ({ + name, + list: list.list.sort((a, b) => (b.unread || 0) - (a.unread || 0)), + unread: list.unread, + })) + .sort((a, b) => b.unread - a.unread) + return { + list, + unread: categories.unread, + } as Response + }, + { + rootKey: ["subscriptions"], + }, + ), categories: (view?: number) => defineQuery(["subscription-categories", view], async () => { const res = await ( @@ -99,9 +100,7 @@ export const subscription = { query: { view: String(view) }, }) ).json() - if (res.code === 1) { - throw new UnAuthorizedError() - } + return res.data }), }