Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/cloudflare-worker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,7 @@ function readLimits(env) {
maxShareBytes: envInt(env, "MAX_SHARE_BYTES", maxBlobBytes + maxManifestBytes),
maxTitleChars: envInt(env, "MAX_TITLE_CHARS", 180),
maxThreadIDChars: envInt(env, "MAX_THREAD_ID_CHARS", 128),
maxTtlSeconds: envInt(env, "MAX_TTL_SECONDS", 24 * 60 * 60),
maxTtlSeconds: envInt(env, "MAX_TTL_SECONDS", 7 * 24 * 60 * 60),
maxDownloadsPerShare: envInt(env, "MAX_DOWNLOADS_PER_SHARE", 10),
liveBytesLimit: envInt(env, "LIVE_BYTES_LIMIT", 4 * GB),
monthlyGbDaysLimit: envInt(env, "MONTHLY_GB_DAYS_LIMIT", 120),
Expand Down
9 changes: 8 additions & 1 deletion deploy/cloudflare-worker/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ import worker, { BudgetGate } from "../src/index.js";

const BASE_URL = "https://capsule.example";
const DEFAULT_INSTALL_COMMAND = "curl -fsSL https://raw.githubusercontent.com/z2z23n0/agent-capsule/main/install.sh | sh";
const DEFAULT_TTL_SECONDS = 7 * 24 * 60 * 60;

test("anonymous upload/download happy path", async () => {
const env = fakeEnv();
const blob = new Blob([new Uint8Array([1, 2, 3])], { type: "application/octet-stream" });
const uploadStartedAt = Date.now();
const upload = await worker.fetch(new Request(BASE_URL + "/v1/shares", {
method: "POST",
body: shareForm(blob)
}), env);
const uploadFinishedAt = Date.now();
assert.equal(upload.status, 201);
const created = await upload.json();
assert.match(created.share_url, /^https:\/\/capsule\.example\/s\//);
assert.ok(Date.parse(created.expires_at) >= uploadStartedAt + DEFAULT_TTL_SECONDS * 1000);
assert.ok(Date.parse(created.expires_at) <= uploadFinishedAt + DEFAULT_TTL_SECONDS * 1000);
const shareID = new URL(created.share_url).pathname.split("/").pop();
assert.match(shareID, /^[A-Za-z0-9_-]{16}$/);
assert.equal(created.manifest_url, BASE_URL + "/v1/shares/" + shareID);
Expand All @@ -33,7 +38,9 @@ test("anonymous upload/download happy path", async () => {

const caps = await worker.fetch(new Request(BASE_URL + "/v1/capabilities"), env);
assert.equal(caps.status, 200);
assert.equal((await caps.json()).max_blob_bytes, 32 * 1024 * 1024);
const capabilities = await caps.json();
assert.equal(capabilities.max_blob_bytes, 32 * 1024 * 1024);
assert.equal(capabilities.max_ttl_seconds, DEFAULT_TTL_SECONDS);
});

test("configured BYO token gates uploads but not public reads", async () => {
Expand Down
2 changes: 1 addition & 1 deletion deploy/cloudflare-worker/wrangler.production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MAX_BLOB_BYTES = "33554432"
MAX_MANIFEST_BYTES = "8388608"
MAX_PREVIEW_PAYLOAD_BYTES = "6291456"
MAX_REQUEST_BYTES = "42008576"
MAX_TTL_SECONDS = "86400"
MAX_TTL_SECONDS = "604800"
MAX_DOWNLOADS_PER_SHARE = "10"
LIVE_BYTES_LIMIT = "4294967296"
MONTHLY_GB_DAYS_LIMIT = "120"
Expand Down
2 changes: 1 addition & 1 deletion deploy/cloudflare-worker/wrangler.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MAX_BLOB_BYTES = "33554432"
MAX_MANIFEST_BYTES = "8388608"
MAX_PREVIEW_PAYLOAD_BYTES = "6291456"
MAX_REQUEST_BYTES = "42008576"
MAX_TTL_SECONDS = "86400"
MAX_TTL_SECONDS = "604800"
MAX_DOWNLOADS_PER_SHARE = "10"
LIVE_BYTES_LIMIT = "4294967296"
MONTHLY_GB_DAYS_LIMIT = "120"
Expand Down
Loading