Skip to content

Commit

Permalink
fix: correct app spec GET automatic rewrites of HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
0-vortex committed Apr 10, 2023
1 parent e656f4e commit 3047cec
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/social-card/social-card.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Head, Header, HttpStatus, Param, Redirect, Res, StreamableFile } from "@nestjs/common";
import { Controller, Get, Header, HttpStatus, Param, Redirect, Res, StreamableFile } from "@nestjs/common";
import {
ApiForbiddenResponse,
ApiNoContentResponse,
Expand All @@ -18,25 +18,6 @@ export class SocialCardController {
private readonly socialCardService: SocialCardService,
) {}

@Head("/:username")
@ApiNoContentResponse({ description: "User social card image is up to date", status: HttpStatus.NO_CONTENT })
@ApiResponse({ description: "User social card image needs regeneration", status: HttpStatus.NOT_MODIFIED })
@ApiNotFoundResponse({ description: "User social card image not found", status: HttpStatus.NOT_FOUND })
async checkUserSocialCard (
@Param("username") username: string,
@Res() res: FastifyReply,
): Promise<void> {
const { fileUrl, hasFile, needsUpdate, lastModified } = await this.socialCardService.checkRequiresUpdate(username);

return res
.headers({
"x-amz-meta-last-modified": lastModified?.toISOString() ?? "",
"x-amz-meta-location": fileUrl,
})
.status(hasFile ? needsUpdate ? HttpStatus.NOT_MODIFIED : HttpStatus.NO_CONTENT : HttpStatus.NOT_FOUND)
.send();
}

@Get("/:username")
@ApiOperation({
operationId: "generateUserSocialCard",
Expand All @@ -49,7 +30,7 @@ export class SocialCardController {
@Redirect()
async generateUserSocialCard (
@Param("username") username: string,
@Res() res: FastifyReply,
@Res({ passthrough: true }) res: FastifyReply,
): Promise<void> {
const { fileUrl, hasFile, needsUpdate } = await this.socialCardService.checkRequiresUpdate(username);

Expand All @@ -61,4 +42,27 @@ export class SocialCardController {

return res.status(HttpStatus.FOUND).redirect(url);
}

@Get("/:username/metadata")
@ApiOperation({
operationId: "getUserSocialCardMetadata",
summary: "Gets latest cache aware social card metadata for :username",
})
@ApiNoContentResponse({ description: "User social card image is up to date", status: HttpStatus.NO_CONTENT })
@ApiResponse({ description: "User social card image needs regeneration", status: HttpStatus.NOT_MODIFIED })
@ApiNotFoundResponse({ description: "User social card image not found", status: HttpStatus.NOT_FOUND })
async checkUserSocialCard (
@Param("username") username: string,
@Res({ passthrough: true }) res: FastifyReply,
): Promise<void> {
const { fileUrl, hasFile, needsUpdate, lastModified } = await this.socialCardService.checkRequiresUpdate(username);

return res
.headers({
"x-amz-meta-last-modified": lastModified?.toISOString() ?? "",
"x-amz-meta-location": fileUrl,
})
.status(hasFile ? needsUpdate ? HttpStatus.NOT_MODIFIED : HttpStatus.NO_CONTENT : HttpStatus.NOT_FOUND)
.send();
}
}

0 comments on commit 3047cec

Please sign in to comment.