refactor(web): typescript
This commit is contained in:
1 parent
e907ddceef
commit
dca2a31639
16 files changed
+547
-428
No files matched your search
@@ -1,57 +0,0 @@
|
||||
/** @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());
|
||||
}
|
||||
|
||||
const jellyfin = new Jellyfin({
|
||||
clientInfo: {
|
||||
name: "JellyPlayer",
|
||||
version: appVer,
|
||||
},
|
||||
deviceInfo: {
|
||||
name: "JellyPlayer",
|
||||
id: deviceId,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @typedef {import("@jellyfin/sdk").Api} Api
|
||||
*/
|
||||
|
||||
export const useApi = create(() => ({
|
||||
/**
|
||||
* @type {Api}
|
||||
*/
|
||||
api: null,
|
||||
deviceId: localStorage.getItem("deviceId"),
|
||||
jellyfin: jellyfin,
|
||||
}));
|
||||
|
||||
/**
|
||||
* Create api
|
||||
* @param {string} serverAddress
|
||||
* @param {string} accessToken
|
||||
* @returns
|
||||
*/
|
||||
export const createApi = (serverAddress, accessToken) =>
|
||||
useApi.setState((state) => ({
|
||||
...state,
|
||||
api: jellyfin.createApi(serverAddress, accessToken, axiosClient),
|
||||
}));
|
||||
@@ -0,0 +1,54 @@
|
||||
/** @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,
|
||||
});
|
||||
|
||||
let deviceId = localStorage.getItem("deviceId");
|
||||
|
||||
if (!deviceId) {
|
||||
let randomId = uuidv4();
|
||||
localStorage.setItem("deviceId", randomId);
|
||||
|
||||
deviceId = randomId;
|
||||
}
|
||||
|
||||
const jellyfin = new Jellyfin({
|
||||
clientInfo: {
|
||||
name: "JellyPlayer",
|
||||
version: appVer,
|
||||
},
|
||||
deviceInfo: {
|
||||
name: "JellyPlayer",
|
||||
id: deviceId!,
|
||||
},
|
||||
});
|
||||
|
||||
export const useApi = create<{
|
||||
api: Api | null;
|
||||
deviceId: string | null;
|
||||
jellyfin: Jellyfin;
|
||||
}>(() => ({
|
||||
api: null,
|
||||
deviceId: deviceId,
|
||||
jellyfin: jellyfin,
|
||||
}));
|
||||
|
||||
export const createApi = (
|
||||
serverAddress: string,
|
||||
accessToken: string | undefined
|
||||
) =>
|
||||
useApi.setState((state) => ({
|
||||
...state,
|
||||
api: jellyfin.createApi(serverAddress, accessToken, axiosClient),
|
||||
}));
|
||||
@@ -1,7 +1,7 @@
|
||||
/** @format */
|
||||
|
||||
import { create } from "zustand";
|
||||
import { getAllServer, getDefaultServer, getServer } from "../storage/servers";
|
||||
import { getAllServers, getDefaultServer, getServer } from "../storage/servers";
|
||||
import { getUser } from "../storage/user";
|
||||
import { version } from "../../../package.json";
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ export const useCentralStore = create(() => ({
|
||||
let a = await getDefaultServer();
|
||||
return await getServer(a);
|
||||
},
|
||||
allServersOnDisk: async () => getAllServer(),
|
||||
allServersOnDisk: async () => getAllServers(),
|
||||
userOnDisk: async () => getUser(),
|
||||
/** This is the initial route that app goes to just after app startups */
|
||||
initialRoute: null,
|
||||
|
||||
Reference in new issue
Block a user