mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04:00

Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
34 lines
978 B
TypeScript
34 lines
978 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import {
|
|
CallHandler,
|
|
ExecutionContext,
|
|
Injectable,
|
|
NestInterceptor,
|
|
} from '@nestjs/common';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { NoteService } from '../../../notes/note.service';
|
|
import { CompleteRequest } from '../request.type';
|
|
|
|
/**
|
|
* Saves the note identified by the `HedgeDoc-Note` header
|
|
* under the `note` property of the request object.
|
|
*/
|
|
@Injectable()
|
|
export class NoteHeaderInterceptor implements NestInterceptor {
|
|
constructor(private noteService: NoteService) {}
|
|
|
|
async intercept<T>(
|
|
context: ExecutionContext,
|
|
next: CallHandler,
|
|
): Promise<Observable<T>> {
|
|
const request: CompleteRequest = context.switchToHttp().getRequest();
|
|
const noteId: string = request.headers['hedgedoc-note'] as string;
|
|
request.noteId = await this.noteService.getNoteIdByAlias(noteId);
|
|
return next.handle();
|
|
}
|
|
}
|