Add git api calls on frontend

This commit is contained in:
2024-09-28 19:39:45 +02:00
parent 4290119b93
commit 5af07a9e35
6 changed files with 317 additions and 87 deletions

View File

@@ -42,6 +42,21 @@ export const saveFileContent = async (filePath, content) => {
return await response.text();
};
export const deleteFile = async (filePath) => {
try {
const response = await fetch(`${API_BASE_URL}/files/${filePath}`, {
method: 'DELETE',
});
if (!response.ok) {
throw new Error('Failed to delete file');
}
return await response.text();
} catch (error) {
console.error('Error deleting file:', error);
throw error;
}
};
export const fetchUserSettings = async (userId) => {
try {
const response = await fetch(`${API_BASE_URL}/settings?userId=${userId}`);
@@ -75,4 +90,38 @@ export const saveUserSettings = async (settings) => {
console.error('Error saving user settings:', error);
throw error;
}
};
};
export const pullChanges = async () => {
try {
const response = await fetch(`${API_BASE_URL}/git/pull`, {
method: 'POST',
});
if (!response.ok) {
throw new Error('Failed to pull changes');
}
return await response.json();
} catch (error) {
console.error('Error pulling changes:', error);
throw error;
}
};
export const commitAndPush = async (message) => {
try {
const response = await fetch(`${API_BASE_URL}/git/commit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message }),
});
if (!response.ok) {
throw new Error('Failed to commit and push changes');
}
return await response.json();
} catch (error) {
console.error('Error committing and pushing changes:', error);
throw error;
}
};