almost working upload and download examples

This commit is contained in:
Ben 2025-05-26 10:46:02 +02:00
parent 29997f6009
commit 162aac8f5d
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
3 changed files with 70 additions and 0 deletions

37
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.16",
"license": "MIT",
"dependencies": {
"@codex-storage/sdk-js": "^0.1.2",
"axios": "^1.6.2",
"boxen": "^7.1.1",
"chalk": "^5.3.0",
@ -39,6 +40,20 @@
"integrity": "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==",
"license": "MIT"
},
"node_modules/@codex-storage/sdk-js": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@codex-storage/sdk-js/-/sdk-js-0.1.2.tgz",
"integrity": "sha512-QOi2gONLA9G1LVtFJLl9WjjZbAAvf4j1VVEAm//BUjUJi0xay309fb1z0kuW771ybNA+KHnVaYQu+RJS1K518Q==",
"dependencies": {
"valibot": "^1.0.0"
},
"engines": {
"node": ">=20.18.1"
},
"peerDependencies": {
"undici": "^7.7.0"
}
},
"node_modules/@esbuild/aix-ppc64": {
"version": "0.25.0",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.0.tgz",
@ -2325,6 +2340,15 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/undici": {
"version": "7.10.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-7.10.0.tgz",
"integrity": "sha512-u5otvFBOBZvmdjWLVW+5DAc9Nkq8f24g0O9oY7qw2JVIF1VocIFoyz9JFkuVOS2j41AufeO0xnlweJ2RLT8nGw==",
"peer": true,
"engines": {
"node": ">=20.18.1"
}
},
"node_modules/undici-types": {
"version": "6.19.8",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
@ -2346,6 +2370,19 @@
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT"
},
"node_modules/valibot": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/valibot/-/valibot-1.1.0.tgz",
"integrity": "sha512-Nk8lX30Qhu+9txPYTwM0cFlWLdPFsFr6LblzqIySfbZph9+BFsAHsNvHOymEviUepeIW6KFHzpX8TKhbptBXXw==",
"peerDependencies": {
"typescript": ">=5"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
},
"node_modules/vite": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/vite/-/vite-6.2.0.tgz",

View File

@ -24,6 +24,7 @@
"author": "Codex Storage",
"license": "MIT",
"dependencies": {
"@codex-storage/sdk-js": "^0.1.2",
"axios": "^1.6.2",
"boxen": "^7.1.1",
"chalk": "^5.3.0",

View File

@ -1,3 +1,6 @@
import { Codex } from "@codex-storage/sdk-js";
import { NodeUploadStategy } from "@codex-storage/sdk-js/node";
export class MainMenu {
constructor(
uiService,
@ -60,6 +63,10 @@ export class MainMenu {
label: "Stop Codex",
action: this.stopCodex,
},
{
label: "DoThing",
action: this.doThing,
},
{
label: "Exit (Codex keeps running)",
action: this.loop.stopLoop,
@ -109,4 +116,29 @@ export class MainMenu {
this.ui.showErrorMessage(`Failed to stop Codex. "${exception}"`);
}
};
doThing = async () => {
console.log("A!");
const codex = new Codex("http://localhost:8080");
const data = codex.data;
const stategy = new NodeUploadStategy("Hello World !");
const uploadResponse = data.upload(stategy);
const res = await uploadResponse.result;
if (res.error) {
console.error(res.data);
return;
}
console.info("CID is", res.data);
const cid = res.data;
const result = await data.networkDownloadStream(cid);
console.log("download: " + JSON.stringify(result));
}
}