summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/middlewares/TestClient.ts4
-rw-r--r--src/api/routes/applications/#id/bot/index.ts2
-rw-r--r--src/api/routes/auth/login.ts8
-rw-r--r--src/api/routes/auth/mfa/totp.ts2
-rw-r--r--src/api/routes/auth/verify/view-backup-codes-challenge.ts8
-rw-r--r--src/api/routes/guilds/#guild_id/member-verification.ts4
-rw-r--r--src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts150
-rw-r--r--src/api/routes/users/@me/mfa/codes-verification.ts20
-rw-r--r--src/api/routes/users/@me/mfa/totp/disable.ts2
-rw-r--r--src/api/routes/users/@me/mfa/totp/enable.ts2
-rw-r--r--src/api/util/index.ts2
-rw-r--r--src/api/util/utility/captcha.ts23
12 files changed, 112 insertions, 115 deletions
diff --git a/src/api/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts

index 2c195994..3afd0339 100644 --- a/src/api/middlewares/TestClient.ts +++ b/src/api/middlewares/TestClient.ts
@@ -45,8 +45,8 @@ export default function TestClient(app: Application) { res.set(name, value); }); } else { - if(req.params.file.endsWith(".map")) { - return res.status(404).send("Not found"); + if (req.params.file.endsWith(".map")) { + return res.status(404).send("Not found"); } console.log(`[TestClient] Downloading file not yet cached! Asset file: ${req.params.file}`); response = await fetch(`https://discord.com/assets/${req.params.file}`, { diff --git a/src/api/routes/applications/#id/bot/index.ts b/src/api/routes/applications/#id/bot/index.ts
index 2ac3523b..6d054c75 100644 --- a/src/api/routes/applications/#id/bot/index.ts +++ b/src/api/routes/applications/#id/bot/index.ts
@@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import { Application, Config, FieldErrors, generateToken, handleFile, OrmUtils, trimSpecial, User, HTTPError } from "@fosscord/util"; +import { Application, Config, FieldErrors, generateToken, handleFile, HTTPError, OrmUtils, trimSpecial, User } from "@fosscord/util"; import { Request, Response, Router } from "express"; import { verifyToken } from "node-2fa"; diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts
index 68b2656a..045b86eb 100644 --- a/src/api/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts
@@ -1,7 +1,7 @@ -import { Request, Response, Router } from "express"; -import { route, getIpAdress, verifyCaptcha } from "@fosscord/api"; -import { Config, User, generateToken, adjustEmail, FieldErrors, LoginSchema } from "@fosscord/util"; +import { getIpAdress, route, verifyCaptcha } from "@fosscord/api"; +import { adjustEmail, Config, FieldErrors, generateToken, LoginSchema, User } from "@fosscord/util"; import crypto from "crypto"; +import { Request, Response, Router } from "express"; let bcrypt: any; try { @@ -38,7 +38,7 @@ router.post("/", route({ body: "LoginSchema" }), async (req: Request, res: Respo captcha_key: verify["error-codes"], captcha_sitekey: sitekey, captcha_service: service - }) + }); } } diff --git a/src/api/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts
index 4b080af6..65ec7f2f 100644 --- a/src/api/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts
@@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import { BackupCode, generateToken, TotpSchema, User, HTTPError } from "@fosscord/util"; +import { BackupCode, generateToken, HTTPError, TotpSchema, User } from "@fosscord/util"; import { Request, Response, Router } from "express"; import { verifyToken } from "node-2fa"; const router = Router(); diff --git a/src/api/routes/auth/verify/view-backup-codes-challenge.ts b/src/api/routes/auth/verify/view-backup-codes-challenge.ts
index d524e0f7..846e186b 100644 --- a/src/api/routes/auth/verify/view-backup-codes-challenge.ts +++ b/src/api/routes/auth/verify/view-backup-codes-challenge.ts
@@ -1,6 +1,6 @@ -import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; -import { FieldErrors, User, BackupCodesChallengeSchema } from "@fosscord/util"; +import { BackupCodesChallengeSchema, FieldErrors, User } from "@fosscord/util"; +import { Request, Response, Router } from "express"; let bcrypt: any; try { @@ -17,13 +17,13 @@ router.post("/", route({ body: "BackupCodesChallengeSchema" }), async (req: Requ const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] }); - if (!await bcrypt.compare(password, user.data.hash || "")) { + if (!(await bcrypt.compare(password, user.data.hash || ""))) { throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } }); } return res.json({ nonce: "NoncePlaceholder", - regenerate_nonce: "RegenNoncePlaceholder", + regenerate_nonce: "RegenNoncePlaceholder" }); }); diff --git a/src/api/routes/guilds/#guild_id/member-verification.ts b/src/api/routes/guilds/#guild_id/member-verification.ts
index 265a1b35..bb3ffb0a 100644 --- a/src/api/routes/guilds/#guild_id/member-verification.ts +++ b/src/api/routes/guilds/#guild_id/member-verification.ts
@@ -1,8 +1,8 @@ -import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; +import { Request, Response, Router } from "express"; const router = Router(); -router.get("/",route({}), async (req: Request, res: Response) => { +router.get("/", route({}), async (req: Request, res: Response) => { // TODO: member verification res.status(404).json({ diff --git a/src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts b/src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts
index f8c78bc5..a5fe0cf2 100644 --- a/src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts +++ b/src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts
@@ -134,159 +134,159 @@ const skus = new Map([ price: 0, price_tier: null } - ], + ] ], [ "978380684370378762", [ [ { - "id": "978380692553465866", - "name": "Premium Tier 0 Monthly", - "interval": 1, - "interval_count": 1, - "tax_inclusive": true, - "sku_id": "978380684370378762", - "currency": "usd", - "price": 299, - "price_tier": null, - "prices": { + id: "978380692553465866", + name: "Premium Tier 0 Monthly", + interval: 1, + interval_count: 1, + tax_inclusive: true, + sku_id: "978380684370378762", + currency: "usd", + price: 299, + price_tier: null, + prices: { "0": { - "country_prices": { - "country_code": "US", - "prices": [ + country_prices: { + country_code: "US", + prices: [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] }, - "payment_source_prices": { + payment_source_prices: { "775487223059316758": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "736345864146255982": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "683074999590060249": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] } }, "3": { - "country_prices": { - "country_code": "US", - "prices": [ + country_prices: { + country_code: "US", + prices: [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] }, - "payment_source_prices": { + payment_source_prices: { "775487223059316758": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "736345864146255982": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "683074999590060249": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] } }, "4": { - "country_prices": { - "country_code": "US", - "prices": [ + country_prices: { + country_code: "US", + prices: [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] }, - "payment_source_prices": { + payment_source_prices: { "775487223059316758": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "736345864146255982": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "683074999590060249": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] } }, "1": { - "country_prices": { - "country_code": "US", - "prices": [ + country_prices: { + country_code: "US", + prices: [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] }, - "payment_source_prices": { + payment_source_prices: { "775487223059316758": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "736345864146255982": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ], "683074999590060249": [ { - "currency": "usd", - "amount": 0, - "exponent": 2 + currency: "usd", + amount: 0, + exponent: 2 } ] } diff --git a/src/api/routes/users/@me/mfa/codes-verification.ts b/src/api/routes/users/@me/mfa/codes-verification.ts
index 071c71fa..570606e0 100644 --- a/src/api/routes/users/@me/mfa/codes-verification.ts +++ b/src/api/routes/users/@me/mfa/codes-verification.ts
@@ -1,6 +1,6 @@ -import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; -import { BackupCode, generateMfaBackupCodes, User, CodesVerificationSchema } from "@fosscord/util"; +import { BackupCode, CodesVerificationSchema, generateMfaBackupCodes, User } from "@fosscord/util"; +import { Request, Response, Router } from "express"; const router = Router(); @@ -14,27 +14,23 @@ router.post("/", route({ body: "CodesVerificationSchema" }), async (req: Request var codes: BackupCode[]; if (regenerate) { - await BackupCode.update( - { user: { id: req.user_id } }, - { expired: true } - ); + await BackupCode.update({ user: { id: req.user_id } }, { expired: true }); codes = generateMfaBackupCodes(req.user_id); - await Promise.all(codes.map(x => x.save())); - } - else { + await Promise.all(codes.map((x) => x.save())); + } else { codes = await BackupCode.find({ where: { user: { - id: req.user_id, + id: req.user_id }, - expired: false, + expired: false } }); } return res.json({ - backup_codes: codes.map(x => ({ ...x, expired: undefined })), + backup_codes: codes.map((x) => ({ ...x, expired: undefined })) }); }); diff --git a/src/api/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts
index 07fdbb05..a53fa816 100644 --- a/src/api/routes/users/@me/mfa/totp/disable.ts +++ b/src/api/routes/users/@me/mfa/totp/disable.ts
@@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import { BackupCode, generateToken, TotpDisableSchema, User, HTTPError } from "@fosscord/util"; +import { BackupCode, generateToken, HTTPError, TotpDisableSchema, User } from "@fosscord/util"; import { Request, Response, Router } from "express"; import { verifyToken } from "node-2fa"; diff --git a/src/api/routes/users/@me/mfa/totp/enable.ts b/src/api/routes/users/@me/mfa/totp/enable.ts
index adf51d6e..0bf1a188 100644 --- a/src/api/routes/users/@me/mfa/totp/enable.ts +++ b/src/api/routes/users/@me/mfa/totp/enable.ts
@@ -1,5 +1,5 @@ import { route } from "@fosscord/api"; -import { BackupCode, Config, generateMfaBackupCodes, generateToken, TotpEnableSchema, User, HTTPError } from "@fosscord/util"; +import { BackupCode, Config, generateMfaBackupCodes, generateToken, HTTPError, TotpEnableSchema, User } from "@fosscord/util"; import { Request, Response, Router } from "express"; import { verifyToken } from "node-2fa"; diff --git a/src/api/util/index.ts b/src/api/util/index.ts
index 31e75325..d06860cd 100644 --- a/src/api/util/index.ts +++ b/src/api/util/index.ts
@@ -3,8 +3,8 @@ export * from "./handlers/Message"; export * from "./handlers/route"; export * from "./handlers/Voice"; export * from "./utility/Base64"; +export * from "./utility/captcha"; export * from "./utility/ipAddress"; export * from "./utility/passwordStrength"; export * from "./utility/RandomInviteID"; export * from "./utility/String"; -export * from "./utility/captcha"; \ No newline at end of file diff --git a/src/api/util/utility/captcha.ts b/src/api/util/utility/captcha.ts
index 739647d2..02983f3f 100644 --- a/src/api/util/utility/captcha.ts +++ b/src/api/util/utility/captcha.ts
@@ -7,8 +7,8 @@ export interface hcaptchaResponse { hostname: string; credit: boolean; "error-codes": string[]; - score: number; // enterprise only - score_reason: string[]; // enterprise only + score: number; // enterprise only + score_reason: string[]; // enterprise only } export interface recaptchaResponse { @@ -22,8 +22,8 @@ export interface recaptchaResponse { const verifyEndpoints = { hcaptcha: "https://hcaptcha.com/siteverify", - recaptcha: "https://www.google.com/recaptcha/api/siteverify", -} + recaptcha: "https://www.google.com/recaptcha/api/siteverify" +}; export async function verifyCaptcha(response: string, ip?: string) { const { security } = Config.get(); @@ -34,13 +34,14 @@ export async function verifyCaptcha(response: string, ip?: string) { const res = await fetch(verifyEndpoints[service], { method: "POST", headers: { - "Content-Type": "application/x-www-form-urlencoded", + "Content-Type": "application/x-www-form-urlencoded" }, - body: `response=${encodeURIComponent(response)}` - + `&secret=${encodeURIComponent(secret!)}` - + `&sitekey=${encodeURIComponent(sitekey!)}` - + (ip ? `&remoteip=${encodeURIComponent(ip!)}` : ""), + body: + `response=${encodeURIComponent(response)}` + + `&secret=${encodeURIComponent(secret!)}` + + `&sitekey=${encodeURIComponent(sitekey!)}` + + (ip ? `&remoteip=${encodeURIComponent(ip!)}` : "") }); - return await res.json() as hcaptchaResponse | recaptchaResponse; -} \ No newline at end of file + return (await res.json()) as hcaptchaResponse | recaptchaResponse; +}