@20syldev/api 3.4.8 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/app.js +39 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://api.sylvain.sh"><img src="https://api.sylvain.sh/favicon.ico" alt="Logo" width="25%" height="auto"/></a>
|
|
3
3
|
|
|
4
4
|
# API Personnelle
|
|
5
|
-
[](https://github.com/20syldev/api/releases/latest)
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
8
|
---
|
|
@@ -72,7 +72,7 @@ Enfin, **exécutez** le script de build, qui installera les **dépendances** et
|
|
|
72
72
|
$ npm run build
|
|
73
73
|
```
|
|
74
74
|
```console
|
|
75
|
-
> @20syldev/api@3.
|
|
75
|
+
> @20syldev/api@3.5.0 build
|
|
76
76
|
> npm install && node app.js
|
|
77
77
|
|
|
78
78
|
[...]
|
package/app.js
CHANGED
|
@@ -107,7 +107,7 @@ const ticTacToeStorage = {
|
|
|
107
107
|
const documentation = 'https://docs.sylvain.sh';
|
|
108
108
|
|
|
109
109
|
// Define global variables
|
|
110
|
-
let
|
|
110
|
+
let activity = [], lastFetch = 0, requests = 0, requestLimit, resetTime = Date.now() + 3600000;
|
|
111
111
|
|
|
112
112
|
// ----------- ----------- MIDDLEWARES SETUP ----------- ----------- //
|
|
113
113
|
|
|
@@ -581,26 +581,21 @@ app.get('/:version/website', async (req, res) => {
|
|
|
581
581
|
try {
|
|
582
582
|
const username = '20syldev';
|
|
583
583
|
const token = process.env.GITHUB_TOKEN;
|
|
584
|
-
const today = new Date().toISOString().split('T')[0];
|
|
585
|
-
const monthFirst = new Date(new Date().getFullYear(), new Date().getMonth(), 1).toISOString().split('T')[0];
|
|
586
584
|
const lastYear = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString().split('T')[0];
|
|
587
585
|
|
|
588
586
|
const query = `
|
|
589
587
|
{
|
|
590
588
|
user(login: "${username}") {
|
|
591
|
-
contributionsCollection(from: "${
|
|
592
|
-
contributionCalendar {
|
|
593
|
-
totalContributions
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
contributions_month: contributionsCollection(from: "${monthFirst}T00:00:00Z") {
|
|
597
|
-
contributionCalendar {
|
|
598
|
-
totalContributions
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
contributions_year: contributionsCollection(from: "${lastYear}T00:00:00Z") {
|
|
589
|
+
contributionsCollection(from: "${lastYear}T00:00:00Z") {
|
|
602
590
|
contributionCalendar {
|
|
603
591
|
totalContributions
|
|
592
|
+
weeks {
|
|
593
|
+
firstDay
|
|
594
|
+
contributionDays {
|
|
595
|
+
date
|
|
596
|
+
contributionCount
|
|
597
|
+
}
|
|
598
|
+
}
|
|
604
599
|
}
|
|
605
600
|
}
|
|
606
601
|
}
|
|
@@ -617,17 +612,18 @@ app.get('/:version/website', async (req, res) => {
|
|
|
617
612
|
const data = await apiResponse.json();
|
|
618
613
|
const user = data?.data?.user;
|
|
619
614
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
615
|
+
const weeks = user?.contributionsCollection?.contributionCalendar?.weeks || [];
|
|
616
|
+
activity = weeks.map(w => ({
|
|
617
|
+
week: w.firstDay,
|
|
618
|
+
total: w.contributionDays.reduce((sum, d) => sum + d.contributionCount, 0),
|
|
619
|
+
days: w.contributionDays.map(d => ({ date: d.date, count: d.contributionCount }))
|
|
620
|
+
}));
|
|
625
621
|
|
|
626
622
|
lastFetch = currentTime;
|
|
627
|
-
} catch {
|
|
623
|
+
} catch { activity = []; }
|
|
628
624
|
}
|
|
629
625
|
|
|
630
|
-
|
|
626
|
+
const response = {
|
|
631
627
|
versions: {
|
|
632
628
|
2048: process.env.G_2048,
|
|
633
629
|
api: process.env.API,
|
|
@@ -678,13 +674,31 @@ app.get('/:version/website', async (req, res) => {
|
|
|
678
674
|
3: process.env.STATS3,
|
|
679
675
|
4: process.env.STATS4,
|
|
680
676
|
5: Object.keys(ipLimits).length,
|
|
681
|
-
|
|
682
|
-
this_month: contributions.month.toString(),
|
|
683
|
-
last_year: contributions.year.toString(),
|
|
677
|
+
activity
|
|
684
678
|
},
|
|
685
679
|
tag: process.env.TAG,
|
|
686
680
|
active: process.env.ACTIVE === 'true'
|
|
687
|
-
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
const key = req.query.key;
|
|
684
|
+
if (key) {
|
|
685
|
+
const keys = key.split('.');
|
|
686
|
+
let result = response;
|
|
687
|
+
|
|
688
|
+
for (const k of keys) {
|
|
689
|
+
if (result == null || typeof result !== 'object' || !(k in result)) {
|
|
690
|
+
return res.status(404).jsonResponse({
|
|
691
|
+
error: `Key '${key}' not found.`,
|
|
692
|
+
available: Object.keys(result ?? {})
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
result = result[k];
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return res.jsonResponse({ [key]: result });
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
res.jsonResponse(response);
|
|
688
702
|
});
|
|
689
703
|
|
|
690
704
|
// ----------- ----------- POST ENDPOINTS ----------- ----------- //
|
package/package.json
CHANGED