landing page added
This commit is contained in:
41
src/shared/request/plagiarismapi.ts
Normal file
41
src/shared/request/plagiarismapi.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// ─── Constants ───────────────────────────────────────────────────────────────
|
||||
|
||||
import {
|
||||
PlagiarismSubmissionPayload,
|
||||
PlagiarismSubmissionResponse,
|
||||
} from '@/widgets/fileUpload/lib/types';
|
||||
|
||||
const API_BASE_URL = process.env.VITE_API_BASE_URL ?? '/api';
|
||||
const ENDPOINT = `${API_BASE_URL}/plagiarism/submit`;
|
||||
|
||||
// ─── API Function ────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Submits a document for plagiarism checking.
|
||||
* Sends a multipart/form-data request to the backend API.
|
||||
*/
|
||||
export async function submitPlagiarismCheck(
|
||||
payload: PlagiarismSubmissionPayload,
|
||||
): Promise<PlagiarismSubmissionResponse> {
|
||||
const formData = new FormData();
|
||||
formData.append('topic', payload.topic);
|
||||
formData.append('senderFullName', payload.senderFullName);
|
||||
formData.append('file', payload.file);
|
||||
formData.append('withCertificate', String(payload.withCertificate));
|
||||
|
||||
const response = await fetch(ENDPOINT, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
// Do NOT set Content-Type manually — the browser sets it with the boundary
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorBody = await response.json().catch(() => ({}));
|
||||
throw new Error(
|
||||
(errorBody as { message?: string }).message ??
|
||||
`Request failed with status ${response.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
return response.json() as Promise<PlagiarismSubmissionResponse>;
|
||||
}
|
||||
Reference in New Issue
Block a user