Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed an issue where Overseerr's 'requested by' rule failed to f… #1231

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions server/src/modules/api/overseerr-api/overseerr-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface OverseerrUser {
email: string;
username: string;
plexToken: string;
plexId?: number;
plexUsername: string;
userType: number;
permissions: number;
Expand Down Expand Up @@ -116,6 +117,31 @@ interface OverseerMedia {
serviceUrl: string;
}

interface OverseerrUserResponse {
pageInfo: {
pages: number;
pageSize: number;
results: number;
page: number;
};
results: OverseerrUserResponseResult[];
}

interface OverseerrUserResponseResult {
permissions: number;
id: number;
email: string;
plexUsername: string;
username: string;
userType: number;
plexId: number;
avatar: string;
createdAt: string;
updatedAt: string;
requestCount: number;
displayName: string;
}

@Injectable()
export class OverseerrApiService {
api: OverseerrApi;
Expand Down Expand Up @@ -170,6 +196,37 @@ export class OverseerrApiService {
}
}

public async getUsers(): Promise<any> {
try {
const size = 50;
let hasNext = true;
let skip = 0;

let users: OverseerrUserResponseResult[] = [];

while (hasNext) {
let resp: OverseerrUserResponse = await this.api.get(
`/user?take=${size}&skip=${skip}`,
);

users.push(...resp.results);

if (resp?.pageInfo?.page < resp?.pageInfo?.pages) {
skip = skip + size;
} else {
hasNext = false;
}
}
return users;
} catch (err) {
this.logger.warn(
`Couldn't fetch Overseerr users. Is the application running?`,
);
this.logger.debug(err);
return [];
}
}

public async deleteRequest(requestId: string) {
try {
const response: OverseerBasicApiResponse = await this.api.delete(
Expand Down
7 changes: 4 additions & 3 deletions server/src/modules/rules/getter/overseerr-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class OverseerrGetterService {

const prop = this.appProperties.find((el) => el.id === id);
const tmdb = await this.tmdbIdHelper.getTmdbIdFromPlexData(libItem);
// const overseerrUsers = await this.overseerrApi.getUsers();

let mediaResponse: OverSeerrMediaResponse;
if (tmdb && tmdb.id) {
Expand Down Expand Up @@ -123,8 +124,8 @@ export class OverseerrGetterService {
? request.requestedBy?.username
: plexUsers.find(
(u) =>
u.username ===
request.requestedBy?.plexUsername,
u.plexId ===
request.requestedBy?.plexId,
)?.username,
);
}
Expand All @@ -135,7 +136,7 @@ export class OverseerrGetterService {
? request.requestedBy?.username
: plexUsers.find(
(u) =>
u.username === request.requestedBy?.plexUsername,
u.plexId === request.requestedBy?.plexId,
)?.username,
);
}
Expand Down
Loading