mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-09-13 12:11:30 +08:00
Add delete message feature
Remove deleted property from Message Add dedicated route for delete_message Pre-commit Revert change to promp_repository fetch_message Remove blank line
This commit is contained in:
@@ -17,6 +17,8 @@ export const get = (url: string) => api.get(url).then((res) => res.data);
|
||||
|
||||
export const post = (url: string, { arg: data }) => api.post(url, data).then((res) => res.data);
|
||||
|
||||
export const del = (url: string) => api.delete(url).then((res) => res.data);
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
|
||||
@@ -89,6 +89,13 @@ export class OasstApiClient {
|
||||
return this.get<Message>(`/api/v1/messages/${message_id}?username=${user.id}&auth_method=${user.auth_method}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a message by its id
|
||||
*/
|
||||
async delete_message(message_id: string): Promise<void> {
|
||||
return this.delete<void>(`/api/v1/messages/${message_id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a report about a message
|
||||
*/
|
||||
@@ -202,6 +209,10 @@ export class OasstApiClient {
|
||||
return this.request<T>("PUT", path);
|
||||
}
|
||||
|
||||
private async delete<T>(path: string) {
|
||||
return this.request<T>("DELETE", path);
|
||||
}
|
||||
|
||||
private async get<T>(path: string, query?: Record<string, string | number | boolean | undefined>) {
|
||||
if (!query) {
|
||||
return this.request<T>("GET", path);
|
||||
@@ -216,7 +227,11 @@ export class OasstApiClient {
|
||||
return this.request<T>("GET", `${path}?${params}`);
|
||||
}
|
||||
|
||||
private async request<T>(method: "GET" | "POST" | "PUT", path: string, init?: RequestInit): Promise<T | null> {
|
||||
private async request<T>(
|
||||
method: "GET" | "POST" | "PUT" | "DELETE",
|
||||
path: string,
|
||||
init?: RequestInit
|
||||
): Promise<T | null> {
|
||||
const resp = await fetch(`${this.oasstApiUrl}${path}`, {
|
||||
method,
|
||||
...init,
|
||||
|
||||
Reference in New Issue
Block a user