72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001';
|
|
import { authHeaders } from './auth';
|
|
|
|
export async function fetchCV() {
|
|
const response = await fetch(`${API_URL}/api/cv`);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch CV: ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export async function updateCV(data) {
|
|
const response = await fetch(`${API_URL}/api/cv`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...authHeaders(),
|
|
},
|
|
body: JSON.stringify(data),
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to update CV: ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export async function exportCV() {
|
|
const response = await fetch(`${API_URL}/api/cv/export`);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to export CV: ${response.statusText}`);
|
|
}
|
|
return response.blob();
|
|
}
|
|
|
|
export async function importCV(data) {
|
|
const response = await fetch(`${API_URL}/api/cv/import`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
...authHeaders(),
|
|
},
|
|
body: JSON.stringify(data),
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to import CV: ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export async function getAuthConfig() {
|
|
const response = await fetch(`${API_URL}/api/auth/config`);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to get auth config: ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export async function login(password) {
|
|
const response = await fetch(`${API_URL}/api/auth/login`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ password }),
|
|
});
|
|
if (!response.ok) {
|
|
const error = await response.json();
|
|
throw new Error(error.error || 'Login failed');
|
|
}
|
|
return response.json();
|
|
}
|