Skip to content

Commit

Permalink
Merge pull request #25 from labscommunity/fix/free-uploads-limit
Browse files Browse the repository at this point in the history
fix: Fetch turbo free uploads limit & send repoId over Github sync trigger
  • Loading branch information
pawanpaudel93 authored Mar 11, 2024
2 parents 46477c1 + 0cb9b91 commit 323b060
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changeset/kind-goats-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@protocol.land/git-remote-helper': minor
---

- fix: Fetch turbo free upload limit & send repo id over github sync api call #25
- feat: Clone repo using username/repoName or repo id #26
- perf: Improve warp caching #27
- feat: support tx subsidization #28
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ This command sets the global threshold cost for push consent to `0.0003 AR`. Whe

Here's how it decides when to ask for your consent before uploading:

- **No Set Threshold**: Without the threshold set, you'll only be asked for consent if the upload size exceeds the free subsidy size (For example: Turbo bundler used here allows upto 500KB uploads for free).
- **No Set Threshold**: Without the threshold set, you'll only be asked for consent if the upload size exceeds the free subsidy size (For example: Turbo bundler used here allows upto 105KB uploads for free).
- **Over the Threshold**: If the upload cost is more than the threshold, consent is requested only if the upload size is larger than what's freely allowed.
- **Under the Threshold**: For costs below the threshold, consent isn't needed, and uploads proceed automatically.

Expand Down
24 changes: 22 additions & 2 deletions src/lib/arweaveHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ const shouldPushChanges = async (
}
};

async function getTurboSubsidy() {
const defaultSubsidy = 107520;
try {
const response = await fetch('https://turbo.ardrive.io/');
if (!response.ok) return defaultSubsidy;

const data = (await response.json()) as {
freeUploadLimitBytes: number;
};

const freeUploadLimitBytes = +data.freeUploadLimitBytes;

if (Number.isFinite(freeUploadLimitBytes)) return freeUploadLimitBytes;

return defaultSubsidy;
} catch (err) {}
return defaultSubsidy;
}

export async function uploadRepo(
zipBuffer: Buffer,
tags: Tag[],
Expand All @@ -127,8 +146,9 @@ export async function uploadRepo(
//continue
}

// 500KB subsidySize for TurboUpload and 0 subsidySize for ArweaveUpload
const subsidySize = Math.max(500 * 1024, 0);
// 105KB subsidySize for TurboUpload and 0 subsidySize for ArweaveUpload
const turboSubsidySize = await getTurboSubsidy();
const subsidySize = Math.max(turboSubsidySize, 0);
const pushChanges = await shouldPushChanges(
uploadSize,
uploadCost,
Expand Down
5 changes: 4 additions & 1 deletion src/lib/githubSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export async function triggerGithubSync(repo: Repo) {
'X-GitHub-Api-Version': '2022-11-28',
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({ ref: githubSync?.branch, inputs: {} }),
body: JSON.stringify({
ref: githubSync?.branch,
inputs: { repoId: repo.id },
}),
}
);

Expand Down

0 comments on commit 323b060

Please sign in to comment.