Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
078040d
feat: add bytes stats format option for top-languages card (#3708)
abap34 Sep 16, 2025
d210391
feat: add Norwegian translations (#3653)
marcusotterstad Sep 16, 2025
1655c95
feat: add Serbian translations (#3542)
Trysha-rbrn Sep 16, 2025
ef7f139
build(deps): bump axios from 1.11.0 to 1.12.2 (#4423)
dependabot[bot] Sep 16, 2025
f179fbe
build(deps-dev): bump eslint-plugin-jsdoc from 55.3.0 to 57.0.8 (#4424)
dependabot[bot] Sep 16, 2025
63b4021
docs: add information about fine-grained personal access tokens (PATs…
opheliagoldstein Sep 17, 2025
b594b57
feat: implement commits year option and display appropriate year labe…
vzsky Sep 17, 2025
f441d16
feat: add Persian (Farsi) translations (#4263)
4Min4m Sep 17, 2025
5306118
chore: fix jsdoc for rank calculation function (#4427)
opheliagoldstein Sep 17, 2025
10526a0
chore: make stats card create text node function jsdoc shorter (#4429)
opheliagoldstein Sep 17, 2025
a8c56ff
fix: react on both type and message-based rate-limit signals (#4440)
opheliagoldstein Sep 18, 2025
6bda67e
chore: make create progress node function jsdoc shorter (#4441)
opheliagoldstein Sep 18, 2025
4f33921
fix: remove Chinese from long locales (#4442)
opheliagoldstein Sep 18, 2025
f48a59b
feat: add Thai translations (#4247)
HKornchanok Sep 18, 2025
3e6ce83
feat: add Hindi translations (#3985)
VaibhavVermaa16 Sep 18, 2025
68e5862
docs: sort list of available languages alphabetically inside readme (…
opheliagoldstein Sep 19, 2025
c3585cc
chore: sort stats card long locales alphabetically (#4446)
opheliagoldstein Sep 19, 2025
e918802
chore: move original english translations to the top for convenience …
opheliagoldstein Sep 19, 2025
51664ce
tests(e2e): fix gist description (#4450)
opheliagoldstein Sep 19, 2025
42130f1
fix: mark Portuguese locale as long for stats card (#4451)
opheliagoldstein Sep 19, 2025
b53807b
Merge remote-tracking branch 'upstream/master'
Sep 20, 2025
4859cc7
ci: restrict repositories for theme pull requests closer workflow (#4…
opheliagoldstein Sep 24, 2025
3dd8095
ci: set proper trigger event for theme pull requests closer workflow …
opheliagoldstein Sep 24, 2025
be0dba8
ci: update message in theme pull requests closer workflow (#4465)
opheliagoldstein Sep 24, 2025
4f17194
fix: display correct data when user don't have any pull requests (#4452)
webdev-mohdamir Sep 24, 2025
c81f3eb
feat: add Serbian (Latin) translations (#4448)
rammba Sep 24, 2025
a298e1c
build(deps-dev): bump @eslint/js from 9.35.0 to 9.36.0 (#4454)
dependabot[bot] Sep 26, 2025
d34a706
build(deps-dev): bump eslint from 9.35.0 to 9.36.0 (#4455)
dependabot[bot] Sep 26, 2025
8d0d044
build(deps-dev): bump eslint-plugin-jsdoc from 57.0.8 to 60.1.1 (#4453)
dependabot[bot] Sep 26, 2025
31f34d9
build(deps-dev): bump lint-staged from 16.1.6 to 16.2.0 (#4456)
dependabot[bot] Sep 26, 2025
3131cf7
ci(deps): bump bahmutov/npm-install from 1.10.10 to 1.11.0 (#4457)
dependabot[bot] Sep 26, 2025
fd15fce
chore: remove redundant gitattributes file (#4471)
opheliagoldstein Sep 29, 2025
1b579cd
chore: add more folders into vercelignore (#4473)
opheliagoldstein Sep 29, 2025
4c30073
feat: add Catalan translations (#4134)
Alexasto12 Sep 29, 2025
b246514
docs(readme): fix stats card options table markdown syntax (#4475)
opheliagoldstein Sep 29, 2025
bce273d
docs(readme): remove redundant steps words from tokens retrieval guid…
opheliagoldstein Sep 29, 2025
b118aee
docs(readme): enhance the description of deploy first steps section (…
opheliagoldstein Sep 30, 2025
e9bf75e
docs(readme): update wording since token scopes is not about stats ca…
opheliagoldstein Sep 30, 2025
c6380b7
docs(readme): add warning about new wakatime accounts (#4485)
opheliagoldstein Sep 30, 2025
18c808a
feat: add Filipino translations (#3800)
aanthonytomas Sep 30, 2025
d286fa3
fix: mark Filipino langiage as long for stats card (#4486)
opheliagoldstein Sep 30, 2025
e466ada
feat: add Hebrew translations (#3957)
TheBooker66 Sep 30, 2025
651de3a
docs(readme): add notice about hacktoberfest (#4491)
opheliagoldstein Oct 1, 2025
0d60641
tests: use custom benchmarking solution instead of outdated `jest-ben…
harryzcy Oct 1, 2025
ed942e8
feat: update express.js to support containerized deployments + replic…
EstoesMoises Oct 1, 2025
c689c51
feat: add Urdu translations (#3958)
LessonsWithSarfaraz Oct 1, 2025
ca3c5d5
feat: add Bulgarian translations (#3987)
mihailkondov Oct 1, 2025
df8f7a6
fix: update Hindi translations (#4488)
AayushSahani01 Oct 1, 2025
8e8a15b
fix: update Malayalam translations (#4490)
DhiaShams Oct 1, 2025
aac5735
docs(readme): fix deploy vercel instance link inside important notice…
opheliagoldstein Oct 1, 2025
a38ff10
fix: mark Bulgarian language as long for stats card (#4493)
opheliagoldstein Oct 1, 2025
02cf32c
docs(readme): fix environment variables link inside common options se…
opheliagoldstein Oct 1, 2025
e0d573e
chore: add more entries into vercelignore (#4499)
opheliagoldstein Oct 2, 2025
5031e32
fix: make Bulgarian total commits translation shorter to prevent item…
opheliagoldstein Oct 2, 2025
b25904c
chore: improve bench tests utils jsdoc readability (#4501)
opheliagoldstein Oct 2, 2025
98412a1
build(deps-dev): add express for testing custom deployment issues (#4…
opheliagoldstein Oct 2, 2025
0e30562
ci(deps): bump bahmutov/npm-install from 1.11.0 to 1.11.1 (#4474)
dependabot[bot] Oct 3, 2025
cacc32a
build(deps-dev): bump lint-staged from 16.2.0 to 16.2.3 (#4472)
dependabot[bot] Oct 3, 2025
811f458
build(deps-dev): bump jest-environment-jsdom from 30.1.2 to 30.2.0 (#…
dependabot[bot] Oct 3, 2025
29560fe
build(deps-dev): bump eslint-plugin-jsdoc from 60.1.1 to 60.5.0 (#4478)
dependabot[bot] Oct 3, 2025
a8dd065
refactor: update languages JSON (#4487)
github-actions[bot] Oct 3, 2025
bfa895d
docs(contributing): add notice about hacktoberfest (#4506)
alexandr-garbuzov Oct 4, 2025
3ce1fd7
docs(readme): update string about express inside the section about de…
alexandr-garbuzov Oct 4, 2025
ba9406e
chore: add comment with issue link to the retryer rate limit detectio…
alexandr-garbuzov Oct 4, 2025
3548538
build(deps): remove unused upgrade dependency (#4509)
alexandr-garbuzov Oct 4, 2025
9f3223f
feat: add Swahili translations (#3911)
Ericode254 Oct 4, 2025
7b7f781
feat: add Tamil translations (#4504)
DhiaShams Oct 4, 2025
2641d69
feat: add Sanskrit translations (#4503)
arjav007 Oct 4, 2025
e09f69c
chore: enable ts-check for bench tests utils (#4512)
alexandr-garbuzov Oct 4, 2025
9abfce8
chore: remove package lock from vercelignore to prevent discrepancies…
alexandr-garbuzov Oct 4, 2025
3456ceb
docs(readme): update notice about hacktoberfest (#4516)
alexandr-garbuzov Oct 5, 2025
f5de3eb
docs(contributing): update notice about hacktoberfest (#4517)
alexandr-garbuzov Oct 5, 2025
41317e8
fix: mark Tamil as long language for stats card (#4518)
alexandr-garbuzov Oct 5, 2025
361e827
chore: enable dependabot updates for devcontainer (#4519)
alexandr-garbuzov Oct 5, 2025
39b93b5
feat: wakatime card width customization (#4458)
martin-mfg Oct 5, 2025
a697215
feat: add support for EXCLUDE_REPO env variable (#1299)
Bear-03 Oct 5, 2025
24b1df0
fix: mark Swahili language as long for stats card (#4528)
alexandr-garbuzov Oct 6, 2025
f5b1ffa
refactor: move all envs related code into separate file (#4529)
alexandr-garbuzov Oct 6, 2025
e5f40eb
fix: prevent items overlap by making swahili translation shorter for …
alexandr-garbuzov Oct 6, 2025
fde1363
docs(readme): add description of FETCH_MULTI_PAGE_STARS environment v…
alexandr-garbuzov Oct 6, 2025
ade7d53
refactor: move cache seconds calculation logic into reusable function…
alexandr-garbuzov Oct 6, 2025
09627ce
refactor: move cache headers logic into reusable functions (#4533)
alexandr-garbuzov Oct 6, 2025
195e2fc
refactor: move access guards logic into reusable functions (#4535)
opheliagoldstein Oct 7, 2025
f792090
refactor: improve cache control headers formatting (#4536)
opheliagoldstein Oct 7, 2025
e9d0e8f
refactor: named arguments for render error function (#4537)
opheliagoldstein Oct 7, 2025
6676461
fix: ensure top langs error card dont ignore customization options (#…
opheliagoldstein Oct 7, 2025
e8e5cf8
feat: disable cache with proper headers when CACHE_SECONDS env is zer…
opheliagoldstein Oct 7, 2025
e9cc6c0
chore: configure tab size for javascript in vscode settings (#4540)
opheliagoldstein Oct 7, 2025
12caf46
fix: remove duplicate jest globals imports inside tests files (#4541)
opheliagoldstein Oct 7, 2025
879463b
refactor: organize imports inside tests files (#4542)
opheliagoldstein Oct 7, 2025
956d6de
feat: disable caching when NODE_ENV is development (#4543)
opheliagoldstein Oct 7, 2025
4f0aadc
docs(readme): update information about CACHE_SECONDS environment vari…
opheliagoldstein Oct 7, 2025
4ce7b8b
docs(contributing): add note about NODE_ENV variable to disable cachi…
opheliagoldstein Oct 8, 2025
756a601
docs(readme): add warning about required redeploy after changing envi…
opheliagoldstein Oct 8, 2025
abda6d3
docs(readme): add warning that custom title value should be URL encod…
opheliagoldstein Oct 8, 2025
b399521
docs(readme): remove redundant backslashes (#4548)
opheliagoldstein Oct 8, 2025
3c22841
docs(contributing): remove redundant backslashes (#4549)
opheliagoldstein Oct 8, 2025
0afa6c4
refactor: reorganize cache TTL constants (#4550)
opheliagoldstein Oct 9, 2025
7b0b366
docs(readme): add missing info about wakatime card default cache timi…
opheliagoldstein Oct 9, 2025
f6e5d50
docs(readme): use same markdown syntax for lists across all file and …
opheliagoldstein Oct 9, 2025
b164ece
refactor: move errors related code into separate file (#4554)
opheliagoldstein Oct 9, 2025
99b95fb
ci(deps): bump ossf/scorecard-action from 2.4.2 to 2.4.3 (#4520)
dependabot[bot] Oct 10, 2025
3fd9ce0
build(deps-dev): bump @eslint/js from 9.36.0 to 9.37.0 (#4521)
dependabot[bot] Oct 10, 2025
9648e8c
build(deps-dev): bump eslint from 9.36.0 to 9.37.0 (#4523)
dependabot[bot] Oct 10, 2025
16e5bb5
build(deps-dev): bump eslint-plugin-jsdoc from 60.7.1 to 60.8.2 (#4527)
dependabot[bot] Oct 10, 2025
b507f55
build(deps): bump dotenv from 17.2.2 to 17.2.3 (#4526)
dependabot[bot] Oct 10, 2025
3d3786d
build(deps-dev): bump @testing-library/jest-dom from 6.8.0 to 6.9.1 (…
dependabot[bot] Oct 10, 2025
6d6b87c
build(deps-dev): bump jest from 29.7.0 to 30.2.0 (#4524)
dependabot[bot] Oct 10, 2025
0849165
fix: resolve vscode type errors in API endpoints files (#4555)
opheliagoldstein Oct 11, 2025
6a542c8
fix: resolve vscode errors inside colors related code (#4556)
opheliagoldstein Oct 11, 2025
701068b
refactor: move all color related code into separate file (#4557)
opheliagoldstein Oct 11, 2025
33f0c91
fix: resolve vscode errors inside cards svg generation code (#4558)
opheliagoldstein Oct 11, 2025
92d6dfa
fix: resolve vscode type errors in cache utils (#4559)
opheliagoldstein Oct 11, 2025
90955dc
fix: remove repository link display on missing param errors (#4560)
opheliagoldstein Oct 12, 2025
d3a7a90
ci: prevent codeql analysis workflow from running in forks (#4561)
opheliagoldstein Oct 12, 2025
adbed1e
fix: mark Azerbaijani locale as long for stats card (#4562)
opheliagoldstein Oct 12, 2025
7caaa21
fix: improve Ukrainian translations (#4563)
opheliagoldstein Oct 12, 2025
4143c6d
feat: implement number precision parameter for stats card (#4514)
lulunac27a Oct 13, 2025
c1d13ea
refactor: move color related tests into separate file (#4564)
opheliagoldstein Oct 13, 2025
c4a59b5
refactor: reduce magic numbers inside wakatime card generation code (…
martin-mfg Oct 13, 2025
5df2e63
refactor: move formatting related code into separate file (#4568)
opheliagoldstein Oct 13, 2025
b9c3bf6
refactor: move fmt related tests into separate file (#4569)
opheliagoldstein Oct 13, 2025
ab53e30
refactor: move wrap text multiline function into fmt module (#4572)
alexandr-garbuzov Oct 14, 2025
fda2916
refactor: move wrap text multiline function tests into fmt module (#4…
alexandr-garbuzov Oct 14, 2025
d574feb
refactor: better naming for kformatter function tests (#4574)
alexandr-garbuzov Oct 14, 2025
306d0a3
fix: update Burmese translations (#4570)
wynaung19 Oct 14, 2025
4e44891
fix: mark Czech as long locale for stats card (#4576)
alexandr-garbuzov Oct 14, 2025
da318a6
refactor: move long locales const to the top and infer types (#4577)
alexandr-garbuzov Oct 14, 2025
2df3552
refactor: move HTTP related code into separate module (#4578)
alexandr-garbuzov Oct 15, 2025
bf021b0
fix: resolve several vscode type errors inside fetchers code (#4579)
alexandr-garbuzov Oct 15, 2025
6d1a5e5
refactor: move logger into separate module (#4581)
alexandr-garbuzov Oct 15, 2025
e158f0d
refactor: move operations into separate module (#4582)
alexandr-garbuzov Oct 15, 2025
dff0cfe
fix: mark Finnish locale as long for stats card (#4583)
alexandr-garbuzov Oct 15, 2025
a97ab2d
fix: resolve vscode type errors inside utils tests (#4585)
alexandr-garbuzov Oct 16, 2025
93e4893
refactor: move operations tests into separate module (#4586)
alexandr-garbuzov Oct 16, 2025
516472f
tests: implement more test cases for operations (#4587)
alexandr-garbuzov Oct 16, 2025
33f6276
docs(readme): making main title bigger to improve appearance (#4580)
Sudhss Oct 16, 2025
c43fd65
refactor: move svg rendering related code into separate module (#4588)
alexandr-garbuzov Oct 16, 2025
62c43e9
fix: mark Greek as long locale for stats card (#4589)
alexandr-garbuzov Oct 16, 2025
432595e
ci(deps): bump stefanzweifel/git-auto-commit-action from 6.0.1 to 7.0…
dependabot[bot] Oct 17, 2025
351da08
build(deps-dev): bump lint-staged from 16.2.3 to 16.2.4 (#4565)
dependabot[bot] Oct 17, 2025
af1d8ca
build(deps-dev): bump eslint-plugin-jsdoc from 60.8.2 to 61.1.2 (#4566)
dependabot[bot] Oct 17, 2025
b240a06
refactor: move encode HTML function into separate module (#4591)
alexandr-garbuzov Oct 17, 2025
a72d88f
fix: resolve vscode type errors inside card class (#4592)
alexandr-garbuzov Oct 17, 2025
f5de29f
refactor: move encode HTML function tests into separate module (#4593)
alexandr-garbuzov Oct 17, 2025
a11169e
refactor: move create progress node function into render module (#4594)
alexandr-garbuzov Oct 17, 2025
1d6014d
Merge remote-tracking branch 'upstream/master'
Oct 17, 2025
f3164e6
docs: remove redundant caching language
Oct 17, 2025
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
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ updates:
commit-message:
prefix: "ci(deps)"
prefix-development: "ci(deps-dev)"

# Maintain dependencies for Devcontainers
- package-ecosystem: devcontainers
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
commit-message:
prefix: "build(deps)"
prefix-development: "build(deps-dev)"
2 changes: 2 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ permissions:

jobs:
CodeQL-Build:
if: github.repository == 'anuraghazra/github-readme-stats'

# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Deployment Prep
run: python ./.github/workflows/deploy-prep.py
- uses: stefanzweifel/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0 # v6.0.1
- uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0
with:
branch: vercel
create_branch: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ossf-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
with:
results_file: results.sarif
results_format: sarif
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/preview-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm

- uses: bahmutov/npm-install@3714964fb879ebbbc108e167f0f3a0c81ec075c9 # v1.10.10
- uses: bahmutov/npm-install@4488656f8e90d3c85e3a964db0018dd624f340e7 # v1.11.1
with:
useLockFile: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale-theme-pr-closer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm

- uses: bahmutov/npm-install@3714964fb879ebbbc108e167f0f3a0c81ec075c9 # v1.10.10
- uses: bahmutov/npm-install@4488656f8e90d3c85e3a964db0018dd624f340e7 # v1.11.1
with:
useLockFile: false

Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/theme-prs-closer.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Theme Pull Requests Closer

on:
pull_request:
types:
- labeled
- pull_request_target

permissions:
actions: read
Expand All @@ -21,8 +19,8 @@ permissions:

jobs:
close-prs:
if: github.repository == 'anuraghazra/github-readme-stats'
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand All @@ -34,7 +32,7 @@ jobs:

- name: Close Pull Requests
run: |
comment_message="We are currently pausing addition of new themes. If this theme is exclusively for your personal use, then instead of adding it to our theme collection, you can use card customization options."
comment_message="We are currently pausing addition of new themes. If this theme is exclusively for your personal use, then instead of adding it to our theme collection, you can use card [customization options](https://github.com/anuraghazra/github-readme-stats?tab=readme-ov-file#customization)."

for pr_number in $(gh pr list -l "themes" -q is:open --json number -q ".[].number"); do
gh pr close $pr_number -c "$comment_message"
Expand Down
16 changes: 14 additions & 2 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
.devcontainer
.github
.husky
.vscode
benchmarks
coverage
scripts
tests
.env
package-lock.json
coverage
**/*.md
**/*.svg
.eslintrc.json
.prettierignore
.pretterrc.json
codecov.yml
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
"markdown.extension.toc.levels": "1..3",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.tabSize": 2
}
}
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Contributing to [github-readme-stats](https://github.com/anuraghazra/github-readme-stats)

> [!IMPORTANT]
> Please note that we are NOT participating in Hacktoberfest this year. As a small team, we cannot handle the increased volume of PRs and issues that the event brings. We appreciate your understanding.

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

- Reporting [an issue](https://github.com/anuraghazra/github-readme-stats/issues/new?assignees=&labels=bug&template=bug_report.yml).
Expand Down Expand Up @@ -35,16 +38,17 @@ _(make sure you already have a [Vercel](https://vercel.com/) account)_
3. Run `npm install` in the repository root.
4. Run the command `vercel` in the root and follow the steps there.
5. Run the command `vercel dev` to start a development server at <http://localhost:3000>.
6. The cards will then be available from this local endpoint (i.e. `http://localhost:3000/api?username=anuraghazra`).
6. Create a `.env` file in the root and add the following line `NODE_ENV=development`, this will disable caching for local development.
7. The cards will then be available from this local endpoint (i.e. `http://localhost:3000/api?username=anuraghazra`).

> [!NOTE]\
> [!NOTE]
> You can debug the package code in [Vscode](https://code.visualstudio.com/) by using the [Node.js: Attach to process](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_setting-up-an-attach-configuration) debug option. You can also debug any tests using the [VSCode Jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest). For more information, see https://github.com/jest-community/vscode-jest/issues/912.

## Themes Contribution

We're currently paused addition of new themes to decrease maintenance efforts. All pull requests related to new themes will be closed.

> [!NOTE]\
> [!NOTE]
> If you are considering contributing your theme just because you are using it personally, then instead of adding it to our theme collection, you can use card [customization options](./readme.md#customization).

## Translations Contribution
Expand Down
120 changes: 70 additions & 50 deletions api/gist.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import {
clampValue,
CONSTANTS,
renderError,
parseBoolean,
} from "../src/common/utils.js";
import { gistWhitelist } from "../src/common/whitelist.js";
// @ts-check

import { renderError } from "../src/common/render.js";
import { isLocaleAvailable } from "../src/translations.js";
import { renderGistCard } from "../src/cards/gist.js";
import { fetchGist } from "../src/fetchers/gist.js";
import {
CACHE_TTL,
resolveCacheSeconds,
setCacheHeaders,
setErrorCacheHeaders,
} from "../src/common/cache.js";
import { guardAccess } from "../src/common/access.js";
import {
MissingParamError,
retrieveSecondaryMessage,
} from "../src/common/error.js";
import { parseBoolean } from "../src/common/ops.js";

// @ts-ignore
export default async (req, res) => {
const {
id,
Expand All @@ -27,51 +36,48 @@ export default async (req, res) => {

res.setHeader("Content-Type", "image/svg+xml");

if (gistWhitelist && !gistWhitelist.includes(id)) {
const access = guardAccess({
res,
id,
type: "gist",
colors: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
});
if (!access.isPassed) {
return access.result;
}

if (locale && !isLocaleAvailable(locale)) {
return res.send(
renderError(
"This gist ID is not whitelisted",
"Please deploy your own instance",
{
renderError({
message: "Something went wrong",
secondaryMessage: "Language not found",
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
show_repo_link: false,
},
),
);
}

if (locale && !isLocaleAvailable(locale)) {
return res.send(
renderError("Something went wrong", "Language not found", {
title_color,
text_color,
bg_color,
border_color,
theme,
}),
);
}

try {
const gistData = await fetchGist(id);
const cacheSeconds = resolveCacheSeconds({
requested: parseInt(cache_seconds, 10),
def: CACHE_TTL.GIST_CARD.DEFAULT,
min: CACHE_TTL.GIST_CARD.MIN,
max: CACHE_TTL.GIST_CARD.MAX,
});

let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_DAY, 10),
CONSTANTS.TWO_DAY,
CONSTANTS.SIX_DAY,
);
cacheSeconds = process.env.CACHE_SECONDS
? parseInt(process.env.CACHE_SECONDS, 10) || cacheSeconds
: cacheSeconds;

res.setHeader(
"Cache-Control",
`max-age=${cacheSeconds}, s-maxage=${cacheSeconds}`,
);
setCacheHeaders(res, cacheSeconds);

return res.send(
renderGistCard(gistData, {
Expand All @@ -88,19 +94,33 @@ export default async (req, res) => {
}),
);
} catch (err) {
res.setHeader(
"Cache-Control",
`max-age=${CONSTANTS.ERROR_CACHE_SECONDS / 2}, s-maxage=${
CONSTANTS.ERROR_CACHE_SECONDS
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
); // Use lower cache period for errors.
setErrorCacheHeaders(res);
if (err instanceof Error) {
return res.send(
renderError({
message: err.message,
secondaryMessage: retrieveSecondaryMessage(err),
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
show_repo_link: !(err instanceof MissingParamError),
},
}),
);
}
return res.send(
renderError(err.message, err.secondaryMessage, {
title_color,
text_color,
bg_color,
border_color,
theme,
renderError({
message: "An unknown error occurred",
renderOptions: {
title_color,
text_color,
bg_color,
border_color,
theme,
},
}),
);
}
Expand Down
Loading
Loading