Skip to content

Commit

Permalink
Merge branch 'test-sdks' of https://github.com/mendableai/firecrawl i…
Browse files Browse the repository at this point in the history
…nto test-sdks
  • Loading branch information
rafaelsideguide committed May 27, 2024
2 parents 19decd1 + 3c8edf6 commit 667d3e4
Show file tree
Hide file tree
Showing 13 changed files with 384 additions and 39 deletions.
7 changes: 7 additions & 0 deletions apps/api/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ kill_timeout = '5s'
hard_limit = 200
soft_limit = 100

[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
timeout = "5s"
path = "/"

[[services]]
protocol = 'tcp'
internal_port = 8080
Expand Down
20 changes: 11 additions & 9 deletions apps/api/src/controllers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { parseApi } from "../../src/lib/parseApi";
import { getRateLimiter, } from "../../src/services/rate-limiter";
import { getRateLimiter, } from "../../src/services/rate-limiter";
import { AuthResponse, RateLimiterMode } from "../../src/types";
import { supabase_service } from "../../src/services/supabase";
import { withAuth } from "../../src/lib/withAuth";
import { RateLimiterRedis } from "rate-limiter-flexible";
import { setTraceAttributes } from '@hyperdx/node-opentelemetry';

export async function authenticateUser(req, res, mode?: RateLimiterMode) : Promise<AuthResponse> {
export async function authenticateUser(req, res, mode?: RateLimiterMode): Promise<AuthResponse> {
return withAuth(supaAuthenticateUser)(req, res, mode);
}
function setTrace(team_id: string, api_key: string) {
Expand All @@ -18,7 +18,7 @@ function setTrace(team_id: string, api_key: string) {
} catch (error) {
console.error('Error setting trace attributes:', error);
}

}
export async function supaAuthenticateUser(
req,
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function supaAuthenticateUser(
team_id: team_id,
plan: plan
}
switch (mode) {
switch (mode) {
case RateLimiterMode.Crawl:
rateLimiter = getRateLimiter(RateLimiterMode.Crawl, token, subscriptionData.plan);
break;
Expand Down Expand Up @@ -126,9 +126,11 @@ export async function supaAuthenticateUser(
await rateLimiter.consume(iptoken);
} catch (rateLimiterRes) {
console.error(rateLimiterRes);
const secs = Math.round(rateLimiterRes.msBeforeNext / 1000) || 1;
const retryDate = new Date(Date.now() + rateLimiterRes.msBeforeNext);
return {
success: false,
error: "Rate limit exceeded. Too many requests, try again in 1 minute.",
error: `Rate limit exceeded. Consumed points: ${rateLimiterRes.consumedPoints}, Remaining points: ${rateLimiterRes.remainingPoints}. Please retry after ${secs}s, resets at ${retryDate}`,
status: 429,
};
}
Expand All @@ -155,9 +157,9 @@ export async function supaAuthenticateUser(
normalizedApi = parseApi(token);

const { data, error } = await supabase_service
.from("api_keys")
.select("*")
.eq("key", normalizedApi);
.from("api_keys")
.select("*")
.eq("key", normalizedApi);

if (error || !data || data.length === 0) {
return {
Expand All @@ -170,7 +172,7 @@ export async function supaAuthenticateUser(
subscriptionData = data[0];
}

return { success: true, team_id: subscriptionData.team_id };
return { success: true, team_id: subscriptionData.team_id };
}

function getPlanByPriceId(price_id: string) {
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/controllers/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export async function searchHelper(

const tbs = searchOptions.tbs ?? null;
const filter = searchOptions.filter ?? null;
const num_results = searchOptions.limit ?? 7;
const num_results_buffer = Math.floor(num_results * 1.5);

let res = await search({
query: query,
advanced: advanced,
num_results: searchOptions.limit ?? 7,
num_results: num_results_buffer,
tbs: tbs,
filter: filter,
lang: searchOptions.lang ?? "en",
Expand All @@ -47,6 +49,9 @@ export async function searchHelper(
}

res = res.filter((r) => !isUrlBlocked(r.url));
if (res.length > num_results) {
res = res.slice(0, num_results);
}

if (res.length === 0) {
return { success: true, error: "No search results found", returnCode: 200 };
Expand Down
1 change: 0 additions & 1 deletion apps/api/src/scraper/WebScraper/utils/blocklist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const socialMediaBlocklist = [
'facebook.com',
'twitter.com',
'x.com',
'instagram.com',
'linkedin.com',
'pinterest.com',
Expand Down
Loading

0 comments on commit 667d3e4

Please sign in to comment.