Feat: add auto download frp.exe

This commit is contained in:
unitwk 2023-01-15 15:16:10 +08:00
parent b166a3b180
commit 2c848665f2
3 changed files with 8 additions and 1 deletions

View File

@ -52,12 +52,17 @@ export default class OpenFrpTask implements ILifeCycleTask {
if (!openFrpToken || !openFrpTunnelId) return; if (!openFrpToken || !openFrpTunnelId) return;
if (!fs.existsSync(OpenFrpTask.FRP_EXE_PATH)) { if (!fs.existsSync(OpenFrpTask.FRP_EXE_PATH)) {
const tmpTask = setInterval(() => {
instance.println("FRP", $t("frp.installing"));
}, 1000);
try { try {
await downloadFileToLocalFile(OpenFrpTask.FRP_DOWNLOAD_ADDR + OpenFrpTask.FRP_EXE_NAME, OpenFrpTask.FRP_EXE_PATH); await downloadFileToLocalFile(OpenFrpTask.FRP_DOWNLOAD_ADDR + OpenFrpTask.FRP_EXE_NAME, OpenFrpTask.FRP_EXE_PATH);
} catch (error) { } catch (error) {
logger.error($t("frp.downloadErr"), error); logger.error($t("frp.downloadErr"), error);
fs.remove(OpenFrpTask.FRP_EXE_PATH, () => {}); fs.remove(OpenFrpTask.FRP_EXE_PATH, () => {});
return; return;
} finally {
clearInterval(tmpTask);
} }
} }

View File

@ -220,6 +220,7 @@
"hiperError": "网络映射进程已存在,不可重复启动!" "hiperError": "网络映射进程已存在,不可重复启动!"
}, },
"frp": { "frp": {
"downloadErr": "下载 FRP 应用程序失败,无法正常启动 FRP 内网映射程序。" "downloadErr": "下载 FRP 应用程序失败,无法正常启动 FRP 内网映射程序。",
"installing": "正在同时下载并安装 FRP 内网映射程序,稍后我们将自动启动映射功能"
} }
} }

View File

@ -10,6 +10,7 @@ export function downloadFileToLocalFile(url: string, localFilePath: string): Pro
logger.info(`Download File: ${url} --> ${path.normalize(localFilePath)}`); logger.info(`Download File: ${url} --> ${path.normalize(localFilePath)}`);
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
if (fs.existsSync(localFilePath)) fs.removeSync(localFilePath);
const writeStream = fs.createWriteStream(path.normalize(localFilePath)); const writeStream = fs.createWriteStream(path.normalize(localFilePath));
const response = await axios<Readable>({ const response = await axios<Readable>({
url, url,