Spaces:
Configuration error
Configuration error
| // 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(); | |
| } |