nacho commited on
Commit
072194e
·
1 Parent(s): 5332bb0

feat: 将最大并发浏览器数量限制开放至 Web 网页控制台动态配置

Browse files
Files changed (2) hide show
  1. main.py +3 -0
  2. static/index.html +13 -5
main.py CHANGED
@@ -667,6 +667,8 @@ def _apply_settings(data: dict):
667
  enabled=data["log_file_enabled"],
668
  max_mb=data.get("log_file_max_mb", 10),
669
  )
 
 
670
  if "accounts" in data:
671
  for acc in data["accounts"]:
672
  if acc.get("email") and acc.get("password") and acc.get("email") not in manager.accounts:
@@ -708,6 +710,7 @@ async def get_settings(admin_key: str = Header(...)):
708
  "log_level": logging.getLogger().level,
709
  "log_file_enabled": _file_handler is not None,
710
  "log_file_max_mb": _load_settings().get("log_file_max_mb", 10),
 
711
  }
712
 
713
 
 
667
  enabled=data["log_file_enabled"],
668
  max_mb=data.get("log_file_max_mb", 10),
669
  )
670
+ if "max_active_browsers" in data:
671
+ manager.max_active_browsers = max(1, int(data["max_active_browsers"]))
672
  if "accounts" in data:
673
  for acc in data["accounts"]:
674
  if acc.get("email") and acc.get("password") and acc.get("email") not in manager.accounts:
 
710
  "log_level": logging.getLogger().level,
711
  "log_file_enabled": _file_handler is not None,
712
  "log_file_max_mb": _load_settings().get("log_file_max_mb", 10),
713
+ "max_active_browsers": manager.max_active_browsers,
714
  }
715
 
716
 
static/index.html CHANGED
@@ -285,11 +285,17 @@ select{cursor:pointer;appearance:none;background-image:url("data:image/svg+xml,%
285
  <label>API Keys(每行一个)</label>
286
  <textarea id="setApiKeys" placeholder="sk-key1&#10;sk-key2" style="min-height:60px"></textarea>
287
  </div>
288
- <div class="form-group">
289
- <label>Admin Key</label>
290
- <input type="password" id="setAdminKey" placeholder="管理密钥">
 
 
 
 
 
 
291
  </div>
292
- <div style="margin-top:14px;padding-top:14px;border-top:1px solid var(--border)">
293
  <div class="form-group">
294
  <label>日志文件</label>
295
  <div class="row" style="gap:10px">
@@ -596,6 +602,7 @@ async function loadSettings(){
596
  const d=await api('/admin/settings',{headers:{'admin-key':getAdminKey()}});
597
  document.getElementById('setApiKeys').value=(d.api_keys||[]).join('\n');
598
  document.getElementById('setAdminKey').value=d.admin_key||'';
 
599
  document.getElementById('setLogFile').checked=d.log_file_enabled||false;
600
  document.getElementById('setLogMaxMb').value=d.log_file_max_mb||10;
601
  // Update level buttons
@@ -609,11 +616,12 @@ async function saveSettings(){
609
  const ak=document.getElementById('setAdminKey').value.trim();
610
  const logFile=document.getElementById('setLogFile').checked;
611
  const logMax=parseInt(document.getElementById('setLogMaxMb').value)||10;
 
612
  if(!keys.length){toast('请至少填写一个 API Key',0);return}
613
  try{
614
  await api('/admin/settings',{
615
  method:'POST',json:true,
616
- body:JSON.stringify({api_keys:keys,admin_key:ak||undefined,log_file_enabled:logFile,log_file_max_mb:logMax}),
617
  headers:{'admin-key':getAdminKey()}
618
  });
619
  if(ak&&ak!==_adminKey){_adminKey=ak;LS.set('adminKey',ak)}
 
285
  <label>API Keys(每行一个)</label>
286
  <textarea id="setApiKeys" placeholder="sk-key1&#10;sk-key2" style="min-height:60px"></textarea>
287
  </div>
288
+ <div class="row" style="gap:10px">
289
+ <div class="form-group" style="flex:1">
290
+ <label>Admin Key</label>
291
+ <input type="password" id="setAdminKey" placeholder="管理密钥">
292
+ </div>
293
+ <div class="form-group" style="flex:1">
294
+ <label>并发浏览器数量</label>
295
+ <input type="number" id="setMaxBrowsers" placeholder="3" title="建议1核机器设为2-3">
296
+ </div>
297
  </div>
298
+ <div style="margin-top:0px;padding-top:14px;border-top:1px solid var(--border)">
299
  <div class="form-group">
300
  <label>日志文件</label>
301
  <div class="row" style="gap:10px">
 
602
  const d=await api('/admin/settings',{headers:{'admin-key':getAdminKey()}});
603
  document.getElementById('setApiKeys').value=(d.api_keys||[]).join('\n');
604
  document.getElementById('setAdminKey').value=d.admin_key||'';
605
+ document.getElementById('setMaxBrowsers').value=d.max_active_browsers||3;
606
  document.getElementById('setLogFile').checked=d.log_file_enabled||false;
607
  document.getElementById('setLogMaxMb').value=d.log_file_max_mb||10;
608
  // Update level buttons
 
616
  const ak=document.getElementById('setAdminKey').value.trim();
617
  const logFile=document.getElementById('setLogFile').checked;
618
  const logMax=parseInt(document.getElementById('setLogMaxMb').value)||10;
619
+ const maxBrowsers=parseInt(document.getElementById('setMaxBrowsers').value)||3;
620
  if(!keys.length){toast('请至少填写一个 API Key',0);return}
621
  try{
622
  await api('/admin/settings',{
623
  method:'POST',json:true,
624
+ body:JSON.stringify({api_keys:keys,admin_key:ak||undefined,max_active_browsers:maxBrowsers,log_file_enabled:logFile,log_file_max_mb:logMax}),
625
  headers:{'admin-key':getAdminKey()}
626
  });
627
  if(ak&&ak!==_adminKey){_adminKey=ak;LS.set('adminKey',ak)}