diff --git a/nodeService.js b/nodeService.js index f5afe37..c79a2a6 100644 --- a/nodeService.js +++ b/nodeService.js @@ -48,14 +48,20 @@ app.use(bodyParser.json()); // linux系统下创建快捷方式接口 app.post('/createShortcut', (req, res) => { - const { folderPath, shortcutName, shortcutURL } = req.body; + const { + folderPath, + shortcutName, + shortcutURL + } = req.body; if (!folderPath || !shortcutName || !shortcutURL) { return res.status(400).send('少了参数!'); } if (!fs.existsSync(folderPath)) { - fs.mkdirSync(folderPath, { recursive: true }); + fs.mkdirSync(folderPath, { + recursive: true + }); } const shortcutLinkPath = path.join(folderPath, shortcutName); @@ -64,7 +70,36 @@ app.post('/createShortcut', (req, res) => { fs.unlinkSync(shortcutLinkPath); } - fs.symlink(shortcutURL, shortcutLinkPath, 'file', (err) => { + // 快捷方式的配置 + const config = { + name: shortcutName, + exec: 'x-www-browser', + // icon: '/path/to/favicon.png', // 图标路径,可选 + icon: '', + url: shortcutURL, + terminal: false, + type: 'Application', + categories: 'Network;WebBrowser;' + }; + + // 快捷方式文件内容 + let desktopFileContent = `[Desktop Entry] + Name=${config.name} + Exec=${config.exec} ${config.url} + Type=${config.type} + Icon=${config.icon || ''} + Terminal=${config.terminal} + Categories=${config.categories} + Comment=Open ${config.name} in your web browser`; + + // 如果有图标路径,确保图标文件存在 + // if (config.icon && !fs.existsSync(config.icon)) { + // console.error('Icon file does not exist.'); + // process.exit(1); + // } + + // 创建快捷方式文件 + fs.writeFile(shortcutLinkPath, desktopFileContent, 'utf8', function (err) { if (err) { console.error(err); res.status(500).send('安装失败!'); @@ -72,6 +107,18 @@ app.post('/createShortcut', (req, res) => { res.status(200).send('安装成功!'); } }); + + // fs.symlink(shortcutURL, shortcutLinkPath, 'file', (err) => { + // if (err) { + // console.error(err); + // res.status(500).send('安装失败!'); + // } else { + // res.status(200).send('安装成功!'); + // } + // }); + + + }); // 运行项目 需要进入到当前的文件夹目录打开终端 执行 node nodeService.js