Commit d4f60dfe authored by nanahira's avatar nanahira

allow query user with id

parent c765c453
Pipeline #19493 passed with stages
in 2 minutes and 16 seconds
......@@ -193,10 +193,21 @@ export const UpdateAccount = async (ctx: Context) => {
ctx.body = (await userRep.save(user)).cleanSensitiveData();
};
async function queryUser(username: string) {
if (!username) return;
const userRepository = getEntityManager().getRepository(User);
const possibleId = parseInt(username);
const query = userRepository.createQueryBuilder('user')
.where('user.username = :username', { username })
if (!isNaN(possibleId)) {
query.orWhere('user.id = :id', { id: possibleId });
}
return query.getOne();
}
export const legacyYGOProAuth = async (ctx: Context) => {
const userRepository = getEntityManager().getRepository(User);
const user = await userRepository.findOne({ username: ctx.params.username });
const user = await queryUser(ctx.params.username);
if (!user) {
return ctx.throw(404);
}
......@@ -205,8 +216,11 @@ export const legacyYGOProAuth = async (ctx: Context) => {
};
export const legacyYGOProAvatar = async (ctx: Context) => {
const userRepository = getEntityManager().getRepository(User);
const user = await userRepository.findOne({ username: ctx.params.username });
// block request from pro2
if ((ctx.header['user-agent'] as string)?.startsWith('UnityPlayer')) {
return ctx.throw(404);
}
const user = await queryUser(ctx.params.username);
if (!user) {
return ctx.throw(404);
}
......@@ -214,17 +228,12 @@ export const legacyYGOProAvatar = async (ctx: Context) => {
if (avatarUrl) {
ctx.redirect(avatarUrl);
}
// block request from pro2
if ((ctx.header['user-agent'] as string)?.startsWith('UnityPlayer')) {
ctx.throw(404);
}
ctx.redirect('https://cdn02.moecube.com:444/accounts/default_avatar.jpg');
};
export const getUserAvatar = async (ctx: Context) => {
const userRepository = getEntityManager().getRepository(User);
const user = await userRepository.findOne({ username: ctx.params.username });
if (!user) {
const user = await queryUser(ctx.params.username);
if (!user) {
return ctx.throw(404);
}
ctx.body = user.avatarURL()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment