summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-09 18:29:27 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-09 18:29:27 +0900
commite82268db7ee9863b2eaeea64f843afa091b024f8 (patch)
tree0f88d55d7f9bf3e1d3a4a91aafdd972af87117af /src/api
parentなんかもうめっちゃ変えた (diff)
downloadsharkey-e82268db7ee9863b2eaeea64f843afa091b024f8.tar.gz
sharkey-e82268db7ee9863b2eaeea64f843afa091b024f8.tar.bz2
sharkey-e82268db7ee9863b2eaeea64f843afa091b024f8.zip
:v:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/endpoints.ts5
-rw-r--r--src/api/endpoints/othello/games.ts6
-rw-r--r--src/api/endpoints/othello/games/show.ts16
-rw-r--r--src/api/models/othello-game.ts6
4 files changed, 29 insertions, 4 deletions
diff --git a/src/api/endpoints.ts b/src/api/endpoints.ts
index fad6667111..1fc9465cd0 100644
--- a/src/api/endpoints.ts
+++ b/src/api/endpoints.ts
@@ -254,6 +254,11 @@ const endpoints: Endpoint[] = [
},
{
+ name: 'othello/games/show',
+ withCredential: true
+ },
+
+ {
name: 'mute/create',
withCredential: true,
kind: 'account/write'
diff --git a/src/api/endpoints/othello/games.ts b/src/api/endpoints/othello/games.ts
index dd3ee523a8..2a6bbb4043 100644
--- a/src/api/endpoints/othello/games.ts
+++ b/src/api/endpoints/othello/games.ts
@@ -23,7 +23,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('cannot set since_id and until_id');
}
- const q = my ? {
+ const q: any = my ? {
is_started: true,
$or: [{
user1_id: user._id
@@ -34,7 +34,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
is_started: true
};
-
const sort = {
_id: -1
};
@@ -52,7 +51,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Fetch games
const games = await Game.find(q, {
- sort
+ sort,
+ limit
});
// Reponse
diff --git a/src/api/endpoints/othello/games/show.ts b/src/api/endpoints/othello/games/show.ts
new file mode 100644
index 0000000000..9dc8f24900
--- /dev/null
+++ b/src/api/endpoints/othello/games/show.ts
@@ -0,0 +1,16 @@
+import $ from 'cafy';
+import Game, { pack } from '../../../models/othello-game';
+
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'game_id' parameter
+ const [gameId, gameIdErr] = $(params.game_id).id().$;
+ if (gameIdErr) return rej('invalid game_id param');
+
+ const game = await Game.findOne({ _id: gameId });
+
+ if (game == null) {
+ return rej('game not found');
+ }
+
+ res(await pack(game, user));
+});
diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts
index 7ae48b8aab..82c0042108 100644
--- a/src/api/models/othello-game.ts
+++ b/src/api/models/othello-game.ts
@@ -2,7 +2,6 @@ import * as mongo from 'mongodb';
import deepcopy = require('deepcopy');
import db from '../../db/mongodb';
import { IUser, pack as packUser } from './user';
-import { Map } from '../../common/othello/maps';
const Game = db.get<IGame>('othello_games');
export default Game;
@@ -79,6 +78,11 @@ export const pack = (
if (opts.detail === false) {
delete _game.logs;
delete _game.settings.map;
+ } else {
+ // 互換性のため
+ if (_game.settings.map.hasOwnProperty('size')) {
+ _game.settings.map = _game.settings.map.data.match(new RegExp(`.{1,${_game.settings.map.size}}`, 'g'));
+ }
}
// Populate user