|
12 | 12 | import SkeletonVideoEntry from "./SkeletonVideoEntry.svelte";
|
13 | 13 | import type { HistoryResponse, VideoInfo } from "./video";
|
14 | 14 | import VideoEntry from "./VideoEntry.svelte";
|
15 |
| - import { onDestroy } from "svelte"; |
| 15 | + import { onDestroy, onMount } from "svelte"; |
16 | 16 | import type { SearchMetadata } from "./search";
|
17 | 17 | import { delay } from "./api.js";
|
18 | 18 | import { MeiliSearch, SearchResponse } from "meilisearch";
|
|
21 | 21 | let page = 1;
|
22 | 22 | let limit = 25;
|
23 | 23 |
|
| 24 | + $: title = "History - pomu.app"; |
| 25 | + let onlyOneForArchivePage = false; |
| 26 | +
|
24 | 27 | let searchValue = "";
|
25 | 28 | let lastSearch: SearchResponse<Partial<VideoInfo>> = null;
|
26 | 29 | $: offset = (page - 1) * limit;
|
|
73 | 76 | sort: ["scheduledStart:desc"],
|
74 | 77 | page: page,
|
75 | 78 | offset: offset,
|
76 |
| - hitsPerPage: limit, |
| 79 | + hitsPerPage: onlyOneForArchivePage ? 1 : limit, |
77 | 80 | }, {
|
78 | 81 | signal: abortController.signal
|
79 | 82 | });
|
80 | 83 |
|
| 84 | + if (onlyOneForArchivePage) { |
| 85 | + onlyOneForArchivePage = false; |
| 86 | + } |
| 87 | +
|
81 | 88 | // fix up download urls (as they are not populated, hence the `Partial` in `Partial<VideoInfo>`
|
82 | 89 | search.hits.forEach((part, index, array) => {
|
83 | 90 | array[index].downloadUrl = `/api/download/${part.id}/video`;
|
|
95 | 102 |
|
96 | 103 | onDestroy(() => abortController.abort());
|
97 | 104 |
|
| 105 | + if (window.location.pathname.startsWith("/archive/")) { |
| 106 | + searchValue = window.location.pathname.substring("/archive/".length); |
| 107 | +
|
| 108 | + onMount(async () => { |
| 109 | + let data = await requestMeilisearchData(); |
| 110 | +
|
| 111 | + if (!data.enabled) { |
| 112 | + return; |
| 113 | + } |
| 114 | +
|
| 115 | + onlyOneForArchivePage = true; |
| 116 | + let search = await startSearch(); |
| 117 | +
|
| 118 | + if ((search.estimatedTotalHits ?? search.totalHits) >= 1) { |
| 119 | + let hit = search.hits[0]; |
| 120 | + title = `${hit.title} by ${hit.channelName} - archived on pomu.app`; |
| 121 | + } |
| 122 | + }); |
| 123 | + } |
| 124 | +
|
98 | 125 | let history = requestHistory();
|
99 | 126 | </script>
|
100 | 127 |
|
| 128 | +<svelte:head> |
| 129 | + <title>{title}</title> |
| 130 | +</svelte:head> |
| 131 | + |
101 | 132 | <Grid>
|
102 | 133 | <Row>
|
103 | 134 | <Column>
|
|
0 commit comments