- Affiches TMDB : on garde l'adresse au lieu de copier l'image dans la fiche (~50 Ko par fiche, renvoyés au serveur à chaque modification et chez les amis) ; le service worker les garde en cache pour le hors-ligne - Service worker : pré-téléchargement réduit de 2 Mo à 1 Mo (les 17 autres langues, l'admin et les variantes de police sont mises en cache à la demande) - Cache des fiches TMDB, saisons, personnes et notes Trakt (affichage immédiat, hors-ligne) ; caches d'images séparés (affiches / grandes images) - React dans un fichier à part, gardé en cache d'une version à l'autre ; fichier principal 190 → 116 Ko compressés - Chargés à la demande : assistant d'import (Réglages 73 → 25 Ko), dessin des cartes de partage, lecture des anciennes sauvegardes - Code mort retiré ; base : extension pg_net (inutilisée) supprimée, index des notifications revus Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
11 files changed
+120
-65
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { t } from '../i18n'
|
||||
import { Download, Share2, X } from 'lucide-react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { shareImage } from '../lib/shareCard'
|
||||
import { shareImage } from '../lib/shareImage'
|
||||
import { useBackToClose } from '../lib/backNav'
|
||||
import { useEscape } from '../lib/escape'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
|
||||
@@ -57,7 +57,7 @@ export function BugReportRow() {
|
||||
}
|
||||
|
||||
/** Formulaire « Signaler un bug » : description + infos techniques (montrées avant l'envoi, rien de personnel). */
|
||||
export default function BugReportDialog({ onClose }: { onClose: () => void }) {
|
||||
function BugReportDialog({ onClose }: { onClose: () => void }) {
|
||||
const { settings } = useMedia()
|
||||
const info = useMemo(() => techInfo(settings.themeMode), [settings.themeMode])
|
||||
const [text, setText] = useState('')
|
||||
|
||||
@@ -5,7 +5,6 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
import { getTitleExtras, getTmdbCredits, getTmdbDetails, getTmdbExtras, type SearchResult, type TitleExtras } from '../../lib/catalogApi'
|
||||
import { CRITERIA, STATUS_BY_VALUE, TYPE_BY_VALUE } from '../../lib/constants'
|
||||
import { genreLabel } from '../../lib/genres'
|
||||
import { remotePosterToLocal } from '../../lib/image'
|
||||
import { airedCount, nextAirDate, useAiringCache } from '../../lib/airing'
|
||||
import { useBackToClose } from '../../lib/backNav'
|
||||
import { useEscape } from '../../lib/escape'
|
||||
@@ -164,8 +163,9 @@ export default function TitleSheet({ item: initial, seed, onClose, onOpenPerson,
|
||||
try {
|
||||
const base: Partial<MediaInput> = { ...(seed.source === 'tmdb' ? meta : seed.prefill) }
|
||||
if (seed.source === 'tmdb' && !meta) Object.assign(base, await getTmdbDetails(seed, settings.tmdbKey ?? ''))
|
||||
// TMDB autorise la copie locale de l'affiche (visible hors-ligne) ; AniList non, on garde l'adresse.
|
||||
if (seed.posterUrl) base.poster = seed.source === 'tmdb' ? await remotePosterToLocal(seed.posterUrl).catch(() => seed.posterUrl) : seed.posterUrl
|
||||
// On garde l'adresse de l'affiche (le service worker la met en cache : visible hors-ligne). La copier dans
|
||||
// la fiche l'alourdissait d'environ 50 Ko, renvoyés au serveur à chaque modification et chez les amis.
|
||||
if (seed.posterUrl) base.poster = seed.posterUrl
|
||||
if (extras?.average != null) base.publicRating = extras.average
|
||||
const created = await add({
|
||||
...BLANK,
|
||||
|
||||
+8
-4
@@ -2,7 +2,6 @@ import { t } from '../i18n'
|
||||
import type { BackupFile, Criteria, CustomList, MediaItem, MediaType, Settings, TopCategory, TopEntry, WatchStatus } from '../types'
|
||||
import { ALL_TOP_CATEGORIES, MEDIA_TYPES, STATUSES } from './constants'
|
||||
import { episodeCap } from './franchise'
|
||||
import { convertLegacyBackup, isLegacyBackup } from './legacyImport'
|
||||
import { cleanThemeMode } from './theme'
|
||||
import {
|
||||
cleanText,
|
||||
@@ -225,9 +224,14 @@ export async function parseBackupFile(file: File): Promise<ParsedBackup> {
|
||||
} catch {
|
||||
throw new Error(t('backup.notJson'))
|
||||
}
|
||||
if (isLegacyBackup(data)) {
|
||||
const legacy = convertLegacyBackup(data)
|
||||
return { items: dedupe(legacy.items), skipped: legacy.skipped, format: 'legacy' }
|
||||
// Ancien format (AzuuCine) : son convertisseur n'est chargé que pour ces fichiers-là
|
||||
const first = isPlainObject(data) && Array.isArray(data.items) ? (data.items[0] as unknown) : undefined
|
||||
if (isPlainObject(first) && ('tmdb_id' in first || 'media_type' in first || 'poster_path' in first)) {
|
||||
const { convertLegacyBackup, isLegacyBackup } = await import('./legacyImport')
|
||||
if (isLegacyBackup(data)) {
|
||||
const legacy = convertLegacyBackup(data)
|
||||
return { items: dedupe(legacy.items), skipped: legacy.skipped, format: 'legacy' }
|
||||
}
|
||||
}
|
||||
const rawItems = Array.isArray(data) ? data : isPlainObject(data) && Array.isArray(data.items) ? data.items : null
|
||||
if (!rawItems) throw new Error(t('backup.noItems'))
|
||||
|
||||
+2
-25
@@ -1,8 +1,8 @@
|
||||
import { t } from '../i18n'
|
||||
import { LIMITS, safePosterUrl } from './security'
|
||||
import { LIMITS } from './security'
|
||||
|
||||
/**
|
||||
* Convertit une image (photo de la galerie, affiche téléchargée…) en petit JPEG
|
||||
* Convertit une image (photo de la galerie) en petit JPEG
|
||||
* compressé (data URL), pour garder la base légère et 100 % hors-ligne.
|
||||
*/
|
||||
export function blobToPosterDataURL(blob: Blob, maxWidth = 360, quality = 0.8): Promise<string> {
|
||||
@@ -42,29 +42,6 @@ export function fileToPosterDataURL(file: File) {
|
||||
return blobToPosterDataURL(file)
|
||||
}
|
||||
|
||||
/**
|
||||
* Télécharge une affiche distante et la garde en local (visible hors-ligne).
|
||||
* Si le serveur refuse (CORS, réseau), on garde simplement l'URL.
|
||||
*/
|
||||
export async function remotePosterToLocal(url: string): Promise<string | undefined> {
|
||||
const safe = safePosterUrl(url)
|
||||
if (!safe || safe.startsWith('data:')) return safe
|
||||
try {
|
||||
const res = await fetch(safe, { mode: 'cors', credentials: 'omit', referrerPolicy: 'no-referrer', signal: AbortSignal.timeout(15_000) })
|
||||
// Réponse en erreur ou annoncée trop grosse : on ne lit pas le corps
|
||||
const announced = Number(res.headers.get('Content-Length'))
|
||||
if (!res.ok || (Number.isFinite(announced) && announced > LIMITS.imageFileBytes)) {
|
||||
await res.body?.cancel().catch(() => {})
|
||||
return safe
|
||||
}
|
||||
const blob = await res.blob()
|
||||
if (!blob.type.startsWith('image/') || blob.size > LIMITS.imageFileBytes) return safe
|
||||
return await blobToPosterDataURL(blob)
|
||||
} catch {
|
||||
return safe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Photo de profil ou bannière : recadrée au centre aux dimensions voulues et ré-encodée en JPEG
|
||||
* (aucune métadonnée cachée n'est conservée).
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { findTmdbSeries, getAniListById, getTmdbDetails, releaseToResult, type GlobalRelease } from './catalogApi'
|
||||
import { remotePosterToLocal } from './image'
|
||||
import type { MediaInput } from '../types'
|
||||
|
||||
/**
|
||||
@@ -13,7 +12,7 @@ export async function releaseToInput(r: GlobalRelease, tmdbKey?: string): Promis
|
||||
const series = r.externalId.startsWith('anilist:') && hasKey ? await findTmdbSeries([r.title, r.originalTitle], tmdbKey!).catch(() => undefined) : undefined
|
||||
if (series) {
|
||||
data = await getTmdbDetails(series, tmdbKey!)
|
||||
poster = series.posterUrl ? await remotePosterToLocal(series.posterUrl) : undefined
|
||||
poster = series.posterUrl
|
||||
} else if (r.externalId.startsWith('anilist:')) {
|
||||
const res = await getAniListById(r.externalId)
|
||||
data = { ...res?.prefill }
|
||||
@@ -21,7 +20,7 @@ export async function releaseToInput(r: GlobalRelease, tmdbKey?: string): Promis
|
||||
} else {
|
||||
const res = releaseToResult(r)
|
||||
if (res && hasKey) data = await getTmdbDetails(res, tmdbKey!)
|
||||
poster = r.poster ? await remotePosterToLocal(r.poster) : undefined
|
||||
poster = r.poster
|
||||
}
|
||||
return {
|
||||
title: r.title,
|
||||
|
||||
@@ -423,28 +423,6 @@ export async function renderTopCard(title: string, entries: (MediaItem | undefin
|
||||
return toBlob(canvas)
|
||||
}
|
||||
|
||||
/** Ouvre la feuille de partage (mobile) ou télécharge l'image. */
|
||||
export async function shareImage(blob: Blob, filename: string, title: string): Promise<'shared' | 'downloaded'> {
|
||||
const file = new File([blob], filename, { type: 'image/png' })
|
||||
if (navigator.canShare?.({ files: [file] })) {
|
||||
try {
|
||||
await navigator.share({ files: [file], title })
|
||||
return 'shared'
|
||||
} catch (e) {
|
||||
if ((e as DOMException)?.name === 'AbortError') return 'shared'
|
||||
}
|
||||
}
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = filename
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
||||
return 'downloaded'
|
||||
}
|
||||
|
||||
export const slug = (s: string) =>
|
||||
s
|
||||
.normalize('NFD')
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Petit module à part : la fenêtre d'aperçu l'importe directement, sans embarquer le dessin des cartes (shareCard, chargé à la demande).
|
||||
|
||||
/** Ouvre la feuille de partage (mobile) ou télécharge l'image. */
|
||||
export async function shareImage(blob: Blob, filename: string, title: string): Promise<'shared' | 'downloaded'> {
|
||||
const file = new File([blob], filename, { type: 'image/png' })
|
||||
if (navigator.canShare?.({ files: [file] })) {
|
||||
try {
|
||||
await navigator.share({ files: [file], title })
|
||||
return 'shared'
|
||||
} catch (e) {
|
||||
if ((e as DOMException)?.name === 'AbortError') return 'shared'
|
||||
}
|
||||
}
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = filename
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
setTimeout(() => URL.revokeObjectURL(url), 2000)
|
||||
return 'downloaded'
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { t } from '../i18n'
|
||||
import { LanguageSelect } from '../i18n/react'
|
||||
import { Check, Download, ExternalLink, HardDrive, Import, ShieldCheck, Trash2, Upload, UserX } from 'lucide-react'
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import { lazy, Suspense, useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import AccountSection from '../components/AccountSection'
|
||||
import ConfirmDialog from '../components/ConfirmDialog'
|
||||
import ImportWizard from '../components/ImportWizard'
|
||||
import { PageHeader, SectionTitle } from '../components/ui'
|
||||
import { exportBackup, parseBackupFile, type ParsedBackup } from '../lib/backup'
|
||||
import { ALL_TOP_CATEGORIES, TOP_CATEGORIES } from '../lib/constants'
|
||||
@@ -16,6 +15,9 @@ import { BugReportRow } from '../components/moderation/BugReport'
|
||||
import { alertsSummary, useAdminAlerts } from '../components/moderation/useAdminAlerts'
|
||||
import { APP_VERSION, buildLabel } from '../lib/appInfo'
|
||||
|
||||
// Assistant d'import (lecture des fichiers, recherche des titres) : chargé seulement quand on l'ouvre
|
||||
const ImportWizard = lazy(() => import('../components/ImportWizard'))
|
||||
|
||||
type Message = { kind: 'ok' | 'error'; text: string }
|
||||
|
||||
function Row({ icon, title, hint, onClick, danger }: { icon: ReactNode; title: string; hint?: string; onClick: () => void; danger?: boolean }) {
|
||||
@@ -221,7 +223,11 @@ export default function SettingsPage({ onOpenAdmin }: { onOpenAdmin: () => void
|
||||
<input ref={fileRef} type="file" accept="application/json,.json" hidden onChange={(e) => onFile(e.target.files?.[0])} />
|
||||
<Row icon={<Import size={19} />} title={t('import.row')} hint={t('import.rowHint')} onClick={() => setShowImport(true)} />
|
||||
</div>
|
||||
{showImport && <ImportWizard onClose={() => setShowImport(false)} />}
|
||||
{showImport && (
|
||||
<Suspense fallback={null}>
|
||||
<ImportWizard onClose={() => setShowImport(false)} />
|
||||
</Suspense>
|
||||
)}
|
||||
|
||||
{pending && (
|
||||
<div className="card mt-3 space-y-3 border-ink p-4">
|
||||
|
||||
Reference in new issue
Block a user