Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["react", "typescript", "nextjs"],
"env": {
"es6": true,
"browser": true,
"node": true
},
"globals": {
"__DEV__": "readonly",
"Generator": "readonly",
"XMLHttpRequest": "readonly"
},
"ignorePatterns": [
".next/**",
"out/**",
"build/**",
"dist/**",
"next-env.d.ts"
],
"rules": {
"no-case-declarations": "off",
"no-unused-vars": "off",
"react/no-unescaped-entities": "off",
"react/no-unknown-property": ["error", { "ignore": ["jsx"] }],
"react/react-in-jsx-scope": "off"
}
}
2 changes: 1 addition & 1 deletion components/help-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</li>
<li>
<code>cache</code>
Live badge are cached in cdn for 24hrs (86400), you may limit it to a minimum of 5min (300).
Control how long live badges may be cached by downstream clients and the CDN. Minimum value is 5min (300).
&nbsp;<a href='/npm/dm/express?cache=600'>e.g.</a>
</li>
</ul>
Expand Down Expand Up @@ -160,7 +160,7 @@
})
}

const explainCode = (isFlat: Boolean) => {

Check warning on line 163 in components/help-info.tsx

View workflow job for this annotation

GitHub Actions / build

typescript(no-wrapper-object-types)

Do not use wrapper object types.
const text = `
https://badgen.net/badge/:subject/:status/:color?icon=github
──┬── ───┬─── ──┬─── ──┬── ────┬──────
Expand Down
65 changes: 0 additions & 65 deletions eslint.config.mjs

This file was deleted.

23 changes: 23 additions & 0 deletions libs/badge-cache-control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const MIN_BADGE_CACHE_SECONDS = 300

export function resolveBadgeCacheMaxAge (
cache: string | string[] | undefined,
fallbackSeconds: number
): number {
const cacheValue = Array.isArray(cache) ? cache[0] : cache

if (cacheValue === undefined) {
return fallbackSeconds
}

const parsedCacheSeconds = parseInt(String(cacheValue), 10)
if (Number.isNaN(parsedCacheSeconds)) {
return MIN_BADGE_CACHE_SECONDS
}

return Math.max(parsedCacheSeconds, MIN_BADGE_CACHE_SECONDS)
}

export function createBadgeCacheControlHeader (cacheSeconds: number): string {
return `public, max-age=${cacheSeconds}, s-maxage=${cacheSeconds}, stale-while-revalidate=86400`
}
4 changes: 2 additions & 2 deletions libs/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function restGitlab<T = any>(path: string, fullResponse = false) {
const headers = {
authorization: token ? `Bearer ${token}` : undefined,
}
const prefixUrl = process.env.GITLAB_API || 'https://gitlab.com/api/v4'
return fullResponse ? ky.get(path, { prefixUrl, headers }) : ky.get(path, { prefixUrl, headers }).json<T>()
const prefix = process.env.GITLAB_API || 'https://gitlab.com/api/v4'
return fullResponse ? ky.get(path, { prefix, headers }) : ky.get(path, { prefix, headers }).json<T>()
}

function pickGitlabToken() {
Expand Down
5 changes: 3 additions & 2 deletions libs/serve-badge-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import icons from 'badgen-icons'
import originalUrl from 'original-url'

import { BadgenParams } from './types'
import { createBadgeCacheControlHeader, resolveBadgeCacheMaxAge } from './badge-cache-control'

import type { NextApiRequest, NextApiResponse } from 'next'

Expand Down Expand Up @@ -41,8 +42,8 @@ export async function serveBadgeNext (req: NextApiRequest, res: NextApiResponse,

// Minimum s-maxage is set to 300s(5m)
if (res.getHeader('cache-control') === undefined) {
const cacheMaxAge = cache ? Math.max(parseInt(String(cache)), 300) : sMaxAge
res.setHeader('cache-control', `public, max-age=86400, s-maxage=${cacheMaxAge}, stale-while-revalidate=86400`)
const cacheMaxAge = resolveBadgeCacheMaxAge(cache, sMaxAge)
res.setHeader('cache-control', createBadgeCacheControlHeader(cacheMaxAge))
}

res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
Expand Down
5 changes: 3 additions & 2 deletions libs/serve-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { IncomingMessage, ServerResponse } from 'http'
import { BadgenParams } from './types'
import { createBadgeCacheControlHeader, resolveBadgeCacheMaxAge } from './badge-cache-control'

type ServeBadgeOptions = {
code?: number
Expand All @@ -20,7 +21,7 @@
const _icon = await resolveIcon(icon, iconWidth)

// TODO: review usage of list
list && console.log(`FEAT-LIST ${req.url}`)

Check warning on line 24 in libs/serve-badge.ts

View workflow job for this annotation

GitHub Actions / build

eslint(no-unused-expressions)

Expected expression to be used

const badge = badgen({
labelColor,
Expand All @@ -33,8 +34,8 @@
scale: parseFloat(scale || '1'),
})

const cacheMaxAge = cache ? Math.max(parseInt(cache as string) || 0, 300) : sMaxAge
res.setHeader('Cache-Control', `public, max-age=120, s-maxage=${cacheMaxAge}, stale-while-revalidate=86400`)
const cacheMaxAge = resolveBadgeCacheMaxAge(cache, sMaxAge)
res.setHeader('Cache-Control', createBadgeCacheControlHeader(cacheMaxAge))
res.setHeader('Content-Type', 'image/svg+xml;charset=utf-8')
res.statusCode = code
res.end(badge)
Expand Down
Loading
Loading