-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fixer to backfill plex server client identifiers
- Loading branch information
1 parent
759b379
commit dbdca6a
Showing
16 changed files
with
183 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,30 @@ | ||
import { find, isNil } from 'lodash-es'; | ||
import { EntityManager } from '../../dao/dataSource.js'; | ||
import { PlexServerSettings } from '../../dao/entities/PlexServerSettings.js'; | ||
import { Plex } from '../../plex.js'; | ||
import Fixer from './fixer.js'; | ||
|
||
export class AddPlexServerIdsFixer extends Fixer { | ||
async runInternal(em: EntityManager): Promise<void> { | ||
const plexServers = await em | ||
.repo(PlexServerSettings) | ||
.find({ clientIdentifier: null }); | ||
|
||
for (const server of plexServers) { | ||
const api = new Plex(server); | ||
const devices = await api.getDevices(); | ||
if (!isNil(devices) && devices.MediaContainer.Device) { | ||
const matchingServer = find( | ||
devices.MediaContainer.Device, | ||
(d) => d.provides.includes('server') && d.name === server.name, | ||
); | ||
if (matchingServer) { | ||
server.clientIdentifier = matchingServer.clientIdentifier; | ||
em.persist(server); | ||
} | ||
} | ||
} | ||
|
||
await em.flush(); | ||
} | ||
} |
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
Oops, something went wrong.