Move all components from window.api to api #202
This commit is contained in:
22 files changed
+316
-269
No files matched your search
+138
-136
@@ -81,7 +81,11 @@ import "@fontsource-variable/jetbrains-mono";
|
||||
import { Jellyfin } from "@jellyfin/sdk";
|
||||
import { version as appVer } from "../package.json";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { delServer, getServer } from "./utils/storage/servers.js";
|
||||
import {
|
||||
delServer,
|
||||
getDefaultServer,
|
||||
getServer,
|
||||
} from "./utils/storage/servers.js";
|
||||
import { delUser, getUser } from "./utils/storage/user.js";
|
||||
|
||||
import { useBackdropStore } from "./utils/store/backdrop.js";
|
||||
@@ -99,6 +103,8 @@ import PlaylistTitlePage from "./routes/playlist/index.jsx";
|
||||
import axios from "axios";
|
||||
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
|
||||
import { useApi } from "./utils/store/api.js";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api.js";
|
||||
|
||||
export const axiosClient = axios.create({
|
||||
adapter: axiosTauriApiAdapter,
|
||||
@@ -106,35 +112,6 @@ export const axiosClient = axios.create({
|
||||
timeout: 60000,
|
||||
});
|
||||
|
||||
const deviceId = localStorage.getItem("deviceId");
|
||||
|
||||
if (!deviceId) {
|
||||
localStorage.setItem("deviceId", uuidv4());
|
||||
}
|
||||
|
||||
const jellyfin = new Jellyfin({
|
||||
clientInfo: {
|
||||
name: "JellyPlayer",
|
||||
version: appVer,
|
||||
},
|
||||
deviceInfo: {
|
||||
name: "JellyPlayer",
|
||||
id: deviceId,
|
||||
},
|
||||
});
|
||||
|
||||
event.on("create-jellyfin-api", (serverAddress) => {
|
||||
window.api = jellyfin.createApi(serverAddress, null, axiosClient);
|
||||
// window.api = jellyfin.createApi(serverAddress);
|
||||
});
|
||||
event.on("set-api-accessToken", (serverAddress) => {
|
||||
window.api = jellyfin.createApi(
|
||||
serverAddress,
|
||||
sessionStorage.getItem("accessToken"),
|
||||
axiosClient,
|
||||
);
|
||||
});
|
||||
|
||||
const anim = {
|
||||
initial: {
|
||||
transform: "scale(0.98)",
|
||||
@@ -171,6 +148,15 @@ const AnimationWrapper = () => {
|
||||
function App() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
/**
|
||||
* @type {[import("@jellyfin/sdk").Api, function, Jellyfin]}
|
||||
*/
|
||||
const [api, createApi, jellyfin] = useApi((state) => [
|
||||
state.api,
|
||||
state.createApi,
|
||||
state.jellyfin,
|
||||
]);
|
||||
|
||||
const [serverReachable, setServerReachable] = useState(true);
|
||||
|
||||
const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [
|
||||
@@ -179,113 +165,93 @@ function App() {
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const createApi = async () => {
|
||||
const server = await getServer();
|
||||
event.emit("create-jellyfin-api", server.Ip);
|
||||
};
|
||||
|
||||
const serverAvailable = async () => {
|
||||
const server = await getServer();
|
||||
|
||||
if (server == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const usersAvailable = async () => {
|
||||
const users = await getUserApi(window.api).getPublicUsers();
|
||||
if (users.status == 200 || users.data.length >= 1) {
|
||||
return true;
|
||||
const serverSaved = async () => {
|
||||
const defaultServer = await getDefaultServer();
|
||||
// console.log(defaultServer);
|
||||
if (defaultServer) {
|
||||
return defaultServer;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const userSaved = async () => {
|
||||
const user = await getUser();
|
||||
if (user == null) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const pingServer = async () => {
|
||||
const server = await getServer();
|
||||
try {
|
||||
const result = await axiosClient.get(
|
||||
new URL(`${server.Ip}/System/Ping`).href,
|
||||
);
|
||||
|
||||
if (result.data == "Jellyfin Server") {
|
||||
event.emit("create-jellyfin-api", server.Ip);
|
||||
setServerReachable(true);
|
||||
} else {
|
||||
setServerReachable(false);
|
||||
}
|
||||
} catch (error) {
|
||||
setServerReachable(false);
|
||||
enqueueSnackbar("Unable to verfiy server address.", {
|
||||
variant: "error",
|
||||
});
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const userLogin = async () => {
|
||||
const user = await getUser();
|
||||
const auth = await window.api.authenticateUserByName(
|
||||
user.Name,
|
||||
user.Password,
|
||||
);
|
||||
sessionStorage.setItem("accessToken", auth.data.AccessToken);
|
||||
event.emit("set-api-accessToken", window.api.basePath);
|
||||
};
|
||||
|
||||
const LogicalRoutes = () => {
|
||||
serverAvailable().then(async (server) => {
|
||||
if (server == true) {
|
||||
createApi().then(() => {
|
||||
pingServer();
|
||||
if (serverReachable == true) {
|
||||
userSaved().then((user_available) => {
|
||||
if (user_available == true) {
|
||||
navigate("/home");
|
||||
serverSaved()
|
||||
.then(async (server) => {
|
||||
console.log(server);
|
||||
if (server) {
|
||||
const savedServer = await getServer(server);
|
||||
console.log(savedServer);
|
||||
createApi(savedServer.address);
|
||||
try {
|
||||
const ping = await getSystemApi(
|
||||
api,
|
||||
).getPingSystem();
|
||||
if (ping.status == 200) {
|
||||
console.info(api);
|
||||
const userSaved = await getUser();
|
||||
if (userSaved) {
|
||||
try {
|
||||
const authenticate =
|
||||
await api.authenticateUserByName(
|
||||
userSaved.Name,
|
||||
userSaved.Password,
|
||||
);
|
||||
if (authenticate.status == 200) {
|
||||
createApi(
|
||||
savedServer,
|
||||
authenticate.data
|
||||
.AccessToken,
|
||||
);
|
||||
navigate("/home");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Unable to login");
|
||||
enqueueSnackbar("Unable to login");
|
||||
}
|
||||
} else {
|
||||
usersAvailable().then(
|
||||
(users_list_available) => {
|
||||
if (
|
||||
users_list_available ==
|
||||
true
|
||||
) {
|
||||
navigate("/login/users");
|
||||
} else {
|
||||
navigate(
|
||||
"/login/manual",
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
try {
|
||||
const usersList = await getUserApi(
|
||||
api,
|
||||
).getPublicUsers();
|
||||
if (usersList.data.length > 0) {
|
||||
navigate("/login/users");
|
||||
} else {
|
||||
navigate("/login/manual");
|
||||
}
|
||||
} catch (error1) {
|
||||
console.error(error1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
navigate("/setup/server");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
navigate("/setup/server");
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
enqueueSnackbar(String(error), { variant: "error" });
|
||||
});
|
||||
};
|
||||
|
||||
const LoginLogicalRoutes = () => {
|
||||
usersAvailable().then((users_list_available) => {
|
||||
if (users_list_available == true) {
|
||||
const usersAvailable = async () => {
|
||||
try {
|
||||
const usersList = await getUserApi(api).getPublicUsers();
|
||||
if (usersList.data.length > 0) {
|
||||
navigate("/login/users");
|
||||
} else {
|
||||
navigate("/login/manual");
|
||||
}
|
||||
});
|
||||
} catch (error1) {
|
||||
console.error(error1);
|
||||
}
|
||||
};
|
||||
|
||||
const LoginLogicalRoutes = () => {
|
||||
usersAvailable();
|
||||
};
|
||||
|
||||
const handleRelaunch = async (event, reason) => {
|
||||
@@ -301,26 +267,56 @@ function App() {
|
||||
await relaunch();
|
||||
};
|
||||
|
||||
if (!api) {
|
||||
serverSaved()
|
||||
.then(async (server) => {
|
||||
if (server) {
|
||||
const savedServer = await getServer(server);
|
||||
createApi(savedServer.address);
|
||||
try {
|
||||
const ping = await getSystemApi(
|
||||
api,
|
||||
).getPingSystem();
|
||||
if (ping.status == 200) {
|
||||
console.info(api);
|
||||
const userSaved = await getUser();
|
||||
if (userSaved) {
|
||||
try {
|
||||
const authenticate =
|
||||
await api.authenticateUserByName(
|
||||
userSaved.Name,
|
||||
userSaved.Password,
|
||||
);
|
||||
if (authenticate.status == 200) {
|
||||
createApi(
|
||||
savedServer,
|
||||
authenticate.data
|
||||
.AccessToken,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Unable to login");
|
||||
enqueueSnackbar("Unable to login");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
enqueueSnackbar(String(error), { variant: "error" });
|
||||
});
|
||||
}
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo(0, 0);
|
||||
}, [location.key]);
|
||||
|
||||
if (!window.api) {
|
||||
serverAvailable().then((available) => {
|
||||
if (available) {
|
||||
createApi().then(
|
||||
userSaved().then((userSavedBool) => {
|
||||
if (userSavedBool) {
|
||||
userLogin();
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const [audioPlayerVisible, currentAudioIndex] = useAudioPlayback(
|
||||
(state) => [state.display, state.currentTrack],
|
||||
);
|
||||
@@ -479,7 +475,13 @@ function App() {
|
||||
<Route element={<AnimationWrapper />}>
|
||||
<Route
|
||||
path="/"
|
||||
exact
|
||||
element={<LogicalRoutes />}
|
||||
loader={async () => {
|
||||
const defaultServer =
|
||||
await getDefaultServer();
|
||||
console.log(defaultServer);
|
||||
}}
|
||||
/>
|
||||
<Route
|
||||
path="/login"
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
/** @format */
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
|
||||
import MuiAppBar from "@mui/material/AppBar";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Toolbar from "@mui/material/Toolbar";
|
||||
import Avatar from "@mui/material/Avatar";
|
||||
import Box from "@mui/material/Box";
|
||||
import ListItemIcon from "@mui/material/ListItemIcon";
|
||||
import Menu from "@mui/material/Menu";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import useScrollTrigger from "@mui/material/useScrollTrigger";
|
||||
|
||||
import { MdiMagnify } from "../icons/mdiMagnify";
|
||||
@@ -22,7 +17,7 @@ import { MdiMagnify } from "../icons/mdiMagnify";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { useIsMutating, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import "./appBar.module.scss";
|
||||
import { MdiAccount } from "../icons/mdiAccount";
|
||||
@@ -36,11 +31,12 @@ import { delServer } from "../../utils/storage/servers";
|
||||
import { delUser } from "../../utils/storage/user";
|
||||
import { MdiDelete } from "../icons/mdiDelete";
|
||||
|
||||
import logo from "../../assets/logo.png";
|
||||
import { MdiLogoutVariant } from "../icons/mdiLogoutVariant";
|
||||
import { EventEmitter as event } from "../../eventEmitter";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
export const AppBar = () => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [display, setDisplay] = useState(false);
|
||||
@@ -51,7 +47,7 @@ export const AppBar = () => {
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
let usr = await getUserApi(window.api).getCurrentUser();
|
||||
let usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
enabled: display,
|
||||
@@ -81,10 +77,10 @@ export const AppBar = () => {
|
||||
};
|
||||
const handleLogout = async () => {
|
||||
console.log("Logging out user...");
|
||||
await window.api.logout();
|
||||
await api.logout();
|
||||
delUser();
|
||||
sessionStorage.removeItem("accessToken");
|
||||
event.emit("create-jellyfin-api", window.api.basePath);
|
||||
event.emit("create-jellyfin-api", api.basePath);
|
||||
queryClient.clear();
|
||||
setAnchorEl(null);
|
||||
navigate("/login");
|
||||
@@ -182,7 +178,7 @@ export const AppBar = () => {
|
||||
<Avatar
|
||||
className="appBar-avatar"
|
||||
src={
|
||||
window.api.basePath +
|
||||
api.basePath +
|
||||
"/Users/" +
|
||||
user.data.Id +
|
||||
"/Images/Primary"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/** @format */
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import Box from "@mui/material/Box";
|
||||
@@ -7,7 +8,10 @@ import { MdiAccount } from "../icons/mdiAccount";
|
||||
|
||||
import "./avatar.module.scss";
|
||||
|
||||
export const AvatarImage = ({ userId, userImageTags }) => {
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
export const AvatarImage = ({ userId }) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
return (
|
||||
<Box className="avatar-image-container">
|
||||
<div
|
||||
@@ -15,7 +19,7 @@ export const AvatarImage = ({ userId, userImageTags }) => {
|
||||
style={{
|
||||
backgroundImage:
|
||||
"url('" +
|
||||
window.api.basePath +
|
||||
api.basePath +
|
||||
"/Users/" +
|
||||
userId +
|
||||
"/Images/Primary')",
|
||||
|
||||
@@ -13,6 +13,8 @@ import { MdiHeartOutline } from "../icons/mdiHeartOutline";
|
||||
import { useSnackbar } from "notistack";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
const LikeButton = ({
|
||||
itemId,
|
||||
isFavorite,
|
||||
@@ -21,17 +23,18 @@ const LikeButton = ({
|
||||
itemName,
|
||||
color = "white",
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const queryClient = useQueryClient();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const handleLiking = async () => {
|
||||
if (isFavorite) {
|
||||
await getUserLibraryApi(window.api).unmarkFavoriteItem({
|
||||
await getUserLibraryApi(api).unmarkFavoriteItem({
|
||||
userId: userId,
|
||||
itemId: itemId,
|
||||
});
|
||||
} else if (!isFavorite) {
|
||||
await getUserLibraryApi(window.api).markFavoriteItem({
|
||||
await getUserLibraryApi(api).markFavoriteItem({
|
||||
userId: userId,
|
||||
itemId: itemId,
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/** @format */
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import React from "react";
|
||||
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
@@ -12,19 +12,22 @@ import { green } from "@mui/material/colors";
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
|
||||
import { MdiCheck } from "../icons/mdiCheck";
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const handleMarking = async () => {
|
||||
if (!isPlayed) {
|
||||
await getPlaystateApi(window.api).markPlayedItem({
|
||||
await getPlaystateApi(api).markPlayedItem({
|
||||
userId: userId,
|
||||
itemId: itemId,
|
||||
});
|
||||
} else if (isPlayed) {
|
||||
await getPlaystateApi(window.api).markUnplayedItem({
|
||||
await getPlaystateApi(api).markUnplayedItem({
|
||||
userId: userId,
|
||||
itemId: itemId,
|
||||
});
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { useSnackbar } from "notistack";
|
||||
import { useAudioPlayback } from "../../utils/store/audioPlayback";
|
||||
import { getPlaylistsApi } from "@jellyfin/sdk/lib/utils/api/playlists-api";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
const PlayButton = ({
|
||||
itemId,
|
||||
@@ -45,6 +46,8 @@ const PlayButton = ({
|
||||
playlistItemId = "",
|
||||
trackIndex,
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const [
|
||||
setUrl,
|
||||
@@ -102,18 +105,14 @@ const PlayButton = ({
|
||||
setPlaybackDataLoading(true);
|
||||
let result;
|
||||
if (playlistItem) {
|
||||
result = await getPlaylistsApi(window.api).getPlaylistItems(
|
||||
{
|
||||
userId: userId,
|
||||
playlistId: playlistItemId,
|
||||
},
|
||||
);
|
||||
result = await getPlaylistsApi(api).getPlaylistItems({
|
||||
userId: userId,
|
||||
playlistId: playlistItemId,
|
||||
});
|
||||
} else {
|
||||
switch (itemType) {
|
||||
case BaseItemKind.Series:
|
||||
result = await getTvShowsApi(
|
||||
window.api,
|
||||
).getEpisodes({
|
||||
result = await getTvShowsApi(api).getEpisodes({
|
||||
seriesId: itemId,
|
||||
limit: 1,
|
||||
startIndex: 0,
|
||||
@@ -126,14 +125,14 @@ const PlayButton = ({
|
||||
break;
|
||||
case BaseItemKind.Playlist:
|
||||
result = await getPlaylistsApi(
|
||||
window.api,
|
||||
api,
|
||||
).getPlaylistItems({
|
||||
userId: userId,
|
||||
playlistId: playlistItemId,
|
||||
});
|
||||
break;
|
||||
case BaseItemKind.MusicAlbum:
|
||||
result = await getItemsApi(window.api).getItems({
|
||||
result = await getItemsApi(api).getItems({
|
||||
parentId: itemId,
|
||||
userId: userId,
|
||||
fields: [
|
||||
@@ -145,7 +144,7 @@ const PlayButton = ({
|
||||
});
|
||||
break;
|
||||
case BaseItemKind.MusicArtist:
|
||||
result = await getItemsApi(window.api).getItems({
|
||||
result = await getItemsApi(api).getItems({
|
||||
artistIds: [itemId],
|
||||
recursive: true,
|
||||
includeItemTypes: [BaseItemKind.Audio],
|
||||
@@ -163,7 +162,7 @@ const PlayButton = ({
|
||||
});
|
||||
break;
|
||||
default:
|
||||
result = await getItemsApi(window.api).getItems({
|
||||
result = await getItemsApi(api).getItems({
|
||||
ids: [itemId],
|
||||
userId: userId,
|
||||
fields: [
|
||||
@@ -185,7 +184,7 @@ const PlayButton = ({
|
||||
setCurrentTrack(trackIndex);
|
||||
setAudioTracks(item.Items);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${item.Items[trackIndex].Id}/universal?deviceId=${window.api.deviceInfo.id}&userId=${userId}&api_key=${window.api.accessToken}`,
|
||||
`${api.basePath}/Audio/${item.Items[trackIndex].Id}/universal?deviceId=${api.deviceInfo.id}&userId=${userId}&api_key=${api.accessToken}`,
|
||||
);
|
||||
setAudioItem(item.Items[trackIndex]);
|
||||
setAudioDisplay(true);
|
||||
@@ -193,7 +192,7 @@ const PlayButton = ({
|
||||
setAudioItem(item.Items[0]);
|
||||
setAudioTracks(item.Items);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${item.Items[0].Id}/universal?deviceId=${window.api.deviceInfo.id}&userId=${userId}&api_key=${window.api.accessToken}`,
|
||||
`${api.basePath}/Audio/${item.Items[0].Id}/universal?deviceId=${api.deviceInfo.id}&userId=${userId}&api_key=${api.accessToken}`,
|
||||
);
|
||||
setAudioDisplay(true);
|
||||
} else {
|
||||
@@ -220,7 +219,7 @@ const PlayButton = ({
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<img
|
||||
src={`${window.api.basePath}/Items/${item.Items[0].Id}/Images/Logo`}
|
||||
src={`${api.basePath}/Items/${item.Items[0].Id}/Images/Logo`}
|
||||
className="video-osd-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
@@ -243,7 +242,7 @@ const PlayButton = ({
|
||||
setItemName(
|
||||
<div className="video-osd-name">
|
||||
<img
|
||||
src={`${window.api.basePath}/Items/${item.Items[0].SeriesId}/Images/Logo`}
|
||||
src={`${api.basePath}/Items/${item.Items[0].SeriesId}/Images/Logo`}
|
||||
className="video-osd-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
@@ -299,9 +298,9 @@ const PlayButton = ({
|
||||
setPosition(item.Items[0].UserData?.PlaybackPositionTicks);
|
||||
|
||||
setUrl(
|
||||
`${window.api.basePath}/Videos/${item.Items[0].Id}/stream.
|
||||
`${api.basePath}/Videos/${item.Items[0].Id}/stream.
|
||||
${item.Items[0].MediaSources[0].Container}
|
||||
?Static=true&mediaSourceId=${item.Items[0].Id}&deviceId=${window.api.deviceInfo.id}&api_key=${window.api.accessToken}&Tag=${item.Items[0].MediaSources[0].ETag}&videoStreamIndex=${currentVideoTrack}&audioStreamIndex=${currentAudioTrack}`,
|
||||
?Static=true&mediaSourceId=${item.Items[0].Id}&deviceId=${api.deviceInfo.id}&api_key=${api.accessToken}&Tag=${item.Items[0].MediaSources[0].ETag}&videoStreamIndex=${currentVideoTrack}&audioStreamIndex=${currentAudioTrack}`,
|
||||
);
|
||||
|
||||
navigate(`/player`);
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
/** @format */
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import React from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import MuiCard from "@mui/material/Card";
|
||||
import CardActionArea from "@mui/material/CardActionArea";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
|
||||
import { Blurhash } from "react-blurhash";
|
||||
|
||||
import { TypeIconCollectionCard } from "../utils/iconsCollection";
|
||||
import "./card.module.scss";
|
||||
import { MdiCheck } from "../icons/mdiCheck";
|
||||
|
||||
import LikeButton from "../buttons/likeButton";
|
||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { MdiAccountTie } from "../icons/mdiAccountTie";
|
||||
|
||||
const cardImageAspectRatios = {
|
||||
thumb: 1.777,
|
||||
portrait: 0.666,
|
||||
square: 1,
|
||||
};
|
||||
|
||||
const availableSpecialRoutes = [BaseItemKind.Series];
|
||||
import "./card.module.scss";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
@@ -56,6 +41,7 @@ export const ActorCard = ({
|
||||
onClick,
|
||||
disablePadding,
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const navigate = useNavigate();
|
||||
const defaultOnClick = () => {
|
||||
navigate(`/person/${item.Id}`);
|
||||
@@ -67,7 +53,7 @@ export const ActorCard = ({
|
||||
borderRadius: "calc(0.6em + 6px)",
|
||||
}}
|
||||
className="card-container"
|
||||
onClick={!!onClick ? onClick : defaultOnClick}
|
||||
onClick={onClick ? onClick : defaultOnClick}
|
||||
>
|
||||
<MuiCard className="card card-actor" elevation={0}>
|
||||
<div className="card-box">
|
||||
@@ -91,8 +77,8 @@ export const ActorCard = ({
|
||||
<MdiAccountTie className="card-image-icon" />
|
||||
</div>
|
||||
<img
|
||||
src={window.api.getItemImageUrl(
|
||||
!!seriesId ? item.SeriesId : item.Id,
|
||||
src={api.getItemImageUrl(
|
||||
seriesId ? item.SeriesId : item.Id,
|
||||
"Primary",
|
||||
{
|
||||
quality: 80,
|
||||
|
||||
@@ -18,6 +18,7 @@ import LikeButton from "../buttons/likeButton";
|
||||
import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
const cardImageAspectRatios = {
|
||||
thumb: 1.777,
|
||||
@@ -73,6 +74,7 @@ export const Card = ({
|
||||
disablePadding,
|
||||
overrideIcon,
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const navigate = useNavigate();
|
||||
const defaultOnClick = () => {
|
||||
if (availableSpecialRoutes.includes(item.Type)) {
|
||||
@@ -154,8 +156,8 @@ export const Card = ({
|
||||
<img
|
||||
src={
|
||||
overrideIcon == "User"
|
||||
? `${window.api.basePath}/Users/${item.Id}/Images/Primary`
|
||||
: window.api.getItemImageUrl(
|
||||
? `${api.basePath}/Users/${item.Id}/Images/Primary`
|
||||
: api.getItemImageUrl(
|
||||
seriesId
|
||||
? item.SeriesId
|
||||
: item.AlbumId
|
||||
|
||||
@@ -17,6 +17,7 @@ import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { MdiTelevisionClassic } from "../icons/mdiTelevisionClassic";
|
||||
import { getRuntimeCompact } from "../../utils/date/time";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
@@ -44,6 +45,7 @@ export const EpisodeCard = ({
|
||||
userId,
|
||||
onClick,
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const navigate = useNavigate();
|
||||
const defaultOnClick = () => {
|
||||
navigate(`/episode/${item.Id}`);
|
||||
@@ -91,7 +93,7 @@ export const EpisodeCard = ({
|
||||
<MdiTelevisionClassic className="card-image-icon" />
|
||||
</div>
|
||||
<img
|
||||
src={window.api.getItemImageUrl(
|
||||
src={api.getItemImageUrl(
|
||||
item.Id,
|
||||
"Primary",
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/** @format */
|
||||
|
||||
import { useState } from "react";
|
||||
import React, { useState } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import Carousel from "react-multi-carousel";
|
||||
|
||||
@@ -27,6 +27,7 @@ import MarkPlayedButton from "../buttons/markPlayedButton";
|
||||
import { useCarouselStore } from "../../utils/store/carousel";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
const availableSpecialRoutes = [
|
||||
BaseItemKind.Series,
|
||||
@@ -45,12 +46,13 @@ const availableSpecialRoutes = [
|
||||
* @returns {React.Component}
|
||||
*/
|
||||
const CarouselSlide = ({ item }) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
let usr = await getUserApi(window.api).getCurrentUser();
|
||||
let usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
@@ -107,8 +109,8 @@ const CarouselSlide = ({ item }) => {
|
||||
className="hero-carousel-background-image"
|
||||
src={
|
||||
item.ParentBackdropItemId
|
||||
? `${window.api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop`
|
||||
: `${window.api.basePath}/Items/${item.Id}/Images/Backdrop`
|
||||
? `${api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop`
|
||||
: `${api.basePath}/Items/${item.Id}/Images/Backdrop`
|
||||
}
|
||||
style={{
|
||||
opacity: 0,
|
||||
@@ -165,7 +167,7 @@ const CarouselSlide = ({ item }) => {
|
||||
<img
|
||||
className="hero-carousel-text-logo"
|
||||
src={
|
||||
window.api.basePath +
|
||||
api.basePath +
|
||||
"/Items/" +
|
||||
item.Id +
|
||||
"/Images/Logo?quality=80&tag=" +
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
/** @format */
|
||||
|
||||
import React from "react";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { MdiEmoticonDead } from "../icons/mdiEmoticonDead";
|
||||
import Divider from "@mui/material/Divider";
|
||||
|
||||
import { red } from "@mui/material/colors";
|
||||
|
||||
import slideBackground from "../../assets/errorbg.png";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/** @format */
|
||||
import React, { useState } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Typography from "@mui/material/Typography";
|
||||
@@ -11,7 +10,6 @@ import { Link } from "react-router-dom";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
|
||||
import { getRuntimeMusic } from "../../../utils/date/time";
|
||||
|
||||
@@ -22,12 +20,14 @@ import "./albumArtist.scss";
|
||||
import { useAudioPlayback } from "../../../utils/store/audioPlayback";
|
||||
import LikeButton from "../../buttons/likeButton";
|
||||
import { SortOrder } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useApi } from "../../../utils/store/api";
|
||||
|
||||
export const ArtistAlbum = ({ user, album, boxProps }) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const albumTracks = useQuery({
|
||||
queryKey: ["artist", "album", album.Id],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(window.api).getItems({
|
||||
const result = await getItemsApi(api).getItems({
|
||||
userId: user.Id,
|
||||
parentId: album.Id,
|
||||
sortOrder: SortOrder.Ascending,
|
||||
@@ -60,7 +60,7 @@ export const ArtistAlbum = ({ user, album, boxProps }) => {
|
||||
setAudioTracks(albumTracks.data.Items);
|
||||
setCurrentAudioTrack(index);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${albumTracks.data.Items[index].Id}/universal?deviceId=${window.api.deviceInfo.id}&userId=${user.Id}&api_key=${window.api.accessToken}`,
|
||||
`${api.basePath}/Audio/${albumTracks.data.Items[index].Id}/universal?deviceId=${api.deviceInfo.id}&userId=${user.Id}&api_key=${api.accessToken}`,
|
||||
);
|
||||
setAudioItem(albumTracks.data.Items[index]);
|
||||
setAudioDisplay(true);
|
||||
@@ -79,7 +79,7 @@ export const ArtistAlbum = ({ user, album, boxProps }) => {
|
||||
{!!album.ImageTags?.Primary && (
|
||||
<div className="album-image">
|
||||
<img
|
||||
src={`${window.api.basePath}/Items/${album.Id}/Images/Primary?fillHeight=532&fillWidth=532&quality=96`}
|
||||
src={`${api.basePath}/Items/${album.Id}/Images/Primary?fillHeight=532&fillWidth=532&quality=96`}
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
@@ -173,7 +173,7 @@ export const ArtistAlbum = ({ user, album, boxProps }) => {
|
||||
justifySelf: "end",
|
||||
}}
|
||||
>
|
||||
{!!track.IndexNumber
|
||||
{track.IndexNumber
|
||||
? track.IndexNumber
|
||||
: "-"}
|
||||
</Typography>
|
||||
|
||||
@@ -8,21 +8,23 @@ import { CardsSkeleton } from "../../skeleton/cards";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useApi } from "../../../utils/store/api";
|
||||
|
||||
/**
|
||||
* @description Latest Media Section
|
||||
*/
|
||||
export const LatestMediaSection = ({ latestMediaLib }) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
let usr = await getUserApi(window.api).getCurrentUser();
|
||||
let usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
});
|
||||
const fetchLatestMedia = async (library) => {
|
||||
const media = await getUserLibraryApi(window.api).getLatestMedia({
|
||||
const media = await getUserLibraryApi(api).getLatestMedia({
|
||||
userId: user.data.Id,
|
||||
parentId: library,
|
||||
limit: 16,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { MediaStreamType } from "@jellyfin/sdk/lib/generated-client/models/media
|
||||
|
||||
import { Card } from "../../card/card";
|
||||
import { MdiStar } from "../../icons/mdiStar";
|
||||
import { green, red, yellow } from "@mui/material/colors";
|
||||
import { yellow } from "@mui/material/colors";
|
||||
import { endsAt, getRuntime, getRuntimeFull } from "../../../utils/date/time";
|
||||
import LikeButton from "../../buttons/likeButton";
|
||||
import MarkPlayedButton from "../../buttons/markPlayedButton";
|
||||
@@ -24,9 +24,7 @@ import "./hero.module.scss";
|
||||
import { Blurhash } from "react-blurhash";
|
||||
import TextLink from "../../textLink";
|
||||
|
||||
import { MdiHdr } from "../../../components/icons/mdiHdr";
|
||||
import { MdiCheck } from "../../icons/mdiCheck";
|
||||
import { MdiClose } from "../../icons/mdiClose";
|
||||
import { useApi } from "../../../utils/store/api";
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemDto} item
|
||||
@@ -71,6 +69,8 @@ const Hero = ({
|
||||
cardType = "portrait",
|
||||
enableVideoInfoStrip = false,
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const filterMediaStreamVideo = (source) => {
|
||||
if (source.Type == MediaStreamType.Video) {
|
||||
return true;
|
||||
@@ -198,8 +198,8 @@ const Hero = ({
|
||||
className="hero-backdrop-image"
|
||||
src={
|
||||
item.ParentBackdropItemId
|
||||
? `${window.api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop`
|
||||
: `${window.api.basePath}/Items/${item.Id}/Images/Backdrop`
|
||||
? `${api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop`
|
||||
: `${api.basePath}/Items/${item.Id}/Images/Backdrop`
|
||||
}
|
||||
style={{
|
||||
opacity: 0,
|
||||
@@ -232,7 +232,7 @@ const Hero = ({
|
||||
>
|
||||
{item.ParentLogoImageTag ? (
|
||||
<img
|
||||
src={`${window.api.basePath}/Items/${item.SeriesId}/Images/Logo`}
|
||||
src={`${api.basePath}/Items/${item.SeriesId}/Images/Logo`}
|
||||
className="hero-name-logo"
|
||||
onLoad={(e) => {
|
||||
e.target.style.opacity = 1;
|
||||
@@ -255,8 +255,8 @@ const Hero = ({
|
||||
<img
|
||||
src={
|
||||
item.SeriesId
|
||||
? `${window.api.basePath}/Items/${item.SeriesId}/Images/Logo`
|
||||
: `${window.api.basePath}/Items/${item.Id}/Images/Logo`
|
||||
? `${api.basePath}/Items/${item.SeriesId}/Images/Logo`
|
||||
: `${api.basePath}/Items/${item.Id}/Images/Logo`
|
||||
}
|
||||
className="hero-name-logo"
|
||||
onLoad={(e) => {
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
/** @format */
|
||||
|
||||
import React from "react";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Card } from "../../../card/card";
|
||||
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { useApi } from "../../../../utils/store/api";
|
||||
|
||||
const GenreView = ({ libraryId, genreId, genreName, userId }) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const items = useQuery({
|
||||
queryKey: ["library", "genreItem", genreId],
|
||||
queryFn: async () => {
|
||||
const result = await getItemsApi(window.api).getItems({
|
||||
const result = await getItemsApi(api).getItems({
|
||||
genreIds: [genreId],
|
||||
parentId: libraryId,
|
||||
userId: userId,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/** @format */
|
||||
import React from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { delUser } from "../../utils/storage/user";
|
||||
|
||||
@@ -8,8 +9,6 @@ import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
|
||||
import { useNavigate, NavLink, useLocation } from "react-router-dom";
|
||||
|
||||
import { theme } from "../../theme";
|
||||
|
||||
import { styled } from "@mui/material/styles";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
@@ -34,7 +33,7 @@ import { EventEmitter as event } from "../../eventEmitter.js";
|
||||
|
||||
import "./sidemenu.module.scss";
|
||||
import { useDrawerStore } from "../../utils/store/drawer";
|
||||
import { MdiHomeVariant } from "../icons/mdiHomeVariant";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
const DrawerHeader = styled("div")(({ theme }) => ({
|
||||
display: "flex",
|
||||
@@ -54,7 +53,8 @@ const MiniDrawer = styled(MuiDrawer, {
|
||||
overflowX: "hidden",
|
||||
}));
|
||||
|
||||
export const SideMenu = ({}) => {
|
||||
export const SideMenu = () => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const location = useLocation();
|
||||
|
||||
const [display, setDisplay] = useState(false);
|
||||
@@ -63,7 +63,7 @@ export const SideMenu = ({}) => {
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
let usr = await getUserApi(window.api).getCurrentUser();
|
||||
let usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
enabled: display,
|
||||
@@ -72,7 +72,7 @@ export const SideMenu = ({}) => {
|
||||
let libraries = useQuery({
|
||||
queryKey: ["libraries"],
|
||||
queryFn: async () => {
|
||||
let libs = await getUserViewsApi(window.api).getUserViews({
|
||||
let libs = await getUserViewsApi(api).getUserViews({
|
||||
userId: user.data.Id,
|
||||
});
|
||||
return libs.data;
|
||||
@@ -83,10 +83,10 @@ export const SideMenu = ({}) => {
|
||||
|
||||
const handleLogout = async () => {
|
||||
console.log("Logging out user...");
|
||||
await window.api.logout();
|
||||
await api.logout();
|
||||
delUser();
|
||||
sessionStorage.removeItem("accessToken");
|
||||
event.emit("create-jellyfin-api", window.api.basePath);
|
||||
event.emit("create-jellyfin-api", api.basePath);
|
||||
navigate("/login");
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import TextLink from "../textLink";
|
||||
import PlayButton from "../buttons/playButton";
|
||||
import { useAudioPlayback } from "../../utils/store/audioPlayback";
|
||||
import { MdiMusic } from "../icons/mdiMusic";
|
||||
import { useApi } from "../../utils/store/api";
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
@@ -34,6 +35,7 @@ const MusicTrack = ({
|
||||
trackIndex,
|
||||
className = "",
|
||||
}) => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const [currentTrackItem] = useAudioPlayback((state) => [state.item]);
|
||||
|
||||
return (
|
||||
@@ -48,7 +50,7 @@ const MusicTrack = ({
|
||||
/>
|
||||
</div>
|
||||
<img
|
||||
src={window.api.getItemImageUrl(
|
||||
src={api.getItemImageUrl(
|
||||
Object.keys(item.ImageTags).length == 0
|
||||
? item.AlbumId
|
||||
: item.Id,
|
||||
|
||||
@@ -34,8 +34,10 @@ import { MdiVolumeHigh } from "../../icons/mdiVolumeHigh";
|
||||
import { MdiVolumeOff } from "../../icons/mdiVolumeOff";
|
||||
import { MdiPlaylistMusicOutline } from "../../icons/mdiPlaylistMusicOutline";
|
||||
import MusicTrack from "../../musicTrack";
|
||||
import { useApi } from "../../../utils/store/api";
|
||||
|
||||
const AudioPlayer = () => {
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
const [
|
||||
url,
|
||||
display,
|
||||
@@ -67,7 +69,7 @@ const AudioPlayer = () => {
|
||||
const user = useQuery({
|
||||
queryKey: ["user"],
|
||||
queryFn: async () => {
|
||||
let usr = await getUserApi(window.api).getCurrentUser();
|
||||
let usr = await getUserApi(api).getCurrentUser();
|
||||
return usr.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
@@ -135,12 +137,12 @@ const AudioPlayer = () => {
|
||||
if (currentTrack != tracks.length - 1) {
|
||||
setCurrentTrack(currentTrack + 1);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${
|
||||
`${api.basePath}/Audio/${
|
||||
tracks[currentTrack + 1].Id
|
||||
}/universal?deviceId=${
|
||||
window.api.deviceInfo.id
|
||||
api.deviceInfo.id
|
||||
}&userId=${user.data.Id}&api_key=${
|
||||
window.api.accessToken
|
||||
api.accessToken
|
||||
}`,
|
||||
);
|
||||
setAudioItem(tracks[currentTrack + 1]);
|
||||
@@ -173,11 +175,11 @@ const AudioPlayer = () => {
|
||||
setPlaying(false);
|
||||
setCurrentTrack(currentTrack + 1);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${
|
||||
`${api.basePath}/Audio/${
|
||||
tracks[currentTrack + 1].Id
|
||||
}/universal?deviceId=${window.api.deviceInfo.id}&userId=${
|
||||
}/universal?deviceId=${api.deviceInfo.id}&userId=${
|
||||
user.data.Id
|
||||
}&api_key=${window.api.accessToken}`,
|
||||
}&api_key=${api.accessToken}`,
|
||||
);
|
||||
setAudioItem(tracks[currentTrack + 1]);
|
||||
setShowWaveform(false);
|
||||
@@ -187,11 +189,11 @@ const AudioPlayer = () => {
|
||||
setPlaying(false);
|
||||
setCurrentTrack(currentTrack - 1);
|
||||
setAudioUrl(
|
||||
`${window.api.basePath}/Audio/${
|
||||
`${api.basePath}/Audio/${
|
||||
tracks[currentTrack - 1].Id
|
||||
}/universal?deviceId=${window.api.deviceInfo.id}&userId=${
|
||||
}/universal?deviceId=${api.deviceInfo.id}&userId=${
|
||||
user.data.Id
|
||||
}&api_key=${window.api.accessToken}`,
|
||||
}&api_key=${api.accessToken}`,
|
||||
);
|
||||
setAudioItem(tracks[currentTrack - 1]);
|
||||
setShowWaveform(false);
|
||||
@@ -236,7 +238,7 @@ const AudioPlayer = () => {
|
||||
<div className="audio-player-image-container">
|
||||
<img
|
||||
className="audio-player-image"
|
||||
src={window.api.getItemImageUrl(
|
||||
src={api.getItemImageUrl(
|
||||
Object.keys(item.ImageTags)
|
||||
.length == 0
|
||||
? item.AlbumId
|
||||
|
||||
+17
-13
@@ -1,8 +1,8 @@
|
||||
/** @format */
|
||||
|
||||
import { useState } from "react";
|
||||
import React, { useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate, useParams, Link } from "react-router-dom";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { EventEmitter as event } from "../../eventEmitter.js";
|
||||
|
||||
import { saveUser } from "../../utils/storage/user.js";
|
||||
@@ -37,10 +37,13 @@ import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api";
|
||||
|
||||
import "./login.module.scss";
|
||||
import { ErrorNotice } from "../../components/notices/errorNotice/errorNotice.jsx";
|
||||
import { useApi } from "../../utils/store/api.js";
|
||||
|
||||
export const LoginWithImage = () => {
|
||||
const { userName, userId } = useParams();
|
||||
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const [password, setPassword] = useState({
|
||||
showpass: false,
|
||||
});
|
||||
@@ -67,7 +70,7 @@ export const LoginWithImage = () => {
|
||||
|
||||
const authUser = async () => {
|
||||
try {
|
||||
const auth = await window.api.authenticateUserByName(
|
||||
const auth = await api.authenticateUserByName(
|
||||
userName,
|
||||
password.password,
|
||||
);
|
||||
@@ -86,7 +89,7 @@ export const LoginWithImage = () => {
|
||||
if (rememberMe == true) {
|
||||
saveUser(userName, password.password);
|
||||
}
|
||||
event.emit("set-api-accessToken", window.api.basePath);
|
||||
event.emit("set-api-accessToken", api.basePath);
|
||||
setLoading(false);
|
||||
navigate(`/home`);
|
||||
};
|
||||
@@ -216,9 +219,11 @@ export const LoginWithImage = () => {
|
||||
};
|
||||
|
||||
export const UserLogin = () => {
|
||||
const [userList, setUsers] = useState([]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
console.log(api);
|
||||
|
||||
const handleChangeServer = () => {
|
||||
navigate("/servers/list");
|
||||
};
|
||||
@@ -228,10 +233,10 @@ export const UserLogin = () => {
|
||||
const users = useQuery({
|
||||
queryKey: ["login", "users"],
|
||||
queryFn: async () => {
|
||||
const users = await getUserApi(window.api).getPublicUsers();
|
||||
const users = await getUserApi(api).getPublicUsers();
|
||||
return users.data;
|
||||
},
|
||||
networkMode: "always",
|
||||
enabled: Boolean(api),
|
||||
});
|
||||
|
||||
if (users.isLoading) {
|
||||
@@ -329,6 +334,7 @@ export const UserLogin = () => {
|
||||
export const UserLoginManual = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [rememberMe, setRememberMe] = useState(true);
|
||||
const [api] = useApi((state) => [state.api]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
@@ -341,12 +347,10 @@ export const UserLoginManual = () => {
|
||||
const server = useQuery({
|
||||
queryKey: ["login, manual", "serverInfo"],
|
||||
queryFn: async () => {
|
||||
const result = await getBrandingApi(
|
||||
window.api,
|
||||
).getBrandingOptions();
|
||||
const result = await getBrandingApi(api).getBrandingOptions();
|
||||
return result.data;
|
||||
},
|
||||
enabled: !!window.api,
|
||||
enabled: !!api,
|
||||
networkMode: "always",
|
||||
});
|
||||
|
||||
@@ -370,7 +374,7 @@ export const UserLoginManual = () => {
|
||||
|
||||
const authUser = async () => {
|
||||
try {
|
||||
const auth = await window.api.authenticateUserByName(
|
||||
const auth = await api.authenticateUserByName(
|
||||
userName,
|
||||
password.password,
|
||||
);
|
||||
@@ -391,7 +395,7 @@ export const UserLoginManual = () => {
|
||||
if (rememberMe == true) {
|
||||
saveUser(userName, password.password);
|
||||
}
|
||||
event.emit("set-api-accessToken", window.api.basePath);
|
||||
event.emit("set-api-accessToken", api.basePath);
|
||||
// setAccessToken(user.data.AccessToken)
|
||||
setLoading(false);
|
||||
navigate(`/home`);
|
||||
|
||||
@@ -4,7 +4,7 @@ import React, { useState, useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
import { EventEmitter as event } from "../../../eventEmitter.js";
|
||||
import { setServer } from "../../../utils/storage/servers.js";
|
||||
import { setDefaultServer, setServer } from "../../../utils/storage/servers.js";
|
||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
|
||||
|
||||
@@ -161,10 +161,12 @@ export const ServerSetup = () => {
|
||||
onSuccess: (bestServer) => {
|
||||
if (bestServer) {
|
||||
console.info(bestServer);
|
||||
createApi(bestServer.address, null);
|
||||
setDefaultServer(bestServer.systemInfo.Id);
|
||||
setServer(bestServer.systemInfo.Id, bestServer);
|
||||
enqueueSnackbar("Client added successfully", {
|
||||
variant: "success",
|
||||
});
|
||||
createApi(bestServer.address, null);
|
||||
navigate("/login");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -6,28 +6,65 @@ const servers = new Store(".servers.dat");
|
||||
|
||||
/**
|
||||
* Set server in .servers.dat
|
||||
* @param {object} data - Server info
|
||||
* @param {string} serverId
|
||||
* @param {object} serverInfo
|
||||
*/
|
||||
const setServer = async (data) => {
|
||||
let server = servers.set("server", data);
|
||||
export const setServer = async (serverId, serverInfo) => {
|
||||
servers.set(serverId, serverInfo);
|
||||
await servers.save();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Server list
|
||||
* Set default server
|
||||
* @param {string} serverId
|
||||
*/
|
||||
export const setDefaultServer = async (serverId) => {
|
||||
servers.set("defaultServer", serverId);
|
||||
await servers.save();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a Server
|
||||
* @returns {object} server
|
||||
*/
|
||||
const getServer = async () => {
|
||||
let server = await servers.get("server");
|
||||
export const getServer = async (serverId) => {
|
||||
let server = await servers.get(serverId);
|
||||
return server;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all Servers
|
||||
*/
|
||||
export const getAllServer = async () => {
|
||||
let server = await servers.entries();
|
||||
return server;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get default server
|
||||
*/
|
||||
export const getDefaultServer = async () => {
|
||||
let server = await servers.get("defaultServer");
|
||||
return server;
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete the given server from client storage
|
||||
* @param {string} serverId
|
||||
*/
|
||||
const delServer = async () => {
|
||||
await servers.delete("server");
|
||||
export const delServer = async (serverId) => {
|
||||
await servers.delete(serverId);
|
||||
// remove the default server
|
||||
await setDefaultServer(null);
|
||||
await servers.save();
|
||||
};
|
||||
|
||||
export { setServer, getServer, delServer };
|
||||
/**
|
||||
* Delete the all servers from client storage
|
||||
*/
|
||||
export const delAllServer = async () => {
|
||||
await servers.clear();
|
||||
// remove the default server
|
||||
await setDefaultServer(null);
|
||||
await servers.save();
|
||||
};
|
||||
Reference in new issue
Block a user