|
@@ -3,28 +3,40 @@ const express = require('express');
|
|
|
const axios = require('axios');
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
|
|
|
+const { isAfter, addMonths } = require('date-fns');
|
|
|
|
|
|
|
|
const contributors = require('../../../client/js/components/StaffCredit/Contributor');
|
|
const contributors = require('../../../client/js/components/StaffCredit/Contributor');
|
|
|
|
|
|
|
|
|
|
+let expiredAt;
|
|
|
|
|
+
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
|
|
|
|
|
|
router.get('/', async(req, res) => {
|
|
router.get('/', async(req, res) => {
|
|
|
|
|
+ const now = new Date();
|
|
|
|
|
+
|
|
|
const growiCloudUri = await crowi.configManager.getConfig('crowi', 'app:growiCloudUri');
|
|
const growiCloudUri = await crowi.configManager.getConfig('crowi', 'app:growiCloudUri');
|
|
|
if (growiCloudUri == null) {
|
|
if (growiCloudUri == null) {
|
|
|
- return res.json({});
|
|
|
|
|
- }
|
|
|
|
|
- const url = new URL('_api/staffCredit', growiCloudUri);
|
|
|
|
|
- try {
|
|
|
|
|
- const gcContributorsRes = await axios.get(url.toString());
|
|
|
|
|
- // prevent merge gcContributors to contributors more than once
|
|
|
|
|
- if (contributors[1].sectionName !== 'GROWI-cloud') {
|
|
|
|
|
- contributors.splice(1, 0, gcContributorsRes.data);
|
|
|
|
|
- }
|
|
|
|
|
return res.apiv3({ contributors });
|
|
return res.apiv3({ contributors });
|
|
|
}
|
|
}
|
|
|
- catch (err) {
|
|
|
|
|
- return res.apiv3Err(err, 500);
|
|
|
|
|
|
|
+ if (expiredAt == null || isAfter(now, expiredAt)) {
|
|
|
|
|
+ const url = new URL('_api/staffCredit', growiCloudUri);
|
|
|
|
|
+ try {
|
|
|
|
|
+ const gcContributorsRes = await axios.get(url.toString());
|
|
|
|
|
+ // prevent merge gcContributors to contributors more than once
|
|
|
|
|
+ if (contributors[1].sectionName !== 'GROWI-cloud') {
|
|
|
|
|
+ contributors.splice(1, 0, gcContributorsRes.data);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ contributors.splice(1, 1, gcContributorsRes.data);
|
|
|
|
|
+ }
|
|
|
|
|
+ // caching 'expiredAt' for 1 month
|
|
|
|
|
+ expiredAt = addMonths(now, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ return res.apiv3Err(err, 500);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ return res.apiv3({ contributors });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
return router;
|
|
return router;
|