summaryrefslogtreecommitdiff
path: root/apps/web/app/api/export
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-07 01:42:57 -0800
committerFuwn <[email protected]>2026-02-07 01:42:57 -0800
commit5c5b1993edd890a80870ee05607ac5f088191d4e (patch)
treea721b76bcd49ba10826c53efc87302c7a689512f /apps/web/app/api/export
downloadasa.news-5c5b1993edd890a80870ee05607ac5f088191d4e.tar.xz
asa.news-5c5b1993edd890a80870ee05607ac5f088191d4e.zip
feat: asa.news RSS reader with developer tier, REST API, and webhooks
Full-stack RSS reader SaaS: Supabase + Next.js + Go worker. Includes three subscription tiers (free/pro/developer), API key auth, read-only REST API, webhook push notifications, Stripe billing with proration, and PWA support.
Diffstat (limited to 'apps/web/app/api/export')
-rw-r--r--apps/web/app/api/export/route.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/apps/web/app/api/export/route.ts b/apps/web/app/api/export/route.ts
new file mode 100644
index 0000000..4842f83
--- /dev/null
+++ b/apps/web/app/api/export/route.ts
@@ -0,0 +1,67 @@
+import { NextResponse } from "next/server"
+import { createSupabaseServerClient } from "@/lib/supabase/server"
+
+export async function GET() {
+ const supabaseClient = await createSupabaseServerClient()
+ const {
+ data: { user },
+ } = await supabaseClient.auth.getUser()
+
+ if (!user) {
+ return NextResponse.json({ error: "Not authenticated" }, { status: 401 })
+ }
+
+ const { data: profile } = await supabaseClient
+ .from("user_profiles")
+ .select("tier, display_name")
+ .eq("id", user.id)
+ .single()
+
+ const tier = profile?.tier ?? "free"
+
+ const { data: savedEntries } = await supabaseClient
+ .from("user_entry_states")
+ .select(
+ "entries(id, title, url, author, summary, published_at, feeds(title, url))"
+ )
+ .eq("user_id", user.id)
+ .eq("saved", true)
+
+ const exportData: Record<string, unknown> = {
+ exportedAt: new Date().toISOString(),
+ tier,
+ savedEntries:
+ (savedEntries ?? []).map((row) => (row as Record<string, unknown>).entries) ?? [],
+ }
+
+ if (tier === "pro" || tier === "developer") {
+ const [subscriptionsResult, foldersResult, mutedKeywordsResult] =
+ await Promise.all([
+ supabaseClient
+ .from("subscriptions")
+ .select("id, feed_id, folder_id, custom_title, feeds(title, url)")
+ .eq("user_id", user.id),
+ supabaseClient
+ .from("folders")
+ .select("id, name, position")
+ .eq("user_id", user.id),
+ supabaseClient
+ .from("muted_keywords")
+ .select("id, keyword")
+ .eq("user_id", user.id),
+ ])
+
+ exportData.subscriptions = subscriptionsResult.data ?? []
+ exportData.folders = foldersResult.data ?? []
+ exportData.mutedKeywords = mutedKeywordsResult.data ?? []
+ }
+
+ const jsonString = JSON.stringify(exportData, null, 2)
+
+ return new Response(jsonString, {
+ headers: {
+ "Content-Type": "application/json",
+ "Content-Disposition": `attachment; filename="asa-news-export-${new Date().toISOString().slice(0, 10)}.json"`,
+ },
+ })
+}