Files
profilarr/frontend/src/api/api.js
Sam Chau ae75baca26 feat(backend): Major overhaul of backend structure, git integration, and settings management
- **Backend Refactor:**
  - Merged route and operation files for regex and format.
  - Updated directory structure and consolidated utility functions.
  - Removed unnecessary app.py, using `__init__.py` for app creation.

- **Git Integration:**
  - Enhanced git cloning and merging methods, ensuring accurate local file updates.
  - Implemented comprehensive git status fetching with improved file status display and error handling.
  - Added branch management features, including branch creation, checkout, deletion, and associated UI improvements.
  - Integrated loading indicators and fun messages for better user feedback during git operations.

- **Settings Manager Enhancements:**
  - Expanded Git status display, including connected repository link, branch information, and detailed change listings.
  - Added revert functionality for individual files and all changes, with conditional UI updates based on file statuses.
  - Integrated `react-toastify` for alert notifications with improved styling.
  - Improved file name parsing, handling of file paths, and consistent API request structure.
  - Added UI components for a smooth tab transition and enhanced settings layout.

- **General Improvements:**
  - Revised sanitization logic for less aggressive handling, particularly for regex101 links.
  - Refactored backend logic to improve performance, specifically optimizing git status checks.
  - Implemented dynamic retrieval of default branches and enhanced handling of IDs in files.

**fixes, refactors, and additional features included**:
- Bug fixes for branch handling, git status accuracy, and file name adjustments.
- Improved error handling, logging, and user feedback across various components.
2025-02-05 16:09:58 +10:30

237 lines
6.5 KiB
JavaScript

import axios from 'axios';
const API_BASE_URL = 'http://localhost:5000';
export const getRegexes = async () => {
try {
const response = await axios.get(`${API_BASE_URL}/regex`);
return response.data;
} catch (error) {
console.error('Error fetching regexes:', error);
throw error;
}
};
export const saveRegex = async (regex) => {
try {
const response = await axios.post(`${API_BASE_URL}/regex`, regex);
return response.data;
} catch (error) {
console.error('Error saving regex:', error);
throw error;
}
};
export const updateRegex = async (id, regex) => {
try {
const response = await axios.put(`${API_BASE_URL}/regex/${id}`, regex);
return response.data;
} catch (error) {
console.error('Error updating regex:', error);
throw error;
}
};
export const deleteRegex = async (id) => {
try {
const response = await axios.delete(`${API_BASE_URL}/regex/${id}`, {
validateStatus: (status) => {
return status >= 200 && status < 300 || status === 409; // Accept 200-299 or 409 Conflict
}
});
return response.data;
} catch (error) {
console.error('Error deleting regex:', error);
throw error;
}
};
export const getFormats = async () => {
try {
const response = await axios.get(`${API_BASE_URL}/format`);
return response.data;
} catch (error) {
console.error('Error fetching formats:', error);
throw error;
}
};
export const saveFormat = async (format) => {
try {
const response = await axios.post(`${API_BASE_URL}/format`, format);
return response.data;
} catch (error) {
console.error('Error saving format:', error);
throw error;
}
};
export const updateFormat = async (id, format) => {
try {
const response = await axios.put(`${API_BASE_URL}/format/${id}`, format);
return response.data;
} catch (error) {
console.error('Error updating format:', error);
throw error;
}
};
export const deleteFormat = async (id) => {
try {
const response = await axios.delete(`${API_BASE_URL}/format/${id}`);
return response.data;
} catch (error) {
console.error('Error deleting format:', error);
throw error;
}
};
export const createRegex101Link = async (regexData) => {
try {
const response = await axios.post(`${API_BASE_URL}/regex/regex101`, regexData);
return response.data;
} catch (error) {
console.error('Error creating regex101 link:', error);
throw error;
}
};
export const getSettings = async () => {
try {
const response = await axios.get(`${API_BASE_URL}/settings`);
return response.data;
} catch (error) {
console.error('Error fetching settings:', error);
throw error;
}
};
export const saveSettings = async (settings) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings`, settings);
return response.data;
} catch (error) {
console.error('Error saving settings:', error);
throw error;
}
};
export const getGitStatus = async () => {
try {
const response = await axios.get(`${API_BASE_URL}/settings/status`);
return response.data;
} catch (error) {
console.error('Error fetching Git status:', error);
throw error;
}
};
export const getBranches = async () => {
try {
const response = await axios.get(`${API_BASE_URL}/settings/branches`);
return response.data;
} catch (error) {
console.error('Error fetching branches:', error);
throw error;
}
};
export const checkoutBranch = async (branchName) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/checkout`, { branch: branchName });
return response.data;
} catch (error) {
console.error('Error checking out branch:', error);
throw error;
}
};
export const createBranch = async (branchName, baseBranch) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/branch`, { name: branchName, base: baseBranch });
return response.data;
} catch (error) {
console.error('Error creating branch:', error);
throw error;
}
};
export const deleteBranch = async (branchName) => {
try {
const response = await axios.delete(`${API_BASE_URL}/settings/branch/${branchName}`);
return response.data;
} catch (error) {
console.error('Error deleting branch:', error);
throw error;
}
};
export const pullBranch = async (branchName) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/pull`, { branch: branchName });
return response.data;
} catch (error) {
console.error('Error pulling branch:', error);
throw error;
}
};
export const addFiles = async (files) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/stage`, { files });
return response.data;
} catch (error) {
console.error('Error staging files:', error);
throw error;
}
};
export const pushFiles = async (files, commitMessage) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/push`, {
files,
commit_message: commitMessage
});
return response.data;
} catch (error) {
console.error('Error pushing files:', error);
throw error;
}
};
export const revertFile = async (filePath) => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/revert`, {
file_path: filePath
});
return response.data;
} catch (error) {
console.error('Error reverting file:', error);
throw error;
}
};
export const revertAll = async () => {
try {
const response = await axios.post(`${API_BASE_URL}/settings/revert-all`);
return response.data;
} catch (error) {
console.error('Error reverting all changes:', error);
throw error;
}
};
export const deleteFile = async (filePath) => {
try {
const response = await axios.delete(`${API_BASE_URL}/settings/file`, {
data: { file_path: filePath },
});
return response.data;
} catch (error) {
console.error('Error deleting file:', error);
return { success: false, error: 'Error deleting file' };
}
};