server/database/entities/Instance.ts

89 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-09-13 02:29:13 +02:00
import {
BaseEntity,
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from "typeorm";
2023-09-12 22:48:10 +02:00
import { APIInstance } from "~types/entities/instance";
import { User } from "./User";
2023-09-28 20:19:21 +02:00
/**
* Represents an instance in the database.
*/
2023-09-12 22:48:10 +02:00
@Entity({
name: "instances",
})
export class Instance extends BaseEntity {
2023-09-28 20:19:21 +02:00
/**
* The unique identifier of the instance.
*/
2023-09-12 22:48:10 +02:00
@PrimaryGeneratedColumn("uuid")
id!: string;
2023-09-28 20:19:21 +02:00
/**
* The contact account associated with the instance.
*/
2023-09-13 02:29:13 +02:00
@ManyToOne(() => User, user => user.id)
2023-09-12 22:48:10 +02:00
contact_account!: User;
2023-09-28 20:19:21 +02:00
/**
* The configuration of the instance.
*/
2023-09-12 22:48:10 +02:00
@Column("jsonb", {
default: {
media_attachments: {
image_matrix_limit: 0,
image_size_limit: 0,
supported_mime_types: [],
video_frame_limit: 0,
video_matrix_limit: 0,
video_size_limit: 0,
},
polls: {
max_options: 0,
max_characters_per_option: 0,
max_expiration: 0,
min_expiration: 0,
},
statuses: {
characters_reserved_per_url: 0,
max_characters: 0,
max_media_attachments: 0,
},
},
})
configuration!: APIInstance["configuration"];
2023-09-28 20:19:21 +02:00
/**
* Converts the instance to an API instance.
* @returns The API instance.
*/
2023-09-12 22:48:10 +02:00
async toAPI(): Promise<APIInstance> {
return {
uri: "",
approval_required: false,
email: "",
thumbnail: "",
title: "",
version: "",
configuration: this.configuration,
contact_account: await this.contact_account.toAPI(),
description: "",
invites_enabled: false,
languages: [],
registrations: false,
rules: [],
stats: {
domain_count: 0,
status_count: 0,
user_count: 0,
},
urls: {
streaming_api: "",
},
max_toot_chars: 0,
};
}
2023-09-13 02:29:13 +02:00
}