Skip to content

Commit

Permalink
Refactor example to use Node
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Aug 23, 2024
1 parent c643fa5 commit 2a6ba2a
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 134 deletions.
1 change: 1 addition & 0 deletions examples/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.15.0
1 change: 1 addition & 0 deletions examples/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.15.0
21 changes: 21 additions & 0 deletions examples/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const BUNDLE_ID = process.env.BUNDLE_ID;

if (!BUNDLE_ID) {
console.error("BUNDLE_ID must be present in the environment");
process.exit(1);
}

console.log(`Downloading bundle: ${BUNDLE_ID}`);

const url = `http://0.0.0.0:5558/files/${BUNDLE_ID}`;

const response = await fetch(url);

if (!response.ok) {
console.error(`Failed to download bundle. Status code: ${response.status}`);
process.exit(1);
}

const text = await response.text();

console.log(`Downloaded bundle with content: ${text}`);
71 changes: 0 additions & 71 deletions examples/fetch-bundle.py

This file was deleted.

6 changes: 6 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "xmtp-message-history-server-example",
"version": "0.0.0",
"private": true,
"type": "module"
}
2 changes: 0 additions & 2 deletions examples/requirements.txt

This file was deleted.

5 changes: 0 additions & 5 deletions examples/test_bundle.jsonl

This file was deleted.

1 change: 1 addition & 0 deletions examples/test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
56 changes: 0 additions & 56 deletions examples/upload-bundle.py

This file was deleted.

26 changes: 26 additions & 0 deletions examples/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";

const file = readFileSync(join(import.meta.dirname, "test_file.txt"), {
encoding: "utf-8",
});

console.log(`Uploading file test_file.txt with content: ${file}`);

const response = await fetch("http://0.0.0.0:5558/upload", {
method: "POST",
body: file,
});

if (response.ok) {
console.log("File uploaded successfully");
} else {
console.error(`Failed to upload file. Status code: ${response.status}`);
process.exit(1);
}

const bundleId = await response.text();
console.log(`Bundle ID: ${bundleId}`);
console.log(
`Run "BUNDLE_ID=${bundleId} node download.js" to download the file`
);

0 comments on commit 2a6ba2a

Please sign in to comment.