This commit is contained in:
simva committed 2026-10-23 12:05:26 +09:00
commit d9ef64eafe
35 files changed
+4733

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
const BASE_URL = '/api';
export async function fetchStatus() {
const res = await fetch(`${BASE_URL}/status`);
if (!res.ok) throw new Error('상태 정보를 가져올 수 없습니다.');
return await res.json();
}
export async function fetchTorrents() {
const res = await fetch(`${BASE_URL}/torrents`);
if (!res.ok) throw new Error('토렌트 목록을 불러오지 못했습니다.');
return await res.json();
}
export async function addMagnet({ magnet, download_dir, paused }) {
const res = await fetch(`${BASE_URL}/torrents/add`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ magnet, download_dir, paused }),
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.detail || '토렌트 추가에 실패했습니다.');
}
return data;
}
export async function removeTorrent(torrentId, deleteData = false) {
const res = await fetch(`${BASE_URL}/torrents/${torrentId}?delete_data=${deleteData}`, {
method: 'DELETE',
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.detail || '토렌트 삭제에 실패했습니다.');
}
return data;
}
export async function startTorrent(torrentId) {
const res = await fetch(`${BASE_URL}/torrents/${torrentId}/start`, {
method: 'POST',
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.detail || '토렌트 시작 실패');
}
return data;
}
export async function stopTorrent(torrentId) {
const res = await fetch(`${BASE_URL}/torrents/${torrentId}/stop`, {
method: 'POST',
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.detail || '토렌트 일시정지 실패');
}
return data;
}