Commit 9f488f78 authored by nanahira's avatar nanahira

fix result cache

parent c62b2392
Pipeline #15422 passed with stages
in 3 minutes and 49 seconds
This diff is collapsed.
......@@ -74,6 +74,7 @@
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"express": "^4.18.1",
"jest": "27.0.6",
"prettier": "^2.3.2",
"supertest": "^6.1.3",
......
import { Body, Controller, Get, Header, Param, ParseArrayPipe, Post, Query, Render, ValidationPipe } from '@nestjs/common';
import { Body, Controller, Get, Header, Param, ParseArrayPipe, Post, Query, Render, Res, ValidationPipe } from '@nestjs/common';
import { UpdateService } from './update.service';
import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { DepotDto } from '../dto/Depot.dto';
import { Response } from 'express';
@Controller('update')
@ApiTags('update')
......@@ -14,19 +15,26 @@ export class UpdateController {
return this.updateService.getAppsJson();
}
private async cacheResult<T>(res: Response, prom: Promise<T>) {
const result = await prom;
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
return result;
}
@Get('checksums/:id/:version')
@Render('checksums')
@ApiOperation({ summary: '获取 app 校验和', description: '是 shasum 的格式' })
@ApiParam({ name: 'id', description: 'APP 的 id' })
@ApiParam({ name: 'version', description: 'APP 的版本号' })
@ApiOkResponse({ type: String })
@Header('Cache-Control', 'public, max-age=31536000, immutable')
// @Header('Cache-Control', 'public, max-age=31536000, immutable')
async getChecksum(
@Param('id') id: string,
@Query(new ValidationPipe({ transform: true })) depot: DepotDto,
@Param('version') version: string
@Param('version') version: string,
@Res({ passthrough: true }) res: Response
) {
return this.updateService.getChecksum(id, depot, version);
return this.cacheResult(res, this.updateService.getChecksum(id, depot, version));
}
@Get('metalinks/:id/:version')
......@@ -35,13 +43,14 @@ export class UpdateController {
@ApiParam({ name: 'id', description: 'APP 的 id' })
@ApiParam({ name: 'version', description: 'APP 的版本号' })
@ApiOkResponse({ type: String })
@Header('Cache-Control', 'public, max-age=31536000, immutable')
// @Header('Cache-Control', 'public, max-age=31536000, immutable')
async getFullPackageMetalink(
@Param('id') id: string,
@Query(new ValidationPipe({ transform: true })) depot: DepotDto,
@Param('version') version: string
@Param('version') version: string,
@Res({ passthrough: true }) res: Response
) {
return this.updateService.getFullPackageMetalink(id, depot, version);
return this.cacheResult(res, this.updateService.getFullPackageMetalink(id, depot, version));
}
@Post('update/:id/:version')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment