fix: pr suggestions

This commit is contained in:
sct
2025-04-02 12:31:30 +09:00
parent ab1d31cc04
commit 56f8a7ffb5
6 changed files with 72 additions and 20 deletions

View File

@@ -365,7 +365,7 @@ class PlexTvAPI extends ExternalAPI {
}
}
public async pingToken() {
public async pingToken(displayName?: string) {
try {
const response = await this.axios.get('/api/v2/ping', {
headers: {
@@ -379,6 +379,7 @@ class PlexTvAPI extends ExternalAPI {
logger.error('Failed to ping token', {
label: 'Plex Refresh Token',
errorMessage: e.message,
userDisplayName: displayName,
});
}
}

View File

@@ -45,7 +45,7 @@ class AvailabilitySync {
if (admin?.plexToken) {
this.plexClient = new PlexAPI({ plexToken: admin.plexToken });
} else {
logger.warn('Plex is not configured. Skipping availability sync.');
logger.warn('Plex is not configured. Skipping Plex availability sync.');
}
for await (const media of this.loadAvailableMediaPaginated(pageSize)) {

View File

@@ -28,7 +28,7 @@ class RefreshToken {
}
const plexTvApi = new PlexTvAPI(user.plexToken);
plexTvApi.pingToken();
plexTvApi.pingToken(user.displayName);
}
}

View File

@@ -189,6 +189,34 @@ authRoutes.post('/plex', async (req, res, next) => {
}
});
authRoutes.get('/plex/refresh', isAuthenticated(), async (req, res, next) => {
const userRepository = getRepository(User);
try {
if (!req.user) {
throw new Error('User data is not present in request.');
}
const user = await userRepository.findOneByOrFail({ id: req.user.id });
if (user.plexToken) {
const plexTvApi = new PlexTvAPI(user.plexToken);
plexTvApi.pingToken(user.displayName);
}
return res.status(204).send();
} catch (e) {
logger.error('Something went wrong while refreshing a users Plex token', {
label: 'API',
errorMessage: e.message,
userId: req.user?.id,
});
return next({
status: 500,
message: 'Unable to refresh Plex token.',
});
}
});
authRoutes.get('/plex/unlink', isAuthenticated(), async (req, res, next) => {
const userRepository = getRepository(User);
try {