You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
930 B
38 lines
930 B
import PlexTvAPI from '@server/api/plextv';
|
|
import { getRepository } from '@server/datasource';
|
|
import { User } from '@server/entity/User';
|
|
import logger from '@server/logger';
|
|
|
|
class RefreshToken {
|
|
public async run() {
|
|
const userRepository = getRepository(User);
|
|
|
|
const users = await userRepository
|
|
.createQueryBuilder('user')
|
|
.addSelect('user.plexToken')
|
|
.where("user.plexToken != ''")
|
|
.getMany();
|
|
|
|
for (const user of users) {
|
|
await this.refreshUserToken(user);
|
|
}
|
|
}
|
|
|
|
private async refreshUserToken(user: User) {
|
|
if (!user.plexToken) {
|
|
logger.warn('Skipping user refresh token for user without plex token', {
|
|
label: 'Plex Refresh Token',
|
|
user: user.displayName,
|
|
});
|
|
return;
|
|
}
|
|
|
|
const plexTvApi = new PlexTvAPI(user.plexToken);
|
|
plexTvApi.pingToken();
|
|
}
|
|
}
|
|
|
|
const refreshToken = new RefreshToken();
|
|
|
|
export default refreshToken;
|