-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Nounspace/hypo_v0_data_read_write
feat: add data read/write for users
- Loading branch information
Showing
5 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NEXT_PUBLIC_MOD_PROTOCOL_API_URL = 'https://api.modprotocol.org/api' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters