From 15e89fc299aefd210778daf4ab3f4b6e5181caf3 Mon Sep 17 00:00:00 2001 From: Andcool-Systems Date: Mon, 25 Nov 2024 16:45:32 +0300 Subject: [PATCH] added referrer query in bandage creation notification --- .prettierrc | 9 ++++++--- package-lock.json | 6 +++--- package.json | 3 ++- src/auth/auth.service.ts | 22 ++++++++++++++-------- src/minecraft/minecraft.service.ts | 12 ++++++++---- src/workshop/bandage.service.ts | 13 +++++-------- 6 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.prettierrc b/.prettierrc index dcb7279..7cbc164 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,7 @@ { - "singleQuote": true, - "trailingComma": "all" -} \ No newline at end of file + "singleQuote": true, + "trailingComma": "none", + "endOfLine": "crlf", + "tabWidth": 4, + "printWidth": 250 +} diff --git a/package-lock.json b/package-lock.json index b4bc22d..d494857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3982,9 +3982,9 @@ "dev": true }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "dependencies": { "path-key": "^3.1.0", diff --git a/package.json b/package.json index 677db86..e44ba7d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "prod": "nest build && node dist/main", - "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "lint": "eslint \"{src,apps,libs,test}/**/*.ts\"", + "lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 3900a84..0577ed4 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -219,24 +219,30 @@ export class AuthService { // ----------------------- Create session token --------------------------- - const sessionId = sign({ userId: user_db.id }, 'ppl_super_secret', { expiresIn: Number(process.env.SESSION_TTL) }); + const session = await this.createSession(user_db.id, user_agent); + return { + message: 'logged in', + message_ru: 'Вход произведен успешно', + sessionId: session.sessionId, + statusCode: 200 + }; + } + + + async createSession(user_id: string, user_agent: string) { + const sessionId = sign({ userId: user_id }, 'ppl_super_secret', { expiresIn: Number(process.env.SESSION_TTL) }); const token_record = await this.prisma.sessions.create({ data: { sessionId: sessionId, User_Agent: user_agent, User: { connect: { - id: user_db.id + id: user_id } } } }); - return { - message: 'logged in', - message_ru: 'Вход произведен успешно', - sessionId: token_record.sessionId, - statusCode: 200 - }; + return token_record; } async validateSession(session: string | undefined, user_agent: string): Promise { diff --git a/src/minecraft/minecraft.service.ts b/src/minecraft/minecraft.service.ts index e776af8..ec67309 100644 --- a/src/minecraft/minecraft.service.ts +++ b/src/minecraft/minecraft.service.ts @@ -232,6 +232,12 @@ export class MinecraftService { return { statusCode: 200, new_data: result.valid }; } + async getByCode(code: string): Promise<{ nickname: string, UUID: string } | null> { + const response = await axios.get(`https://mc-oauth.andcool.ru/code/${code}`, { validateStatus: () => true }); + if (response.status !== 200) return null; + return response.data as { nickname: string, UUID: string }; + } + async connect(session: Session, code: string) { /* connect minecraft account to a user profile */ @@ -243,16 +249,14 @@ export class MinecraftService { }; } - const user_data = await axios.get(`https://mc-oauth.andcool.ru/code/${code}`, { validateStatus: () => true }); - if (user_data.status !== 200) { + const data = await this.getByCode(code); + if (!data) { return { statusCode: 404, message: 'Code not found', message_ru: 'Код не найден' }; } - - const data = user_data.data as { nickname: string, UUID: string }; const skin_data = await this.updateSkinCache(data.UUID, true); if (!skin_data) { diff --git a/src/workshop/bandage.service.ts b/src/workshop/bandage.service.ts index 3069e8c..5411e3c 100644 --- a/src/workshop/bandage.service.ts +++ b/src/workshop/bandage.service.ts @@ -242,7 +242,7 @@ export class BandageService { ); await this.notifications.createNotification(session.user.id, { - content: `Повязка ${result.title} создана и отправлена на проверку!` + content: `Повязка ${result.title} создана и отправлена на проверку!` }); return { @@ -256,11 +256,8 @@ export class BandageService { const admin = hasAccess(session?.user, RolesEnum.ManageBandages); const categories = await this.prisma.category.findMany({ - where: for_edit ? { - reachable: admin ? undefined : true, - only_admins: admin ? undefined : false, - visible: true - } : { + where: { + reachable: for_edit && !admin ? true : undefined, only_admins: admin ? undefined : false, visible: true }, @@ -449,14 +446,14 @@ export class BandageService { const difference_after = validated_categories.filter(element => !bandage_categories.includes(element)); if (difference_after.includes(moderation_id[1])) { await this.notifications.createNotification(bandage.userId, { - content: `Повязка ${bandage.title} была отклонена. Пожалуйста, свяжитесь с администрацией для уточнения причин.`, + content: `Повязка ${bandage.title} была отклонена. Пожалуйста, свяжитесь с администрацией для уточнения причин.`, type: 2 }); } else if (moderation_id.some(element => difference.includes(element))) { await this.notifications.createNotification(bandage.userId, { - content: `Повязка ${bandage.title} успешно прошла проверку и теперь доступна остальным в мастерской!`, + content: `Повязка ${bandage.title} успешно прошла проверку и теперь доступна остальным в мастерской!`, type: 1 }); }