mirror of
https://github.com/LukeHagar/plexjs.git
synced 2025-12-07 20:47:49 +00:00
177 lines
4.6 KiB
Plaintext
177 lines
4.6 KiB
Plaintext
/* tslint:disable */
|
|
/* eslint-disable */
|
|
{{>licenseInfo}}
|
|
import { IAxiosRetryConfig } from "axios-retry";
|
|
|
|
export type ConfigurationParameters = {
|
|
plexToken?: string;
|
|
clientIdentifier?: string;
|
|
device?: string;
|
|
deviceName?: string;
|
|
platform?: string;
|
|
platformVersion?: string;
|
|
product?: string;
|
|
version?: string;
|
|
basePath?: string;
|
|
}
|
|
|
|
export class Configuration {
|
|
/**
|
|
* Plex Media Server or Plex.TV Authentication token
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
plexToken?: string;
|
|
|
|
/**
|
|
* UUID, serial number, or other number unique per device
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
clientIdentifier?: string;
|
|
|
|
/**
|
|
* Device name and model number, eg iPhone3,2, Motorola XOOM™, LG5200TV
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
device?: string;
|
|
|
|
/**
|
|
* Customized Device Name
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
deviceName?: string;
|
|
|
|
/**
|
|
* Platform name, eg iOS, MacOSX, Android, LG, etc
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
platform?: string;
|
|
|
|
/**
|
|
* Operating system version, eg 4.3.1, 10.6.7, 3.2
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
platformVersion?: string;
|
|
|
|
/**
|
|
* Plex application name, eg Laika, Plex Media Server, Media Link
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
product?: string;
|
|
|
|
/**
|
|
* Plex application version number
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
version?: string;
|
|
|
|
/**
|
|
* parameter for apiKey security
|
|
* @param name security name
|
|
* @memberof Configuration
|
|
*/
|
|
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
|
|
|
|
/**
|
|
* override base path
|
|
*
|
|
* @type {string}
|
|
* @memberof Configuration
|
|
*/
|
|
basePath?: string;
|
|
|
|
/**
|
|
* base options for axios calls
|
|
*
|
|
* @type {any}
|
|
* @memberof Configuration
|
|
*/
|
|
baseOptions?: any;
|
|
|
|
/**
|
|
* The FormData constructor that will be used to create multipart form data
|
|
* requests. You can inject this here so that execution environments that
|
|
* do not support the FormData class can still run the generated client.
|
|
*
|
|
* @type {new () => FormData}
|
|
*/
|
|
formDataCtor?: new () => any;
|
|
|
|
/**
|
|
* axios retry configuration
|
|
*
|
|
* @type {IAxiosRetryConfig}
|
|
* @memberof Configuration
|
|
*/
|
|
retriesConfig?: IAxiosRetryConfig
|
|
|
|
constructor(param: ConfigurationParameters = {}) {
|
|
this.plexToken = param.plexToken || "";
|
|
this.clientIdentifier = param.clientIdentifier || "{{npmName}}";
|
|
this.device = param.device || "{{npmName}}";
|
|
this.deviceName = param.deviceName || "{{npmName}}";
|
|
this.platform = param.platform || "{{npmName}}";
|
|
this.platformVersion = param.platformVersion || "{{npmVersion}}";
|
|
this.product = param.product || "{{npmName}}";
|
|
this.version = param.version || "{{npmVersion}}";
|
|
|
|
this.apiKey = (header: string) => {
|
|
switch (header) {
|
|
case "X-Plex-Token":
|
|
return this.plexToken
|
|
case "X-Plex-Client-Identifier":
|
|
return this.clientIdentifier
|
|
case "X-Plex-Device-Name":
|
|
return this.deviceName
|
|
case "X-Plex-Device":
|
|
return this.device
|
|
case "X-Plex-Platform-Version":
|
|
return this.platformVersion
|
|
case "X-Plex-Platform":
|
|
return this.platform
|
|
case "X-Plex-Product":
|
|
return this.product
|
|
case "X-Plex-Version":
|
|
return this.version
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
this.basePath = param.basePath;
|
|
}
|
|
|
|
public setAuthToken(token: string) {
|
|
this.plexToken = token
|
|
}
|
|
|
|
/**
|
|
* Check if the given MIME is a JSON MIME.
|
|
* JSON MIME examples:
|
|
* application/json
|
|
* application/json; charset=UTF8
|
|
* APPLICATION/JSON
|
|
* application/vnd.company+json
|
|
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
* @return True if the given MIME is JSON, false otherwise.
|
|
*/
|
|
public isJsonMime(mime: string): boolean {
|
|
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
}
|
|
}
|