canape/frontend/js/actions/torrents.js

51 lines
868 B
JavaScript

import { configureAxios, request } from "../requests"
import { addAlertOk } from "./alerts"
export function addTorrent(url) {
return request(
"ADD_TORRENT",
configureAxios().post("/torrents", {
url: url,
}),
[
addAlertOk("Torrent added"),
],
)
}
export function removeTorrent(id) {
return request(
"REMOVE_TORRENT",
configureAxios().delete(`/torrents/${id}`),
[
() => fetchTorrents(),
]
)
}
export function fetchTorrents() {
return request(
"TORRENTS_FETCH",
configureAxios().get("/torrents")
)
}
export function searchTorrents(url) {
return request(
"TORRENTS_SEARCH",
configureAxios().get(url)
)
}
export function setFetchedTorrents(torrents) {
return {
type: "TORRENTS_FETCH_FULFILLED",
payload: {
response: {
data : torrents,
},
},
}
}