1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 02:12:40 +01:00

Merge pull request #1206 from DEVTomatoCake/feat/more-application-properties

Add more application properties
This commit is contained in:
Madeline 2024-08-31 20:03:39 +10:00 committed by GitHub
commit f9ed681272
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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

@ -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

@ -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;
};*/
}