Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: file name parsing #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/api/avatar/[name].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function (req: NextRequest) {
const name = url.searchParams.get("name");
const text = url.searchParams.get("text");
const size = Number(url.searchParams.get("size") || "120");
const [username, type] = name?.split(".") || [];
const { 0: username, length, [length - 1]: type }: { length: number, [key: number]: string } = name?.split(".") || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { 0: username, length, [length - 1]: type }: { length: number, [key: number]: string } = name?.split(".") || [];
const lastDot = name?.lastIndexOf(".");
const username = name?.slice(0, lastDot);
const type = name?.slice(lastDot + 1);

Let's try this so that all the other dots are included in the username.

const fileType = type?.includes("svg") ? "svg" : "png";

const gradient = generateGradient(username || Math.random() + "");
Expand Down