Add report flow and post_info by id

This commit is contained in:
LeonspaceX
2026-01-27 13:19:18 +08:00
parent 72204c74b0
commit 0bce1d49da
7 changed files with 228 additions and 4 deletions

View File

@@ -299,6 +299,37 @@ export const postComment = async (commentData: PostCommentRequest): Promise<Post
}
};
export interface ReportPostResponse {
id: number;
}
export const reportPost = async (reportData: { id: number; title: string; content: string }): Promise<ReportPostResponse> => {
try {
const identity = await get_id_token();
const response = await fetch('/api/report', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
...reportData,
identity,
}),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const json = await response.json();
if (json.code === 1001 && json.data?.id !== undefined) {
return { id: Number(json.data.id) };
}
throw new Error(json.data || 'Report failed');
} catch (error) {
console.error('Failed to report post:', error);
throw error;
}
};
export const uploadImage = async (file: File): Promise<string> => {
try {
const identity_token = await get_id_token();