From de8be5d9cd1ac02066f98f81d6e99e8b26154860 Mon Sep 17 00:00:00 2001 From: amber <146651411+tuta-amb@users.noreply.github.com> Date: Wed, 15 May 2024 23:04:25 -0400 Subject: [PATCH 1/2] fix(session/container): emails with special characters can now be used see issue #6 --- src/lib/session/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/session/index.ts b/src/lib/session/index.ts index 1aa1a31..5065420 100644 --- a/src/lib/session/index.ts +++ b/src/lib/session/index.ts @@ -8,6 +8,7 @@ import { getAuthSession } from "../auth"; import { revalidatePath } from "next/cache"; import { consola } from "consola"; const getRandomNumber = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min; +const encodeEmailLocal = (email: string) => Array.from(email).map(char => /[a-zA-Z0-9_.-]/.test(char) ? char : char.charCodeAt(0)).join(""); /** * Creates a new Stardust session * @param Image Docker image to use for making the session @@ -32,7 +33,7 @@ async function createSession(Image: string) { } const container = await docker .createContainer({ - name: `stardust-${Date.now()}-${userSession.user.email?.split("@")[0]}`, + name: `stardust-${Date.now()}-${encodeEmailLocal(userSession.user.email?.split("@")[0])}`, Image, HostConfig: { PortBindings: { From 74f4a1a314c6a497f660624a1bb35027fad9c887 Mon Sep 17 00:00:00 2001 From: incognitotgt Date: Wed, 15 May 2024 23:23:41 -0400 Subject: [PATCH 2/2] chore: format and lint --- src/lib/session/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/session/index.ts b/src/lib/session/index.ts index 5065420..97dbd79 100644 --- a/src/lib/session/index.ts +++ b/src/lib/session/index.ts @@ -8,7 +8,10 @@ import { getAuthSession } from "../auth"; import { revalidatePath } from "next/cache"; import { consola } from "consola"; const getRandomNumber = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min; -const encodeEmailLocal = (email: string) => Array.from(email).map(char => /[a-zA-Z0-9_.-]/.test(char) ? char : char.charCodeAt(0)).join(""); +const encodeEmailLocal = (email: string) => + Array.from(email) + .map((char) => (/[a-zA-Z0-9_.-]/.test(char) ? char : char.charCodeAt(0))) + .join(""); /** * Creates a new Stardust session * @param Image Docker image to use for making the session @@ -33,7 +36,7 @@ async function createSession(Image: string) { } const container = await docker .createContainer({ - name: `stardust-${Date.now()}-${encodeEmailLocal(userSession.user.email?.split("@")[0])}`, + name: `stardust-${Date.now()}-${encodeEmailLocal((userSession.user?.email as string).split("@")[0])}`, Image, HostConfig: { PortBindings: {