1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-16 15:52:25 +02:00

Add more application properties

This commit is contained in:
TomatoCake 2024-08-31 11:04:18 +02:00
parent 3a63ae89cc
commit e807037145
8 changed files with 1363 additions and 11 deletions

View File

@ -136,6 +136,9 @@
"icon": {
"type": "string"
},
"cover_image": {
"type": "string"
},
"interactions_endpoint_url": {
"type": "string"
},
@ -169,6 +172,12 @@
},
"flags": {
"type": "integer"
},
"custom_install_url": {
"type": "string"
},
"guild_id": {
"type": "string"
}
}
},
@ -3099,6 +3108,15 @@
"privacy_policy_url": {
"type": "string"
},
"guild_id": {
"type": "string"
},
"guild": {
"$ref": "#/components/schemas/Guild"
},
"custom_install_url": {
"type": "string"
},
"team": {
"$ref": "#/components/schemas/Team"
},

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
@ -21,6 +21,7 @@ import {
Application,
ApplicationModifySchema,
DiscordApiErrors,
Guild,
handleFile,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
@ -90,6 +91,24 @@ router.patch(
body.icon as string,
);
}
if (body.cover_image) {
body.cover_image = await handleFile(
`/app-icons/${app.id}`,
body.cover_image as string,
);
}
if (body.guild_id) {
const guild = await Guild.findOneOrFail({
where: { id: body.guild_id },
select: ["owner_id"],
});
if (guild.owner_id != req.user_id)
throw new HTTPError(
"You must be the owner of the guild to link it to an application",
400,
);
}
if (app.bot) {
app.bot.assign({ bio: body.description });

View File

@ -16,11 +16,19 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from "typeorm";
import {
Column,
Entity,
JoinColumn,
ManyToOne,
OneToOne,
RelationId,
} from "typeorm";
import { BaseClass } from "./BaseClass";
import { Team } from "./Team";
import { User } from "./User";
import { dbEngine } from "../util/Database";
import { Guild } from "./Guild";
@Entity({
name: "applications",
@ -108,15 +116,22 @@ export class Application extends BaseClass {
@Column({ nullable: true })
privacy_policy_url?: string;
@Column({ nullable: true })
@RelationId((application: Application) => application.guild)
guild_id?: string;
@JoinColumn({ name: "guild_id" })
@ManyToOne(() => Guild)
guild?: Guild; // guild to which the app is linked, e.g. a developer support server
@Column({ nullable: true })
custom_install_url?: string;
//just for us
//@Column({ type: "simple-array", nullable: true })
//rpc_origins?: string[];
//@JoinColumn({ name: "guild_id" })
//@ManyToOne(() => Guild)
//guild?: Guild; // if this application is a game sold, this field will be the guild to which it has been linked
//@Column({ nullable: true })
//primary_sku_id?: string; // if this application is a game sold, this field will be the id of the "Game SKU" that is created,

View File

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class ApplicationProperties1725090962922 implements MigrationInterface {
name = "ApplicationProperties1725090962922";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE `applications` ADD COLUMN `guild_id` VARCHAR(255) NOT NULL",
);
await queryRunner.query(
"ALTER TABLE `applications` ADD COLUMN `custom_install_url` TEXT NOT NULL",
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE `applications` DROP COLUMN `guild_id`",
);
await queryRunner.query(
"ALTER TABLE `applications` DROP COLUMN `custom_install_url`",
);
}
}

View File

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class ApplicationProperties1725090962922 implements MigrationInterface {
name = "ApplicationProperties1725090962922";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE `applications` ADD COLUMN `guild_id` VARCHAR(255) NOT NULL",
);
await queryRunner.query(
"ALTER TABLE `applications` ADD COLUMN `custom_install_url` TEXT NOT NULL",
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE `applications` DROP COLUMN `guild_id`",
);
await queryRunner.query(
"ALTER TABLE `applications` DROP COLUMN `custom_install_url`",
);
}
}

View File

@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class ApplicationProperties1725090962922 implements MigrationInterface {
name = "ApplicationProperties1725090962922";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE applications ADD COLUMN guild_id TEXT NOT NULL",
);
await queryRunner.query(
"ALTER TABLE applications ADD COLUMN custom_install_url TEXT NOT NULL",
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE applications DROP COLUMN guild_id",
);
await queryRunner.query(
"ALTER TABLE applications DROP COLUMN custom_install_url",
);
}
}

View File

@ -1,17 +1,17 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
Copyright (C) 2023 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
@ -19,6 +19,7 @@
export interface ApplicationModifySchema {
description?: string;
icon?: string;
cover_image?: string;
interactions_endpoint_url?: string;
max_participants?: number | null;
name?: string;
@ -29,4 +30,10 @@ export interface ApplicationModifySchema {
bot_public?: boolean;
bot_require_code_grant?: boolean;
flags?: number;
custom_install_url?: string;
guild_id?: string;
/*install_params?: { TODO: Validation
scopes: string[];
permissions: string;
};*/
}