refactor(database): ♻️ Make user avatar and header into a Media instead of plaintext

This commit is contained in:
Jesse Wierzbinski 2025-01-28 19:07:55 +01:00
parent bc961b70bb
commit ba431e2b11
No known key found for this signature in database
11 changed files with 2480 additions and 89 deletions

View file

@ -1,7 +1,6 @@
import { mimeLookup } from "@/content_types.ts";
import { randomString } from "@/math.ts";
import { createRoute, z } from "@hono/zod-openapi";
import { Token, User, db } from "@versia/kit/db";
import { Media, Token, User, db } from "@versia/kit/db";
import { type SQL, and, eq, isNull } from "@versia/kit/drizzle";
import { OpenIdAccounts, RolePermissions, Users } from "@versia/kit/tables";
import { setCookie } from "hono/cookie";
@ -243,18 +242,15 @@ export default (plugin: PluginType): void => {
? !!(await User.fromSql(eq(Users.email, email)))
: false;
const avatar = picture
? await Media.fromUrl(new URL(picture))
: null;
// Create new user
const user = await User.fromDataLocal({
email: doesEmailExist ? undefined : email,
username,
avatar: picture
? {
url: picture,
content_type: await mimeLookup(
new URL(picture),
),
}
: undefined,
avatar: avatar ?? undefined,
password: undefined,
});