refactor(services): 重构服务文件结构,将服务按功能分类到不同目录
- 将服务文件按功能分类到core、ai、analytics、security等目录 - 修复logger导入路径问题,统一使用相对路径 - 更新相关文件的导入路径引用 - 添加新的批量操作组件导出文件 - 修复dashboard页面中的类型错误 - 添加dotenv依赖到package.json
This commit is contained in:
63
fix-method-headers.js
Normal file
63
fix-method-headers.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const servicesDir = 'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\services';
|
||||
|
||||
const files = fs.readdirSync(servicesDir).filter(f => f.endsWith('DataSource.ts'));
|
||||
|
||||
const fixFile = (filename) => {
|
||||
const filePath = path.join(servicesDir, filename);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
console.log(`File not found: ${filePath}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let content = fs.readFileSync(filePath, 'utf8');
|
||||
let modified = false;
|
||||
|
||||
const patterns = [
|
||||
{
|
||||
regex: /http\.(get|post|put|delete)\(([^,]+),\s*\{\s*method:\s*'POST',\s*headers:\s*\{\s*'Content-Type':\s*'application\/json'\s*\},\s*JSON\.stringify\(([^)]+)\),?\s*\}\s*\)/g,
|
||||
replacement: 'http.post($2, $3)'
|
||||
},
|
||||
{
|
||||
regex: /http\.(get|post|put|delete)\(([^,]+),\s*\{\s*method:\s*'PUT',\s*headers:\s*\{\s*'Content-Type':\s*'application\/json'\s*\},\s*JSON\.stringify\(([^)]+)\),?\s*\}\s*\)/g,
|
||||
replacement: 'http.put($2, $3)'
|
||||
},
|
||||
{
|
||||
regex: /http\.(get|post|put|delete)\(([^,]+),\s*\{\s*method:\s*'DELETE',\s*headers:\s*\{\s*'Content-Type':\s*'application\/json'\s*\},?\s*\}\s*\)/g,
|
||||
replacement: 'http.delete($2)'
|
||||
},
|
||||
{
|
||||
regex: /http\.(get|post|put|delete)\(([^,]+),\s*\{\s*method:\s*'GET',\s*headers:\s*\{\s*'Content-Type':\s*'application\/json'\s*\},?\s*\}\s*\)/g,
|
||||
replacement: 'http.get($2)'
|
||||
},
|
||||
];
|
||||
|
||||
patterns.forEach(({ regex, replacement }) => {
|
||||
if (regex.test(content)) {
|
||||
content = content.replace(regex, replacement);
|
||||
modified = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (modified) {
|
||||
fs.writeFileSync(filePath, content, 'utf8');
|
||||
console.log(`Fixed: ${filename}`);
|
||||
} else {
|
||||
console.log(`No changes needed: ${filename}`);
|
||||
}
|
||||
};
|
||||
|
||||
console.log('Fixing method and headers issues...\n');
|
||||
|
||||
files.forEach(file => {
|
||||
try {
|
||||
fixFile(file);
|
||||
} catch (error) {
|
||||
console.error(`Error fixing ${file}:`, error.message);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('\nAll files processed!');
|
||||
Reference in New Issue
Block a user