2026-03-14 11:55:45 +08:00
|
|
|
import type { VideoItem, LiveRoom } from '../services/types';
|
2026-03-11 14:20:20 +08:00
|
|
|
|
|
|
|
|
export interface NormalRow {
|
|
|
|
|
type: 'pair';
|
|
|
|
|
left: VideoItem;
|
|
|
|
|
right: VideoItem | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface BigRow {
|
|
|
|
|
type: 'big';
|
|
|
|
|
item: VideoItem;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 11:55:45 +08:00
|
|
|
export interface LiveRow {
|
|
|
|
|
type: 'live';
|
|
|
|
|
left: LiveRoom;
|
|
|
|
|
right?: LiveRoom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ListRow = NormalRow | BigRow | LiveRow;
|
2026-03-11 14:20:20 +08:00
|
|
|
|
2026-03-14 11:55:45 +08:00
|
|
|
export function toListRows(pages: VideoItem[][], liveRooms?: LiveRoom[]): ListRow[] {
|
2026-03-11 14:20:20 +08:00
|
|
|
const rows: ListRow[] = [];
|
2026-03-14 12:27:03 +08:00
|
|
|
let roomIdx = 0;
|
2026-03-14 11:55:45 +08:00
|
|
|
|
2026-03-13 21:52:09 +08:00
|
|
|
for (const chunk of pages) {
|
|
|
|
|
if (chunk.length === 0) continue;
|
2026-03-14 11:55:45 +08:00
|
|
|
|
|
|
|
|
// Highest view count becomes BigRow
|
|
|
|
|
let bigIdx = 0;
|
|
|
|
|
let maxView = chunk[0].stat?.view ?? 0;
|
|
|
|
|
for (let i = 1; i < chunk.length; i++) {
|
|
|
|
|
const v = chunk[i].stat?.view ?? 0;
|
|
|
|
|
if (v > maxView) { maxView = v; bigIdx = i; }
|
2026-03-11 20:53:18 +08:00
|
|
|
}
|
2026-03-14 11:55:45 +08:00
|
|
|
|
2026-03-13 00:30:07 +08:00
|
|
|
const bigItem = chunk[bigIdx];
|
|
|
|
|
const rest = chunk.filter((_, i) => i !== bigIdx);
|
2026-03-14 11:55:45 +08:00
|
|
|
|
2026-03-14 12:27:03 +08:00
|
|
|
const pairs: (NormalRow | LiveRow)[] = [];
|
2026-03-13 00:30:07 +08:00
|
|
|
for (let i = 0; i < rest.length; i += 2) {
|
2026-03-17 15:14:23 +08:00
|
|
|
if (rest[i + 1]) {
|
|
|
|
|
pairs.push({ type: 'pair', left: rest[i], right: rest[i + 1] ?? null });
|
|
|
|
|
}
|
2026-03-13 00:30:07 +08:00
|
|
|
}
|
2026-03-14 11:55:45 +08:00
|
|
|
|
|
|
|
|
|
2026-03-17 15:14:23 +08:00
|
|
|
|
|
|
|
|
// if (liveRooms && roomIdx < liveRooms.length && pairs.length > 0) {
|
|
|
|
|
// const seed = chunk[0]?.aid ?? 0;
|
|
|
|
|
// const insertAt = seed % (pairs.length + 1);
|
|
|
|
|
// pairs.splice(insertAt, 0, {
|
|
|
|
|
// type: 'live',
|
|
|
|
|
// left: liveRooms[roomIdx],
|
|
|
|
|
// });
|
|
|
|
|
// roomIdx++;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rows.length < 20) {
|
|
|
|
|
rows.push({ type: 'big', item: bigItem }, ...pairs);
|
|
|
|
|
} else {
|
|
|
|
|
rows.push(...pairs, { type: 'big', item: bigItem });
|
|
|
|
|
}
|
2026-03-11 14:20:20 +08:00
|
|
|
}
|
|
|
|
|
return rows;
|
|
|
|
|
}
|