Skip to content

Commit

Permalink
feat: add support for custom wakatime api domain (anuraghazra#620)
Browse files Browse the repository at this point in the history
* feat: add support for custom wakatime api domain

* Update src/fetchers/wakatime-fetcher.js

* Update src/fetchers/wakatime-fetcher.js

Co-authored-by: 춤추는망고 <[email protected]>

Co-authored-by: Nathan Chu <[email protected]>
Co-authored-by: 춤추는망고 <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2021
1 parent 72f94ad commit c1a88ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = async (req, res) => {
custom_title,
locale,
layout,
api_domain,
} = req.query;

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

try {
const last7Days = await fetchLast7Days({ username });
const last7Days = await fetchLast7Days({ username, api_domain });

let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),
Expand Down
8 changes: 5 additions & 3 deletions src/fetchers/wakatime-fetcher.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const axios = require("axios");

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

return data.data;
} catch (err) {
if (err.response.status === 404) {
if (err.response.status < 200 || err.response.status > 299) {
throw new Error(
"Wakatime user not found, make sure you have a wakatime profile",
);
Expand Down

0 comments on commit c1a88ba

Please sign in to comment.