feat(api): copy /api endpoints (#59283)

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
This commit is contained in:
Oliver Eyton-Williams
2025-04-04 13:55:43 +02:00
committed by GitHub
parent 7e10d90f5a
commit 087d17abe6
8 changed files with 206 additions and 29 deletions

View File

@@ -17,6 +17,9 @@ module.exports = function (app) {
router.get('/ue/:unsubscribeId', unsubscribeById);
router.get('/resubscribe/:unsubscribeId', resubscribe);
router.get('/api/users/get-public-profile', blockUserAgent, getPublicProfile);
router.get('/users/get-public-profile', blockUserAgent, getPublicProfile);
const getUserExists = createGetUserExists(app);
router.get('/users/exists', getUserExists);
app.use(router);
@@ -168,6 +171,17 @@ module.exports = function (app) {
});
}
function createGetUserExists(app) {
const User = app.models.User;
return function getUserExists(req, res) {
const username = req.query.username.toLowerCase();
User.doesExist(username, null).then(exists => {
res.send({ exists });
});
};
}
function prepUserForPublish(user, profileUI) {
const {
about,

View File

@@ -13,8 +13,10 @@ import { getUserById as _getUserById } from '../utils/user-stats';
const authRE = /^\/auth\//;
const confirmEmailRE = /^\/confirm-email$/;
const newsShortLinksRE = /^\/n\/|^\/p\//;
const publicUserRE = /^\/api\/users\/get-public-profile$/;
const publicUsernameRE = /^\/api\/users\/exists$/;
const publicApiUserRE = /^\/api\/users\/get-public-profile$/;
const publicUserRE = /^\/users\/get-public-profile$/;
const publicApiUsernameRE = /^\/api\/users\/exists$/;
const publicUsernameRE = /^\/users\/exists$/;
const resubscribeRE = /^\/resubscribe\//;
const showCertRE = /^\/certificate\/showCert\//;
// note: signin may not have a trailing slash
@@ -32,7 +34,9 @@ const _pathsAllowedREs = [
authRE,
confirmEmailRE,
newsShortLinksRE,
publicApiUserRE,
publicUserRE,
publicApiUsernameRE,
publicUsernameRE,
resubscribeRE,
showCertRE,

View File

@@ -39,8 +39,10 @@ describe('request-authorization', () => {
const authRE = /^\/auth\//;
const confirmEmailRE = /^\/confirm-email$/;
const newsShortLinksRE = /^\/n\/|^\/p\//;
const publicUserRE = /^\/api\/users\/get-public-profile$/;
const publicUsernameRE = /^\/api\/users\/exists$/;
const publicApiUserRE = /^\/api\/users\/get-public-profile$/;
const publicUserRE = /^\/users\/get-public-profile$/;
const publicApiUsernameRE = /^\/api\/users\/exists$/;
const publicUsernameRE = /^\/users\/exists$/;
const resubscribeRE = /^\/resubscribe\//;
const showCertRE = /^\/certificate\/showCert\//;
// note: signin may not have a trailing slash
@@ -53,7 +55,9 @@ describe('request-authorization', () => {
authRE,
confirmEmailRE,
newsShortLinksRE,
publicApiUserRE,
publicUserRE,
publicApiUsernameRE,
publicUsernameRE,
resubscribeRE,
showCertRE,