diff --git a/package.json b/package.json index c33ef57..1d2ddf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "6.4.3", + "version": "6.4.4", "license": "BUSL-1.1", "private": true, "packageManager": "pnpm@9.14.4", diff --git a/src/app.d.ts b/src/app.d.ts index 49f064d..c994c45 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -100,6 +100,17 @@ export interface TorrentSettings { torrentPeX: boolean } +export interface LibraryEntry { + mediaID: number + episode: number + files: number + hash: string + progress: number + date: number + size: number + name: string +} + export interface Native { authAL: (url: string) => Promise restart: () => Promise @@ -127,7 +138,8 @@ export interface Native { checkAvailableSpace: (_?: unknown) => Promise checkIncomingConnections: (port: number) => Promise updatePeerCounts: (hashes: string[]) => Promise> - playTorrent: (id: string) => Promise + playTorrent: (id: string, mediaID: number, episode: number) => Promise + library: () => Promise attachments: (hash: string, id: number) => Promise tracks: (hash: string, id: number) => Promise> subtitles: (hash: string, id: number, cb: (subtitle: { text: string, time: number, duration: number }, trackNumber: number) => void) => Promise diff --git a/src/lib/components/EpisodesList.svelte b/src/lib/components/EpisodesList.svelte index 0674eaf..15146d1 100644 --- a/src/lib/components/EpisodesList.svelte +++ b/src/lib/components/EpisodesList.svelte @@ -63,8 +63,8 @@ return list.slice((page - 1) * perPage, page * perPage) } - $: _progress = progress(media) ?? 0 $: completed = list(media) === 'COMPLETED' + $: _progress = completed ? 0 : progress(media) ?? 0 $: currentPage = Math.floor((!completed ? _progress : 0) / perPage) + 1 diff --git a/src/lib/components/ui/torrentclient/library/cells/index.ts b/src/lib/components/ui/torrentclient/library/cells/index.ts index 2934165..655fe38 100644 --- a/src/lib/components/ui/torrentclient/library/cells/index.ts +++ b/src/lib/components/ui/torrentclient/library/cells/index.ts @@ -1,2 +1,3 @@ export { default as StatusCell } from './status.svelte' export { default as NameCell } from './name.svelte' +export { default as MediaCell } from './mediatitle.svelte' diff --git a/src/lib/components/ui/torrentclient/library/cells/mediatitle.svelte b/src/lib/components/ui/torrentclient/library/cells/mediatitle.svelte new file mode 100644 index 0000000..0686fdf --- /dev/null +++ b/src/lib/components/ui/torrentclient/library/cells/mediatitle.svelte @@ -0,0 +1,11 @@ + + +{#await client.single(value)} + ? +{:then query} + {query.data?.Media?.title?.userPreferred ?? '?'} +{/await} diff --git a/src/lib/components/ui/torrentclient/library/table.svelte b/src/lib/components/ui/torrentclient/library/table.svelte index b099159..7354e42 100644 --- a/src/lib/components/ui/torrentclient/library/table.svelte +++ b/src/lib/components/ui/torrentclient/library/table.svelte @@ -1,64 +1,76 @@
@@ -94,7 +106,7 @@ {#if $pageRows.length} {#each $pageRows as row (row.id)} - + { if (row instanceof DataBodyRow) playEntry(row.original) }}> {#each row.cells as cell (cell.id)} diff --git a/src/lib/modules/native.ts b/src/lib/modules/native.ts index 0ddb4a9..e7607de 100644 --- a/src/lib/modules/native.ts +++ b/src/lib/modules/native.ts @@ -95,6 +95,7 @@ export default Object.assign>({ updatePeerCounts: async () => [], isApp: false, playTorrent: async () => dummyFiles, + library: async () => [], attachments: async () => [], tracks: async () => [], subtitles: async () => undefined, diff --git a/src/lib/modules/torrent/client.ts b/src/lib/modules/torrent/client.ts index 0d6b2f9..c84a241 100644 --- a/src/lib/modules/torrent/client.ts +++ b/src/lib/modules/torrent/client.ts @@ -5,7 +5,7 @@ import { persisted } from 'svelte-persisted-store' import native from '../native' import { w2globby } from '../w2g/lobby' -import type { FileInfo, PeerInfo, TorrentFile, TorrentInfo } from '$lib/../app' +import type { TorrentFile, TorrentInfo } from '$lib/../app' import type { Media } from '../anilist' const defaultTorrentInfo: TorrentInfo = { @@ -22,60 +22,38 @@ const defaultTorrentInfo: TorrentInfo = { const defaultProtocolStatus = { dht: false, lsd: false, pex: false, nat: false, forwarding: false, persisting: false, streaming: false } export const server = new class ServerClient { - last = persisted<{media: Media, id: string, episode: number} | null>('last-torrent', null) - active = writable>() + last = persisted<{ media: Media, id: string, episode: number } | null>('last-torrent', null) + active = writable>() downloaded = writable(this.cachedSet()) - stats = readable(defaultTorrentInfo, set => { - let listener = 0 + stats = this._timedSafeReadable(defaultTorrentInfo, native.torrentInfo, 200) - const update = async () => { - const id = (await get(this.active))?.id - if (id) set(await native.torrentInfo(id)) - listener = setTimeout(update, 200) - } + protocol = this._timedSafeReadable(defaultProtocolStatus, native.protocolStatus) - update() - return () => clearTimeout(listener) - }) + peers = this._timedSafeReadable([], native.peerInfo) - protocol = readable(defaultProtocolStatus, set => { - let listener = 0 + files = this._timedSafeReadable([], native.fileInfo) - const update = async () => { - const id = (await get(this.active))?.id - if (id) set(await native.protocolStatus(id)) - listener = setTimeout(update, 5000) - } + library = this._timedSafeReadable([], native.library, 120_000) - update() - return () => clearTimeout(listener) - }) + _timedSafeReadable (defaultData: T, fn: (id: string) => Promise, duration = 5000) { + return readable(defaultData, set => { + let listener = 0 - peers = readable([], set => { - let listener = 0 + const update = async () => { + try { + const id = (await get(this.active))?.id + if (id) set(await fn(id)) + } catch (error) { + console.error(error) + } + listener = setTimeout(update, duration) + } - const update = async () => { - const id = (await get(this.active))?.id - if (id) set(await native.peerInfo(id)) - listener = setTimeout(update, 5000) - } - - update() - return () => clearTimeout(listener) - }) - - files = readable([], set => { - let listener = 0 - const update = async () => { - const id = (await get(this.active))?.id - if (id) set(await native.fileInfo(id)) - listener = setTimeout(update, 5000) - } - - update() - return () => clearTimeout(listener) - }) + update() + return () => clearTimeout(listener) + }) + } constructor () { const last = get(this.last) @@ -98,7 +76,7 @@ export const server = new class ServerClient { } async _play (id: string, media: Media, episode: number) { - const result = { id, media, episode, files: await native.playTorrent(id) } + const result = { id, media, episode, files: await native.playTorrent(id, media.id, episode) } this.downloaded.value = this.cachedSet() return result } diff --git a/src/routes/app/anime/[id]/+layout.svelte b/src/routes/app/anime/[id]/+layout.svelte index 75130f2..0b05721 100644 --- a/src/routes/app/anime/[id]/+layout.svelte +++ b/src/routes/app/anime/[id]/+layout.svelte @@ -111,7 +111,7 @@
-
+