-
Notifications
You must be signed in to change notification settings - Fork 749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] implement a github proxy to avoid rate limits #905
Comments
Let me help design a solution to avoid GitHub API rate limits when downloading pipes. Here's a proposed approach using Supabase storage and a periodic sync mechanism:
// Add near imports
import { createClient } from '@supabase/supabase-js';
// Add this helper function
async function downloadFromProxy(url: string): Promise<Response | null> {
try {
// Extract repo info from GitHub URL
const match = url.match(/github\.com\/([^\/]+)\/([^\/]+)/);
if (!match) return null;
const [_, owner, repo] = match;
// Try to fetch from our proxy first
const proxyUrl = `https://screenpipe-proxy.supabase.co/storage/v1/pipes/${owner}/${repo}/latest.zip`;
const response = await fetch(proxyUrl);
if (!response.ok) return null;
return response;
} catch (error) {
console.error("proxy fetch failed:", error);
return null;
}
}
// Update the handleDownloadPipe function
const handleDownloadPipe = async (url: string) => {
try {
posthog.capture("download_pipe", { pipe_id: url });
// Show progress toast
const t = toast({
title: "downloading pipe",
description: (
<div className="space-y-2">
<Progress value={0} className="h-1" />
<p className="text-xs">starting download...</p>
</div>
),
duration: 100000,
});
// Try proxy first
const proxyResponse = await downloadFromProxy(url);
// If proxy fails, fall back to direct GitHub
const response = await fetch("http://localhost:3030/pipes/download", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
url,
proxyData: proxyResponse ? await proxyResponse.arrayBuffer() : null
}),
});
// Rest of the existing code...
} catch (error) {
console.error("Failed to download pipe:", error);
toast({
title: "error downloading pipe",
description: "please try again or check the logs for more information.",
variant: "destructive",
});
}
};
# .github/workflows/sync-pipes.yml
name: Sync Pipes to Storage
on:
schedule:
- cron: '0 */6 * * *' # Every 6 hours
workflow_dispatch: # Manual trigger
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm install @supabase/supabase-js
- name: Sync pipes
run: node scripts/sync-pipes.js
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
// scripts/sync-pipes.js
const { createClient } = require('@supabase/supabase-js');
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_KEY
);
// List of pipes to sync
const PIPES = [
{ owner: 'mediar-ai', repo: 'screenpipe', path: 'pipes/data-table' },
// Add other pipes here
];
async function syncPipe(pipe) {
const { owner, repo, path: pipePath } = pipe;
// Create temp dir
const tempDir = `/tmp/${owner}-${repo}`;
execSync(`rm -rf ${tempDir}`);
execSync(`mkdir -p ${tempDir}`);
// Clone repo
execSync(`git clone https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${owner}/${repo}.git ${tempDir}`);
// Create zip
const zipPath = `${tempDir}/pipe.zip`;
execSync(`cd ${tempDir}/${pipePath} && zip -r ${zipPath} .`);
// Upload to Supabase
const { error } = await supabase.storage
.from('pipes')
.upload(`${owner}/${repo}/latest.zip`, fs.readFileSync(zipPath));
if (error) throw error;
}
async function main() {
for (const pipe of PIPES) {
try {
await syncPipe(pipe);
console.log(`Synced ${pipe.owner}/${pipe.repo}`);
} catch (error) {
console.error(`Failed to sync ${pipe.owner}/${pipe.repo}:`, error);
}
}
}
main(); This solution:
Benefits:
Let me know if you'd like me to explain any part in more detail or make adjustments to the implementation! |
dont like this solution we should probably just be able to say pipes.rs to use another URL as download api - like env var simple one file change + just copy pasting the code in object storage |
/bounty 120 suggest idea first - i can give you access to supabase, cloudflare, gcp, aws, azure whatever |
💎 $120 bounty • Screenpi.peSteps to solve:
Thank you for contributing to mediar-ai/screenpipe! Add a bounty • Share on socials
|
Hi, @louis030195. Here's my solution to the problem.
This way we don't have to put much stuff on api or ratelimits etc (as long as it's open and github doesn't put restrictions). Please let me know if this solution works or help in any way. |
💡 @neo773 submitted a pull request that claims the bounty. You can visit your bounty board to reward. |
🎉🎈 @neo773 has been awarded $120! 🎈🎊 |
when downloading stuff from screenpipe's store i regularly get rate limited
we could store a recent version of repo in an api and expose it
The text was updated successfully, but these errors were encountered: