Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import define from "../../define.js";
|
||||
import { cancelMatch } from "../../../../services/reversi/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account"
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
userId: {
|
||||
type: "string",
|
||||
format: "misskey:id",
|
||||
nullable: true
|
||||
}
|
||||
},
|
||||
required: []
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
await cancelMatch(user, ps.userId);
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Brackets } from "typeorm";
|
||||
import define from "../../define.js";
|
||||
import { ReversiGames } from "../../../../models/index.js";
|
||||
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: false,
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
limit: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
maximum: 100,
|
||||
default: 10
|
||||
},
|
||||
sinceId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
untilId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
my: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
}
|
||||
},
|
||||
required: []
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const query = makePaginationQuery(ReversiGames.createQueryBuilder("game"), ps.sinceId, ps.untilId).innerJoinAndSelect("game.user1", "user1").innerJoinAndSelect("game.user2", "user2");
|
||||
if (ps.my && user) {
|
||||
query.andWhere(new Brackets((qb)=>{
|
||||
qb.where("game.user1Id = :userId", {
|
||||
userId: user.id
|
||||
}).orWhere("game.user2Id = :userId", {
|
||||
userId: user.id
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
query.andWhere("game.isStarted = TRUE");
|
||||
}
|
||||
const games = await query.take(ps.limit).getMany();
|
||||
return await Promise.all(games.map((game)=>ReversiGames.packLite(game)));
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import define from "../../define.js";
|
||||
import { Users } from "../../../../models/index.js";
|
||||
import { getInvitations } from "../../../../services/reversi/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "read:account",
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: []
|
||||
};
|
||||
export default define(meta, paramDef, async (_ps, user)=>{
|
||||
const ids = await getInvitations(user);
|
||||
return await Users.packMany(ids, user, {
|
||||
detail: false
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { Users, ReversiGames } from "../../../../models/index.js";
|
||||
import { matchAnyUser, matchSpecificUser } from "../../../../services/reversi/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account",
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
message: "No such user.",
|
||||
code: "NO_SUCH_USER",
|
||||
id: "0b4f0559-b484-4e31-9581-3f73cee89b28"
|
||||
},
|
||||
isYourself: {
|
||||
message: "Target user is yourself.",
|
||||
code: "TARGET_IS_YOURSELF",
|
||||
id: "96fd7bd6-d2bc-426c-a865-d055dcd2828e"
|
||||
}
|
||||
},
|
||||
res: {
|
||||
type: "object",
|
||||
optional: true,
|
||||
nullable: false
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
userId: {
|
||||
type: "string",
|
||||
format: "misskey:id",
|
||||
nullable: true
|
||||
},
|
||||
noIrregularRules: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
},
|
||||
multiple: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
}
|
||||
},
|
||||
required: []
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
if (ps.userId === user.id) throw new ApiError(meta.errors.isYourself);
|
||||
const target = ps.userId ? await Users.findOneBy({
|
||||
id: ps.userId
|
||||
}).then((u)=>{
|
||||
if (!u) throw new ApiError(meta.errors.noSuchUser);
|
||||
return u;
|
||||
}) : null;
|
||||
const game = target ? await matchSpecificUser(user, target, ps.multiple) : await matchAnyUser(user, {
|
||||
noIrregularRules: ps.noIrregularRules
|
||||
}, ps.multiple);
|
||||
return game ? await ReversiGames.packDetail(game) : undefined;
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { ReversiGames } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: false,
|
||||
errors: {
|
||||
noSuchGame: {
|
||||
message: "No such game.",
|
||||
code: "NO_SUCH_GAME",
|
||||
id: "f13a03db-fae1-46c9-87f3-43c8165419e1"
|
||||
}
|
||||
},
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
gameId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"gameId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps)=>{
|
||||
const game = await ReversiGames.findOne({
|
||||
where: {
|
||||
id: ps.gameId
|
||||
},
|
||||
relations: {
|
||||
user1: true,
|
||||
user2: true
|
||||
}
|
||||
});
|
||||
if (!game) throw new ApiError(meta.errors.noSuchGame);
|
||||
return await ReversiGames.packDetail(game);
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import define from "../../define.js";
|
||||
import { surrender } from "../../../../services/reversi/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account"
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
gameId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"gameId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
await surrender(ps.gameId, user);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import define from "../../define.js";
|
||||
import { ReversiGames } from "../../../../models/index.js";
|
||||
import { checkCrc } from "../../../../services/reversi/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"reversi"
|
||||
],
|
||||
requireCredential: false,
|
||||
res: {
|
||||
type: "object",
|
||||
optional: true,
|
||||
nullable: false
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
gameId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
crc32: {
|
||||
anyOf: [
|
||||
{
|
||||
type: "string"
|
||||
},
|
||||
{
|
||||
type: "number"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"gameId",
|
||||
"crc32"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps)=>{
|
||||
const game = await checkCrc(ps.gameId, ps.crc32);
|
||||
return game ? await ReversiGames.packDetail(game) : undefined;
|
||||
});
|
||||
Reference in New Issue
Block a user