jellyfish-web/src/utils/jellyfin-apiclient/compat.ts

24 lines
698 B
TypeScript
Raw Normal View History

2022-10-28 01:09:59 -04:00
import { Api, Jellyfin } from '@jellyfin/sdk';
import { ApiClient } from 'jellyfin-apiclient';
/**
* Returns an SDK Api instance using the same parameters as the provided ApiClient.
* @param {ApiClient} apiClient The (legacy) ApiClient.
* @returns {Api} An equivalent SDK Api instance.
*/
export const toApi = (apiClient: ApiClient): Api => {
return (new Jellyfin({
clientInfo: {
name: apiClient.appName(),
version: apiClient.appVersion()
},
deviceInfo: {
name: apiClient.deviceName(),
id: apiClient.deviceId()
}
})).createApi(
apiClient.serverAddress(),
apiClient.accessToken()
);
};