Add report flow and post_info by id
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user