Skip to content

Commit 90a0c3a

Browse files
feat(sdk): add arweave upload size limit
1 parent b882f7e commit 90a0c3a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

packages/sdk/src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const CHAIN_CONFIG: Record<ChainId, ChainConfig> = {
2929
export const DEFAULT_CHAIN_ID = 134;
3030
export const DEFAULT_ARWEAVE_UPLOAD_API = 'http://localhost:3000'; // TODO change this
3131
export const DEFAULT_ARWEAVE_GATEWAY = 'https://arweave.net';
32+
export const ARWEAVE_FREE_UPLOAD_MAX_SIZE = 100 * 1024; // 100kb
3233
export const DEFAULT_DATA_NAME = '';
3334
export const SCONE_TAG = ['tee', 'scone'];
3435
export const DEFAULT_MAX_PRICE = 0;

packages/sdk/src/services/arweave.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
DEFAULT_ARWEAVE_GATEWAY,
33
DEFAULT_ARWEAVE_UPLOAD_API,
4+
ARWEAVE_FREE_UPLOAD_MAX_SIZE,
45
} from '../config/config.js';
56

67
interface AddOptions {
@@ -12,8 +13,15 @@ const add = async (
1213
content: Uint8Array,
1314
{ arweaveGateway, arweaveUploadApi }: AddOptions = {}
1415
): Promise<string> => {
15-
let arweaveId: string;
16+
if (content.length >= ARWEAVE_FREE_UPLOAD_MAX_SIZE) {
17+
throw Error(
18+
`Arweave upload ${(ARWEAVE_FREE_UPLOAD_MAX_SIZE / 1024).toFixed(
19+
0
20+
)}kb size limit reached`
21+
);
22+
}
1623

24+
let arweaveId: string;
1725
try {
1826
const payload = new FormData();
1927
payload.append('file', new Blob([content]));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, it } from '@jest/globals';
2+
import { ARWEAVE_FREE_UPLOAD_MAX_SIZE } from '../../../src/config/config.js';
3+
import * as arweave from '../../../src/services/arweave.js';
4+
5+
describe('arweave.add()', () => {
6+
describe('when content to upload is too large', () => {
7+
it('throws an error', async () => {
8+
const content = Buffer.alloc(ARWEAVE_FREE_UPLOAD_MAX_SIZE, 0);
9+
await expect(arweave.add(content)).rejects.toThrow(
10+
Error('Arweave upload 100kb size limit reached')
11+
);
12+
});
13+
});
14+
});

0 commit comments

Comments
 (0)