42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
|
|
import {
|
|
PlagiarismSubmissionPayload,
|
|
PlagiarismSubmissionResponse,
|
|
} from '@/widgets/plagiatCheck/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>;
|
|
}
|