Skip to content

Commit

Permalink
Fix content cache
Browse files Browse the repository at this point in the history
  • Loading branch information
opcatdev committed Nov 8, 2024
1 parent 1aa0706 commit 30c5c3e
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions packages/tracker/src/routes/collection/collection.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Header, Param, Query, Res } from '@nestjs/common';
import { Controller, Get, Param, Query, Res } from '@nestjs/common';
import { CollectionService } from './collection.service';
import { okResponse, errorResponse } from '../../common/utils';
import { ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
Expand Down Expand Up @@ -53,7 +53,6 @@ export class CollectionController {
}

@Get(':collectionIdOrAddr/content')
@Header('Cache-Control', 'public, max-age=31536000')
@ApiTags('collection')
@ApiOperation({ summary: 'Get collection content' })
@ApiParam({
Expand All @@ -69,16 +68,17 @@ export class CollectionController {
try {
const content =
await this.collectionService.getCollectionContent(collectionIdOrAddr);
if (content?.type) {
res.setHeader('Content-Type', content.type);
}
if (content?.encoding) {
res.setHeader('Content-Encoding', content.encoding);
}
if (content?.lastModified) {
res.setHeader('Last-Modified', content.lastModified.toUTCString());
}
if (content?.raw) {
if (content?.type) {
res.setHeader('Content-Type', content.type);
}
if (content?.encoding) {
res.setHeader('Content-Encoding', content.encoding);
}
if (content?.lastModified) {
res.setHeader('Last-Modified', content.lastModified.toUTCString());
}
res.setHeader('Cache-Control', 'public, max-age=31536000');
res.send(content.raw);
} else {
res.sendStatus(404);
Expand Down Expand Up @@ -119,7 +119,6 @@ export class CollectionController {
}

@Get(':collectionIdOrAddr/localId/:localId/content')
@Header('Cache-Control', 'public, max-age=31536000')
@ApiTags('collection')
@ApiOperation({ summary: 'Get nft content' })
@ApiParam({
Expand All @@ -144,16 +143,17 @@ export class CollectionController {
collectionIdOrAddr,
localId,
);
if (content?.type) {
res.setHeader('Content-Type', content.type);
}
if (content?.encoding) {
res.setHeader('Content-Encoding', content.encoding);
}
if (content?.lastModified) {
res.setHeader('Last-Modified', content.lastModified.toUTCString());
}
if (content?.raw) {
if (content?.type) {
res.setHeader('Content-Type', content.type);
}
if (content?.encoding) {
res.setHeader('Content-Encoding', content.encoding);
}
if (content?.lastModified) {
res.setHeader('Last-Modified', content.lastModified.toUTCString());
}
res.setHeader('Cache-Control', 'public, max-age=31536000');
res.send(content.raw);
} else {
res.sendStatus(404);
Expand Down

0 comments on commit 30c5c3e

Please sign in to comment.