mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-03 23:33:37 +08:00
feat: 添加钉钉登录
This commit is contained in:
@@ -1,64 +1,23 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const Axios = require('axios')
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
async function downloadFile(url) {
|
||||
try {
|
||||
const iconPath = path.resolve(__dirname, '../src/assets/fonts/iconfont.js')
|
||||
const iconDir = path.dirname(iconPath)
|
||||
|
||||
// 检查目录是否存在,如果不存在则创建
|
||||
if (!fs.existsSync(iconDir)) {
|
||||
console.log(`目录 ${iconDir} 不存在,正在创建...`)
|
||||
fs.mkdirSync(iconDir, { recursive: true })
|
||||
console.log('目录创建成功')
|
||||
}
|
||||
|
||||
console.log(`开始下载图标文件到: ${iconPath}`)
|
||||
|
||||
const writer = fs.createWriteStream(iconPath)
|
||||
const response = await Axios({
|
||||
url: `https:${url}`,
|
||||
method: 'GET',
|
||||
responseType: 'stream',
|
||||
timeout: 30000, // 30秒超时
|
||||
})
|
||||
|
||||
response.data.pipe(writer)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on('finish', () => {
|
||||
console.log('图标文件下载成功!')
|
||||
resolve()
|
||||
})
|
||||
writer.on('error', (err) => {
|
||||
console.error('写入文件时出错:', err.message)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('下载过程中出错:', error.message)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
const iconPath = path.resolve(__dirname, "../src/assets/fonts/iconfont.js");
|
||||
const iconDir = path.dirname(iconPath);
|
||||
|
||||
async function main() {
|
||||
const argument = process.argv.splice(2)
|
||||
|
||||
if (!argument[0]) {
|
||||
console.error('错误: 请提供下载URL作为参数')
|
||||
console.log('使用方法: node downLoadIcon.cjs <url>')
|
||||
process.exit(1)
|
||||
// 检查目录是否存在,不存在则创建
|
||||
if (!fs.existsSync(iconDir)) {
|
||||
fs.mkdirSync(iconDir, { recursive: true });
|
||||
console.log(`目录 ${iconDir} 已创建`);
|
||||
}
|
||||
|
||||
try {
|
||||
await downloadFile(argument[0])
|
||||
console.log('所有操作完成!')
|
||||
} catch (error) {
|
||||
console.error('脚本执行失败:', error.message)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
const response = await fetch(`https:${url}`, {
|
||||
method: "GET",
|
||||
// responseType: "stream", // fetch 不支持此参数
|
||||
}).then((res) => res.text());
|
||||
fs.writeFileSync(iconPath, response);
|
||||
console.log("Download Icon Success");
|
||||
}
|
||||
let argument = process.argv.splice(2);
|
||||
downloadFile(argument[0]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user