Skip to content

Commit

Permalink
Generate initial avatars for anonymous access
Browse files Browse the repository at this point in the history
  • Loading branch information
julio-cfa committed Aug 13, 2024
1 parent 1c32906 commit 9036724
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions apps/meteor/server/routes/avatar/middlewares/auth.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { userCanAccessAvatar } from '../utils';
import { userCanAccessAvatar, renderSVGLetters } from '../utils';

// protect all avatar endpoints
export const protectAvatars = async (req, res, next) => {
if (!(await userCanAccessAvatar(req))) {
res.writeHead(403);
res.write('Forbidden');
let roomOrUsername;

if (req.url.startsWith('/room')) {
roomOrUsername = req.url.split('/')[2] || 'Room';
} else {
roomOrUsername = req.url.split('/')[1] || 'Anonymous';
}

res.writeHead(200, { 'Content-Type': 'image/svg+xml' });
res.write(renderSVGLetters(roomOrUsername, 200));
res.end();

return;
}

Expand Down

0 comments on commit 9036724

Please sign in to comment.