mirror of
https://github.com/aljazceru/pubky-explorer.git
synced 2025-12-17 05:54:27 +01:00
Merge branch 'pubky:pubky-explorer' into pubky-explorer
This commit is contained in:
2
.env-sample
Normal file
2
.env-sample
Normal file
@@ -0,0 +1,2 @@
|
||||
# Read from the local homeserver for testing
|
||||
VITE_TESTNET=true
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,6 +7,9 @@ yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Environment file
|
||||
.env
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
|
||||
58
package-lock.json
generated
58
package-lock.json
generated
@@ -9,7 +9,7 @@
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^8.4.1",
|
||||
"@synonymdev/pubky": "^0.1.16",
|
||||
"@synonymdev/pubky": "^0.4.0-rc3",
|
||||
"solid-js": "^1.8.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -956,9 +956,13 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@synonymdev/pubky": {
|
||||
"version": "0.1.16",
|
||||
"resolved": "https://registry.npmjs.org/@synonymdev/pubky/-/pubky-0.1.16.tgz",
|
||||
"integrity": "sha512-jtFahEUUDfrTE7vpZx6m/uB4wMEBoqpEtuUoWCf30HH8cmm0Hfrv8v0xmwaSwPfSdcZlIG8beE5XjbX+eLmLUA=="
|
||||
"version": "0.4.0-rc3",
|
||||
"resolved": "https://registry.npmjs.org/@synonymdev/pubky/-/pubky-0.4.0-rc3.tgz",
|
||||
"integrity": "sha512-x8Tpw/oPBEC/osbSS4kouFtbcIfNuhtmXbbAnChy76VPz6N9ubuGZc0agKhEmmzfGk0BLtM5wyCgah1xc2jbqg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fetch-cookie": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/babel__core": {
|
||||
"version": "7.20.5",
|
||||
@@ -1253,6 +1257,16 @@
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fetch-cookie": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fetch-cookie/-/fetch-cookie-3.1.0.tgz",
|
||||
"integrity": "sha512-s/XhhreJpqH0ftkGVcQt8JE9bqk+zRn4jF5mPJXWZeQMCI5odV9K+wEWYbnzFPHgQZlvPSMjS4n4yawWE8RINw==",
|
||||
"license": "Unlicense",
|
||||
"dependencies": {
|
||||
"set-cookie-parser": "^2.4.8",
|
||||
"tough-cookie": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
||||
@@ -1631,6 +1645,12 @@
|
||||
"seroval": "^1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/set-cookie-parser": {
|
||||
"version": "2.7.1",
|
||||
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.1.tgz",
|
||||
"integrity": "sha512-IOc8uWeOZgnb3ptbCURJWNjWUPcO3ZnTTdzsurqERrP6nPyv+paC55vJM0LpOlT2ne+Ix+9+CRG1MNLlyZ4GjQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/solid-js": {
|
||||
"version": "1.9.2",
|
||||
"resolved": "https://registry.npmjs.org/solid-js/-/solid-js-1.9.2.tgz",
|
||||
@@ -1676,6 +1696,24 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/tldts": {
|
||||
"version": "6.1.73",
|
||||
"resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.73.tgz",
|
||||
"integrity": "sha512-/h4bVmuEMm57c2uCiAf1Q9mlQk7cA22m+1Bu0K92vUUtTVT9D4mOFWD9r4WQuTULcG9eeZtNKhLl0Il1LdKGog==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tldts-core": "^6.1.73"
|
||||
},
|
||||
"bin": {
|
||||
"tldts": "bin/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/tldts-core": {
|
||||
"version": "6.1.73",
|
||||
"resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.73.tgz",
|
||||
"integrity": "sha512-k1g5eX87vxu3g//6XMn62y4qjayu4cYby/PF7Ksnh4F4uUK1Z1ze/mJ4a+y5OjdJ+cXRp+YTInZhH+FGdUWy1w==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/to-fast-properties": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
@@ -1685,6 +1723,18 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/tough-cookie": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.0.tgz",
|
||||
"integrity": "sha512-rvZUv+7MoBYTiDmFPBrhL7Ujx9Sk+q9wwm22x8c8T5IJaR+Wsyc7TNxbVxo84kZoRJZZMazowFLqpankBEQrGg==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"tldts": "^6.1.32"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^8.4.1",
|
||||
"@synonymdev/pubky": "^0.1.16",
|
||||
"@synonymdev/pubky": "^0.4.0-rc3",
|
||||
"solid-js": "^1.8.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -3,7 +3,7 @@ import './css/App.css'
|
||||
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 { store, setStore, updateDir, switchShallow, } from "./state.ts"
|
||||
|
||||
|
||||
function App() {
|
||||
|
||||
@@ -91,4 +91,7 @@ input:focus-visible {
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
input {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
|
||||
53
src/state.ts
53
src/state.ts
@@ -1,7 +1,9 @@
|
||||
import { PubkyClient } from '@synonymdev/pubky'
|
||||
import { Client } from '@synonymdev/pubky'
|
||||
import { createStore } from 'solid-js/store';
|
||||
|
||||
export const client = new PubkyClient();
|
||||
export const client = import.meta.env.VITE_TESTNET == "true" ?
|
||||
Client.testnet() :
|
||||
new Client();
|
||||
|
||||
export const [store, setStore] = createStore<{
|
||||
explorer: Boolean,
|
||||
@@ -73,6 +75,14 @@ export function loadMore() {
|
||||
// @ts-ignore
|
||||
setStore('list', Array.from(map.values()))
|
||||
setStore('dir', path)
|
||||
})
|
||||
.catch((e: String) => {
|
||||
setStore('loading', false)
|
||||
if (e === "error sending request") {
|
||||
console.log(e, ": cannot reach homeserver or pk does not exist")
|
||||
} else {
|
||||
console.log("ERROR: ", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,25 +110,30 @@ export function updateDir(path: string) {
|
||||
loadList()
|
||||
}
|
||||
|
||||
export function downloadFile(link: string) {
|
||||
export async function downloadFile(link: string) {
|
||||
setStore("loading", true);
|
||||
|
||||
client.get(link).then(bytes => {
|
||||
if (bytes) {
|
||||
try {
|
||||
const response: Response = await client.fetch(link);
|
||||
|
||||
const element = document.createElement('a');
|
||||
|
||||
const fileBlob = new Blob([bytes]);
|
||||
|
||||
element.href = URL.createObjectURL(fileBlob);
|
||||
let parts = link.split('/')
|
||||
element.download = parts[parts.length - 1];
|
||||
document.body.appendChild(element); // Required for this to work in FireFox
|
||||
element.click();
|
||||
|
||||
element.remove()
|
||||
setStore("loading", false);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch file: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fileBlob: Blob = await response.blob();
|
||||
|
||||
const element = document.createElement('a');
|
||||
element.href = URL.createObjectURL(fileBlob);
|
||||
const parts = link.split('/');
|
||||
element.download = parts[parts.length - 1];
|
||||
|
||||
document.body.appendChild(element);
|
||||
element.click();
|
||||
element.remove();
|
||||
} catch (err: unknown) {
|
||||
console.error("Error fetching file:", err);
|
||||
}
|
||||
finally {
|
||||
setStore("loading", false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user