-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
185 additions
and
64 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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<meta name="theme-color" content="#484A65"> | ||
<meta name="description" content="Demo "> | ||
<title>Demo</title> | ||
|
||
</head> | ||
<body> | ||
<h1>Hello</h1> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="theme-color" content="#484A65" /> | ||
<meta name="description" content="Demo " /> | ||
<title>Demo</title> | ||
</head> | ||
<body> | ||
<h1>Working 🚏</h1> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
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,4 +1,56 @@ | ||
import { randomBytes } from '@wnfs-wg/nest' | ||
import { CID, FileSystem, Path } from '@wnfs-wg/nest' | ||
import { IDBBlockstore } from 'blockstore-idb' | ||
import * as uint8arrays from 'uint8arrays' | ||
|
||
// eslint-disable-next-line no-console | ||
console.log(randomBytes(10)) | ||
declare global { | ||
var fs: FileSystem | ||
var Path: typeof Path | ||
} | ||
|
||
// HTML | ||
const h1 = document.querySelector('h1') | ||
if (!h1) throw new Error('Expected to find a h1 element') | ||
|
||
// Blockstore | ||
const blockstore = new IDBBlockstore('path/to/store') | ||
await blockstore.open() | ||
|
||
// Load existing file system or create a new one | ||
const dataRoot = localStorage.getItem('fs-pointer') | ||
const storedKey = localStorage.getItem('capsule-key') | ||
|
||
const fs = | ||
dataRoot === null | ||
? await FileSystem.create({ blockstore }) | ||
: await FileSystem.fromCID(CID.parse(dataRoot), { blockstore }) | ||
|
||
globalThis.fs = fs | ||
globalThis.Path = Path | ||
|
||
// Create new private directory at the root | ||
const { capsuleKey } = await fs.mountPrivateNode({ | ||
path: Path.directory(), | ||
capsuleKey: | ||
storedKey === null | ||
? undefined | ||
: uint8arrays.fromString(storedKey, 'base64'), | ||
}) | ||
|
||
// Read from or write to the file system | ||
const filePath = Path.file('private', 'init') | ||
|
||
if (await fs.exists(filePath)) { | ||
h1.textContent = 'Time first seen: ' + (await fs.read(filePath, 'utf8')) | ||
} else { | ||
const dateTime = new Date().toString() | ||
const result = await fs.write(filePath, 'utf8', dateTime) | ||
|
||
localStorage.setItem('fs-pointer', result.dataRoot.toString()) | ||
localStorage.setItem( | ||
'capsule-key', | ||
uint8arrays.toString(capsuleKey, 'base64') | ||
) | ||
|
||
// eslint-disable-next-line no-console | ||
h1.textContent = 'Time first seen: ' + dateTime | ||
} |
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,10 @@ | ||
import { defineConfig } from 'vite' | ||
import wasm from 'vite-plugin-wasm' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
build: { | ||
target: 'esnext', | ||
}, | ||
plugins: [wasm()], | ||
}) |
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
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
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
Oops, something went wrong.