Skip to content

Commit

Permalink
Merge pull request #8 from Nounspace/hypo_v0_data_read_write
Browse files Browse the repository at this point in the history
feat: add data read/write for users
  • Loading branch information
hiporox authored Apr 18, 2024
2 parents d9f9f95 + fbf0d0c commit 82e87e3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_MOD_PROTOCOL_API_URL = 'https://api.modprotocol.org/api'
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_VERCEL_ENV = development
NEXT_PUBLIC_URL = 'http://localhost:3000'
3 changes: 1 addition & 2 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NEXT_PUBLIC_VERCEL_ENV = production
NEXT_PUBLIC_URL = 'https://nounspace.com'
NEXT_PUBLIC_MOD_PROTOCOL_API_URL = 'https://api.modprotocol.org/api'
NEXT_PUBLIC_URL = 'https://nounspace.com'
46 changes: 46 additions & 0 deletions src/shared/data/fidgetData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createClient } from "@/space/common/helpers/supabase/component";

export async function readPublicFidgetData(fidgetName, key) {
return readFidgetData(fidgetName, key);
}

export async function writePublicFidgetData(fidgetName, key, value) {
return writeFidgetData(fidgetName, key, value);
}

export async function readPrivateFidgetData(fidgetName, key) {
return readFidgetData(fidgetName, key, true);
}

export async function writePivateFidgetData(fidgetName, key, value) {
return writeFidgetData(fidgetName, key, value, true);
}

async function writeFidgetData(fidgetName, key, value, isPrivate = false) {
const supabase = createClient();
const { data } = await supabase.storage.from(isPrivate ? "fidgets" : "fidgetsPublic").update(await createFileLoc(fidgetName, key, isPrivate), value, {
cacheControl: '3600',
upsert: false
});
return data;
}

async function readFidgetData(fidgetName, key, isPrivate = false) {
const supabase = createClient();
const { data } = await supabase.storage.from(isPrivate ? "fidgets" : "fidgetsPublic").download(await createFileLoc(fidgetName, key, isPrivate));
return data;
}

async function createFileLoc(fidgetName, key, isPrivate = false) {
let fileLoc = `${fidgetName}/${key}`;
if (isPrivate) {
const supabase = createClient();
const { data: { session }} = await supabase.auth.getSession();
if (session) {
fileLoc = `${session!.user.id}${fileLoc}`
} else {
throw new Error("User is not logged in and cannot access private data")
}
}
return fileLoc;
}
9 changes: 0 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
"jsx": "preserve",
"baseUrl": ".",
"incremental": true,
"types": [
"node",
"react/next",
"react-dom/next"
],
"paths": {
"@/*": [
"src/*"
Expand All @@ -48,9 +43,5 @@
// "./**/*.tsx",
// "./src",
// "./src/**/*.tsx"
],
"exclude": [
"node_modules",
"./node_modules"
]
}

0 comments on commit 82e87e3

Please sign in to comment.