From 416a7186d186f44b1f702784a2025ad12cb17225 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 10 Sep 2023 17:54:14 -1000 Subject: [PATCH] Add more user serialization --- database/entities/User.ts | 50 ++++++++++++++++++++++++++++++++++++++- index.ts | 6 ++++- utils/config.ts | 10 ++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/database/entities/User.ts b/database/entities/User.ts index 9e013411..0b872192 100644 --- a/database/entities/User.ts +++ b/database/entities/User.ts @@ -1,4 +1,8 @@ +import { getConfig, getHost } from "@config"; import { BaseEntity, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm"; +import { Account } from "~types/entities/account"; + +const config = getConfig(); @Entity({ name: "users", @@ -7,15 +11,59 @@ export class User extends BaseEntity { @PrimaryGeneratedColumn("uuid") id!: string; - @Column("varchar") + @Column("varchar", { + unique: true, + }) username!: string; @Column("varchar") password!: string; + @Column("varchar", { + unique: true, + }) + email!: string; + + @Column("varchar", { + default: "", + }) + bio!: string; + @CreateDateColumn() created_at!: Date; @UpdateDateColumn() updated_at!: Date; + + toAccount(): Account { + return { + acct: `@${this.username}@${getHost()}`, + avatar: "", + avatar_static: "", + bot: false, + created_at: this.created_at.toISOString(), + display_name: "", + followers_count: 0, + following_count: 0, + group: false, + header: "", + header_static: "", + id: this.id, + locked: false, + moved: null, + noindex: false, + note: this.bio, + suspended: false, + url: `${config.http.base_url}/@${this.username}`, + username: this.username, + emojis: [], + fields: [], + limited: false, + source: undefined, + statuses_count: 0, + discoverable: undefined, + role: undefined, + mute_expires_at: undefined, + } + } } \ No newline at end of file diff --git a/index.ts b/index.ts index 906dace6..bc6bb8ef 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,5 @@ +import { getConfig } from "@config"; + const router = new Bun.FileSystemRouter({ style: "nextjs", dir: process.cwd() + "/server/api", @@ -5,8 +7,10 @@ const router = new Bun.FileSystemRouter({ console.log("[+] Starting FediProject..."); +const config = getConfig(); + Bun.serve({ - port: 8653, + port: config.http.port, hostname: "0.0.0.0", // defaults to "0.0.0.0" async fetch(req) { const matchedRoute = router.match(req); diff --git a/utils/config.ts b/utils/config.ts index d5f4c076..fa6699f4 100644 --- a/utils/config.ts +++ b/utils/config.ts @@ -8,9 +8,19 @@ export interface ConfigType { password: string; database: string; } + http: { + port: number; + base_url: string; + } [ key: string ]: unknown; } export const getConfig = () => { return data as ConfigType; +} + +export const getHost = () => { + const url = new URL(getConfig().http.base_url); + + return url.host; } \ No newline at end of file