64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
|
|
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!');
|