From 93cb6622822decaff08a660ba305cb6a562d4a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 14 May 2024 10:16:30 +0800 Subject: [PATCH] refactor: scipt and request --- script/napcat-utf8.ps1 | 1 - script/napcat.ps1 | 1 - src/common/utils/request.ts | 5 +++-- src/common/utils/umami.ts | 18 +++++++++++------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/script/napcat-utf8.ps1 b/script/napcat-utf8.ps1 index ada7f56f..7b05d0cd 100644 --- a/script/napcat-utf8.ps1 +++ b/script/napcat-utf8.ps1 @@ -2,7 +2,6 @@ function Get-QQpath { try { $key = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" $uninstallString = $key.UninstallString - throw "get QQ path error:" return [System.IO.Path]::GetDirectoryName($uninstallString) + "\QQ.exe" } catch { throw "get QQ path error: $_" diff --git a/script/napcat.ps1 b/script/napcat.ps1 index f760eb52..a6bcfb2f 100644 --- a/script/napcat.ps1 +++ b/script/napcat.ps1 @@ -2,7 +2,6 @@ function Get-QQpath { try { $key = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" $uninstallString = $key.UninstallString - throw "get QQ path error:" return [System.IO.Path]::GetDirectoryName($uninstallString) + "\QQ.exe" } catch { throw "get QQ path error: $_" diff --git a/src/common/utils/request.ts b/src/common/utils/request.ts index 17e6c6dd..d5c063d2 100644 --- a/src/common/utils/request.ts +++ b/src/common/utils/request.ts @@ -63,9 +63,10 @@ export class RequestUtil { try { let response; if (method.toUpperCase() === 'POST') { - response = await fetch(url, { ...requestInit, body: data }); + //console.log({ method: 'POST', ...requestInit, body: data }); + response = await fetch(url, { method: 'POST', ...requestInit, body: data }); } else { - response = await fetch(url, { ...requestInit }); + response = await fetch(url, { method: method, ...requestInit }); } if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); diff --git a/src/common/utils/umami.ts b/src/common/utils/umami.ts index fbdb1532..991f4535 100644 --- a/src/common/utils/umami.ts +++ b/src/common/utils/umami.ts @@ -14,12 +14,16 @@ export async function postLoginStatus() { 'referrer': 'https://napcat.demo.cn/login?type=onebot11' } }; - await RequestUtil.HttpGetText('https://napcat.wumiao.wang/api/send', - 'POST', - StatesData, { - 'Content-Type': 'application/json', - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0' - }); - resolve(true); + try { + await RequestUtil.HttpGetText('https://napcat.wumiao.wang/api/send', + 'POST', + JSON.stringify(StatesData), { + 'Content-Type': 'application/json', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0' + }); + resolve(true); + } catch { + reject('umami post failed') + } }); }