|
1 | 1 | import { Express } from 'express'; |
2 | 2 | import { Config, ConfigError, Event42, Exam42 } from './interfaces'; |
3 | 3 | import { getCurrentExams, getExamForHostName, getHostNameFromRequest, hostNameToIp, examAvailableForHost, getMessageForHostName } from './utils'; |
4 | | -import { fetchEvents, fetchExams } from './intra'; |
| 4 | +import { fetchEvents, fetchExams, fetchUserImage } from './intra'; |
5 | 5 |
|
6 | 6 | // Intra API |
7 | 7 | import Fast42 from '@codam/fast42'; |
@@ -106,6 +106,28 @@ export default (app: Express) => { |
106 | 106 | cache.set('examModeHosts', ret, 5); // 5 second cache |
107 | 107 | return res.send(ret); |
108 | 108 | }); |
| 109 | + |
| 110 | + app.get('/api/user/:login/.face', async (req, res) => { |
| 111 | + const login = req.params.login; |
| 112 | + if (!login) { |
| 113 | + return res.status(400).send({ error: 'No login provided' }); |
| 114 | + } |
| 115 | + if (!api) { |
| 116 | + return res.status(503).send({ error: 'Intra API not initialized' }); |
| 117 | + } |
| 118 | + if (cache.has(`user-image-${login}`)) { |
| 119 | + const imageUrl = cache.get<string>(`user-image-${login}`); |
| 120 | + if (imageUrl) { |
| 121 | + return res.redirect(imageUrl); |
| 122 | + } |
| 123 | + } |
| 124 | + const imageUrl = await fetchUserImage(api, login); |
| 125 | + if (!imageUrl) { |
| 126 | + return res.status(404).send({ error: 'User not found or no image set' }); |
| 127 | + } |
| 128 | + cache.set(`user-image-${login}`, imageUrl, cacheTTL); // Cache the image URL |
| 129 | + return res.redirect(imageUrl); |
| 130 | + }); |
109 | 131 | }; |
110 | 132 |
|
111 | 133 | const setUpIntraAPI = async function() { |
|
0 commit comments