Skip to content

Commit

Permalink
Merge pull request #922 from MaddyUnderStars/maddy/bodyParserPatch
Browse files Browse the repository at this point in the history
Patch body-parser to use json-bigint, like gateway
  • Loading branch information
MaddyUnderStars authored Jan 2, 2023
2 parents e380255 + 0fe0377 commit b70f8fc
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 50 deletions.
32 changes: 32 additions & 0 deletions assets/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -12064,6 +12064,22 @@
},
"bio": {
"type": "string"
},
"pronouns": {
"type": "string"
},
"theme_colors": {
"type": "array",
"items": [
{
"type": "integer"
},
{
"type": "integer"
}
],
"minItems": 2,
"maxItems": 2
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -19567,6 +19583,22 @@
"null",
"string"
]
},
"pronouns": {
"type": "string"
},
"theme_colors": {
"type": "array",
"items": [
{
"type": "integer"
},
{
"type": "integer"
}
],
"minItems": 2,
"maxItems": 2
}
},
"additionalProperties": false,
Expand Down
88 changes: 44 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"ajv-formats": "2.1.1",
"amqplib": "^0.10.3",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.1",
"body-parser": "1.20.1",
"cheerio": "^1.0.0-rc.12",
"cookie-parser": "^1.4.6",
"dotenv": "^16.0.2",
Expand Down
30 changes: 30 additions & 0 deletions patches/body-parser+1.20.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/node_modules/body-parser/lib/types/json.js b/node_modules/body-parser/lib/types/json.js
index c2745be..7104cfa 100644
--- a/node_modules/body-parser/lib/types/json.js
+++ b/node_modules/body-parser/lib/types/json.js
@@ -18,6 +18,7 @@ var createError = require('http-errors')
var debug = require('debug')('body-parser:json')
var read = require('../read')
var typeis = require('type-is')
+var JSONbig = require("json-bigint");

/**
* Module exports.
@@ -86,7 +87,7 @@ function json (options) {

try {
debug('parse json')
- return JSON.parse(body, reviver)
+ return JSONbig.parse(body, reviver)
} catch (e) {
throw normalizeJsonSyntaxError(e, {
message: e.message,
@@ -157,7 +158,7 @@ function createStrictSyntaxError (str, char) {
: ''

try {
- JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
+ JSONbig.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
} catch (e) {
return normalizeJsonSyntaxError(e, {
message: e.message.replace('#', char),
10 changes: 8 additions & 2 deletions src/api/routes/users/#id/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ router.get(
const userProfile = {
bio: req.user_bot ? null : user.bio,
accent_color: user.accent_color,
banner: user.banner
banner: user.banner,
pronouns: user.pronouns,
theme_colors: user.theme_colors,
};

const guildMemberDto = guild_member
Expand Down Expand Up @@ -126,6 +128,8 @@ router.get(
premium_since: user.premium_since, // TODO
mutual_guilds: mutual_guilds, // TODO {id: "", nick: null} when ?with_mutual_guilds=true
user: userDto,
premium_type: user.premium_type,
profile_themes_experiment_bucket: 4, // TODO: This doesn't make it available, for some reason?
user_profile: userProfile,
guild_member: guild_id && guildMemberDto,
guild_member_profile: guild_id && guildMemberProfile
Expand Down Expand Up @@ -154,7 +158,9 @@ router.patch("/", route({ body: "UserProfileModifySchema" }), async (req: Reques
res.json({
accent_color: user.accent_color,
bio: user.bio,
banner: user.banner
banner: user.banner,
theme_colors: user.theme_colors,
pronouns: user.pronouns,
});
});

Expand Down
1 change: 1 addition & 0 deletions src/gateway/opcodes/Identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
bot: related_user.bot,
bio: related_user.bio,
premium_since: user.premium_since,
premium_type: user.premium_type,
accent_color: related_user.accent_color,
};
users.push(public_related_user);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class UserDefaults {
premium: boolean = false;
premium_type: number = 2;
premium: boolean = true;
premiumType: number = 2;
verified: boolean = true;
}
6 changes: 6 additions & 0 deletions src/util/entities/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export class Member extends BaseClassWithoutId {

@Column()
bio: string;

@Column({ nullable: true, type: "simple-array" })
theme_colors?: number[]; // TODO: Separate `User` and `UserProfile` models

@Column({ nullable: true })
pronouns?: string;

@Column({ nullable: true })
communication_disabled_until: Date;
Expand Down
11 changes: 10 additions & 1 deletion src/util/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export enum PublicUserEnum {
bio,
bot,
premium_since,
premium_type,
theme_colors,
pronouns,
}
export type PublicUserKeys = keyof typeof PublicUserEnum;

Expand Down Expand Up @@ -88,6 +91,12 @@ export class User extends BaseClass {
@Column({ nullable: true })
banner?: string; // hash of the user banner

@Column({ nullable: true, type: "simple-array" })
theme_colors?: number[]; // TODO: Separate `User` and `UserProfile` models

@Column({ nullable: true })
pronouns?: string;

@Column({ nullable: true, select: false })
phone?: string; // phone number of the user

Expand Down Expand Up @@ -351,7 +360,7 @@ export class User extends BaseClass {
valid_tokens_since: new Date(),
},
extended_settings: "{}",
premium_type: Config.get().defaults.user.premium_type,
premium_type: Config.get().defaults.user.premiumType,
premium: Config.get().defaults.user.premium,
verified: Config.get().defaults.user.verified,
settings: settings,
Expand Down
Loading

0 comments on commit b70f8fc

Please sign in to comment.