mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Add Workspace context
This commit is contained in:
@@ -16,76 +16,176 @@ const apiCall = async (url, options = {}) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchFileList = async () => {
|
||||
const response = await apiCall(`${API_BASE_URL}/files`);
|
||||
export const fetchLastWorkspace = async () => {
|
||||
const response = await apiCall(`${API_BASE_URL}/users/1/workspaces/last`);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const fetchFileContent = async (filePath) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/files/${filePath}`);
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const saveFileContent = async (filePath, content) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/files/${filePath}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
body: content,
|
||||
});
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const deleteFile = async (filePath) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/files/${filePath}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const fetchUserSettings = async (userId) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/settings?userId=${userId}`);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const saveUserSettings = async (settings) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/settings`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const pullChanges = async () => {
|
||||
const response = await apiCall(`${API_BASE_URL}/git/pull`, {
|
||||
method: 'POST',
|
||||
});
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const commitAndPush = async (message) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/git/commit`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ message }),
|
||||
});
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const getFileUrl = (filePath) => {
|
||||
return `${API_BASE_URL}/files/${filePath}`;
|
||||
};
|
||||
|
||||
export const lookupFileByName = async (filename) => {
|
||||
export const fetchFileList = async (workspaceId) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/files/lookup?filename=${encodeURIComponent(filename)}`
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files`
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const fetchFileContent = async (workspaceId, filePath) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/${filePath}`
|
||||
);
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const saveFileContent = async (workspaceId, filePath, content) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/${filePath}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
body: content,
|
||||
}
|
||||
);
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const deleteFile = async (workspaceId, filePath) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/${filePath}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
}
|
||||
);
|
||||
return response.text();
|
||||
};
|
||||
|
||||
export const fetchWorkspaceSettings = async (workspaceId) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/settings`
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const saveWorkspaceSettings = async (workspaceId, settings) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/settings`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ settings }),
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const pullChanges = async (workspaceId) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/git/pull`,
|
||||
{
|
||||
method: 'POST',
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const commitAndPush = async (workspaceId, message) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/git/commit`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ message }),
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const getFileUrl = (workspaceId, filePath) => {
|
||||
return `${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/${filePath}`;
|
||||
};
|
||||
|
||||
export const lookupFileByName = async (workspaceId, filename) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/lookup?filename=${encodeURIComponent(
|
||||
filename
|
||||
)}`
|
||||
);
|
||||
const data = await response.json();
|
||||
return data.paths;
|
||||
};
|
||||
|
||||
export const updateLastOpenedFile = async (workspaceId, filePath) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/last`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ filePath }),
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const getLastOpenedFile = async (workspaceId) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}/files/last`
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const listWorkspaces = async () => {
|
||||
const response = await apiCall(`${API_BASE_URL}/users/1/workspaces`);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const createWorkspace = async (name) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/users/1/workspaces`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const updateWorkspace = async (workspaceId, name) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ name }),
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const deleteWorkspace = async (workspaceId) => {
|
||||
const response = await apiCall(
|
||||
`${API_BASE_URL}/users/1/workspaces/${workspaceId}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
}
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const updateLastWorkspace = async (workspaceId) => {
|
||||
const response = await apiCall(`${API_BASE_URL}/users/1/workspaces/last`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ workspaceId }),
|
||||
});
|
||||
return response.json();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user