Compare commits

...

4 Commits

Author SHA1 Message Date
Julian 4315459e87
Merge branch 'main' of git.n2.pm:NotNet/gluestick 2023-04-28 12:09:00 -04:00
Julian 9aa36dd589
fix some avatar shenanigans 2023-04-28 12:08:51 -04:00
Julian 15360eb6b9
raise avatar limits to 2 MB, 1024x1024 2023-04-28 12:08:36 -04:00
Julian da5373ef25
make logger a global 2023-04-28 12:07:44 -04:00
11 changed files with 19 additions and 15 deletions

2
environment.d.ts vendored
View File

@ -2,11 +2,13 @@ import { PrismaClient } from "@prisma/client";
import { Client as LDAPClient } from "ldapts";
import { ApolloClient, InMemoryCache } from "@apollo/client";
import { LLDAPAuthResponse } from "@/ldap";
import { Logger } from "pino";
declare global {
var prisma: PrismaClient | undefined;
var ldapClient: LDAPClient | undefined;
var authResponse: LLDAPAuthResponse | undefined;
var logger: Logger;
namespace NodeJS {
interface ProcessEnv {

View File

@ -53,7 +53,7 @@ export async function POST(request: Request) {
) {
avatarBuf = Buffer.from(avatarBase64, "base64");
if (avatarBuf.length > 1_000_000) {
if (avatarBuf.length > 2_000_000) {
return new Response(
JSON.stringify({
ok: false,

View File

@ -141,7 +141,7 @@ export default function RegisterForm({
(avatarSource != null
? `We found your avatar from ${avatarSource}, but you can change it if you'd like.`
: "") +
" This will automatically be used as your avatar with supported services - maximum 1 MB. "
" This will automatically be used as your avatar with supported services - maximum 2 MB. "
}
type="file"
name="avatar"

View File

@ -55,7 +55,7 @@ export default async function Page({
const blob = await req.blob();
const arrayBuffer = await blob.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
if (buffer.length <= 1_000_000) {
if (buffer.length <= 2_000_000) {
// I hope you are doing well, you deserve the best of luck while working on this project -Ari
try {
const jpg = await ensureJpg(buffer);

View File

@ -68,7 +68,7 @@ export class DiscordAuthProvider extends AuthProvider {
async getAvatar(): Promise<string | null> {
const me = await this.getMe();
return me.avatar !== null
? `https://cdn.discordapp.com/avatars/${me.id}/${me.avatar}.png`
? `https://cdn.discordapp.com/avatars/${me.id}/${me.avatar}.png?size=1024`
: null;
}

View File

@ -9,14 +9,14 @@
flex-direction: column;
}
.avatarChanger .current-avatar,
.avatarChanger .currentAvatar,
.avatarChanger svg {
width: 3em;
height: 3em;
border-radius: 0.25rem;
}
.vertical.vertical .current-avatar {
.vertical.vertical .currentAvatar {
display: block;
width: 100%;
height: inherit;

View File

@ -1,3 +1,4 @@
/* eslint-disable @next/next/no-img-element */
import React, { ChangeEvent } from "react";
import classnames from "classnames";
@ -30,13 +31,12 @@ export default function AvatarChanger({
<div
className={classnames(
styles.avatarChanger,
"avatar-changer",
vertical ? styles.vertical : null
)}
>
{currentAvatarBlob != null ? (
<img
className="current-avatar"
className={styles.currentAvatar}
src={currentAvatarBlob!}
alt="Your avatar"
/>

View File

@ -6,8 +6,8 @@ export default function CheckIcon() {
xmlns="http://www.w3.org/2000/svg"
xmlnsXlink="http://www.w3.org/1999/xlink"
>
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="check" fill="currentColor" fill-rule="nonzero">
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
<g id="check" fill="currentColor" fillRule="nonzero">
<path
d="M107.782834,4.91476009 C111.16323,-0.155833631 118.014111,-1.52600976 123.084704,1.85438606 C128.155298,5.23478187 129.525474,12.0856625 126.145078,17.1562562 L64.5253312,123.085877 C60.662855,128.879591 52.465466,129.691293 47.5417556,124.767582 L3.23188204,89.4577087 C-1.07729401,85.1485327 -1.07729401,78.1619779 3.23188204,73.8528018 C7.54105809,69.5436258 14.5276129,69.5436258 18.8367889,73.8528018 L53.6283699,99.643429 L107.782834,4.91476009 Z"
id="Path-4"

View File

@ -1,7 +1,7 @@
import sharp from "sharp";
export async function ensureJpg(avatar: Buffer) {
const img = await sharp(avatar).toFormat("jpeg").resize(512, 512);
const img = await sharp(avatar).toFormat("jpeg").resize(1024, 1024);
const buf = await img.toBuffer();
return buf.toString("base64");
}

View File

@ -1,7 +1,9 @@
import pino from "pino";
const logger = pino();
if (global.logger == null) {
global.logger = pino();
}
export function getLogger(name: string) {
return logger.child({ name });
return global.logger.child({ name });
}

View File

@ -19,13 +19,13 @@ const CONFIRM_PASSWORD = (name: string) =>
const AVATAR = Yup.string().test(
"file-size",
"File is bigger than 1 MB.",
"File is bigger than 2 MB.",
(value) => {
if (value == null) return true;
try {
const buf = Buffer.from(value, "base64");
return buf.length <= 1_000_000;
return buf.length <= 2_000_000;
} catch (e) {
return false;
}