Skip to content

Commit c1a88ba

Browse files
nathanchuensia96
andauthored
feat: add support for custom wakatime api domain (anuraghazra#620)
* feat: add support for custom wakatime api domain * Update src/fetchers/wakatime-fetcher.js * Update src/fetchers/wakatime-fetcher.js Co-authored-by: 춤추는망고 <ensia96@gmail.com> Co-authored-by: Nathan Chu <63111210+nthnchu@users.noreply.github.com> Co-authored-by: 춤추는망고 <ensia96@gmail.com>
1 parent 72f94ad commit c1a88ba

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

api/wakatime.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = async (req, res) => {
2525
custom_title,
2626
locale,
2727
layout,
28+
api_domain,
2829
} = req.query;
2930

3031
res.setHeader("Content-Type", "image/svg+xml");
@@ -34,7 +35,7 @@ module.exports = async (req, res) => {
3435
}
3536

3637
try {
37-
const last7Days = await fetchLast7Days({ username });
38+
const last7Days = await fetchLast7Days({ username, api_domain });
3839

3940
let cacheSeconds = clampValue(
4041
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),

src/fetchers/wakatime-fetcher.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
const axios = require("axios");
22

3-
const fetchLast7Days = async ({ username }) => {
3+
const fetchLast7Days = async ({ username, api_domain }) => {
44
try {
55
const { data } = await axios.get(
6-
`https://wakatime.com/api/v1/users/${username}/stats/last_7_days?is_including_today=true`,
6+
`https://${
7+
api_domain ? api_domain.replace(/[^a-z-.0-9]/gi, "") : "wakatime.com"
8+
}/api/v1/users/${username}/stats/last_7_days?is_including_today=true`,
79
);
810

911
return data.data;
1012
} catch (err) {
11-
if (err.response.status === 404) {
13+
if (err.response.status < 200 || err.response.status > 299) {
1214
throw new Error(
1315
"Wakatime user not found, make sure you have a wakatime profile",
1416
);

0 commit comments

Comments
 (0)