chore: limit CDN cache to 5 mins (#335)

* fix: missing cheerio

* chore: set cdn cache to 5 min

* chore: eslint --fix

* chore: add github action config
pull/336/head
晋晓炜 Amio / 2020-01-11 15:46:47 +08:00 zatwierdzone przez GitHub
rodzic b9da463bc2
commit bfa4d1bb16
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 36 dodań i 10 usunięć

26
.github/workflows/nodejs.yml vendored 100644
Wyświetl plik

@ -0,0 +1,26 @@
name: Node CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm ci
npm run lint
npm run build --if-present
env:
CI: true

Wyświetl plik

@ -1,4 +1,5 @@
import got from '../libs/got'
import cheerio from 'cheerio'
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
export default createBadgenHandler({
@ -95,11 +96,11 @@ async function buildTestResult ({ org, project, definition, branch = 'master'}:
const passed: {outcome: string, count: number} = runStatistics.find( (value: { outcome: string; }) => value.outcome === 'Passed')
const notExecuted: {outcome: string, count: number} = runStatistics.find( (value: { outcome: string; }) => value.outcome === 'NotExecuted')
const failed: {outcome: string, count: number} = runStatistics.find( (value: { outcome: string; }) => value.outcome === 'Failed')
const passedCount = passed?.count ?? 0
const notExecutedCount = notExecuted?.count ?? 0
const failedCount = failed?.count ?? total - passedCount - notExecutedCount
const status = total == passedCount ? 'succeeded' : total == failedCount ? 'failed' : 'partially succeeded'
const color = colors[status]
return {
@ -157,4 +158,4 @@ async function handler ({ org, project, definition, branch = 'master'}: PathArgs
status,
color
}
}
}

Wyświetl plik

@ -16,13 +16,13 @@ export default createBadgenHandler({
async function handler ({ topic, path }: PathArgs) {
if (path.startsWith('http/')) {
path = path.slice(0, 4) + ':/' + path.slice(4);
path = path.slice(0, 4) + ':/' + path.slice(4)
} else if (path.startsWith('https/')) {
path = path.slice(0, 5) + ':/' + path.slice(5);
path = path.slice(0, 5) + ':/' + path.slice(5)
} else if (path.startsWith('http:/')) {
path = path.slice(0, 5) + '/' + path.slice(5);
path = path.slice(0, 5) + '/' + path.slice(5)
} else if (path.startsWith('https:/')) {
path = path.slice(0, 6) + '/' + path.slice(6);
path = path.slice(0, 6) + '/' + path.slice(6)
}
const endpoint = `https://img.badgesize.io/${path}.json`
const { prettySize, color } = await got(endpoint, {

Wyświetl plik

@ -13,7 +13,7 @@ type ServeBadgeOptions = {
}
export default function (req: IncomingMessage, res: ServerResponse, options: ServeBadgeOptions) {
const { code = 200, sMaxAge = 10800, query = {}, params } = options
const { code = 200, sMaxAge = 300, query = {}, params } = options
const { subject, status, color } = params
const { label, labelColor, icon, iconWidth, list, scale } = query
@ -33,8 +33,7 @@ export default function (req: IncomingMessage, res: ServerResponse, options: Ser
scale: parseFloat(scale || '1'),
})
const staleControl = `stale-while-revalidate=604800, stale-if-error=604800`
const cacheControl = `public, max-age=60, s-maxage=${sMaxAge}, ${staleControl}`
const cacheControl = `public, max-age=120, s-maxage=${sMaxAge}, stale-while-revalidate=86400`
res.setHeader('Cache-Control', cacheControl)
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
res.statusCode = code