@@ -42,19 +42,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
entryId: string;
|
||||
csrfToken: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -71,18 +58,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
query: {
|
||||
entryId: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$post: {
|
||||
input: {
|
||||
@@ -96,19 +71,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
entryId: string;
|
||||
csrfToken: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$delete: {
|
||||
input: {
|
||||
@@ -122,19 +84,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
entryId: string;
|
||||
csrfToken: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -146,23 +95,10 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
data?: string[] | undefined;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
query: {
|
||||
view?: string | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$delete: {
|
||||
input: {
|
||||
@@ -176,19 +112,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
feedIdList: string[];
|
||||
deleteSubscriptions: boolean;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$patch: {
|
||||
input: {
|
||||
@@ -202,32 +125,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
category: string;
|
||||
feedIdList: string[];
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 2;
|
||||
error: string;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 400;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
category: string;
|
||||
feedIdList: string[];
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -243,30 +140,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
query: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 2;
|
||||
error: "Feed not found";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 400;
|
||||
} | {
|
||||
input: {
|
||||
query: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized" | "Only admins can refresh feeds";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -279,7 +152,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
data: {
|
||||
feed: {
|
||||
description: string | null;
|
||||
@@ -317,19 +189,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
keyword: string;
|
||||
type?: "auto" | "rss" | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -350,30 +209,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
csrfToken: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
csrfToken: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Failed to create session";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 500;
|
||||
};
|
||||
};
|
||||
"/auth-app/update-account": {
|
||||
@@ -391,21 +226,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
csrfToken: string;
|
||||
name?: string | null | undefined;
|
||||
image?: string | null | undefined;
|
||||
handle?: string | null | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -466,23 +286,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
feedId?: string | undefined;
|
||||
view?: number | undefined;
|
||||
category?: string | undefined;
|
||||
limit?: number | undefined;
|
||||
offset?: number | undefined;
|
||||
feedIdList?: string[] | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$get: {
|
||||
input: {
|
||||
@@ -526,18 +329,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
query: {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
@@ -576,18 +367,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
query: {
|
||||
view?: string | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$post: {
|
||||
input: {
|
||||
@@ -604,38 +383,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
url: string;
|
||||
view: number;
|
||||
csrfToken: string;
|
||||
category?: string | null | undefined;
|
||||
isPrivate?: boolean | null | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 2;
|
||||
error: string;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 400;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
url: string;
|
||||
view: number;
|
||||
csrfToken: string;
|
||||
category?: string | null | undefined;
|
||||
isPrivate?: boolean | null | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$delete: {
|
||||
input: {
|
||||
@@ -650,34 +397,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
csrfToken: string;
|
||||
url?: string | undefined;
|
||||
feedId?: string | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 2;
|
||||
error: string;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 400;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
csrfToken: string;
|
||||
url?: string | undefined;
|
||||
feedId?: string | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
$patch: {
|
||||
input: {
|
||||
@@ -694,38 +413,6 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
feedId: string;
|
||||
view: number;
|
||||
csrfToken: string;
|
||||
category?: string | null | undefined;
|
||||
isPrivate?: boolean | null | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 2;
|
||||
error: string;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 400;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
feedId: string;
|
||||
view: number;
|
||||
csrfToken: string;
|
||||
category?: string | null | undefined;
|
||||
isPrivate?: boolean | null | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
error: "Unauthorized";
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 401;
|
||||
};
|
||||
};
|
||||
}, "/">;
|
||||
|
||||
@@ -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
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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<string, number> = {}
|
||||
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<string, number> = {}
|
||||
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
|
||||
}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user