-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/services
- Loading branch information
Showing
19 changed files
with
1,089 additions
and
365 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
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,19 @@ | ||
import { Blobs, Repos } from "@/components/Backups" | ||
|
||
export const runtime = 'edge' | ||
|
||
export interface BackupsProps { | ||
params: Promise<{ id: string }> | ||
} | ||
|
||
export default async function Backups ({ params }: BackupsProps) { | ||
const id = (await params).id | ||
|
||
return ( | ||
<div className="bg-white/80 p-10 h-screen"> | ||
<h1 className="text-xl font-mono font-bold uppercase">Backup {id}</h1> | ||
<Repos id={id} className='py-4 w-full' /> | ||
<Blobs id={id} className='py-4 w-full' /> | ||
</div> | ||
) | ||
} |
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,55 @@ | ||
'use client' | ||
|
||
import Dexie, { type EntityTable } from 'dexie' | ||
|
||
interface Backup { | ||
id: number; | ||
accountDid: string; | ||
createdAt: Date; | ||
} | ||
|
||
interface Repo { | ||
cid: string; | ||
backupId: number; | ||
accountDid: string; | ||
} | ||
|
||
interface Blob { | ||
cid: string; | ||
backupId: number; | ||
accountDid: string; | ||
} | ||
|
||
interface Commit { | ||
accountDid: string; | ||
commitRev: string; | ||
} | ||
|
||
const db = new Dexie('storacha-bluesky-backups') as Dexie & { | ||
backups: EntityTable< | ||
Backup, | ||
'id' | ||
>; | ||
repos: EntityTable< | ||
Repo, | ||
'cid' | ||
>; | ||
blobs: EntityTable< | ||
Blob, | ||
'cid' | ||
>; | ||
commits: EntityTable< | ||
Commit, | ||
'accountDid' | ||
>; | ||
}; | ||
|
||
// Schema declaration: | ||
db.version(1).stores({ | ||
backups: 'id++, accountDid, createdAt', | ||
repos: 'cid, backupId, accountDid', | ||
blobs: 'cid, backupId, accountDid', | ||
commits: 'accountDid, commitRev' | ||
}); | ||
|
||
export default db |
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,9 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
@import "tailwindcss"; | ||
|
||
.btn { | ||
@apply px-2 py-1 border rounded-lg cursor-pointer hover:bg-white; | ||
} | ||
|
||
.ipt { | ||
@apply px-2 py-1 border rounded-lg; | ||
} |
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
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,16 +1,29 @@ | ||
import BackupButton from "@/components/BackupButton"; | ||
import BlueskyAuthenticator from "@/components/BlueskyAuthenticator"; | ||
import StorachaAuthenticator from "@/components/StorachaAuthenticator"; | ||
import { Backups } from "@/components/Backups"; | ||
|
||
export default function Home () { | ||
return ( | ||
<div> | ||
<h1>Bluesky Backup Webapp</h1> | ||
<p>Lets get started</p> | ||
<h4>Bluesky Auth</h4> | ||
<BlueskyAuthenticator /> | ||
<div className="bg-white/80 p-10 h-screen"> | ||
<h1 className="text-lg mb-8 font-bold font-mono uppercase">Bluesky Backups</h1> | ||
<div className="mb-4"> | ||
<h4 className="text-sm font-bold font-mono uppercase">Bluesky Auth</h4> | ||
<div className="p-2 bg-white/50 rounded-lg"> | ||
<BlueskyAuthenticator /> | ||
</div> | ||
</div> | ||
|
||
<h4>Storacha Auth</h4> | ||
<StorachaAuthenticator /> | ||
<div className="mb-4"> | ||
<h4 className="text-sm font-bold font-mono uppercase">Storacha Auth</h4> | ||
<div className="p-2 bg-white/50 rounded-lg"> | ||
<StorachaAuthenticator /> | ||
</div> | ||
</div> | ||
|
||
<BackupButton /> | ||
|
||
<Backups className="mt-16" /> | ||
</div> | ||
) | ||
} |
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
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,110 @@ | ||
'use client' | ||
|
||
import { useBskyAuthContext } from "@/contexts" | ||
import { backup, BackupMetadataStore } from "@/lib/bluesky" | ||
import { Space, useW3 } from "@w3ui/react" | ||
import { useState } from "react" | ||
import { SpaceFinder } from "./SpaceFinder" | ||
import db from "@/app/db" | ||
|
||
const backupMetadataStore: BackupMetadataStore = { | ||
async setLatestCommit (accountDid, commitRev) { | ||
await db.commits.put({ accountDid, commitRev }) | ||
}, | ||
async addRepo (cid, backupId, accountDid) { | ||
await db.repos.put({ cid, backupId, accountDid }) | ||
}, | ||
async addBlob (cid, backupId, accountDid) { | ||
await db.blobs.put({ cid, backupId, accountDid }) | ||
}, | ||
async addBackup (accountDid) { | ||
return await db.backups.add({ accountDid, createdAt: new Date() }) | ||
} | ||
} | ||
|
||
export interface BackupButtonProps { | ||
backupMetadataStore: BackupMetadataStore | ||
} | ||
|
||
export default function BackupButton () { | ||
const [isBackingUp, setIsBackingUp] = useState(false) | ||
const [selectedSpace, setSelectedSpace] = useState<Space>() | ||
const [storacha] = useW3() | ||
const bluesky = useBskyAuthContext() | ||
const backupEvents = new EventTarget() | ||
const space = selectedSpace ?? storacha?.spaces[0] | ||
async function onClick () { | ||
if (space && bluesky.userProfile && bluesky.agent && storacha.client) { | ||
await storacha.client.setCurrentSpace(space.did()) | ||
|
||
setIsBackingUp(true) | ||
await backup(bluesky.userProfile, bluesky.agent, storacha.client, backupMetadataStore, { eventTarget: backupEvents }) | ||
setIsBackingUp(false) | ||
} else { | ||
console.log('not backing up, profile, agent, client:', bluesky.userProfile, bluesky.agent, storacha.client) | ||
} | ||
} | ||
const userAuthenticatedToBothServices = bluesky.userProfile && (storacha.accounts.length > 0) | ||
const [backupProgressComponent, setBackupProgressComponent] = useState( | ||
<> | ||
Backing up your Bluesky account... | ||
</> | ||
) | ||
backupEvents.addEventListener('repo:fetching', () => { | ||
setBackupProgressComponent( | ||
<> | ||
Backing up your Bluesky account... | ||
</> | ||
) | ||
}) | ||
backupEvents.addEventListener('repo:fetching', () => { | ||
setBackupProgressComponent( | ||
<> | ||
Backing up your Bluesky account... | ||
</> | ||
) | ||
}) | ||
backupEvents.addEventListener('repo:uploaded', () => { | ||
setBackupProgressComponent( | ||
<> | ||
Backup started... | ||
</> | ||
) | ||
}) | ||
backupEvents.addEventListener('blob:fetching', (e) => { | ||
const { i: loaded, count: total } = (e as CustomEvent).detail ?? { i: 0, count: 1 } | ||
const percentComplete = Math.floor((loaded / total) * 100) | ||
setBackupProgressComponent( | ||
<div> | ||
<h3>Backing up your Bluesky account...</h3> | ||
<div className='relative flex flex-row justify-start border'> | ||
<div className='bg-black h-4' style={{ width: `${percentComplete}%` }}> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
}) | ||
return userAuthenticatedToBothServices ? ( | ||
isBackingUp ? ( | ||
<div> | ||
{backupProgressComponent} | ||
</div> | ||
) : ( | ||
<div> | ||
<p>Please choose the Storacha space where you'd like to back up your Bluesky account:</p> | ||
{storacha.spaces && (storacha.spaces.length > 0) && ( | ||
<SpaceFinder | ||
selected={space} setSelected={setSelectedSpace} spaces={storacha.spaces} | ||
className="w-52" /> | ||
)} | ||
<button | ||
onClick={onClick} disabled={!space} | ||
className="btn"> | ||
{space ? "Back It Up!" : "Please Pick a Space"} | ||
</button> | ||
</div> | ||
) | ||
) : ( | ||
<div>Please authenticate to both Bluesky and Storacha to continue.</div> | ||
) | ||
} |
Oops, something went wrong.