All files / app/services/links links.service.ts

100% Statements 16/16
100% Branches 2/2
100% Functions 5/5
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 274x 4x 4x 4x     4x     4x 7x     5x 1x     4x 6x     6x 4x        
import { LinksApiService } from './links-api.service';
import { inject, Injectable } from '@angular/core';
import { forkJoin, Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
 
// Backend limit per request (WikiLinksApiController::MAX_LINKS)
export const MAX_LINKS = 500;
 
@Injectable()
export class LinksService {
    private readonly linksApiService = inject(LinksApiService);
 
    getLinkStatuses(links: string[]): Observable<Record<string, boolean>> {
        if (links.length === 0) {
            return of({});
        }
 
        const chunks = Array.from({ length: Math.ceil(links.length / MAX_LINKS) }, (_, i) =>
            links.slice(i * MAX_LINKS, (i + 1) * MAX_LINKS),
        );
 
        return forkJoin(chunks.map(chunk => this.linksApiService.checkLinks(chunk))).pipe(
            map(results => Object.assign({}, ...results)),
        );
    }
}