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,
|
body: content,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return response.text();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteFile = async (workspaceName, filePath) => {
|
export const deleteFile = async (workspaceName, filePath) => {
|
||||||
const response = await apiCall(
|
await apiCall(
|
||||||
`${API_BASE_URL}/workspaces/${workspaceName}/files/${filePath}`,
|
`${API_BASE_URL}/workspaces/${workspaceName}/files/${filePath}`,
|
||||||
{
|
{
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return response.text();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getWorkspace = async (workspaceName) => {
|
export const getWorkspace = async (workspaceName) => {
|
||||||
@@ -119,17 +118,13 @@ export const lookupFileByName = async (workspaceName, filename) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const updateLastOpenedFile = async (workspaceName, filePath) => {
|
export const updateLastOpenedFile = async (workspaceName, filePath) => {
|
||||||
const response = await apiCall(
|
await apiCall(`${API_BASE_URL}/workspaces/${workspaceName}/files/last`, {
|
||||||
`${API_BASE_URL}/workspaces/${workspaceName}/files/last`,
|
method: 'PUT',
|
||||||
{
|
headers: {
|
||||||
method: 'PUT',
|
'Content-Type': 'application/json',
|
||||||
headers: {
|
},
|
||||||
'Content-Type': 'application/json',
|
body: JSON.stringify({ filePath }),
|
||||||
},
|
});
|
||||||
body: JSON.stringify({ filePath }),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return response.json();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLastOpenedFile = async (workspaceName) => {
|
export const getLastOpenedFile = async (workspaceName) => {
|
||||||
|
|||||||
@@ -49,13 +49,17 @@ export const apiCall = async (url, options = {}) => {
|
|||||||
throw new Error('Authentication failed');
|
throw new Error('Authentication failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok && response.status !== 204) {
|
||||||
const errorData = await response.json().catch(() => null);
|
const errorData = await response.json().catch(() => null);
|
||||||
throw new Error(
|
throw new Error(
|
||||||
errorData?.message || `HTTP error! status: ${response.status}`
|
errorData?.message || `HTTP error! status: ${response.status}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.status === 204) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`API call failed: ${error.message}`);
|
console.error(`API call failed: ${error.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user