feat: add proxy server
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import path from "node:path";
|
||||
|
||||
export const PROXY_SERVER = Deno.env.get("PROXY_SERVER");
|
||||
export const PROXY_USERNAME = Deno.env.get("PROXY_USERNAME");
|
||||
export const PROXY_PASSWORD = Deno.env.get("PROXY_PASSWORD");
|
||||
|
||||
export const SILVERBULLET_SERVER = Deno.env.get("SILVERBULLET_SERVER");
|
||||
export const TMDB_API_KEY = Deno.env.get("TMDB_API_KEY");
|
||||
export const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
|
||||
|
@@ -226,5 +226,5 @@ export async function extractRecipe(content: string) {
|
||||
response_format: zodResponseFormat(recipeResponseSchema, "recipe-v2"),
|
||||
});
|
||||
|
||||
return recipeSchema.parse(completion.choices[0].message.parsed);
|
||||
return recipeResponseSchema.parse(completion.choices[0].message.parsed);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { firefox } from "npm:playwright-extra";
|
||||
import { createStreamResponse } from "@lib/helpers.ts";
|
||||
import StealthPlugin from "npm:puppeteer-extra-plugin-stealth";
|
||||
import * as env from "@lib/env.ts";
|
||||
|
||||
const userAgentStrings = [
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.2227.0 Safari/537.36",
|
||||
@@ -16,9 +17,18 @@ export async function fetchHtmlWithPlaywright(
|
||||
streamResponse: ReturnType<typeof createStreamResponse>,
|
||||
): Promise<string> {
|
||||
streamResponse.enqueue("booting up playwright");
|
||||
|
||||
|
||||
const config: Parameters<typeof firefox.launch>[0] = {};
|
||||
if (env.PROXY_SERVER) {
|
||||
config.proxy = {
|
||||
server: env.PROXY_SERVER,
|
||||
username: env.PROXY_USERNAME,
|
||||
password: env.PROXY_PASSWORD,
|
||||
};
|
||||
}
|
||||
|
||||
// Launch the Playwright browser
|
||||
const browser = await firefox.launch();
|
||||
const browser = await firefox.launch(config);
|
||||
|
||||
streamResponse.enqueue("fetching html");
|
||||
|
||||
|
@@ -44,4 +44,14 @@ const noRecipeSchema = z.object({
|
||||
|
||||
export const recipeResponseSchema = z.union([recipeSchema, noRecipeSchema]);
|
||||
|
||||
export function isValidRecipe(
|
||||
recipe:
|
||||
| { ingredients?: unknown[]; instructions?: string[]; name?: string }
|
||||
| null
|
||||
| undefined,
|
||||
) {
|
||||
return recipe?.ingredients?.length && recipe?.instructions?.length &&
|
||||
recipe.name?.length;
|
||||
}
|
||||
|
||||
export default recipeSchema;
|
||||
|
Reference in New Issue
Block a user