summaryrefslogtreecommitdiff
path: root/apps/web/app/api/v1/feeds/route.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/app/api/v1/feeds/route.ts')
-rw-r--r--apps/web/app/api/v1/feeds/route.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/apps/web/app/api/v1/feeds/route.ts b/apps/web/app/api/v1/feeds/route.ts
new file mode 100644
index 0000000..adf5422
--- /dev/null
+++ b/apps/web/app/api/v1/feeds/route.ts
@@ -0,0 +1,55 @@
+import { NextResponse } from "next/server"
+import { createSupabaseAdminClient } from "@/lib/supabase/admin"
+import { authenticateApiRequest } from "@/lib/api-auth"
+
+export async function GET(request: Request) {
+ const authResult = await authenticateApiRequest(request)
+
+ if (!authResult.authenticated) {
+ return NextResponse.json(
+ { error: authResult.error },
+ { status: authResult.status }
+ )
+ }
+
+ const adminClient = createSupabaseAdminClient()
+ const { data, error } = await adminClient
+ .from("subscriptions")
+ .select(
+ "id, custom_title, folder_id, feeds!inner(id, url, title, feed_type, site_url)"
+ )
+ .eq("user_id", authResult.user.userIdentifier)
+
+ if (error) {
+ return NextResponse.json(
+ { error: "Failed to load feeds" },
+ { status: 500 }
+ )
+ }
+
+ interface FeedRow {
+ id: string
+ custom_title: string | null
+ folder_id: string | null
+ feeds: {
+ id: string
+ url: string
+ title: string | null
+ feed_type: string | null
+ site_url: string | null
+ }
+ }
+
+ return NextResponse.json({
+ feeds: (data as unknown as FeedRow[]).map((row) => ({
+ subscriptionIdentifier: row.id,
+ feedIdentifier: row.feeds.id,
+ feedUrl: row.feeds.url,
+ feedTitle: row.feeds.title,
+ customTitle: row.custom_title,
+ feedType: row.feeds.feed_type,
+ siteUrl: row.feeds.site_url,
+ folderIdentifier: row.folder_id,
+ })),
+ })
+}