From 61f8d6585ef2ed68e0e14342f921ce3886cae59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E8=AA=89=E7=A8=8B?= <2659568239@qq.com> Date: Thu, 22 Feb 2024 15:02:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B06?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodeService.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/nodeService.js b/nodeService.js index 5f325e5..fcd78da 100644 --- a/nodeService.js +++ b/nodeService.js @@ -58,27 +58,29 @@ app.post('/createShortcut', (req, res) => { return res.status(400).send('少了参数!'); } - // if (!fs.existsSync(folderPath)) { - // fs.mkdirSync(folderPath, { - // recursive: true - // }); - // } + if (!fs.existsSync(folderPath)) { + fs.mkdirSync(folderPath, { + recursive: true + }); + } const shortcutLinkPath = path.join(folderPath, shortcutName); - // if (fs.existsSync(shortcutLinkPath)) { - // fs.unlinkSync(shortcutLinkPath); - // } + if (fs.existsSync(shortcutLinkPath)) { + fs.unlinkSync(shortcutLinkPath); + } + + // 创建快捷方式 + const shortcutFolderPath = path.join(folderPath, shortcutName); + const shortcutFileContent = `[InternetShortcut]\nURL=${shortcutURL}`; - console.log('shortcutURL', shortcutURL); - console.log('shortcutLinkPath', shortcutLinkPath); - fs.symlink(shortcutURL, shortcutLinkPath, 'file', (err) => { + fs.writeFile(shortcutFolderPath, shortcutFileContent, (err) => { if (err) { console.error(err); - res.status(500).send('安装失败'); - return; + res.status(500).send('安装失败!'); + } else { + res.status(200).send('安装成功!'); } - res.send('安装成功'); }); // // 快捷方式的配置