Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
uses: actions/checkout@v4

- name: 🔍 Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
uses: aquasecurity/trivy-action@0.33.1
with:
scan-type: 'fs'
scan-ref: '.'
Expand Down
2 changes: 1 addition & 1 deletion src/prowlarr/interfaces/prowlarr.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ProwlarrIndexer {
definitionName: string;
}

interface ProwlarrItem {
export interface ProwlarrItem {
title: string;
size: number;
publishDate: string;
Expand Down
8 changes: 3 additions & 5 deletions src/prowlarr/prowlarr.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { Test, TestingModule } from '@nestjs/testing';
import { ProwlarrController } from './prowlarr.controller';
import { ProwlarrService } from './prowlarr.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard/jwt-auth.guard';
import {
ProwlarrSearchResult,
ProwlarrIndexer,
} from './interfaces/prowlarr.interface';
import { ProwlarrIndexer } from './interfaces/prowlarr.interface';
import { ProwlarrSearchResultDto } from './dto/prowlarr-responses.dto';

describe('ProwlarrController', () => {
let controller: ProwlarrController;
Expand Down Expand Up @@ -43,7 +41,7 @@ describe('ProwlarrController', () => {
describe('search', () => {
it('should return search results from the service', async () => {
const query = 'test query';
const mockResults: ProwlarrSearchResult = {
const mockResults: ProwlarrSearchResultDto = {
results: [
{
title: 'Movie 1',
Expand Down
2 changes: 1 addition & 1 deletion src/prowlarr/prowlarr.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
ApiQuery,
} from '@nestjs/swagger';
import {
ProwlarrSearchResultDto,
ProwlarrIndexerDto,
ProwlarrSearchResultDto,
} from './dto/prowlarr-responses.dto';

@ApiTags('prowlarr')
Expand Down
20 changes: 13 additions & 7 deletions src/prowlarr/prowlarr.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { ProwlarrService } from './prowlarr.service';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { of, throwError } from 'rxjs';
import {
ProwlarrSearchResult,
ProwlarrIndexer,
} from './interfaces/prowlarr.interface';
import { ProwlarrIndexer, ProwlarrItem } from './interfaces/prowlarr.interface';
import { ProwlarrSearchResultDto } from './dto/prowlarr-responses.dto';

class MockConfigService {
get = jest.fn((key: string) => {
Expand Down Expand Up @@ -64,7 +62,15 @@ describe('ProwlarrService', () => {
});

it('should return search results', async () => {
const mockSearchResults: ProwlarrSearchResult = {
const mockRawResults: ProwlarrItem[] = [
{
title: 'Movie Title.mkv',
size: 1000,
publishDate: '2023-01-01',
downloadUrl: 'download1',
},
];
const mockMappedResults: ProwlarrSearchResultDto = {
results: [
{
title: 'Movie Title.mkv',
Expand All @@ -75,11 +81,11 @@ describe('ProwlarrService', () => {
],
};
(httpService.get as jest.Mock).mockReturnValue(
of({ data: mockSearchResults }),
of({ data: mockRawResults }),
);

const result = await service.search('test query');
expect(result).toEqual(mockSearchResults);
expect(result).toEqual(mockMappedResults);
expect(httpService.get).toHaveBeenCalledWith(
`${service['PROWLARR_BASE_URL']}/api/v1/search`,
{
Expand Down
38 changes: 24 additions & 14 deletions src/prowlarr/prowlarr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { ConfigService } from '@nestjs/config';
import { map } from 'rxjs/operators';
import { lastValueFrom } from 'rxjs';
import { AxiosResponse } from 'axios'; // Import AxiosResponse
import {
ProwlarrSearchResult,
ProwlarrIndexer,
} from './interfaces/prowlarr.interface';
import { ProwlarrIndexer, ProwlarrItem } from './interfaces/prowlarr.interface';
import { ProwlarrSearchResultDto } from './dto/prowlarr-responses.dto';
// import { ProwlarrSearchResultDto } from './dto/prowlarr-responses.dto'; // Removed as it's not directly used here

@Injectable()
export class ProwlarrService {
Expand All @@ -19,12 +18,12 @@ export class ProwlarrService {
private configService: ConfigService,
) {
this.PROWLARR_API_KEY =
this.configService.get<string>('PROWLARR_API_KEY') ?? ''; // Added nullish coalescing
this.configService.get<string>('PROWLARR_API_KEY') ?? '';
this.PROWLARR_BASE_URL =
this.configService.get<string>('PROWLARR_BASE_URL') ?? ''; // Added nullish coalescing
this.configService.get<string>('PROWLARR_BASE_URL') ?? '';
}

async search(query: string): Promise<ProwlarrSearchResult> {
async search(query: string): Promise<ProwlarrSearchResultDto> {
return lastValueFrom(
this.httpService
.get(`${this.PROWLARR_BASE_URL}/api/v1/search`, {
Expand All @@ -34,14 +33,25 @@ export class ProwlarrService {
},
})
.pipe(
map((response: AxiosResponse<ProwlarrSearchResult>) => {
// Filtrer pour ne garder que les fichiers .mkv
const filteredResults = response.data.results.filter((item) =>
item.title.toLowerCase().endsWith('.mkv'),
map((response: AxiosResponse<ProwlarrItem[]>) => { // Le type de la réponse brute est ProwlarrItem[]
console.log('Prowlarr API Raw Response Data:', response.data); // Log la réponse brute
if (!response.data || !Array.isArray(response.data)) {
return { results: [] };
}
const rawResults = response.data;
// Réactiver le filtre pour exclure les résultats contenant 'iso' ou 'dvd'
const filteredResults = rawResults.filter(
(result) => !/iso|dvd/i.test(result.title),
);
return {
results: filteredResults,
};
// Mapper les résultats vers ProwlarrItemDto pour correspondre au DTO Swagger
const mappedResults = filteredResults.map((item) => ({
title: item.title,
size: item.size,
publishDate: item.publishDate,
downloadUrl: item.downloadUrl,
}));
console.log('Mapped Results (filtered):', mappedResults); // Log les résultats mappés et filtrés
return { results: mappedResults };
}),
),
);
Expand Down