feat(providers): phases 7.3/7.4/7.6/8.1 — provenance, health, NDJSON, contrat unique
CI / build-and-test (push) Successful in 14m43s
CI / build-and-test (push) Successful in 14m43s
7.3: capturedAt/source au registre + 6 adaptateurs + module provenance.ts + ?debug=1 (search-transport.mjs). 7.4: ProviderHealthService + badge source degradee. 7.6: squelettes par provider + snapshots progressifs + transport NDJSON /api/search. 8.1: ProviderAdapter unifie (search enveloppe + channelContent/channelMeta/capabilities) via getProviderAdapter + test de contrat offline.
This commit is contained in:
@@ -3,6 +3,9 @@ import { firstValueFrom } from 'rxjs';
|
||||
import type { ProviderAdapter, ProviderSearchParams, SearchResult } from '../models';
|
||||
import { VideoItem } from 'src/app/shared/models/video-item.model';
|
||||
import { withFilterParams } from './filter-params';
|
||||
import { readSearchGroup } from '../search-contract';
|
||||
import { mapProvenance } from './provenance';
|
||||
import { buildPeerTubeComposite, serverRefValue } from '../../shared/providers/channel-ref';
|
||||
|
||||
export class PtAdapter implements ProviderAdapter<VideoItem> {
|
||||
key = 'pt' as const;
|
||||
@@ -16,24 +19,31 @@ export class PtAdapter implements ProviderAdapter<VideoItem> {
|
||||
// le sait, affinés en post-traitement sinon.
|
||||
httpParams = withFilterParams(httpParams, params.filters);
|
||||
const res = await firstValueFrom(this.http.get<any>(`/api/search`, { params: httpParams }));
|
||||
const providerError = typeof res?.errors?.pt?.message === 'string' ? res.errors.pt.message : undefined;
|
||||
const items: VideoItem[] = (res?.groups?.pt || []).map((it: any) => {
|
||||
const { items: rawItems, providerError } = readSearchGroup(res, 'pt');
|
||||
const items: VideoItem[] = rawItems.map((it: any) => {
|
||||
// PeerTube identifie une chaîne par `instance|channel` : l'instance est
|
||||
// dérivée de l'URL vidéo, le nom de chaîne de `channelId`.
|
||||
let channelExternalId: string | undefined;
|
||||
try {
|
||||
const host = it?.url ? new URL(String(it.url)).hostname : '';
|
||||
if (host && it?.channelId) channelExternalId = `${host}|${it.channelId}`;
|
||||
} catch {}
|
||||
// Phase 6 : si le serveur a envoyé `channelRef`, sa valeur canonique
|
||||
// prime — sinon on reconstruit avec la règle historique.
|
||||
let channelExternalId: string | undefined =
|
||||
serverRefValue(it?.channelRef, 'pt') ?? buildPeerTubeComposite(it?.url, it?.channelId);
|
||||
return {
|
||||
// Phase 7.3 — provenance (instant de collecte + voie), commune aux 6.
|
||||
...mapProvenance(it),
|
||||
id: it.id,
|
||||
provider: 'peertube',
|
||||
title: it.title,
|
||||
channelName: it.uploaderName,
|
||||
durationSec: it.duration,
|
||||
thumbnailUrl: it.thumbnail,
|
||||
viewCount: undefined,
|
||||
publishedAt: undefined,
|
||||
// `viewCount: undefined` en dur alors que le serveur envoie déjà le
|
||||
// nombre de vues : les compteurs PeerTube n'arrivaient jamais dans l'UI
|
||||
// (trouvé en gelant la sortie réelle, phase 8.4). On lit le champ
|
||||
// canonique `views` et on garde `viewCount` en repli.
|
||||
viewCount: typeof it.views === 'number' ? it.views
|
||||
: (typeof it.viewCount === 'number' ? it.viewCount : undefined),
|
||||
// Le serveur envoie `publishedAt` (ISO) quand l'instance l'expose.
|
||||
publishedAt: typeof it.publishedAt === 'string' ? it.publishedAt : undefined,
|
||||
channelExternalId,
|
||||
// Signaux de type pour le raffinement client des filtres.
|
||||
type: typeof it.type === 'string' ? it.type : undefined,
|
||||
@@ -43,6 +53,6 @@ export class PtAdapter implements ProviderAdapter<VideoItem> {
|
||||
height: typeof it.height === 'number' ? it.height : undefined,
|
||||
} as VideoItem;
|
||||
});
|
||||
return { items, total: Array.isArray(res?.groups?.pt) ? res.groups.pt.length : 0, providerError };
|
||||
return { items, total: rawItems.length, providerError };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user