mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Add more user serialization
This commit is contained in:
parent
636f2ffff8
commit
416a7186d1
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
6
index.ts
6
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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
Loading…
Reference in a new issue