Files
NewTube/server/providers/peertube.mjs
T
bruno 97e5de74f5
CI / build-and-test (push) Successful in 13m34s
feat(channel): page details chaine multi-providers avec onglets et infinite scroll
- Strategy Pattern front: ChannelProviderInterface + 6 providers (yt/dm/tw/pt/od/ru) + factory (ids longs/courts)
- ChannelContentService: cache par onglet/tri/recherche (TTL 5min), pagination nextPage
- ChannelPage: header (banniere/avatar/subs/description ...plus), tabs dynamiques par capabilities, grilles videos/shorts 9:16/playlists/live, recherche debounced, tri recent/populaire, infinite scroll IntersectionObserver, skeletons/empty/error
- Backend: GET /api/channels/:provider/:id/content (videos/shorts/playlists/live) natif par provider
2026-09-25 10:15:12 -04:00

59 lines
1.8 KiB
JavaScript

/**
* Minimal PeerTube provider handler
*/
const handler = {
id: 'pt',
label: 'PeerTube',
/**
* @param {string} q
* @param {{ limit: number, page?: number }} opts
* @returns {Promise<Array<any>>}
*/
async search(q, opts) {
const { limit = 10, page = 1 } = opts || {};
try {
// Use PeerTube API search
const response = await fetch(
`https://sepiasearch.org/api/v1/search/videos?` +
new URLSearchParams({
search: q,
count: Math.min(limit, 50).toString(),
start: Math.max(0, (Math.max(1, Number(page || 1)) - 1) * Math.min(limit, 50)).toString()
})
);
if (!response.ok) {
throw new Error(`PeerTube API error: ${response.status}`);
}
const data = await response.json();
return (data.data || []).map(item => {
const rawThumb = item.thumbnailUrl || item.thumbnailPath || '';
const thumbnail = rawThumb
? rawThumb.startsWith('http')
? rawThumb
: rawThumb.startsWith('//')
? `https:${rawThumb}`
: new URL(rawThumb, item.url || 'https://sepiasearch.org').toString()
: undefined;
return {
title: item.name,
id: item.uuid,
url: item.url,
thumbnail,
uploaderName: (item.account && (item.account.displayName || item.account.name)) || undefined,
channelId: (item.channel && (item.channel.name || item.channel.uuid)) || (item.account && item.account.name) || undefined,
type: 'video',
duration: typeof item.duration === 'number' && item.duration > 0 ? Math.round(item.duration) : undefined
};
});
} catch (error) {
console.error('PeerTube search error:', error);
return [];
}
}
};
export default handler;