Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): add missing schemas and fix incorrect schemas #13295

Merged
merged 8 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/backend/src/misc/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/jso
import { packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedAnnouncementSchema } from '@/models/json-schema/announcement.js';
import { packedSigninSchema } from '@/models/json-schema/signin.js';
import { packedRoleLiteSchema, packedRoleSchema, packedRolePoliciesSchema } from '@/models/json-schema/role.js';
import {
packedRoleLiteSchema,
packedRoleSchema,
packedRolePoliciesSchema,
packedRoleCondFormulaLogicsSchema,
packedRoleCondFormulaValueNot,
packedRoleCondFormulaValueIsLocalOrRemoteSchema,
packedRoleCondFormulaValueCreatedSchema,
packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
packedRoleCondFormulaValueSchema,
} from '@/models/json-schema/role.js';
import { packedAdSchema } from '@/models/json-schema/ad.js';
import { packedReversiGameLiteSchema, packedReversiGameDetailedSchema } from '@/models/json-schema/reversi-game.js';

Expand Down Expand Up @@ -78,6 +88,12 @@ export const refs = {
EmojiDetailed: packedEmojiDetailedSchema,
Flash: packedFlashSchema,
Signin: packedSigninSchema,
RoleCondFormulaLogics: packedRoleCondFormulaLogicsSchema,
RoleCondFormulaValueNot: packedRoleCondFormulaValueNot,
RoleCondFormulaValueIsLocalOrRemote: packedRoleCondFormulaValueIsLocalOrRemoteSchema,
RoleCondFormulaValueCreated: packedRoleCondFormulaValueCreatedSchema,
RoleCondFormulaFollowersOrFollowingOrNotes: packedRoleCondFormulaFollowersOrFollowingOrNotesSchema,
RoleCondFormulaValue: packedRoleCondFormulaValueSchema,
RoleLite: packedRoleLiteSchema,
Role: packedRoleSchema,
RolePolicies: packedRolePoliciesSchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/models/BubbleGameRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MiBubbleGameRecord {
@Column('jsonb', {
default: [],
})
public logs: any[];
public logs: number[][];

@Column('boolean', {
default: false,
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/models/Role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type CondFormulaValueNotesMoreThanOrEq = {
value: number;
};

export type RoleCondFormulaValue =
export type RoleCondFormulaValue = { id: string } & (
CondFormulaValueAnd |
CondFormulaValueOr |
CondFormulaValueNot |
Expand All @@ -82,7 +82,8 @@ export type RoleCondFormulaValue =
CondFormulaValueFollowingLessThanOrEq |
CondFormulaValueFollowingMoreThanOrEq |
CondFormulaValueNotesLessThanOrEq |
CondFormulaValueNotesMoreThanOrEq;
CondFormulaValueNotesMoreThanOrEq
);

@Entity('role')
export class MiRole {
Expand Down
15 changes: 9 additions & 6 deletions packages/backend/src/models/json-schema/reversi-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export const packedReversiGameLiteSchema = {
user1: {
type: 'object',
optional: false, nullable: false,
ref: 'User',
ref: 'UserLite',
},
user2: {
type: 'object',
optional: false, nullable: false,
ref: 'User',
ref: 'UserLite',
},
winnerId: {
type: 'string',
Expand All @@ -62,7 +62,7 @@ export const packedReversiGameLiteSchema = {
winner: {
type: 'object',
optional: false, nullable: true,
ref: 'User',
ref: 'UserLite',
},
surrenderedUserId: {
type: 'string',
Expand Down Expand Up @@ -165,12 +165,12 @@ export const packedReversiGameDetailedSchema = {
user1: {
type: 'object',
optional: false, nullable: false,
ref: 'User',
ref: 'UserLite',
},
user2: {
type: 'object',
optional: false, nullable: false,
ref: 'User',
ref: 'UserLite',
},
winnerId: {
type: 'string',
Expand All @@ -180,7 +180,7 @@ export const packedReversiGameDetailedSchema = {
winner: {
type: 'object',
optional: false, nullable: true,
ref: 'User',
ref: 'UserLite',
},
surrenderedUserId: {
type: 'string',
Expand Down Expand Up @@ -226,6 +226,9 @@ export const packedReversiGameDetailedSchema = {
items: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'number',
},
},
},
map: {
Expand Down
127 changes: 127 additions & 0 deletions packages/backend/src/models/json-schema/role.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,129 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

export const packedRoleCondFormulaLogicsSchema = {
type: 'object',
properties: {
id: {
type: 'string', optional: false,
},
type: {
type: 'string',
nullable: false, optional: false,
enum: ['and', 'or'],
},
values: {
type: 'array',
nullable: false, optional: false,
items: {
ref: 'RoleCondFormulaValue',
},
},
},
} as const;

export const packedRoleCondFormulaValueNot = {
type: 'object',
properties: {
id: {
type: 'string', optional: false,
},
type: {
type: 'string',
nullable: false, optional: false,
enum: ['not'],
},
value: {
type: 'object',
optional: false,
ref: 'RoleCondFormulaValue',
},
},
} as const;

export const packedRoleCondFormulaValueIsLocalOrRemoteSchema = {
type: 'object',
properties: {
id: {
type: 'string', optional: false,
},
type: {
type: 'string',
nullable: false, optional: false,
enum: ['isLocal', 'isRemote'],
},
},
} as const;

export const packedRoleCondFormulaValueCreatedSchema = {
type: 'object',
properties: {
id: {
type: 'string', optional: false,
},
type: {
type: 'string',
nullable: false, optional: false,
enum: [
'createdLessThan',
'createdMoreThan',
],
},
sec: {
type: 'number',
nullable: false, optional: false,
},
},
} as const;

export const packedRoleCondFormulaFollowersOrFollowingOrNotesSchema = {
type: 'object',
properties: {
id: {
type: 'string', optional: false,
},
type: {
type: 'string',
nullable: false, optional: false,
enum: [
'followersLessThanOrEq',
'followersMoreThanOrEq',
'followingLessThanOrEq',
'followingMoreThanOrEq',
'notesLessThanOrEq',
'notesMoreThanOrEq',
],
},
value: {
type: 'number',
nullable: false, optional: false,
},
},
} as const;

export const packedRoleCondFormulaValueSchema = {
type: 'object',
oneOf: [
{
ref: 'RoleCondFormulaLogics',
},
{
ref: 'RoleCondFormulaValueNot',
},
{
ref: 'RoleCondFormulaValueIsLocalOrRemote',
},
{
ref: 'RoleCondFormulaValueCreated',
},
{
ref: 'RoleCondFormulaFollowersOrFollowingOrNotes',
},
],
} as const;

export const packedRolePoliciesSchema = {
type: 'object',
optional: false, nullable: false,
Expand Down Expand Up @@ -174,6 +300,7 @@ export const packedRoleSchema = {
condFormula: {
type: 'object',
optional: false, nullable: false,
ref: 'RoleCondFormulaValue',
},
isPublic: {
type: 'boolean',
Expand Down
61 changes: 44 additions & 17 deletions packages/backend/src/models/json-schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,38 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

const notificationRecieveConfig = {
export const notificationRecieveConfig = {
type: 'object',
nullable: false, optional: true,
properties: {
type: {
type: 'string',
nullable: false, optional: false,
enum: ['all', 'following', 'follower', 'mutualFollow', 'list', 'never'],
oneOf: [
{
type: 'object',
nullable: false,
properties: {
type: {
type: 'string',
nullable: false,
enum: ['all', 'following', 'follower', 'mutualFollow', 'never'],
},
},
required: ['type'],
},
},
{
type: 'object',
nullable: false,
properties: {
type: {
type: 'string',
nullable: false,
enum: ['list'],
},
userListId: {
type: 'string',
format: 'misskey:id',
},
},
required: ['type', 'userListId'],
},
],
} as const;

export const packedUserLiteSchema = {
Expand Down Expand Up @@ -546,15 +568,20 @@ export const packedMeDetailedOnlySchema = {
type: 'object',
nullable: false, optional: false,
properties: {
app: notificationRecieveConfig,
quote: notificationRecieveConfig,
reply: notificationRecieveConfig,
follow: notificationRecieveConfig,
renote: notificationRecieveConfig,
mention: notificationRecieveConfig,
reaction: notificationRecieveConfig,
pollEnded: notificationRecieveConfig,
receiveFollowRequest: notificationRecieveConfig,
note: { optional: true, ...notificationRecieveConfig },
follow: { optional: true, ...notificationRecieveConfig },
mention: { optional: true, ...notificationRecieveConfig },
reply: { optional: true, ...notificationRecieveConfig },
renote: { optional: true, ...notificationRecieveConfig },
quote: { optional: true, ...notificationRecieveConfig },
reaction: { optional: true, ...notificationRecieveConfig },
pollEnded: { optional: true, ...notificationRecieveConfig },
receiveFollowRequest: { optional: true, ...notificationRecieveConfig },
followRequestAccepted: { optional: true, ...notificationRecieveConfig },
roleAssigned: { optional: true, ...notificationRecieveConfig },
achievementEarned: { optional: true, ...notificationRecieveConfig },
app: { optional: true, ...notificationRecieveConfig },
test: { optional: true, ...notificationRecieveConfig },
},
},
emailNotificationTypes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export const meta = {
requireCredential: true,
requireAdmin: true,
kind: 'write:admin:delete-account',

res: {
},
} as const;

export const paramDef = {
Expand Down
18 changes: 18 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/drive/show-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ export const meta = {
properties: {
type: 'object',
optional: false, nullable: false,
properties: {
width: {
type: 'number',
optional: true, nullable: false,
},
height: {
type: 'number',
optional: true, nullable: false,
},
orientation: {
type: 'number',
optional: true, nullable: false,
},
avgColor: {
type: 'string',
optional: true, nullable: false,
},
},
},
storedInternal: {
type: 'boolean',
Expand Down
12 changes: 12 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/get-table-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ export const meta = {
res: {
type: 'object',
optional: false, nullable: false,
additionalProperties: {
type: 'object',
properties: {
count: {
type: 'number',
},
size: {
type: 'number',
},
},
required: ['count', 'size'],
},
example: {
migrations: {
count: 66,
Expand Down
Loading
Loading