Add profile photo uploads and custom difficulty support
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import { z } from "zod";
|
||||
export const defaultGlowColor = "#ffe6a1";
|
||||
export const profileAvatarBucket = "minegeo-avatars";
|
||||
export const profileAvatarMaxBytes = 5 * 1024 * 1024;
|
||||
export const profileAvatarMimeTypes = [
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/webp",
|
||||
] as const;
|
||||
export const glowColorSchema = z
|
||||
.string()
|
||||
.regex(/^#[a-fA-F0-9]{6}$/, "Choose a valid glow color")
|
||||
@@ -28,6 +35,7 @@ export const prefixUpdateSchema = z
|
||||
.object({ prefix: customPrefixSchema.nullable(), icon: z.enum(prefixIcons) })
|
||||
.strict();
|
||||
export type ProfileAppearance = {
|
||||
avatar_path?: string | null;
|
||||
name_glow?: boolean;
|
||||
glow_color?: string;
|
||||
role?: string;
|
||||
@@ -36,7 +44,7 @@ export type ProfileAppearance = {
|
||||
custom_prefix_icon?: string;
|
||||
};
|
||||
export const appearanceColumns =
|
||||
"name_glow,glow_color,role,bug_finder,custom_prefix,custom_prefix_icon" as const;
|
||||
"avatar_path,name_glow,glow_color,role,bug_finder,custom_prefix,custom_prefix_icon" as const;
|
||||
export type BadgeUser = ProfileAppearance & {
|
||||
id: string;
|
||||
display_name: string;
|
||||
@@ -44,3 +52,10 @@ export type BadgeUser = ProfileAppearance & {
|
||||
export function glowColor(value?: string) {
|
||||
return glowColorSchema.safeParse(value).data ?? defaultGlowColor;
|
||||
}
|
||||
|
||||
export function profileAvatarUrl(path?: string | null) {
|
||||
const base = process.env.NEXT_PUBLIC_SUPABASE_URL?.replace(/\/$/, "");
|
||||
if (!base || !path) return null;
|
||||
const encodedPath = path.split("/").map(encodeURIComponent).join("/");
|
||||
return `${base}/storage/v1/object/public/${profileAvatarBucket}/${encodedPath}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user