Moved feed funcs into own place

This commit is contained in:
WardPearce
2026-03-03 20:07:15 +13:00
parent c17d7ae03e
commit 6c52aa1abf
6 changed files with 58 additions and 56 deletions
@@ -5,7 +5,8 @@
import ContentColumn from '$lib/components/layout/ContentColumn.svelte';
import { onMount } from 'svelte';
import Thumbnail from '$lib/components/thumbnail/VideoThumbnail.svelte';
import { extractUniqueId, timeout, type feedItems } from '$lib/misc';
import { extractUniqueId, type FeedItems } from '$lib/feed';
import { timeout } from '$lib/misc';
import ChannelThumbnail from '$lib/components/thumbnail/ChannelThumbnail.svelte';
import PlaylistThumbnail from '$lib/components/thumbnail/PlaylistThumbnail.svelte';
import HashtagThumbnail from '$lib/components/thumbnail/HashtagThumbnail.svelte';
@@ -15,7 +16,7 @@
import { Capacitor } from '@capacitor/core';
interface Props {
items?: feedItems;
items?: FeedItems;
playlistId?: string;
playlistAuthor?: string;
classes?: string;
+51
View File
@@ -0,0 +1,51 @@
import type {
Channel,
HashTag,
Playlist,
PlaylistPage,
PlaylistPageVideo,
Video,
VideoBase,
VideoWatchHistory
} from './api/model';
export type FeedItem =
| VideoBase
| Video
| PlaylistPageVideo
| Channel
| Video
| Playlist
| HashTag
| PlaylistPage
| VideoWatchHistory;
export type FeedItems = FeedItem[];
export function extractUniqueId(item: FeedItem): string {
if ('videoId' in item) {
return item.videoId;
} else if ('playlistId' in item) {
return item.playlistId;
} else if ('authorId' in item) {
return item.authorId;
} else {
return item.title;
}
}
export function excludeDuplicateFeeds(currentItems: FeedItems, newItems: FeedItems): FeedItems {
const existingIds: string[] = [];
currentItems.forEach((item) => {
existingIds.push(extractUniqueId(item));
});
const nonDuplicatedNewItems: FeedItems = [];
newItems.forEach((item) => {
if (!existingIds.includes(extractUniqueId(item))) {
nonDuplicatedNewItems.push(item);
}
});
return [...nonDuplicatedNewItems, ...currentItems];
}
-51
View File
@@ -14,16 +14,6 @@ import {
rawMasterKeyStore,
searchCacheStore
} from './store';
import type {
Channel,
HashTag,
Playlist,
PlaylistPage,
PlaylistPageVideo,
Video,
VideoBase,
VideoWatchHistory
} from './api/model';
import { Capacitor } from '@capacitor/core';
import { Share } from '@capacitor/share';
import { Clipboard } from '@capacitor/clipboard';
@@ -89,47 +79,6 @@ export function ensureNoTrailingSlash(url: any): string {
return url.endsWith('/') ? url.slice(0, -1) : url;
}
export type feedItem =
| VideoBase
| Video
| PlaylistPageVideo
| Channel
| Video
| Playlist
| HashTag
| PlaylistPage
| VideoWatchHistory;
export type feedItems = feedItem[];
export function extractUniqueId(item: feedItem): string {
if ('videoId' in item) {
return item.videoId;
} else if ('playlistId' in item) {
return item.playlistId;
} else if ('authorId' in item) {
return item.authorId;
} else {
return item.title;
}
}
export function excludeDuplicateFeeds(currentItems: feedItems, newItems: feedItems): feedItems {
const existingIds: string[] = [];
currentItems.forEach((item) => {
existingIds.push(extractUniqueId(item));
});
const nonDuplicatedNewItems: feedItems = [];
newItems.forEach((item) => {
if (!existingIds.includes(extractUniqueId(item))) {
nonDuplicatedNewItems.push(item);
}
});
return [...nonDuplicatedNewItems, ...currentItems];
}
export function expandSummery(id: string) {
const element = document.getElementById(id);
if (element) {
@@ -1,6 +1,6 @@
import { getChannel, getChannelContent } from '$lib/api/index';
import type { ChannelContentVideos, Video } from '$lib/api/model';
import { excludeDuplicateFeeds } from '$lib/misc';
import { excludeDuplicateFeeds } from '$lib/feed';
import { channelCacheStore } from '$lib/store';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
@@ -1,6 +1,6 @@
import { getSearch } from '$lib/api/index';
import type { Channel, HashTag, Playlist, Video } from '$lib/api/model';
import { excludeDuplicateFeeds } from '$lib/misc';
import { excludeDuplicateFeeds } from '$lib/feed';
import { searchCacheStore } from '$lib/store';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
@@ -1,7 +1,8 @@
import { getFeed } from '$lib/api/index';
import type { PlaylistPageVideo, Video, VideoBase } from '$lib/api/model';
import { localDb } from '$lib/dexie';
import { authProtected, excludeDuplicateFeeds } from '$lib/misc';
import { excludeDuplicateFeeds } from '$lib/feed';
import { authProtected } from '$lib/misc';
import { feedCacheStore, feedLoadingStore } from '$lib/store';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';