-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supabase.ts
38 lines (31 loc) · 1.11 KB
/
supabase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import "https://deno.land/x/[email protected]/load.ts";
import "https://deno.land/x/[email protected]/mod.ts";
import { createClient } from "https://esm.sh/@supabase/supabase-js";
export const supabase = createClient(
Deno.env.get("SUPABASE_URL"),
Deno.env.get("SUPABASE_API_KEY"),
);
export async function verifyAuthor(
version: string,
moduleName: string,
access_token: string,
) {
const { data: Version, error } = await supabase.from("Version").select("*")
.eq("name", version).eq("moduleName", moduleName).single();
if (error) return false;
const { data: User, error: userError } = await supabase.from("AccessToken")
.select("username").eq("hash", access_token).single();
if (userError) return false;
return User.username === Version.authorName ? Version : null;
}
export async function createManifestEntry(
version: string,
moduleName: string,
tx: string,
) {
const { data, error } = await supabase.from("Version").update({
manifestid: tx,
}).eq("name", version).eq("moduleName", moduleName);
if (error) throw new Error(`Failed to update manifest tx: ${error.message}`);
return data;
}