mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(database): ♻️ Make user avatar and header into a Media instead of plaintext
This commit is contained in:
parent
bc961b70bb
commit
ba431e2b11
11 changed files with 2480 additions and 89 deletions
|
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue