fix(reader): skip throttling for EPUB file streams (#410)

Allow authenticated EPUB archive file requests to bypass the global request throttle so the streaming reader can load fragmented books without tripping 429 responses. Keep the existing access and archive path checks in place.

Fixes: #409
This commit is contained in:
Haoqian
2026-06-24 00:33:52 +08:00
committed by GitHub
parent 193079621f
commit 303f7f2d6a
2 changed files with 6 additions and 0 deletions
@@ -82,6 +82,10 @@ describe('EpubController', () => {
expect(reply.header).toHaveBeenCalledWith('Cache-Control', 'public, max-age=3600');
});
it('skips global throttling for EPUB archive file streams', () => {
expect(Reflect.getMetadata('THROTTLER:SKIPdefault', EpubController.prototype.getFile)).toBe(true);
});
it('rejects malformed encoded file paths', async () => {
await expect(
controller.getFile(9, 'OPS/text/%E0%A4%A', undefined, { id: 1, isSuperuser: false, permissions: [] } as any, {} as any),
@@ -1,4 +1,5 @@
import { BadRequestException, Controller, Get, Param, ParseIntPipe, Query, Res } from '@nestjs/common';
import { SkipThrottle } from '@nestjs/throttler';
import type { FastifyReply } from 'fastify';
import { CurrentUser } from '../../../common/decorators/current-user.decorator';
@@ -14,6 +15,7 @@ export class EpubController {
return this.epubService.getBookInfo(bookId, this.parseFileId(fileId), user);
}
@SkipThrottle()
@Get(':bookId/file/*')
async getFile(
@Param('bookId', ParseIntPipe) bookId: number,