mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 22:59:04 +08:00
Revert "feat(v1/map): timeout"
This reverts commit 57e98e83d7ab43249963b0a14c157aaec7fd4ec7.
This commit is contained in:
parent
57e98e83d7
commit
831c61706d
@ -1,42 +0,0 @@
|
|||||||
import request from "supertest";
|
|
||||||
import { configDotenv } from "dotenv";
|
|
||||||
import { MapRequestInput } from "../../controllers/v1/types";
|
|
||||||
|
|
||||||
configDotenv();
|
|
||||||
const TEST_URL = "http://127.0.0.1:3002";
|
|
||||||
|
|
||||||
async function map(body: MapRequestInput) {
|
|
||||||
return await request(TEST_URL)
|
|
||||||
.post("/v1/map")
|
|
||||||
.set("Authorization", `Bearer ${process.env.TEST_API_KEY}`)
|
|
||||||
.set("Content-Type", "application/json")
|
|
||||||
.send(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
function expectMapToSucceed(response: Awaited<ReturnType<typeof map>>) {
|
|
||||||
expect(response.statusCode).toBe(200);
|
|
||||||
expect(response.body.success).toBe(true);
|
|
||||||
expect(Array.isArray(response.body.links)).toBe(true);
|
|
||||||
expect(response.body.links.length).toBeGreaterThan(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("Map tests", () => {
|
|
||||||
it("basic map succeeds", async () => {
|
|
||||||
const response = await map({
|
|
||||||
url: "http://firecrawl.dev",
|
|
||||||
});
|
|
||||||
|
|
||||||
expectMapToSucceed(response);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("times out properly", async () => {
|
|
||||||
const response = await map({
|
|
||||||
url: "http://firecrawl.dev",
|
|
||||||
timeout: 1
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(response.statusCode).toBe(408);
|
|
||||||
expect(response.body.success).toBe(false);
|
|
||||||
expect(response.body.error).toBe("Request timed out");
|
|
||||||
});
|
|
||||||
});
|
|
@ -276,10 +276,7 @@ export async function mapController(
|
|||||||
) {
|
) {
|
||||||
req.body = mapRequestSchema.parse(req.body);
|
req.body = mapRequestSchema.parse(req.body);
|
||||||
|
|
||||||
let result: Awaited<ReturnType<typeof getMapResults>>;
|
const result = await getMapResults({
|
||||||
try {
|
|
||||||
result = await Promise.race([
|
|
||||||
getMapResults({
|
|
||||||
url: req.body.url,
|
url: req.body.url,
|
||||||
search: req.body.search,
|
search: req.body.search,
|
||||||
limit: req.body.limit,
|
limit: req.body.limit,
|
||||||
@ -289,21 +286,7 @@ export async function mapController(
|
|||||||
origin: req.body.origin,
|
origin: req.body.origin,
|
||||||
teamId: req.auth.team_id,
|
teamId: req.auth.team_id,
|
||||||
plan: req.auth.plan,
|
plan: req.auth.plan,
|
||||||
}),
|
|
||||||
...(req.body.timeout !== undefined ? [
|
|
||||||
new Promise((resolve, reject) => setTimeout(() => reject("timeout"), req.body.timeout))
|
|
||||||
] : []),
|
|
||||||
]) as any;
|
|
||||||
} catch (error) {
|
|
||||||
if (error === "timeout") {
|
|
||||||
return res.status(408).json({
|
|
||||||
success: false,
|
|
||||||
error: "Request timed out",
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bill the team
|
// Bill the team
|
||||||
billTeam(req.auth.team_id, req.acuc?.sub_id, 1).catch((error) => {
|
billTeam(req.auth.team_id, req.acuc?.sub_id, 1).catch((error) => {
|
||||||
|
@ -429,7 +429,6 @@ export const mapRequestSchema = crawlerOptions
|
|||||||
ignoreSitemap: z.boolean().default(false),
|
ignoreSitemap: z.boolean().default(false),
|
||||||
sitemapOnly: z.boolean().default(false),
|
sitemapOnly: z.boolean().default(false),
|
||||||
limit: z.number().min(1).max(5000).default(5000),
|
limit: z.number().min(1).max(5000).default(5000),
|
||||||
timeout: z.number().positive().finite().optional(),
|
|
||||||
})
|
})
|
||||||
.strict(strictMessage);
|
.strict(strictMessage);
|
||||||
|
|
||||||
@ -439,7 +438,6 @@ export const mapRequestSchema = crawlerOptions
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
export type MapRequest = z.infer<typeof mapRequestSchema>;
|
export type MapRequest = z.infer<typeof mapRequestSchema>;
|
||||||
export type MapRequestInput = z.input<typeof mapRequestSchema>;
|
|
||||||
|
|
||||||
export type Document = {
|
export type Document = {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -235,7 +235,6 @@ export interface MapParams {
|
|||||||
includeSubdomains?: boolean;
|
includeSubdomains?: boolean;
|
||||||
sitemapOnly?: boolean;
|
sitemapOnly?: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
timeout?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user