Files
photo-live/services/api/src/interactions/likes.controller.ts
T

36 lines
1.3 KiB
TypeScript
Raw Normal View History

// services/api/src/interactions/likes.controller.ts —— 点赞批次端点
// (P2 Task 7,ov 域)。路由与契约 likePhotoBatch 一致(tags [interactions],
// 路径前缀不变、部署域名区分);匿名(无 SessionGuard)。IP 取 req.ip 并
// 归一 IPv6 映射前缀(::ffff:127.0.0.1 → 127.0.0.1),仅作限速键——不落库、
// 不进日志(匿名观众端无 IP 留存需求)。真实部署经反代时应配置 trust proxy
// 系按部署环境处理,登记 P5。
import {
Body,
Controller,
HttpCode,
HttpStatus,
Ip,
Param,
Post,
} from '@nestjs/common';
import { LikeBatchDto } from './dto';
import { LikesService, type LikeBatchResponse } from './likes.service';
@Controller('public/albums')
export class LikesController {
constructor(private readonly likes: LikesService) {}
/** 契约 200(含幂等重试与过期拒绝——拒绝也 200,语义在 batchAccepted)。 */
@HttpCode(HttpStatus.OK)
@Post(':token/photos/:photoId/likes')
likeBatch(
@Param('token') token: string,
@Param('photoId') photoId: string,
@Body() dto: LikeBatchDto,
@Ip() ip: string | undefined,
): Promise<LikeBatchResponse> {
const clientIp = ip === undefined ? undefined : ip.replace(/^::ffff:/, '');
return this.likes.likeBatch(token, photoId, dto, clientIp);
}
}