Skip to content

Commit 8fb8f4f

Browse files
Cherrypick fixups
1 parent 3a0f98c commit 8fb8f4f

28 files changed

Lines changed: 46 additions & 956 deletions

src/Server.ts

Whitespace-only changes.

src/api/middlewares/ErrorHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function ErrorHandler(
3838

3939
if (error instanceof HTTPError && error.code) {
4040
code = httpcode = error.code;
41+
// @ts-expect-error - we make it exist
4142
if (error.data) data = error.data;
4243
} else if (error instanceof ApiError) {
4344
code = error.code;

src/api/middlewares/RateLimit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { getIpAdress } from "@spacebar/api";
20-
import { Config, getRights, listenEvent } from "@spacebar/util";
19+
import { Config, getRights, listenEvent, getIpAdress } from "@spacebar/util";
2120
import { NextFunction, Request, Response, Router } from "express";
2221
import { API_PREFIX_TRAILING_SLASH } from "./Authentication";
2322

src/api/routes/auth/forgot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
20-
import { Config, Email, ForgotPasswordSchema, User } from "@spacebar/util";
19+
import { route, verifyCaptcha } from "@spacebar/api";
20+
import { Config, Email, ForgotPasswordSchema, getIpAdress, User } from "@spacebar/util";
2121
import { Request, Response, Router } from "express";
2222
const router = Router();
2323

src/api/routes/auth/generate-registration-tokens.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { random, route } from "@spacebar/api";
20-
import { Config, ValidRegistrationToken } from "@spacebar/util";
19+
import { route } from "@spacebar/api";
20+
import { Config, generateRandomString, ValidRegistrationToken } from "@spacebar/util";
2121
import { Request, Response, Router } from "express";
2222

2323
const router: Router = Router();
@@ -51,7 +51,7 @@ router.get(
5151

5252
for (let i = 0; i < count; i++) {
5353
const token = ValidRegistrationToken.create({
54-
token: random(length),
54+
token: generateRandomString(length),
5555
expires_at: new Date(
5656
Date.now() +
5757
Config.get().security

src/api/routes/auth/location-metadata.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { IPAnalysis, getIpAdress, route } from "@spacebar/api";
19+
import { route } from "@spacebar/api";
2020
import { Request, Response, Router } from "express";
21+
import { getIpAdress, IPAnalysis } from "@spacebar/util";
2122
const router = Router();
2223

2324
router.get(

src/api/routes/auth/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
19+
import { route, verifyCaptcha } from "@spacebar/api";
2020
import {
2121
Config,
2222
FieldErrors,
2323
LoginSchema,
2424
User,
2525
WebAuthn,
2626
generateToken,
27-
generateWebAuthnTicket,
27+
generateWebAuthnTicket, getIpAdress,
2828
} from "@spacebar/util";
2929
import bcrypt from "bcrypt";
3030
import crypto from "crypto";

src/api/routes/auth/register.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
*/
1818

1919
import {
20-
IPAnalysis,
21-
getIpAdress,
22-
isProxy,
2320
route,
2421
verifyCaptcha,
2522
} from "@spacebar/api";
@@ -30,7 +27,7 @@ import {
3027
RegisterSchema,
3128
User,
3229
ValidRegistrationToken,
33-
generateToken,
30+
generateToken, getIpAdress, IPAnalysis, isProxy,
3431
} from "@spacebar/util";
3532
import bcrypt from "bcrypt";
3633
import { Request, Response, Router } from "express";

src/api/routes/auth/verify/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { getIpAdress, route, verifyCaptcha } from "@spacebar/api";
19+
import { route, verifyCaptcha } from "@spacebar/api";
2020
import {
2121
checkToken,
2222
Config,
2323
FieldErrors,
24-
generateToken,
24+
generateToken, getIpAdress,
2525
User,
2626
} from "@spacebar/util";
2727
import { Request, Response, Router } from "express";

src/api/routes/channels/#channel_id/invites.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { random, route } from "@spacebar/api";
19+
import { route } from "@spacebar/api";
2020
import {
2121
Channel,
2222
Guild,
@@ -26,7 +26,7 @@ import {
2626
PublicInviteRelation,
2727
User,
2828
emitEvent,
29-
isTextChannel,
29+
isTextChannel, generateRandomString,
3030
} from "@spacebar/util";
3131
import { Request, Response, Router } from "express";
3232
import { HTTPError } from "lambert-server";
@@ -70,7 +70,7 @@ router.post(
7070
: new Date(body.max_age * 1000 + Date.now());
7171

7272
const invite = await Invite.create({
73-
code: random(),
73+
code: generateRandomString(),
7474
temporary: body.temporary || true,
7575
uses: 0,
7676
max_uses: body.max_uses ? Math.max(0, body.max_uses) : 0,

0 commit comments

Comments
 (0)