import { Controller, Get, Param, Req } from '@nestjs/common'; import { BacklinkView, PhantomLinkView } from '@dorfteich/shared'; import { AuthedRequest } from '../auth/auth.guard'; import { RequiresPagePermission, RequiresPondRole } from '../permissions/permission.decorators'; import { LinksService } from './links.service'; /** Wikilink index reads (issue #47): backlinks and a pond's phantom links. */ @Controller() export class LinksController { constructor(private readonly links: LinksService) {} /** Pages that link to this page (permission-filtered). */ @Get('pages/:id/backlinks') @RequiresPagePermission('read', { idParam: 'id' }) // sources are filtered per page async backlinks(@Param('id') id: string, @Req() request: AuthedRequest): Promise { return this.links.backlinks(request.user!, id); } /** Referenced-but-missing pages in the pond, with their referrers. */ @Get('ponds/:pondId/phantom-links') @RequiresPondRole('reader', { idParam: 'pondId' }) // referrers are filtered per page async phantomLinks( @Param('pondId') pondId: string, @Req() request: AuthedRequest, ): Promise { return this.links.phantomLinks(request.user!, pondId); } }