Spaces:
Configuration error
Configuration error
File size: 1,503 Bytes
9f26583 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | // src/lib/api.js
const BACKEND_URL = 'http://127.0.0.1:8000';
export async function scanApk(file) {
const formData = new FormData();
formData.append('apk', file);
const response = await fetch(`${BACKEND_URL}/scan`, {
method: 'POST',
body: formData,
});
if (!response.ok) {
let message = 'Scan failed';
try {
const data = await response.json();
message = data.detail || message;
} catch {}
throw new Error(message);
}
const result = await response.json();
if (result.grayscale_image_url?.startsWith('/')) {
result.grayscale_image_url = `${BACKEND_URL}${result.grayscale_image_url}`;
}
return result;
}
export async function saveScanHistory(result) {
const token = localStorage.getItem('token');
if (!token) return;
await fetch(`${BACKEND_URL}/history/save`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(result),
});
}
export async function fetchHistory({ search = '', threatType = '', skip = 0, limit = 50 } = {}) {
const token = localStorage.getItem('token');
if (!token) return [];
let url = `${BACKEND_URL}/history/?skip=${skip}&limit=${limit}`;
if (search) url += `&search=${encodeURIComponent(search)}`;
if (threatType) url += `&threat_type=${threatType}`;
const response = await fetch(url, {
headers: { Authorization: `Bearer ${token}` },
});
if (!response.ok) return [];
return response.json();
} |