mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-05 17:00:44 +08:00
Nick: log su usage
This commit is contained in:
parent
0512ad6bce
commit
6567ef81f6
@ -5,6 +5,7 @@ import "dotenv/config";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { configDotenv } from "dotenv";
|
||||
import { saveJobToGCS } from "../../lib/gcs-jobs";
|
||||
import { logStealthUsage } from "./temp-stealth-log";
|
||||
configDotenv();
|
||||
|
||||
function cleanOfNull<T>(x: T): T {
|
||||
@ -109,6 +110,10 @@ export async function logJob(job: FirecrawlJob, force: boolean = false) {
|
||||
if (process.env.FIRE_INDEX_SERVER_URL) {
|
||||
indexJob(job);
|
||||
}
|
||||
|
||||
if (job.scrapeOptions?.proxy === "stealth" && job.team_id) {
|
||||
logStealthUsage(job.team_id);
|
||||
}
|
||||
|
||||
if (process.env.GCS_BUCKET_NAME) {
|
||||
await saveJobToGCS(job);
|
||||
|
43
apps/api/src/services/logging/temp-stealth-log.ts
Normal file
43
apps/api/src/services/logging/temp-stealth-log.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { cacheRedis } from "../../lib/cache";
|
||||
import { logger } from "../../lib/logger";
|
||||
import { supabase_service } from "../supabase";
|
||||
|
||||
export async function logStealthUsage(team_id: string) {
|
||||
try {
|
||||
let useCache = true;
|
||||
if (!cacheRedis) {
|
||||
useCache = false;
|
||||
}
|
||||
// Check Redis first
|
||||
const redisKey = `stealth_usage:${team_id}`;
|
||||
const exists = useCache ? await cacheRedis?.get(redisKey) : false;
|
||||
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check DB if not in Redis
|
||||
const { data } = await supabase_service
|
||||
.from("stealth_usage")
|
||||
.select("team_id")
|
||||
.eq("team_id", team_id);
|
||||
|
||||
if (!data?.length) {
|
||||
// Insert into DB
|
||||
const { error } = await supabase_service.from("stealth_usage").insert([
|
||||
{
|
||||
team_id,
|
||||
},
|
||||
]);
|
||||
|
||||
if (error) {
|
||||
logger.error("Failed to log stealth usage", { error, team_id });
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Cache in Redis for future lookups
|
||||
await cacheRedis?.set(redisKey, "1", "EX", 60 * 60 * 24 * 10); // Cache for 10 days
|
||||
} catch (err) {
|
||||
logger.error("Error logging stealth usage", { error: err, team_id });
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user