mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-22 00:35:12 +02:00
Loads of changes, experimental radarr queuing and integration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Genre } from '$lib/tmdb-api';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export function getRuntime(minutes: number) {
|
||||
export function formatMinutes(minutes: number) {
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = Math.floor(minutes % 60);
|
||||
|
||||
@@ -10,3 +11,49 @@ export function getRuntime(minutes: number) {
|
||||
export function formatGenres(genres: Genre[]) {
|
||||
return genres.map((genre) => genre.name.charAt(0).toUpperCase() + genre.name.slice(1)).join(', ');
|
||||
}
|
||||
|
||||
export function formatSize(size: number) {
|
||||
const gbs = size / 1024 / 1024 / 1024;
|
||||
const mbs = size / 1024 / 1024;
|
||||
|
||||
if (gbs >= 1) {
|
||||
return `${gbs.toFixed(2)} GB`;
|
||||
} else {
|
||||
return `${mbs.toFixed(2)} MB`;
|
||||
}
|
||||
}
|
||||
|
||||
export function request<T, A>(fetcher: (arg: A) => Promise<T>, args: A | undefined = undefined) {
|
||||
const loading = writable(args !== undefined);
|
||||
const error = writable<Error | null>(null);
|
||||
const data = writable<T | null>(null);
|
||||
const didLoad = writable(false);
|
||||
|
||||
async function load(arg: A) {
|
||||
loading.set(true);
|
||||
error.set(null);
|
||||
|
||||
fetcher(arg)
|
||||
.then((d) => {
|
||||
console.log('got data', d);
|
||||
data.set(d);
|
||||
})
|
||||
.catch((e) => error.set(e))
|
||||
.finally(() => {
|
||||
loading.set(false);
|
||||
didLoad.set(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (args) {
|
||||
load(args);
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
error,
|
||||
data,
|
||||
didLoad,
|
||||
load
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user