a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use rpc to get domains

+52 -50
-21
actions/domains/getLeafletDomains.ts
··· 1 - "use server"; 2 - 3 - import { createServerClient } from "@supabase/ssr"; 4 - import { cookies } from "next/headers"; 5 - import { Database } from "supabase/database.types"; 6 - 7 - let supabase = createServerClient<Database>( 8 - process.env.NEXT_PUBLIC_SUPABASE_API_URL as string, 9 - process.env.SUPABASE_SERVICE_ROLE_KEY as string, 10 - { cookies: {} }, 11 - ); 12 - export async function getLeafletDomains(id: string) { 13 - let res = await supabase 14 - .from("permission_tokens") 15 - .select( 16 - "*, permission_token_rights(*), custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*) ", 17 - ) 18 - .eq("id", id) 19 - .single(); 20 - return res.data?.custom_domain_routes; 21 - }
+39
app/api/rpc/[command]/domain_routes.ts
··· 1 + import { z } from "zod"; 2 + import { makeRoute } from "../lib"; 3 + import { Env } from "./route"; 4 + 5 + export const get_domain_status = makeRoute({ 6 + route: "get_domain_status", 7 + input: z.object({ 8 + domain: z.string(), 9 + }), 10 + handler: async ({ domain }, { vercel }: Pick<Env, "vercel">) => { 11 + let [status, config] = await Promise.all([ 12 + vercel.domains.getDomain({ 13 + domain, 14 + teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 15 + }), 16 + vercel.domains.getDomainConfig({ 17 + domain, 18 + teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 19 + }), 20 + ]); 21 + 22 + return { status, config }; 23 + }, 24 + }); 25 + 26 + export const get_leaflet_domains = makeRoute({ 27 + route: "get_leaflet_domains", 28 + input: z.object({ id: z.string() }), 29 + handler: async ({ id }, { supabase }: Env) => { 30 + let res = await supabase 31 + .from("permission_tokens") 32 + .select( 33 + "*, permission_token_rights(*), custom_domain_routes!custom_domain_routes_edit_permission_token_fkey(*) ", 34 + ) 35 + .eq("id", id) 36 + .single(); 37 + return res.data?.custom_domain_routes || null; 38 + }, 39 + });
-24
app/api/rpc/[command]/get_domain_status.ts
··· 1 - import { z } from "zod"; 2 - import { makeRoute } from "../lib"; 3 - import { Env } from "./route"; 4 - 5 - export const get_domain_status = makeRoute({ 6 - route: "get_domain_status", 7 - input: z.object({ 8 - domain: z.string(), 9 - }), 10 - handler: async ({ domain }, { vercel }: Pick<Env, "vercel">) => { 11 - let [status, config] = await Promise.all([ 12 - vercel.domains.getDomain({ 13 - domain, 14 - teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 15 - }), 16 - vercel.domains.getDomainConfig({ 17 - domain, 18 - teamId: "team_42xaJiZMTw9Sr7i0DcLTae9d", 19 - }), 20 - ]); 21 - 22 - return { status, config }; 23 - }, 24 - });
+8 -2
app/api/rpc/[command]/route.ts
··· 7 7 import { pull } from "./pull"; 8 8 import { getFactsFromHomeLeaflets } from "./getFactsFromHomeLeaflets"; 9 9 import { Vercel } from "@vercel/sdk"; 10 - import { get_domain_status } from "./get_domain_status"; 10 + import { get_domain_status, get_leaflet_domains } from "./domain_routes"; 11 11 12 12 const client = postgres(process.env.DB_URL as string, { idle_timeout: 5 }); 13 13 let supabase = createClient<Database>( ··· 26 26 }; 27 27 export type Env = typeof Env; 28 28 export type Routes = typeof Routes; 29 - let Routes = [push, pull, getFactsFromHomeLeaflets, get_domain_status]; 29 + let Routes = [ 30 + push, 31 + pull, 32 + getFactsFromHomeLeaflets, 33 + get_domain_status, 34 + get_leaflet_domains, 35 + ]; 30 36 export async function POST( 31 37 req: Request, 32 38 { params }: { params: { command: string } },
+5 -3
components/PageSWRDataProvider.tsx
··· 3 3 import { SWRConfig } from "swr"; 4 4 import { useReplicache } from "src/replicache"; 5 5 import useSWR from "swr"; 6 - import { getLeafletDomains } from "actions/domains/getLeafletDomains"; 6 + import { callRPC } from "app/api/rpc/client"; 7 7 8 8 export function PageSWRDataProvider(props: { 9 9 leaflet_id: string; ··· 35 35 } 36 36 export function useLeafletDomains() { 37 37 let { permission_token } = useReplicache(); 38 - return useSWR(`${permission_token.id}-domains`, () => 39 - getLeafletDomains(permission_token.id), 38 + return useSWR( 39 + `${permission_token.id}-domains`, 40 + async () => 41 + await callRPC("get_leaflet_domains", { id: permission_token.id }), 40 42 ); 41 43 }