Commit 235bc0b6 authored by Grant's avatar Grant
Browse files

add instance & profile metadata

parent 0f545ee2
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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]
+18 −0
Original line number Diff line number Diff line
-- 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");
+13 −1
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ model Setting {

model User {
  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
+31 −3
Original line number Diff line number Diff line
@@ -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,
    },
    update: {},
    create: {
      sub: [username, hostname].join("@"),
      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,
    },
    create: {
      hostname,
      name: whoami.instance.instance.name,
      logo_url: whoami.instance.instance.logo_uri,
      banner_url: whoami.instance.instance.banner_uri,
    },
  });