mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-11 07:57:28 +00:00
refactor: 代码质量清理与日志规范化
- 替换 System.out.println/printStackTrace 为 Logger: MkgsTool, PodTool, WsTool, IpExtractor, ReqIpUtil, LogStatistics - JsPlaygroundLogger 日志列表限制最大 1000 条防止内存泄漏 - JsScriptLoader JarFile 改用 try-with-resources 防止文件句柄泄漏 - DbServiceImpl Thread.sleep 改为 vertx.setTimer 避免阻塞 event loop - 删除未使用的 api.js,删除空的 ParserApiClientLinkTest - 移除前端未使用的导入和死代码 (downloaderService, monacoTypes) - 提取 previewBaseUrl 到 constants.js 常量文件
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
import axios from 'axios'
|
||||
|
||||
// 创建 axios 实例
|
||||
const api = axios.create({
|
||||
baseURL: process.env.VUE_APP_API_BASE_URL || 'http://localhost:6400',
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
// 请求拦截器
|
||||
api.interceptors.request.use(
|
||||
config => {
|
||||
// 可以在这里添加认证token等
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 响应拦截器
|
||||
api.interceptors.response.use(
|
||||
response => {
|
||||
return response.data
|
||||
},
|
||||
error => {
|
||||
console.error('API请求错误:', error)
|
||||
|
||||
if (error.response) {
|
||||
// 服务器返回错误状态码
|
||||
const message = error.response.data?.message || error.response.data?.error || '服务器错误'
|
||||
return Promise.reject(new Error(message))
|
||||
} else if (error.request) {
|
||||
// 网络错误
|
||||
return Promise.reject(new Error('网络连接失败,请检查网络设置'))
|
||||
} else {
|
||||
// 其他错误
|
||||
return Promise.reject(new Error(error.message || '请求失败'))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
// 客户端链接 API
|
||||
export const clientLinksApi = {
|
||||
/**
|
||||
* 获取所有客户端下载链接
|
||||
* @param {string} shareUrl - 分享链接
|
||||
* @param {string} password - 提取码(可选)
|
||||
* @returns {Promise} 客户端链接响应
|
||||
*/
|
||||
async getClientLinks(shareUrl, password = '') {
|
||||
const params = new URLSearchParams()
|
||||
params.append('url', shareUrl)
|
||||
if (password) {
|
||||
params.append('pwd', password)
|
||||
}
|
||||
|
||||
return await api.get(`/v2/clientLinks?${params.toString()}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取指定类型的客户端下载链接
|
||||
* @param {string} shareUrl - 分享链接
|
||||
* @param {string} password - 提取码(可选)
|
||||
* @param {string} clientType - 客户端类型
|
||||
* @returns {Promise} 指定类型的客户端链接
|
||||
*/
|
||||
async getClientLink(shareUrl, password = '', clientType) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('url', shareUrl)
|
||||
if (password) {
|
||||
params.append('pwd', password)
|
||||
}
|
||||
params.append('clientType', clientType)
|
||||
|
||||
return await api.get(`/v2/clientLink?${params.toString()}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 其他 API(如果需要的话)
|
||||
export const parserApi = {
|
||||
/**
|
||||
* 解析分享链接
|
||||
* @param {string} shareUrl - 分享链接
|
||||
* @param {string} password - 提取码(可选)
|
||||
* @returns {Promise} 解析结果
|
||||
*/
|
||||
async parseLink(shareUrl, password = '') {
|
||||
const params = new URLSearchParams()
|
||||
params.append('url', shareUrl)
|
||||
if (password) {
|
||||
params.append('pwd', password)
|
||||
}
|
||||
|
||||
return await api.get(`/v2/linkInfo?${params.toString()}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param {string} shareUrl - 分享链接
|
||||
* @param {string} password - 提取码(可选)
|
||||
* @param {string} dirId - 目录ID(可选)
|
||||
* @param {string} uuid - UUID(可选)
|
||||
* @returns {Promise} 文件列表
|
||||
*/
|
||||
async getFileList(shareUrl, password = '', dirId = '', uuid = '') {
|
||||
const params = new URLSearchParams()
|
||||
params.append('url', shareUrl)
|
||||
if (password) {
|
||||
params.append('pwd', password)
|
||||
}
|
||||
if (dirId) {
|
||||
params.append('dirId', dirId)
|
||||
}
|
||||
if (uuid) {
|
||||
params.append('uuid', uuid)
|
||||
}
|
||||
|
||||
return await api.get(`/v2/getFileList?${params.toString()}`)
|
||||
}
|
||||
}
|
||||
|
||||
export default api
|
||||
6
web-front/src/utils/constants.js
Normal file
6
web-front/src/utils/constants.js
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 前端全局常量
|
||||
*/
|
||||
|
||||
/** 预览服务基础 URL */
|
||||
export const PREVIEW_BASE_URL = 'https://nfd-parser.github.io/nfd-preview/preview.html?src='
|
||||
@@ -410,7 +410,6 @@ function addThunderDownload(tasks, config) {
|
||||
if (userAgent) taskParam.userAgent = userAgent
|
||||
taskParam.threadCount = '1'
|
||||
|
||||
console.log('[Thunder SDK] newTask params:', JSON.stringify(taskParam))
|
||||
window.thunderLink.newTask(taskParam)
|
||||
return Promise.resolve('thunder-ok')
|
||||
}
|
||||
|
||||
@@ -313,7 +313,6 @@ export async function loadTypesFromApi(monaco) {
|
||||
cachedContent,
|
||||
'file:///types.js'
|
||||
);
|
||||
console.log('从缓存加载types.js成功');
|
||||
// 异步更新缓存
|
||||
updateTypesJsCache();
|
||||
return;
|
||||
@@ -334,7 +333,6 @@ export async function loadTypesFromApi(monaco) {
|
||||
typesJsContent,
|
||||
'file:///types.js'
|
||||
);
|
||||
console.log('加载types.js成功并已缓存');
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('加载types.js失败,使用内置类型定义:', error);
|
||||
@@ -350,7 +348,6 @@ async function updateTypesJsCache() {
|
||||
if (response.ok) {
|
||||
const typesJsContent = await response.text();
|
||||
localStorage.setItem('playground_types_js', typesJsContent);
|
||||
console.log('types.js缓存已更新');
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('更新types.js缓存失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user