mirror of
https://github.com/aljazceru/pubky-explorer.git
synced 2025-12-17 05:54:27 +01:00
feat(pubky-explorer): move away from testnet
This commit is contained in:
31
pubky-explorer/package-lock.json
generated
31
pubky-explorer/package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^8.4.1",
|
||||
"@synonymdev/pubky": "^0.1.13",
|
||||
"@synonymdev/pubky": "file:../../pubky/pubky/pkg",
|
||||
"solid-js": "^1.8.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -18,6 +18,19 @@
|
||||
"vite-plugin-solid": "^2.10.2"
|
||||
}
|
||||
},
|
||||
"../../pubky/pubky/pkg": {
|
||||
"version": "0.1.16",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fetch-cookie": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browser-resolve": "^2.0.0",
|
||||
"esmify": "^2.1.1",
|
||||
"tape": "^5.8.1",
|
||||
"tape-run": "^11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
|
||||
@@ -938,9 +951,8 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@synonymdev/pubky": {
|
||||
"version": "0.1.13",
|
||||
"resolved": "https://registry.npmjs.org/@synonymdev/pubky/-/pubky-0.1.13.tgz",
|
||||
"integrity": "sha512-3Jo2W3lC6nXDD7ktHAREMqsU/u1cN+6Gvjdxn1iNr2wyznPBDqpuyGrc1w7N3Jy/3HzLtEemLodagNXxLIcudg=="
|
||||
"resolved": "../../pubky/pubky/pkg",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@types/babel__core": {
|
||||
"version": "7.20.5",
|
||||
@@ -2181,9 +2193,14 @@
|
||||
"optional": true
|
||||
},
|
||||
"@synonymdev/pubky": {
|
||||
"version": "0.1.13",
|
||||
"resolved": "https://registry.npmjs.org/@synonymdev/pubky/-/pubky-0.1.13.tgz",
|
||||
"integrity": "sha512-3Jo2W3lC6nXDD7ktHAREMqsU/u1cN+6Gvjdxn1iNr2wyznPBDqpuyGrc1w7N3Jy/3HzLtEemLodagNXxLIcudg=="
|
||||
"version": "file:../../pubky/pubky/pkg",
|
||||
"requires": {
|
||||
"browser-resolve": "^2.0.0",
|
||||
"esmify": "^2.1.1",
|
||||
"fetch-cookie": "^3.0.1",
|
||||
"tape": "^5.8.1",
|
||||
"tape-run": "^11.0.0"
|
||||
}
|
||||
},
|
||||
"@types/babel__core": {
|
||||
"version": "7.20.5",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^8.4.1",
|
||||
"@synonymdev/pubky": "^0.1.13",
|
||||
"@synonymdev/pubky": "file:../../pubky/pubky/pkg",
|
||||
"solid-js": "^1.8.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Explorer } from './Explorer.tsx'
|
||||
import { Spinner } from './Spinner.tsx'
|
||||
import { Show, createSignal, } from "solid-js"
|
||||
import { store, setStore, updateDir, resetStore, switchShallow, } from "./state.ts"
|
||||
import { DEMO_PUBKY, populate } from './example.ts'
|
||||
|
||||
|
||||
function App() {
|
||||
@@ -62,29 +61,6 @@ function App() {
|
||||
</input>
|
||||
<label for="s1-14">Shallow</label>
|
||||
</div>
|
||||
<button
|
||||
type='button'
|
||||
disabled={!!store.loading}
|
||||
class="demo-button"
|
||||
title="Explore a populated pubky"
|
||||
onclick={(e) => {
|
||||
e.preventDefault();
|
||||
|
||||
resetStore();
|
||||
|
||||
setStore("loading", true)
|
||||
populate().then(() => {
|
||||
updateDir(DEMO_PUBKY)
|
||||
setStore('explorer', true)
|
||||
setStore("loading", false)
|
||||
}).catch(e => {
|
||||
alert(e.message)
|
||||
})
|
||||
|
||||
}}>
|
||||
Demo
|
||||
</button>
|
||||
|
||||
<button type="submit" disabled={input().length === 0}>
|
||||
Explore
|
||||
</button>
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
import { Keypair, PublicKey } from "@synonymdev/pubky";
|
||||
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { client } from "./state";
|
||||
|
||||
const SECRET_KEY = new Uint8Array(32).fill(10)
|
||||
const KEYPAIR = Keypair.fromSecretKey(SECRET_KEY);
|
||||
const PUBKY = KEYPAIR.publicKey().z32()
|
||||
const HOMESERVER = PublicKey.from("8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo")
|
||||
|
||||
export const DEMO_PUBKY = PUBKY;
|
||||
|
||||
async function doneBefore() {
|
||||
let list = await client.list(`pubky://${PUBKY}/pub/airline/`).catch(_ => []);
|
||||
|
||||
return list?.length > 0
|
||||
}
|
||||
|
||||
export async function populate() {
|
||||
if (await doneBefore()) {
|
||||
return
|
||||
}
|
||||
|
||||
await client.signup(KEYPAIR, HOMESERVER);
|
||||
|
||||
let paths: Array<Array<string>> = [];
|
||||
|
||||
let structure = {
|
||||
"airline": { "aircraftType": ["airplane"] },
|
||||
"animal": {
|
||||
mamal: ["bear", "rabbit", "cat", "dog", "horse", "rodent"],
|
||||
reptile: ["snake"],
|
||||
marine: ["fish"],
|
||||
},
|
||||
"color": ["human", "rgb"],
|
||||
"finance": { "currency": ["iban"] },
|
||||
"location": {
|
||||
"country": {
|
||||
"city": {
|
||||
"street": [
|
||||
"zipCode"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"music": {
|
||||
"genre": ["songname"]
|
||||
},
|
||||
"vehicle": [
|
||||
"bicycle",
|
||||
],
|
||||
"word": [
|
||||
"adverb",
|
||||
"adjective",
|
||||
"noun"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
visit(structure, [], paths)
|
||||
|
||||
const morePaths: string[][] = []
|
||||
|
||||
paths.forEach(path => {
|
||||
for (let i = 0; i <= 100; i++) {
|
||||
let expanded: string[] = []
|
||||
|
||||
path.forEach((p, i) => {
|
||||
if (i === 0) {
|
||||
return expanded.push(p)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
let x = faker[path[0]][p]
|
||||
|
||||
x = x?.()
|
||||
|
||||
if (!x) {
|
||||
return expanded.push(p)
|
||||
} else {
|
||||
expanded.push(p)
|
||||
}
|
||||
|
||||
if (!(x instanceof Object)) {
|
||||
return expanded.push(x.replace(/[^a-zA-Z0-9-_]/g, ''))
|
||||
}
|
||||
|
||||
x = x.name
|
||||
|
||||
if (!(x instanceof Object)) {
|
||||
return expanded.push(x.replace(/[^a-zA-Z0-9-_]/g, ''))
|
||||
}
|
||||
|
||||
x = x.x
|
||||
|
||||
return expanded.push(x.replace(/[^a-zA-Z0-9-_]/g, ''))
|
||||
})
|
||||
|
||||
morePaths.push(expanded)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
for (let parts of morePaths) {
|
||||
await client.put(`pubky://${PUBKY}/pub/${parts.join('/')}`, new Uint8Array(5).fill(0))
|
||||
}
|
||||
}
|
||||
|
||||
function visit(obj: any, acc: string[] = [], paths: string[][]) {
|
||||
if (Array.isArray(obj)) {
|
||||
for (let i of obj) {
|
||||
paths.push([...acc, i])
|
||||
}
|
||||
} else {
|
||||
for (let branch in obj) {
|
||||
visit(obj[branch], [...acc, branch], paths)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PubkyClient } from '@synonymdev/pubky'
|
||||
import { createStore } from 'solid-js/store';
|
||||
|
||||
export const client = PubkyClient.testnet();
|
||||
export const client = new PubkyClient();
|
||||
|
||||
export const [store, setStore] = createStore<{
|
||||
explorer: Boolean,
|
||||
|
||||
Reference in New Issue
Block a user