mirror of
https://github.com/NoCrypt/migu.git
synced 2026-03-11 17:45:32 +00:00
feat: improve extension errors
This commit is contained in:
parent
c344d54190
commit
3ca45b5192
5 changed files with 57 additions and 24 deletions
|
|
@ -22,7 +22,6 @@
|
|||
import ViewAnime from './views/ViewAnime/ViewAnime.svelte'
|
||||
import TorrentModal from './views/TorrentSearch/TorrentModal.svelte'
|
||||
import Menubar from './components/Menubar.svelte'
|
||||
import IspBlock from './views/IspBlock.svelte'
|
||||
import { Toaster } from 'svelte-sonner'
|
||||
import Logout from './components/Logout.svelte'
|
||||
import Navbar from './components/Navbar.svelte'
|
||||
|
|
@ -31,7 +30,6 @@
|
|||
</script>
|
||||
|
||||
<div class='page-wrapper with-transitions bg-dark position-relative' data-sidebar-type='overlayed-all'>
|
||||
<IspBlock />
|
||||
<Menubar bind:page={$page} />
|
||||
<ViewAnime />
|
||||
<Logout />
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@
|
|||
/* --error-text: hsl(358, 100%, 81%); */
|
||||
}
|
||||
|
||||
[data-sonner-toaster] [data-description] {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.z-100 {
|
||||
z-index: 100;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { anilistClient } from '../anilist.js'
|
|||
import { anitomyscript } from '../anime.js'
|
||||
import { client } from '@/modules/torrent.js'
|
||||
import { extensionsWorker } from '@/views/Settings/TorrentSettings.svelte'
|
||||
import { toast } from 'svelte-sonner'
|
||||
|
||||
/** @typedef {import('@thaunknown/ani-resourced/sources/types.d.ts').Options} Options */
|
||||
/** @typedef {import('@thaunknown/ani-resourced/sources/types.d.ts').Result} Result */
|
||||
|
|
@ -33,7 +34,14 @@ export default async function getResultsFromExtensions ({ media, episode, batch,
|
|||
exclusions
|
||||
}
|
||||
|
||||
const results = await worker.query(options, { movie, batch }, settings.value.sources)
|
||||
const { results, errors } = await worker.query(options, { movie, batch }, settings.value.sources)
|
||||
|
||||
for (const error of errors) {
|
||||
console.error(error)
|
||||
toast.error('Source Fetch Failed!', {
|
||||
description: error
|
||||
})
|
||||
}
|
||||
|
||||
const deduped = dedupe(results)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,24 +15,51 @@ class Extensions {
|
|||
|
||||
/**
|
||||
* @param {Options} options
|
||||
* @param {{ movie: boolean, batch: boolean }} param1
|
||||
* @param {Record<string, boolean>} sources
|
||||
* @param {{ movie: boolean, batch: boolean }} types
|
||||
* @param {Record<string, boolean>} sourcesToQuery
|
||||
*/
|
||||
async query (options, { movie, batch }, sources) {
|
||||
/** @type {Promise<Result[]>[]} */
|
||||
async query (options, types, sourcesToQuery) {
|
||||
/** @type {Promise<{ results: Result[], errors: string[] }>[]} */
|
||||
const promises = []
|
||||
for (const source of Object.values(this.sources)) {
|
||||
if (!sources[source.name]) continue
|
||||
if (movie) promises.push(source.movie(options))
|
||||
if (batch) promises.push(source.batch(options))
|
||||
promises.push(source.single(options))
|
||||
if (!sourcesToQuery[source.name]) continue
|
||||
promises.push(this._querySource(source, options, types))
|
||||
}
|
||||
/** @type {Result[]} */
|
||||
const results = []
|
||||
for (const result of await Promise.allSettled(promises)) {
|
||||
if (result.status === 'fulfilled') results.push(...result.value)
|
||||
const errors = []
|
||||
for (const res of await Promise.all(promises)) {
|
||||
results.push(...res.results)
|
||||
errors.push(...res.errors)
|
||||
}
|
||||
return results.flat()
|
||||
|
||||
return { results, errors }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AbstractSource} source
|
||||
* @param {Options} options
|
||||
* @param {{ movie: boolean, batch: boolean }} types
|
||||
* @returns {Promise<{ results: Result[], errors: string[] }>}
|
||||
*/
|
||||
async _querySource (source, options, { movie, batch }) {
|
||||
const promises = []
|
||||
promises.push(source.single(options))
|
||||
if (movie) promises.push(source.movie(options))
|
||||
if (batch) promises.push(source.batch(options))
|
||||
|
||||
const results = []
|
||||
const errors = []
|
||||
for (const result of await Promise.allSettled(promises)) {
|
||||
if (result.status === 'fulfilled') {
|
||||
results.push(...result.value)
|
||||
} else {
|
||||
console.error(result)
|
||||
errors.push('Source ' + source.name + ' failed to load results:\n' + result.reason.message)
|
||||
}
|
||||
}
|
||||
|
||||
return { results, errors }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,15 +52,11 @@ export function getReleasesRSSurl (val) {
|
|||
|
||||
export async function getRSSContent (url) {
|
||||
if (!url) return null
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
if (!res.ok) {
|
||||
throw new Error('Failed fetching RSS!\n' + res.statusText)
|
||||
}
|
||||
return DOMPARSER(await res.text(), 'text/xml')
|
||||
} catch (e) {
|
||||
throw new Error('Failed fetching RSS!\n' + e.message)
|
||||
const res = await fetch(url)
|
||||
if (!res.ok) {
|
||||
throw new Error(res.statusText)
|
||||
}
|
||||
return DOMPARSER(await res.text(), 'text/xml')
|
||||
}
|
||||
|
||||
class RSSMediaManager {
|
||||
|
|
@ -73,9 +69,9 @@ class RSSMediaManager {
|
|||
if (!ignoreErrors) {
|
||||
res.catch(e => {
|
||||
toast.error('Search Failed', {
|
||||
description: 'Failed fetching RSS!\n' + e.message
|
||||
description: 'Failed Loading Media for Home Feed!\n' + e.message
|
||||
})
|
||||
console.error('Failed to fetch rss', e)
|
||||
console.error('Failed Loading Media for Home Feed', e)
|
||||
})
|
||||
}
|
||||
return Array.from({ length: perPage }, (_, i) => ({ type: 'episode', data: this.fromPending(res, i) }))
|
||||
|
|
|
|||
Loading…
Reference in a new issue