mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Update frontend requests
This commit is contained in:
@@ -47,17 +47,16 @@ export const saveFileContent = async (workspaceName, filePath, content) => {
|
||||
body: content,
|
||||
}
|
||||
);
|
||||
return response.text();
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const deleteFile = async (workspaceName, filePath) => {
|
||||
const response = await apiCall(
|
||||
await apiCall(
|
||||
`${API_BASE_URL}/workspaces/${workspaceName}/files/${filePath}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
}
|
||||
);
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const getWorkspace = async (workspaceName) => {
|
||||
@@ -119,17 +118,13 @@ export const lookupFileByName = async (workspaceName, filename) => {
|
||||
};
|
||||
|
||||
export const updateLastOpenedFile = async (workspaceName, filePath) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/workspaces/${workspaceName}/files/last`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ filePath }),
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
await apiCall(`${API_BASE_URL}/workspaces/${workspaceName}/files/last`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ filePath }),
|
||||
});
|
||||
};
|
||||
|
||||
export const getLastOpenedFile = async (workspaceName) => {
|
||||
|
||||
@@ -49,13 +49,17 @@ export const apiCall = async (url, options = {}) => {
|
||||
throw new Error('Authentication failed');
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
if (!response.ok && response.status !== 204) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
throw new Error(
|
||||
errorData?.message || `HTTP error! status: ${response.status}`
|
||||
);
|
||||
}
|
||||
|
||||
if (response.status === 204) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error(`API call failed: ${error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user