fix: youtube thumbnail having strange formats

This commit is contained in:
PandaDEV 2024-12-17 00:00:21 +10:00
parent 14a13f44bb
commit 345f7e3f09
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
2 changed files with 30 additions and 33 deletions

View file

@ -111,7 +111,7 @@ $mutedtext: #78756f;
align-items: center; align-items: center;
overflow: hidden; overflow: hidden;
&:not(:has(.full-image, .image)) { &:not(:has(.image)) {
padding: 8px; padding: 8px;
} }
@ -119,23 +119,6 @@ $mutedtext: #78756f;
font-family: CommitMono Nerd Font !important; font-family: CommitMono Nerd Font !important;
} }
.full-image {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
img {
width: 100%;
height: 100%;
object-fit: contain;
object-position: center;
}
}
.image { .image {
width: 100%; width: 100%;
height: 100%; height: 100%;

View file

@ -87,19 +87,24 @@
</div> </div>
</template> </template>
</OverlayScrollbarsComponent> </OverlayScrollbarsComponent>
<div <div
class="content" class="content"
v-if="selectedItem?.content_type === ContentType.Image"> v-if="selectedItem?.content_type === ContentType.Image">
<img :src="imageUrls[selectedItem.id]" alt="Image" class="image" /> <img :src="imageUrls[selectedItem.id]" alt="Image" class="image" />
</div> </div>
<div
v-else-if="selectedItem && isYoutubeWatchUrl(selectedItem.content)"
class="content">
<img
class="image"
:src="getYoutubeThumbnail(selectedItem.content)"
alt="YouTube Thumbnail" />
</div>
<OverlayScrollbarsComponent v-else class="content"> <OverlayScrollbarsComponent v-else class="content">
<div v-if="selectedItem && isYoutubeWatchUrl(selectedItem.content)" class="full-image"> <span>{{ selectedItem?.content || "" }}</span>
<img
:src="getYoutubeThumbnail(selectedItem.content)"
alt="YouTube Thumbnail" />
</div>
<span v-else>{{ selectedItem?.content || "" }}</span>
</OverlayScrollbarsComponent> </OverlayScrollbarsComponent>
<OverlayScrollbarsComponent <OverlayScrollbarsComponent
class="information" class="information"
:options="{ scrollbars: { autoHide: 'scroll' } }"> :options="{ scrollbars: { autoHide: 'scroll' } }">
@ -399,7 +404,9 @@ const scrollToSelectedItem = (forceScrollTop: boolean = false): void => {
if (isAbove || isBelow) { if (isAbove || isBelow) {
const scrollOffset = isAbove const scrollOffset = isAbove
? elementRect.top - viewportRect.top - (selectedItemIndex.value === 0 ? 36 : 8) ? elementRect.top -
viewportRect.top -
(selectedItemIndex.value === 0 ? 36 : 8)
: elementRect.bottom - viewportRect.bottom + 9; : elementRect.bottom - viewportRect.bottom + 9;
viewport.scrollBy({ top: scrollOffset, behavior: "smooth" }); viewport.scrollBy({ top: scrollOffset, behavior: "smooth" });
@ -504,8 +511,8 @@ const getYoutubeThumbnail = (url: string): string => {
videoId = url.match(/[?&]v=([^&]+)/)?.[1]; videoId = url.match(/[?&]v=([^&]+)/)?.[1];
} }
return videoId return videoId
? `https://img.youtube.com/vi/${videoId}/0.jpg` ? `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`
: "https://via.placeholder.com/150"; : "https://via.placeholder.com/1280x720";
}; };
const getFaviconFromDb = (favicon: string): string => { const getFaviconFromDb = (favicon: string): string => {
@ -515,8 +522,8 @@ const getFaviconFromDb = (favicon: string): string => {
const updateHistory = async (resetScroll: boolean = false): Promise<void> => { const updateHistory = async (resetScroll: boolean = false): Promise<void> => {
const results = await $history.loadHistoryChunk(0, CHUNK_SIZE); const results = await $history.loadHistoryChunk(0, CHUNK_SIZE);
if (results.length > 0) { if (results.length > 0) {
const existingIds = new Set(history.value.map(item => item.id)); const existingIds = new Set(history.value.map((item) => item.id));
const uniqueNewItems = results.filter(item => !existingIds.has(item.id)); const uniqueNewItems = results.filter((item) => !existingIds.has(item.id));
const processedNewItems = await Promise.all( const processedNewItems = await Promise.all(
uniqueNewItems.map(async (item) => { uniqueNewItems.map(async (item) => {
@ -567,7 +574,10 @@ const updateHistory = async (resetScroll: boolean = false): Promise<void> => {
history.value = [...processedNewItems, ...history.value]; history.value = [...processedNewItems, ...history.value];
if (resetScroll && resultsContainer.value?.osInstance()?.elements().viewport) { if (
resetScroll &&
resultsContainer.value?.osInstance()?.elements().viewport
) {
resultsContainer.value.osInstance()?.elements().viewport?.scrollTo({ resultsContainer.value.osInstance()?.elements().viewport?.scrollTo({
top: 0, top: 0,
behavior: "smooth", behavior: "smooth",
@ -604,7 +614,9 @@ const setupEventListeners = async (): Promise<void> => {
const previousState = { const previousState = {
groupIndex: selectedGroupIndex.value, groupIndex: selectedGroupIndex.value,
itemIndex: selectedItemIndex.value, itemIndex: selectedItemIndex.value,
scroll: resultsContainer.value?.osInstance()?.elements().viewport?.scrollTop || 0, scroll:
resultsContainer.value?.osInstance()?.elements().viewport
?.scrollTop || 0,
}; };
await updateHistory(); await updateHistory();
@ -612,7 +624,9 @@ const setupEventListeners = async (): Promise<void> => {
handleSelection(previousState.groupIndex, previousState.itemIndex, false); handleSelection(previousState.groupIndex, previousState.itemIndex, false);
nextTick(() => { nextTick(() => {
const viewport = resultsContainer.value?.osInstance()?.elements().viewport; const viewport = resultsContainer.value
?.osInstance()
?.elements().viewport;
if (viewport) { if (viewport) {
viewport.scrollTo({ viewport.scrollTo({
top: previousState.scroll, top: previousState.scroll,