Feat : Preview on streamers
This commit is contained in:
@@ -916,6 +916,13 @@ export interface WatchTarget {
|
||||
|
||||
/** Photo de profil. */
|
||||
avatarUrl: string | null;
|
||||
/**
|
||||
* Vignette du flux — voir {@link StripchatStatus.previewUrl}. Absente hors
|
||||
* diffusion connue ; la carte ne montre l'aperçu que sur un profil en direct.
|
||||
*/
|
||||
previewUrl: string | null;
|
||||
/** Horodatage de la vignette, à ajouter en paramètre d'URL pour éviter le cache. */
|
||||
snapshotAt: number | null;
|
||||
/**
|
||||
* Début du statut courant d'après la plateforme. Quand `state` vaut `public`,
|
||||
* c'est l'heure de début du stream en cours.
|
||||
@@ -1198,6 +1205,20 @@ export interface StripchatStatus {
|
||||
* du stream en cours — bien plus précis que notre propre première observation.
|
||||
*/
|
||||
statusChangedAt: number | null;
|
||||
/**
|
||||
* Vignette du flux (`previewUrlThumbBig`) — une image, pas un flux vidéo :
|
||||
* l'agent seul pilote un navigateur, le serveur n'a que cette API REST.
|
||||
* Absente si le modèle n'a jamais diffusé.
|
||||
*/
|
||||
previewUrl: string | null;
|
||||
/**
|
||||
* Horodatage de cette vignette côté plateforme, pour invalider le cache du
|
||||
* navigateur : l'URL, elle, ne change pas d'une image à l'autre — le CDN la
|
||||
* sert avec un `max-age` de 30 jours. Sans un paramètre qui varie à chaque
|
||||
* rafraîchissement, le navigateur garderait indéfiniment la toute première
|
||||
* image vue.
|
||||
*/
|
||||
snapshotAt: number | null;
|
||||
}
|
||||
|
||||
export async function fetchStripchatStatus(
|
||||
@@ -1219,12 +1240,27 @@ export async function fetchStripchatStatus(
|
||||
});
|
||||
|
||||
if (response.status === 404) {
|
||||
return { raw: 'notFound', state: 'offline', avatarUrl: null, statusChangedAt: null };
|
||||
return {
|
||||
raw: 'notFound',
|
||||
state: 'offline',
|
||||
avatarUrl: null,
|
||||
statusChangedAt: null,
|
||||
previewUrl: null,
|
||||
snapshotAt: null,
|
||||
};
|
||||
}
|
||||
if (!response.ok) throw new Error(`API Stripchat : HTTP ${response.status}`);
|
||||
|
||||
const payload = (await response.json()) as {
|
||||
user?: { user?: { status?: string; avatarUrl?: string; statusChangedAt?: string } };
|
||||
user?: {
|
||||
user?: {
|
||||
status?: string;
|
||||
avatarUrl?: string;
|
||||
statusChangedAt?: string;
|
||||
previewUrlThumbBig?: string;
|
||||
snapshotTimestamp?: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
const profile = payload?.user?.user;
|
||||
const raw = profile?.status;
|
||||
@@ -1235,12 +1271,19 @@ export async function fetchStripchatStatus(
|
||||
const changedAt = profile?.statusChangedAt
|
||||
? Date.parse(profile.statusChangedAt)
|
||||
: Number.NaN;
|
||||
// Secondes côté API, comme tous les timestamps Unix bruts de cette plateforme.
|
||||
const snapshotAt = Number(profile?.snapshotTimestamp) * 1000;
|
||||
|
||||
return {
|
||||
raw,
|
||||
state: mapStreamStatus(raw, privateStatuses),
|
||||
avatarUrl: typeof profile?.avatarUrl === 'string' && profile.avatarUrl ? profile.avatarUrl : null,
|
||||
statusChangedAt: Number.isFinite(changedAt) ? changedAt : null,
|
||||
previewUrl:
|
||||
typeof profile?.previewUrlThumbBig === 'string' && profile.previewUrlThumbBig
|
||||
? profile.previewUrlThumbBig
|
||||
: null,
|
||||
snapshotAt: Number.isFinite(snapshotAt) && snapshotAt > 0 ? snapshotAt : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user