Start working on new server page #202

This commit is contained in:
Prayag Prajapati committed 2023-10-10 22:15:56 +05:30
1 parent 0e774ebc8c
commit 7e7535edfb
5 files changed
+161 -107

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
/** @format */
import { create } from "zustand";
import { Api, Jellyfin } from "@jellyfin/sdk";
import { version as appVer } from "../../../package.json";
// Initial custom axios client to use tauri's http module
import axios from "axios";
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
import { v4 as uuidv4 } from "uuid";
export const axiosClient = axios.create({
adapter: axiosTauriApiAdapter,
headers: { "Access-Control-Allow-Origin": "*" },
timeout: 60000,
});
const deviceId = localStorage.getItem("deviceId");
if (!deviceId) {
localStorage.setItem("deviceId", uuidv4());
}
// event.on("create-jellyfin-api", (serverAddress) => {
// window.api = ;
// // window.api = jellyfin.createApi(serverAddress);
// });
// event.on("set-api-accessToken", (serverAddress) => {
// window.api = jellyfin.createApi(
// serverAddress,
// sessionStorage.getItem("accessToken"),
// axiosClient,
// );
// // });
const jellyfin = new Jellyfin({
clientInfo: {
name: "JellyPlayer",
version: appVer,
},
deviceInfo: {
name: "JellyPlayer",
id: deviceId,
},
});
/**
* @typedef {import("@jellyfin/sdk").Api} Api
*/
export const useApi = create((set) => ({
/**
* @type {Api}
*/
api: null,
deviceId: localStorage.getItem("deviceId"),
jellyfin: jellyfin,
createApi: (serverAddress, accessToken) =>
set((state) => ({
...state,
api: jellyfin.createApi(serverAddress, accessToken, axiosClient),
})),
}));