Skip to content

Commit f23828a

Browse files
authoredMar 1, 2025
Df/images (#25)
1 parent d8370a8 commit f23828a

File tree

16 files changed

+249
-216
lines changed

16 files changed

+249
-216
lines changed
 

Diff for: ‎apps/web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
},
4242
"devDependencies": {
4343
"@tailwindcss/postcss": "^4.0.9",
44+
"ethfs-cli": "^1.1.4",
4445
"tailwindcss": "3.4.1",
4546
"http-server": "^14.0.0"
4647
}

Diff for: ‎apps/web/src/components/Article.astro

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ console.log("article", article);
99
<article class="border-b border-gray-200 pb-4">
1010
<a href={`/article/${articleKey}`} class="block">
1111
<h3 class="text-xl font-semibold mb-2">{article?.data?.title || "Market Update"}</h3>
12+
<!-- <img src={"data:image/png;base64,"+article?.data?.image} alt="Article Image" class="w-full h-48 object-cover mb-2"/> -->
1213
<p class="text-gray-600 text-sm">
1314
{truncate(article?.data.content)}
1415
</p>

Diff for: ‎apps/web/src/components/local/TokenPriceChartWithProvider.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export const TokenPriceChartWithProvider = () => {
1515
chainId: 1,
1616
address: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
1717
},
18-
{
19-
chainId: 1,
20-
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
21-
},
18+
// {
19+
// chainId: 1,
20+
// address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
21+
// },
2222
]}
2323
/>
2424
</QueryClientProvider>

Diff for: ‎apps/web/src/components/token/token-price-chart-with-feed.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ export const TokenPriceChartWithFeed = ({
8484
) satisfies ChartConfig;
8585

8686
return (
87-
<div className="w-full h-full]">
87+
<div className="w-full h-[200px]">
8888
<ChartContainer
8989
config={chartConfig}
90-
style={{ height: "300px", width: "300px" }}
90+
style={{ height: "200px", width: "300px" }}
9191
>
9292
<LineChart accessibilityLayer data={chartData}>
9393
<CartesianGrid vertical={false} />

Diff for: ‎apps/web/src/content/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const articles = defineCollection({
3838
content,
3939
id: keys[i],
4040
title: titleResults[i]?.title,
41+
imgUrl: getUrl(keys[i]).replace(".md", ".png"),
4142
}));
4243
},
4344
});

Diff for: ‎apps/web/src/lib/defillama/api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function getChart(
6767

6868
const response = await ky(
6969
`${ENDPOINT_COINS}/chart/${tokenIds}?${new URLSearchParams({
70-
start: "1664364537",
70+
start: "1740125794",
7171
span: "10",
7272
// end: "1736827311",
7373
// searchWidth: "600",

Diff for: ‎apps/web/src/pages/article/[slug].astro

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@ export const getStaticPaths = (async () => {
1515
import { getCollection, getEntry, render } from "astro:content";
1616
import { marked } from "marked";
1717
18-
// const articles = await getCollection("articles");
19-
// console.log("article", articles?.[0].id);
20-
// const blog = await getEntry("articles", "a");
21-
2218
const { slug } = Astro.params;
23-
const entry = await getEntry("articles", `${slug}`);
19+
const article = await getEntry("articles", `${slug}`);
2420
25-
const content = marked.parse(entry?.data.content);
21+
const content = marked.parse(article?.data.content);
2622
---
2723
<Layout>
2824
<body class="bg-white font-sans text-gray-900">
2925
<Header />
3026
<div class="container mx-auto px-4 py-8 text-base/10">
27+
<!-- <img src={"data:image/png;base64,"+article?.data?.image} alt={article?.data.title} class="w-full h-96 object-cover rounded-lg" /> -->
3128
<article set:html={content} />
3229

3330
</div>

Diff for: ‎apps/web/src/pages/index.astro

+38-34
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,61 @@ import Article from "@/components/Article.astro";
1010
import { getCollection, getEntry, render } from "astro:content";
1111
import { truncate } from "@/lib/utils";
1212
import { marked } from "marked";
13-
import type { PriceResponse } from '@/types/price';
1413
1514
const articles = await getCollection("articles");
1615
1716
// Token addresses mapping
1817
const TOKEN_ADDRESSES = {
19-
20-
WETH: 'ethereum:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
21-
USDT: 'ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7',
22-
USDC: 'ethereum:0xA0b86991C6218B36c1d19D4a2e9Eb0cE3606EB48',
23-
ETH: 'coingecko:ethereum',
24-
DAI: 'ethereum:0x6B175474E89094C44Da98b954EedeAC495271d0F',
25-
LINK: 'ethereum:0x514910771AF9Ca656af840dff83E8264EcF986CA',
26-
UNI: 'ethereum:0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
27-
SHIB: 'ethereum:0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE',
28-
AAVE: 'ethereum:0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9',
29-
WBTC: 'ethereum:0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
30-
MKR: 'ethereum:0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2',
31-
COMP: 'ethereum:0xc00e94Cb662C3520282E6f5717214004A7f26888',
32-
CRO: 'ethereum:0xA0b73E1FF0B80914AB6FE0444e6586eB6fFf7eA6',
33-
SUSHI: 'ethereum:0x6B3595068778DD592e39A122f4f5a5CF09C90fE2',
34-
YFI: 'ethereum:0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
35-
BAT: 'ethereum:0x0D8775F648430679A709E98d2b0Cb6250d2887EF'
18+
WETH: "ethereum:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
19+
USDT: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7",
20+
USDC: "ethereum:0xA0b86991C6218B36c1d19D4a2e9Eb0cE3606EB48",
21+
ETH: "coingecko:ethereum",
22+
DAI: "ethereum:0x6B175474E89094C44Da98b954EedeAC495271d0F",
23+
LINK: "ethereum:0x514910771AF9Ca656af840dff83E8264EcF986CA",
24+
UNI: "ethereum:0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
25+
SHIB: "ethereum:0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
26+
AAVE: "ethereum:0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9",
27+
WBTC: "ethereum:0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
28+
MKR: "ethereum:0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2",
29+
COMP: "ethereum:0xc00e94Cb662C3520282E6f5717214004A7f26888",
30+
CRO: "ethereum:0xA0b73E1FF0B80914AB6FE0444e6586eB6fFf7eA6",
31+
SUSHI: "ethereum:0x6B3595068778DD592e39A122f4f5a5CF09C90fE2",
32+
YFI: "ethereum:0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e",
33+
BAT: "ethereum:0x0D8775F648430679A709E98d2b0Cb6250d2887EF",
3634
};
3735
3836
const currentTimestamp = Math.floor(Date.now() / 1000);
39-
const historicalTimestamp = currentTimestamp - (4 * 60 * 60); // 4 hours ago
40-
const addresses = Object.values(TOKEN_ADDRESSES).join(',');
37+
const historicalTimestamp = currentTimestamp - 4 * 60 * 60; // 4 hours ago
38+
const addresses = Object.values(TOKEN_ADDRESSES).join(",");
4139
4240
// Fetch both current and historical prices
4341
const [currentResponse, historicalResponse] = await Promise.all([
44-
fetch(`https://coins.llama.fi/prices/historical/${currentTimestamp}/${addresses}?searchWidth=4h`),
45-
fetch(`https://coins.llama.fi/prices/historical/${historicalTimestamp}/${addresses}?searchWidth=4h`)
42+
fetch(
43+
`https://coins.llama.fi/prices/historical/${currentTimestamp}/${addresses}?searchWidth=4h`,
44+
),
45+
fetch(
46+
`https://coins.llama.fi/prices/historical/${historicalTimestamp}/${addresses}?searchWidth=4h`,
47+
),
4648
]);
4749
4850
const [currentPriceData, historicalPriceData] = await Promise.all([
49-
currentResponse.json(),
50-
historicalResponse.json()
51+
currentResponse.json(),
52+
historicalResponse.json(),
5153
]);
5254
5355
// Process price data
5456
const tokens = Object.entries(TOKEN_ADDRESSES).map(([symbol, address]) => {
55-
const currentPrice = currentPriceData.coins[address]?.price || 0;
56-
const historicalPrice = historicalPriceData.coins[address]?.price || 0;
57-
const priceChange = historicalPrice ? ((currentPrice - historicalPrice) / historicalPrice) * 100 : 0;
58-
59-
return {
60-
symbol,
61-
price: currentPrice.toFixed(2),
62-
change: priceChange.toFixed(2)
63-
};
57+
const currentPrice = currentPriceData.coins[address]?.price || 0;
58+
const historicalPrice = historicalPriceData.coins[address]?.price || 0;
59+
const priceChange = historicalPrice
60+
? ((currentPrice - historicalPrice) / historicalPrice) * 100
61+
: 0;
62+
63+
return {
64+
symbol,
65+
price: currentPrice.toFixed(2),
66+
change: priceChange.toFixed(2),
67+
};
6468
});
6569
---
6670

@@ -134,7 +138,7 @@ const tokens = Object.entries(TOKEN_ADDRESSES).map(([symbol, address]) => {
134138
{/* Main Content Area */}
135139
<div class="lg:col-span-8">
136140
<article class="mb-8">
137-
<img src="/sample_image.jpg" alt="Featured Story" class="w-full h-96 object-cover mb-4"/>
141+
<img src={articles?.[0].data?.imgUrl} alt="Article Image" class="w-full h-96 object-cover mb-2"/>
138142
<h1 class="text-3xl font-bold mb-2">{articles?.[0].data.title}</h1>
139143
<p class="text-gray-600 mb-4">{truncate(articles?.[0].data.content)}</p>
140144
</article>

Diff for: ‎apps/web/src/types/price.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
export interface PriceResponse {
2-
coins: {
3-
[key: string]: {
4-
price: number;
5-
timestamp: number;
6-
};
7-
};
2+
coins: {
3+
[key: string]: {
4+
price: number;
5+
timestamp: number;
6+
};
7+
};
88
}
99

1010
export interface BatchPriceResponse {
11-
coins: {
12-
[key: string]: {
13-
prices: [number, number][]; // [timestamp, price][]
14-
symbol: string;
15-
};
16-
};
11+
coins: {
12+
[key: string]: {
13+
prices: [number, number][]; // [timestamp, price][]
14+
symbol: string;
15+
};
16+
};
1717
}

Diff for: ‎packages/agents/package.json

+52-52
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
{
2-
"name": "@seele/agents",
3-
"type": "module",
4-
"version": "0.0.0",
5-
"private": true,
6-
"exports": {
7-
"./*": "./src/*.tsx"
8-
},
9-
"scripts": {
10-
"generate:component": "turbo gen react-component",
11-
"check-types": "tsc --noEmit",
12-
"test": "vitest",
13-
"deploy:arweave": "ts-node src/utils/arweave/deploy.ts",
14-
"arkb": "arkb"
15-
},
16-
"devDependencies": {
17-
"@ar.io/sdk": "^3.8.2",
18-
"@ardrive/turbo-sdk": "^1.23.0",
19-
"@seele/access-gate": "workspace:*",
20-
"@seele/typescript-config": "workspace:*",
21-
"@turbo/gen": "^2.4.0",
22-
"@types/mime-types": "^2.1.4",
23-
"@types/node": "^22.13.0",
24-
"@types/react": "19.0.8",
25-
"@types/react-dom": "19.0.3",
26-
"arkb": "^1.1.61",
27-
"arweave": "^1.15.5",
28-
"eslint": "^9.20.0",
29-
"typescript": "5.7.3"
30-
},
31-
"dependencies": {
32-
"@ai-sdk/openai": "^1.1.13",
33-
"@ethereum-attestation-service/eas-sdk": "^2.7.0",
34-
"@seele/data-fetch": "workspace:*",
35-
"@statelyai/agent": "^1.1.6",
36-
"@tavily/core": "^0.3.1",
37-
"@types/lodash": "^4.17.15",
38-
"ai": "^4.1.46",
39-
"ethers": "v6.13.5",
40-
"graphql-request": "^6.1.0",
41-
"lodash": "^4.17.21",
42-
"mime-types": "^2.1.35",
43-
"openai": "^4.85.4",
44-
"react": "^19.0.0",
45-
"react-dom": "^19.0.0",
46-
"ts-node": "^10.9.2",
47-
"unstorage": "^1.15.0",
48-
"viem": "2.23.5",
49-
"vitest": "^3.0.6",
50-
"xstate": "^5.19.2",
51-
"zkverifyjs": "^0.6.0",
52-
"zod": "^3.24.2"
53-
}
2+
"name": "@seele/agents",
3+
"type": "module",
4+
"version": "0.0.0",
5+
"private": true,
6+
"exports": {
7+
"./*": "./src/*.tsx"
8+
},
9+
"scripts": {
10+
"generate:component": "turbo gen react-component",
11+
"check-types": "tsc --noEmit",
12+
"test": "vitest",
13+
"deploy:arweave": "ts-node src/utils/arweave/deploy.ts",
14+
"arkb": "arkb"
15+
},
16+
"devDependencies": {
17+
"@ar.io/sdk": "^3.8.2",
18+
"@ardrive/turbo-sdk": "^1.23.0",
19+
"@seele/access-gate": "workspace:*",
20+
"@seele/typescript-config": "workspace:*",
21+
"@turbo/gen": "^2.4.0",
22+
"@types/mime-types": "^2.1.4",
23+
"@types/node": "^22.13.0",
24+
"@types/react": "19.0.8",
25+
"@types/react-dom": "19.0.3",
26+
"arkb": "^1.1.61",
27+
"arweave": "^1.15.5",
28+
"eslint": "^9.20.0",
29+
"typescript": "5.7.3"
30+
},
31+
"dependencies": {
32+
"@ai-sdk/openai": "^1.1.13",
33+
"@ethereum-attestation-service/eas-sdk": "^2.7.0",
34+
"@seele/data-fetch": "workspace:*",
35+
"@statelyai/agent": "^1.1.6",
36+
"@tavily/core": "^0.3.1",
37+
"@types/lodash": "^4.17.15",
38+
"ai": "^4.1.46",
39+
"ethers": "v6.13.5",
40+
"graphql-request": "^6.1.0",
41+
"lodash": "^4.17.21",
42+
"mime-types": "^2.1.35",
43+
"openai": "^4.85.4",
44+
"react": "^19.0.0",
45+
"react-dom": "^19.0.0",
46+
"ts-node": "^10.9.2",
47+
"unstorage": "^1.15.0",
48+
"viem": "2.23.5",
49+
"vitest": "^3.0.6",
50+
"xstate": "^5.19.2",
51+
"zkverifyjs": "^0.6.0",
52+
"zod": "^3.24.2"
53+
}
5454
}

Diff for: ‎packages/agents/src/agents/manager.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getUIDsFromAttestReceipt,
55
} from "@ethereum-attestation-service/eas-sdk";
66
import { getEasDataByChain } from "@seele/access-gate/lib/eas/utils";
7-
import { generateText } from "ai";
7+
import { experimental_generateImage as generateImage, generateText } from "ai";
88
import { gql, rawRequest } from "graphql-request";
99
import _ from "lodash";
1010
import type { Address } from "viem";
@@ -73,6 +73,8 @@ export const deployArticles = async (articleMetas: ArticleMeta[]) => {
7373
for (let i = 0; i < articles.length; i++) {
7474
const article = articles[i]!;
7575

76+
let imageResults;
77+
7678
const titleResults = await generateText({
7779
model: agentParamsManager.model,
7880
prompt: `Summarize title for the article, do not include the word title in it.
@@ -88,6 +90,18 @@ export const deployArticles = async (articleMetas: ArticleMeta[]) => {
8890
`,
8991
});
9092

93+
if (i === 0) {
94+
imageResults = await generateImage({
95+
model: openai.image("dall-e-3"),
96+
prompt: `
97+
No Text, No Caption.
98+
News cover image for this title:
99+
${titleResults?.text}
100+
`,
101+
// size: '512x512'
102+
});
103+
}
104+
91105
await persistWithDirectory(
92106
{
93107
privateKey: privateKeyManager,
@@ -110,9 +124,24 @@ export const deployArticles = async (articleMetas: ArticleMeta[]) => {
110124
contentKey: article.key.replace(".md", ".json"),
111125
content: JSON.stringify({
112126
title: titleResults?.text,
127+
// image: imageResults?.image?.base64,
113128
}),
114129
},
115130
);
131+
132+
if (imageResults) {
133+
await persistWithDirectory(
134+
{
135+
privateKey: privateKeyManager,
136+
directoryAddress: directoryAddressManager,
137+
},
138+
{
139+
// namespace: "article",
140+
contentKey: article.key.replace(".md", ".png"),
141+
content: imageResults?.image?.uint8Array,
142+
},
143+
);
144+
}
116145
}
117146
};
118147

Diff for: ‎packages/agents/src/storage.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const persistWithDirectory = async (
4040
data: {
4141
namespace?: string;
4242
contentKey: string;
43-
content: string;
43+
content: string | Uint8Array;
4444
},
4545
) => {
4646
const { namespace, contentKey, content } = data;
@@ -50,11 +50,11 @@ export const persistWithDirectory = async (
5050
const key = [namespace, contentKey].filter(Boolean).join("/");
5151

5252
console.log("upload: key", key, "content", content);
53-
const dataBlob = Buffer.from(content);
53+
// const dataBlob = Buffer.from(content);
5454

5555
const request = {
5656
key,
57-
content: Buffer.from(content),
57+
content: typeof content === "string" ? Buffer.from(content) : content,
5858
type: FileType.Blob,
5959
};
6060

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import path from "node:path";
12
import { describe, it } from "vitest";
2-
import { deployWebApp } from "../deploy.js";
33
import { createWallet } from "../create-wallet.js";
4-
import path from "node:path";
4+
import { deployWebApp } from "../deploy.js";
55
describe("arweave - deploy", () => {
6-
it("should deploy the web app", async () => {
7-
// await createWallet();
8-
await deployWebApp("./dist");
9-
});
6+
it("should deploy the web app", async () => {
7+
// await createWallet();
8+
await deployWebApp("./dist");
9+
});
1010
});

Diff for: ‎packages/agents/src/utils/arweave/create-wallet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import fs from "node:fs";
22
import Arweave from "arweave";
33

44
export const createWallet = async (): Promise<void> => {
5-
const wallet = await new Arweave({}).wallets.generate();
6-
fs.writeFileSync("key.json", JSON.stringify(wallet));
5+
const wallet = await new Arweave({}).wallets.generate();
6+
fs.writeFileSync("key.json", JSON.stringify(wallet));
77
};
88

99
if (require.main === module) {
10-
createWallet();
10+
createWallet();
1111
}

Diff for: ‎packages/agents/src/utils/arweave/deploy.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
import mimeTypes from "mime-types";
43
import * as TurboSdk from "@ardrive/turbo-sdk";
4+
import mimeTypes from "mime-types";
55
console.log("Deploying website...");
66
function getAllFiles(dir, allFiles = []) {
7-
// biome-ignore lint/complexity/noForEach: <explanation>
8-
fs.readdirSync(dir).forEach((file) => {
9-
const filePath = path.join(dir, file);
10-
if (!fs.statSync(filePath).isDirectory()) return allFiles.push(filePath);
11-
getAllFiles(filePath, allFiles);
12-
});
13-
return allFiles;
7+
// biome-ignore lint/complexity/noForEach: <explanation>
8+
fs.readdirSync(dir).forEach((file) => {
9+
const filePath = path.join(dir, file);
10+
if (!fs.statSync(filePath).isDirectory()) return allFiles.push(filePath);
11+
getAllFiles(filePath, allFiles);
12+
});
13+
return allFiles;
1414
}
1515

1616
const file = fs.readFileSync("key.json", { encoding: "utf-8" });
1717

1818
const privateKey = JSON.parse(file);
1919
const turbo = TurboSdk.TurboFactory.authenticated({
20-
privateKey,
20+
privateKey,
2121
});
2222
const uploadResults = [];
2323
for (const filePath of getAllFiles("dist")) {
24-
console.log(`- ${filePath}`);
25-
const result = await turbo.uploadFile({
26-
fileStreamFactory: () => fs.createReadStream(filePath),
27-
fileSizeFactory: () => fs.statSync(filePath).size,
28-
dataItemOpts: {
29-
tags: [{ name: "Content-Type", value: mimeTypes.lookup(filePath) }],
30-
},
31-
});
32-
uploadResults.push({
33-
path: filePath
34-
.replaceAll(path.sep, "/")
35-
.replace("dist/", "")
36-
.replace("/index.html", "/"),
37-
txId: result.id,
38-
});
24+
console.log(`- ${filePath}`);
25+
const result = await turbo.uploadFile({
26+
fileStreamFactory: () => fs.createReadStream(filePath),
27+
fileSizeFactory: () => fs.statSync(filePath).size,
28+
dataItemOpts: {
29+
tags: [{ name: "Content-Type", value: mimeTypes.lookup(filePath) }],
30+
},
31+
});
32+
uploadResults.push({
33+
path: filePath
34+
.replaceAll(path.sep, "/")
35+
.replace("dist/", "")
36+
.replace("/index.html", "/"),
37+
txId: result.id,
38+
});
3939
}
4040
console.log("- manifest.json");
4141
const pathManifest = {
42-
manifest: "arweave/paths",
43-
version: "0.2.0",
44-
index: { path: "index.html" },
45-
paths: uploadResults.reduce(
46-
(paths, file) => ({ ...paths, [file.path]: { id: file.txId } }),
47-
{},
48-
),
42+
manifest: "arweave/paths",
43+
version: "0.2.0",
44+
index: { path: "index.html" },
45+
paths: uploadResults.reduce(
46+
(paths, file) => ({ ...paths, [file.path]: { id: file.txId } }),
47+
{},
48+
),
4949
};
5050
fs.writeFileSync("manifest.json", JSON.stringify(pathManifest));
5151
const result = await turbo.uploadFile({
52-
fileStreamFactory: () => fs.createReadStream("manifest.json"),
53-
fileSizeFactory: () => fs.statSync("manifest.json").size,
54-
dataItemOpts: {
55-
tags: [
56-
{ name: "Content-Type", value: "application/x.arweave-manifest+json" },
57-
],
58-
},
52+
fileStreamFactory: () => fs.createReadStream("manifest.json"),
53+
fileSizeFactory: () => fs.statSync("manifest.json").size,
54+
dataItemOpts: {
55+
tags: [
56+
{ name: "Content-Type", value: "application/x.arweave-manifest+json" },
57+
],
58+
},
5959
});
6060
fs.writeFileSync("deployment-id", result.id);
6161
console.log(`https://arweave.net/${result.id}`);

Diff for: ‎packages/agents/src/utils/arweave/deploy.ts

+54-54
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
import mimeTypes from "mime-types";
43
import * as TurboSdk from "@ardrive/turbo-sdk";
4+
import mimeTypes from "mime-types";
55

66
console.log("Deploying website...");
77
function getAllFiles(dir: string): string[] {
8-
const allFiles: string[] = [];
9-
for (const file of fs.readdirSync(dir)) {
10-
const filePath = path.join(dir, file);
11-
if (!fs.statSync(filePath).isDirectory()) allFiles.push(filePath);
12-
else allFiles.push(...getAllFiles(filePath));
13-
}
14-
return allFiles;
8+
const allFiles: string[] = [];
9+
for (const file of fs.readdirSync(dir)) {
10+
const filePath = path.join(dir, file);
11+
if (!fs.statSync(filePath).isDirectory()) allFiles.push(filePath);
12+
else allFiles.push(...getAllFiles(filePath));
13+
}
14+
return allFiles;
1515
}
1616

1717
export async function deployWebApp(distDir: string) {
18-
const turbo = TurboSdk.TurboFactory.authenticated({
19-
privateKey: JSON.parse(fs.readFileSync("key.json", { encoding: "utf-8" })),
20-
});
21-
const uploadResults = [];
22-
for (const filePath of getAllFiles(distDir)) {
23-
console.log(`- ${filePath}`);
24-
const result = await turbo.uploadFile({
25-
fileStreamFactory: () => fs.createReadStream(filePath),
26-
fileSizeFactory: () => fs.statSync(filePath).size,
27-
dataItemOpts: {
28-
tags: [
29-
{ name: "Content-Type", value: mimeTypes.lookup(filePath) || "" },
30-
],
31-
},
32-
});
33-
uploadResults.push({
34-
path: filePath
35-
.replaceAll(path.sep, "/")
36-
.replace(distDir, "")
37-
.replace("/index.html", "/"),
38-
txId: result.id,
39-
});
40-
}
41-
console.log("- manifest.json");
42-
const pathManifest = {
43-
manifest: "arweave/paths",
44-
version: "0.2.0",
45-
index: { path: "index.html" },
46-
paths: uploadResults.reduce(
47-
(paths, file) => Object.assign(paths, { [file.path]: { id: file.txId } }),
48-
{},
49-
),
50-
};
51-
fs.writeFileSync("manifest.json", JSON.stringify(pathManifest));
52-
const result = await turbo.uploadFile({
53-
fileStreamFactory: () => fs.createReadStream("manifest.json"),
54-
fileSizeFactory: () => fs.statSync("manifest.json").size,
55-
dataItemOpts: {
56-
tags: [
57-
{ name: "Content-Type", value: "application/x.arweave-manifest+json" },
58-
],
59-
},
60-
});
61-
fs.writeFileSync("deployment-id", result.id);
62-
console.log(`https://arweave.net/${result.id}`);
18+
const turbo = TurboSdk.TurboFactory.authenticated({
19+
privateKey: JSON.parse(fs.readFileSync("key.json", { encoding: "utf-8" })),
20+
});
21+
const uploadResults = [];
22+
for (const filePath of getAllFiles(distDir)) {
23+
console.log(`- ${filePath}`);
24+
const result = await turbo.uploadFile({
25+
fileStreamFactory: () => fs.createReadStream(filePath),
26+
fileSizeFactory: () => fs.statSync(filePath).size,
27+
dataItemOpts: {
28+
tags: [
29+
{ name: "Content-Type", value: mimeTypes.lookup(filePath) || "" },
30+
],
31+
},
32+
});
33+
uploadResults.push({
34+
path: filePath
35+
.replaceAll(path.sep, "/")
36+
.replace(distDir, "")
37+
.replace("/index.html", "/"),
38+
txId: result.id,
39+
});
40+
}
41+
console.log("- manifest.json");
42+
const pathManifest = {
43+
manifest: "arweave/paths",
44+
version: "0.2.0",
45+
index: { path: "index.html" },
46+
paths: uploadResults.reduce(
47+
(paths, file) => Object.assign(paths, { [file.path]: { id: file.txId } }),
48+
{},
49+
),
50+
};
51+
fs.writeFileSync("manifest.json", JSON.stringify(pathManifest));
52+
const result = await turbo.uploadFile({
53+
fileStreamFactory: () => fs.createReadStream("manifest.json"),
54+
fileSizeFactory: () => fs.statSync("manifest.json").size,
55+
dataItemOpts: {
56+
tags: [
57+
{ name: "Content-Type", value: "application/x.arweave-manifest+json" },
58+
],
59+
},
60+
});
61+
fs.writeFileSync("deployment-id", result.id);
62+
console.log(`https://arweave.net/${result.id}`);
6363
}
6464

6565
if (require.main === module) {
66-
deployWebApp("dist");
66+
deployWebApp("dist");
6767
}

0 commit comments

Comments
 (0)
Please sign in to comment.