From 235bc0b6cae4adad265dde7adad09fb0be6ccb07 Mon Sep 17 00:00:00 2001 From: Grant Date: Fri, 31 May 2024 14:01:39 -0600 Subject: [PATCH] add instance & profile metadata --- packages/server/prisma/dbml/schema.dbml | 11 ++++++ .../migration.sql | 18 ++++++++++ packages/server/prisma/schema.prisma | 14 +++++++- packages/server/src/api/client.ts | 34 +++++++++++++++++-- 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 packages/server/prisma/migrations/20240531195901_add_profile_and_instance_metadata/migration.sql diff --git a/packages/server/prisma/dbml/schema.dbml b/packages/server/prisma/dbml/schema.dbml index 19dc59d..db73b60 100644 --- a/packages/server/prisma/dbml/schema.dbml +++ b/packages/server/prisma/dbml/schema.dbml @@ -9,6 +9,9 @@ Table Setting { Table User { sub String [pk] + picture_url String + display_name String + profile_url String lastPixelTime DateTime [default: `now()`, not null] pixelStack Int [not null, default: 0] undoExpires DateTime @@ -18,6 +21,14 @@ Table User { FactionMember FactionMember [not null] } +Table Instance { + id Int [pk, increment] + hostname String [unique, not null] + name String + logo_url String + banner_url String +} + Table PaletteColor { id Int [pk, increment] name String [not null] diff --git a/packages/server/prisma/migrations/20240531195901_add_profile_and_instance_metadata/migration.sql b/packages/server/prisma/migrations/20240531195901_add_profile_and_instance_metadata/migration.sql new file mode 100644 index 0000000..74984c9 --- /dev/null +++ b/packages/server/prisma/migrations/20240531195901_add_profile_and_instance_metadata/migration.sql @@ -0,0 +1,18 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "display_name" TEXT, +ADD COLUMN "picture_url" TEXT, +ADD COLUMN "profile_url" TEXT; + +-- CreateTable +CREATE TABLE "Instance" ( + "id" SERIAL NOT NULL, + "hostname" TEXT NOT NULL, + "name" TEXT, + "logo_url" TEXT, + "banner_url" TEXT, + + CONSTRAINT "Instance_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Instance_hostname_key" ON "Instance"("hostname"); diff --git a/packages/server/prisma/schema.prisma b/packages/server/prisma/schema.prisma index 85f3280..df0b78f 100644 --- a/packages/server/prisma/schema.prisma +++ b/packages/server/prisma/schema.prisma @@ -20,7 +20,11 @@ model Setting { } model User { - sub String @id + sub String @id + display_name String? + picture_url String? + profile_url String? + lastPixelTime DateTime @default(now()) // the time the last pixel was placed at pixelStack Int @default(0) // amount of pixels stacked for this user undoExpires DateTime? // when the undo for the most recent pixel expires at @@ -32,6 +36,14 @@ model User { FactionMember FactionMember[] } +model Instance { + id Int @id @default(autoincrement()) + hostname String @unique + name String? + logo_url String? + banner_url String? +} + model PaletteColor { id Int @id @default(autoincrement()) name String diff --git a/packages/server/src/api/client.ts b/packages/server/src/api/client.ts index ed0bd8b..652e87c 100644 --- a/packages/server/src/api/client.ts +++ b/packages/server/src/api/client.ts @@ -3,6 +3,7 @@ import { prisma } from "../lib/prisma"; import { OpenID } from "../lib/oidc"; import { TokenSet, errors as OIDC_Errors } from "openid-client"; import { Logger } from "../lib/Logger"; +import Canvas from "../lib/Canvas"; const ClientParams = { TYPE: "auth_type", @@ -135,13 +136,40 @@ app.get("/callback", async (req, res) => { const [username, hostname] = whoami.sub.split("@"); + const sub = [username, hostname].join("@"); await prisma.user.upsert({ where: { - sub: [username, hostname].join("@"), + sub, + }, + update: { + sub, + display_name: whoami.name, + picture_url: whoami.picture, + profile_url: whoami.profile, + }, + create: { + sub, + display_name: whoami.name, + picture_url: whoami.picture, + profile_url: whoami.profile, + }, + }); + + await prisma.instance.upsert({ + where: { + hostname, + }, + update: { + hostname, + name: whoami.instance.instance.name, + logo_url: whoami.instance.instance.logo_uri, + banner_url: whoami.instance.instance.banner_uri, }, - update: {}, create: { - sub: [username, hostname].join("@"), + hostname, + name: whoami.instance.instance.name, + logo_url: whoami.instance.instance.logo_uri, + banner_url: whoami.instance.instance.banner_uri, }, }); -- GitLab