xiongzhu 1 年間 前
コミット
06c0d6fb88
2 ファイル変更41 行追加7 行削除
  1. 39 1
      app.mjs
  2. 2 6
      login.mjs

+ 39 - 1
app.mjs

@@ -113,6 +113,22 @@ sequelize
             if (!settings.find((setting) => setting.name === "match_country")) {
                 Settings.create({ name: "match_country", value: "US,CA" });
             }
+            if (!settings.find((setting) => setting.name === "proxy_host")) {
+                Settings.create({
+                    name: "proxy_host",
+                    value: "199.188.93.128:8000",
+                });
+            }
+            if (
+                !settings.find((setting) => setting.name === "proxy_username")
+            ) {
+                Settings.create({ name: "proxy_username", value: "proxy" });
+            }
+            if (
+                !settings.find((setting) => setting.name === "proxy_password")
+            ) {
+                Settings.create({ name: "proxy_password", value: "40gyxQ2" });
+            }
         });
     })
     .catch((error) => {
@@ -201,8 +217,30 @@ fastify.post("/login", async function (request, reply) {
             .send({ error: "email and password are required" });
     } else {
         const { email, password } = request.body;
+        const proxy_host = (
+            await Settings.findOne({ where: { name: "proxy_host" } })
+        )?.value;
+        const proxy_username = (
+            await Settings.findOne({ where: { name: "proxy_username" } })
+        )?.value;
+        const proxy_password = (
+            await Settings.findOne({ where: { name: "proxy_password" } })
+        )?.value;
+        let proxy = null;
+        if (proxy_host && proxy_username && proxy_password) {
+            proxy = {
+                server: proxy_host,
+                username: proxy_username,
+                password: proxy_password,
+            };
+        }
+
         try {
-            const { points, cookies, options } = await login(email, password);
+            const { points, cookies, options } = await login(
+                email,
+                password,
+                proxy
+            );
             let balance = null;
             let dollarsRedeemable = null;
             if (points) {

+ 2 - 6
login.mjs

@@ -2,7 +2,7 @@ import { chromium } from "playwright";
 import uniqueRandomArray from "unique-random-array";
 import userAgents from "top-user-agents";
 
-export async function login(email, password) {
+export async function login(email, password, proxy) {
     const browser = await chromium.launch({
         headless: true,
         devtools: false,
@@ -17,11 +17,7 @@ export async function login(email, password) {
         locale: "en-CA",
         timezoneId: "America/Toronto",
         serviceWorkers: "block",
-        proxy: {
-            server: "199.188.93.128:8000",
-            username: "proxy",
-            password: "40gyxQ2",
-        },
+        proxy,
     };
 
     const context = await browser.newContext(options);