-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): validate plex when settings are saved
- Loading branch information
Showing
7 changed files
with
182 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import NodePlexAPI from 'plex-api'; | ||
import { getSettings } from '../lib/settings'; | ||
|
||
class PlexAPI { | ||
private plexClient: typeof NodePlexAPI; | ||
|
||
constructor({ plexToken }: { plexToken?: string }) { | ||
const settings = getSettings(); | ||
|
||
this.plexClient = new NodePlexAPI({ | ||
hostname: settings.plex.ip, | ||
post: settings.plex.port, | ||
token: plexToken, | ||
authenticator: { | ||
authenticate: ( | ||
_plexApi: typeof PlexAPI, | ||
cb: (err?: string, token?: string) => void | ||
) => { | ||
if (!plexToken) { | ||
return cb('Plex Token not found!'); | ||
} | ||
cb(undefined, plexToken); | ||
}, | ||
}, | ||
options: { | ||
identifier: settings.clientId, | ||
product: 'Overseerr', | ||
deviceName: 'Overseerr', | ||
platform: 'Overseerr', | ||
}, | ||
}); | ||
} | ||
|
||
public async getStatus() { | ||
return await this.plexClient.query('/'); | ||
} | ||
} | ||
|
||
export default PlexAPI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'plex-api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters