mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-21 16:25:11 +02:00
add: Update checker
fix: Jellyfin user id being hard coded
This commit is contained in:
@@ -17,11 +17,26 @@ export const JellyfinApi = createClient<paths>({
|
||||
}
|
||||
});
|
||||
|
||||
export const getJellyfinContinueWatching = (): Promise<JellyfinItem[]> =>
|
||||
let userId: string | undefined = undefined;
|
||||
const getUserId = async () => {
|
||||
if (userId) return userId;
|
||||
|
||||
const user = JellyfinApi.get('/Users', {
|
||||
params: {},
|
||||
headers: {
|
||||
'cache-control': 'max-age=3600'
|
||||
}
|
||||
}).then((r) => r.data?.[0]?.Id || '');
|
||||
|
||||
userId = await user;
|
||||
return user;
|
||||
};
|
||||
|
||||
export const getJellyfinContinueWatching = async (): Promise<JellyfinItem[]> =>
|
||||
JellyfinApi.get('/Users/{userId}/Items/Resume', {
|
||||
params: {
|
||||
path: {
|
||||
userId: get(settings).jellyfin.userId
|
||||
userId: await getUserId()
|
||||
},
|
||||
query: {
|
||||
mediaTypes: ['Video'],
|
||||
@@ -30,21 +45,21 @@ export const getJellyfinContinueWatching = (): Promise<JellyfinItem[]> =>
|
||||
}
|
||||
}).then((r) => r.data?.Items || []);
|
||||
|
||||
export const getJellyfinNextUp = () =>
|
||||
export const getJellyfinNextUp = async () =>
|
||||
JellyfinApi.get('/Shows/NextUp', {
|
||||
params: {
|
||||
query: {
|
||||
userId: get(settings).jellyfin.userId,
|
||||
userId: await getUserId(),
|
||||
fields: ['ProviderIds']
|
||||
}
|
||||
}
|
||||
}).then((r) => r.data?.Items || []);
|
||||
|
||||
export const getJellyfinItems = () =>
|
||||
export const getJellyfinItems = async () =>
|
||||
JellyfinApi.get('/Users/{userId}/Items', {
|
||||
params: {
|
||||
path: {
|
||||
userId: get(settings).jellyfin.userId
|
||||
userId: await getUserId()
|
||||
},
|
||||
query: {
|
||||
hasTmdbId: true,
|
||||
@@ -59,7 +74,7 @@ export const getJellyfinItems = () =>
|
||||
// JellyfinApi.get('/Users/{userId}/Items', {
|
||||
// params: {
|
||||
// path: {
|
||||
// userId: get(settings).jellyfin.userId
|
||||
// userId: env.PUBLIC_JELLYFIN_USER_ID || ""
|
||||
// },
|
||||
// query: {
|
||||
// hasTmdbId: true,
|
||||
@@ -69,11 +84,11 @@ export const getJellyfinItems = () =>
|
||||
// }
|
||||
// }).then((r) => r.data?.Items || []);
|
||||
|
||||
export const getJellyfinEpisodes = () =>
|
||||
export const getJellyfinEpisodes = async () =>
|
||||
JellyfinApi.get('/Users/{userId}/Items', {
|
||||
params: {
|
||||
path: {
|
||||
userId: get(settings).jellyfin.userId
|
||||
userId: await getUserId()
|
||||
},
|
||||
query: {
|
||||
recursive: true,
|
||||
@@ -91,12 +106,12 @@ export const getJellyfinEpisodesBySeries = (seriesId: string) =>
|
||||
export const getJellyfinItemByTmdbId = (tmdbId: string) =>
|
||||
getJellyfinItems().then((items) => items.find((i) => i.ProviderIds?.Tmdb == tmdbId));
|
||||
|
||||
export const getJellyfinItem = (itemId: string) =>
|
||||
export const getJellyfinItem = async (itemId: string) =>
|
||||
JellyfinApi.get('/Users/{userId}/Items/{itemId}', {
|
||||
params: {
|
||||
path: {
|
||||
itemId,
|
||||
userId: get(settings).jellyfin.userId
|
||||
userId: await getUserId()
|
||||
}
|
||||
}
|
||||
}).then((r) => r.data);
|
||||
@@ -104,7 +119,7 @@ export const getJellyfinItem = (itemId: string) =>
|
||||
export const requestJellyfinItemByTmdbId = () =>
|
||||
request((tmdbId: string) => getJellyfinItemByTmdbId(tmdbId));
|
||||
|
||||
export const getJellyfinPlaybackInfo = (
|
||||
export const getJellyfinPlaybackInfo = async (
|
||||
itemId: string,
|
||||
playbackProfile: DeviceProfile,
|
||||
startTimeTicks = 0
|
||||
@@ -115,7 +130,7 @@ export const getJellyfinPlaybackInfo = (
|
||||
itemId: itemId
|
||||
},
|
||||
query: {
|
||||
userId: get(settings).jellyfin.userId,
|
||||
userId: await getUserId(),
|
||||
startTimeTicks,
|
||||
autoOpenLiveStream: true,
|
||||
maxStreamingBitrate: 140000000
|
||||
@@ -184,11 +199,11 @@ export const reportJellyfinPlaybackStopped = (
|
||||
}
|
||||
});
|
||||
|
||||
export const setJellyfinItemWatched = (jellyfinId: string) =>
|
||||
export const setJellyfinItemWatched = async (jellyfinId: string) =>
|
||||
JellyfinApi.post('/Users/{userId}/PlayedItems/{itemId}', {
|
||||
params: {
|
||||
path: {
|
||||
userId: get(settings).jellyfin.userId,
|
||||
userId: await getUserId(),
|
||||
itemId: jellyfinId
|
||||
},
|
||||
query: {
|
||||
@@ -197,11 +212,11 @@ export const setJellyfinItemWatched = (jellyfinId: string) =>
|
||||
}
|
||||
});
|
||||
|
||||
export const setJellyfinItemUnwatched = (jellyfinId: string) =>
|
||||
export const setJellyfinItemUnwatched = async (jellyfinId: string) =>
|
||||
JellyfinApi.del('/Users/{userId}/PlayedItems/{itemId}', {
|
||||
params: {
|
||||
path: {
|
||||
userId: get(settings).jellyfin.userId,
|
||||
userId: await getUserId(),
|
||||
itemId: jellyfinId
|
||||
}
|
||||
}
|
||||
|
||||
28
src/lib/components/UpdateChecker.svelte
Normal file
28
src/lib/components/UpdateChecker.svelte
Normal file
@@ -0,0 +1,28 @@
|
||||
<script lang="ts">
|
||||
import { skippedVersion } from '$lib/localstorage';
|
||||
import axios from 'axios';
|
||||
import IconButton from './IconButton.svelte';
|
||||
import { Cross2 } from 'radix-icons-svelte';
|
||||
import { log } from '$lib/utils';
|
||||
import { version } from '$app/environment';
|
||||
|
||||
let visible = true;
|
||||
|
||||
function fetchLatestVersion() {
|
||||
return axios
|
||||
.get('https://api.github.com/repos/aleksilassila/reiverr/tags')
|
||||
.then((res) => res.data?.[0]?.name)
|
||||
.then(log);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#await fetchLatestVersion() then latestVersion}
|
||||
{#if latestVersion !== `v${version}` && latestVersion !== $skippedVersion && visible}
|
||||
<div class="fixed inset-x-0 bottom-0 p-2 flex items-center justify-center z-20 bg-stone-800">
|
||||
<a href="https://github.com/aleksilassila/reiverr">New version is available!</a>
|
||||
<IconButton on:click={() => (visible = false)} class="absolute right-8 inset-y-0">
|
||||
<Cross2 size={20} />
|
||||
</IconButton>
|
||||
</div>
|
||||
{/if}
|
||||
{/await}
|
||||
15
src/lib/localstorage.ts
Normal file
15
src/lib/localstorage.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
function createLocalStorageStore(key: string) {
|
||||
const store = writable(JSON.parse(localStorage.getItem(key) || 'null') || null);
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe,
|
||||
set: (value: any) => {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
store.set(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const skippedVersion = createLocalStorageStore('skipped-version');
|
||||
@@ -44,9 +44,6 @@ const defaultSettings: Settings = {
|
||||
qualityProfileId: 4,
|
||||
profileId: 4,
|
||||
rootFolderPath: '/movies'
|
||||
},
|
||||
jellyfin: {
|
||||
userId: '75dcb061c9404115a7acdc893ea6bbbc'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user