From 19e12bf5cf6f56aed429333594444a40184c8a06 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 17 Jan 2017 10:39:21 +0900 Subject: [PATCH] :v: --- package.json | 3 ++- src/api/models/access-token.ts | 6 +++--- src/api/models/app.ts | 8 ++++---- src/api/models/appdata.ts | 2 +- src/api/models/auth-session.ts | 2 +- src/api/models/drive-file.ts | 2 +- src/api/models/drive-folder.ts | 2 +- src/api/models/drive-tag.ts | 2 +- src/api/models/favorite.ts | 2 +- src/api/models/following.ts | 2 +- src/api/models/like.ts | 2 +- src/api/models/messaging-history.ts | 2 +- src/api/models/messaging-message.ts | 2 +- src/api/models/notification.ts | 2 +- src/api/models/post.ts | 2 +- src/api/models/signin.ts | 2 +- src/api/models/user.ts | 6 +++--- src/api/private/signup.ts | 4 +--- src/db/mongodb.ts | 4 ++-- 19 files changed, 28 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index f8e12fc7f..2a727bb75 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@types/js-yaml": "3.5.29", "@types/mocha": "2.2.37", "@types/mongodb": "2.1.36", + "@types/monk": "1.0.5", "@types/ms": "0.7.29", "@types/multer": "0.0.32", "@types/ratelimiter": "2.1.28", @@ -108,7 +109,7 @@ "mime-types": "2.1.14", "mocha": "3.2.0", "mongodb": "2.2.21", - "mongoskin": "^2.1.0", + "monk": "3.1.3", "ms": "0.7.2", "multer": "1.2.1", "nprogress": "0.2.0", diff --git a/src/api/models/access-token.ts b/src/api/models/access-token.ts index a24286547..ff7189fa3 100644 --- a/src/api/models/access-token.ts +++ b/src/api/models/access-token.ts @@ -1,8 +1,8 @@ import db from '../../db/mongodb'; -const collection = db.collection('access_tokens'); +const collection = db.get('access_tokens'); -collection.createIndex('token'); -collection.createIndex('hash'); +(collection as any).index('token'); // fuck type definition +(collection as any).index('hash'); // fuck type definition export default collection; diff --git a/src/api/models/app.ts b/src/api/models/app.ts index 39bb6cfa6..68d74be32 100644 --- a/src/api/models/app.ts +++ b/src/api/models/app.ts @@ -1,9 +1,9 @@ import db from '../../db/mongodb'; -const collection = db.collection('apps'); +const collection = db.get('apps'); -collection.createIndex('name_id'); -collection.createIndex('name_id_lower'); -collection.createIndex('secret'); +(collection as any).index('name_id'); // fuck type definition +(collection as any).index('name_id_lower'); // fuck type definition +(collection as any).index('secret'); // fuck type definition export default collection; diff --git a/src/api/models/appdata.ts b/src/api/models/appdata.ts index 8dab199fe..5224ccfc3 100644 --- a/src/api/models/appdata.ts +++ b/src/api/models/appdata.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('appdata'); +export default db.get('appdata'); diff --git a/src/api/models/auth-session.ts b/src/api/models/auth-session.ts index 1ee8299f5..308b4adce 100644 --- a/src/api/models/auth-session.ts +++ b/src/api/models/auth-session.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('auth_sessions'); +export default db.get('auth_sessions'); diff --git a/src/api/models/drive-file.ts b/src/api/models/drive-file.ts index cc49cf44c..64e023534 100644 --- a/src/api/models/drive-file.ts +++ b/src/api/models/drive-file.ts @@ -1,6 +1,6 @@ import db from '../../db/mongodb'; -export default db.collection('drive_files'); +export default db.get('drive_files'); export function validateFileName(name: string): boolean { return ( diff --git a/src/api/models/drive-folder.ts b/src/api/models/drive-folder.ts index 44e6c6f5c..aa9e0712d 100644 --- a/src/api/models/drive-folder.ts +++ b/src/api/models/drive-folder.ts @@ -1,6 +1,6 @@ import db from '../../db/mongodb'; -export default db.collection('drive_folders'); +export default db.get('drive_folders'); export function isValidFolderName(name: string): boolean { return ( diff --git a/src/api/models/drive-tag.ts b/src/api/models/drive-tag.ts index e4b044242..3e2e93b39 100644 --- a/src/api/models/drive-tag.ts +++ b/src/api/models/drive-tag.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('drive_tags'); +export default db.get('drive_tags'); diff --git a/src/api/models/favorite.ts b/src/api/models/favorite.ts index 448b00777..0aef3deed 100644 --- a/src/api/models/favorite.ts +++ b/src/api/models/favorite.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('favorites'); +export default db.get('favorites'); diff --git a/src/api/models/following.ts b/src/api/models/following.ts index d509c60d8..9dd2ba140 100644 --- a/src/api/models/following.ts +++ b/src/api/models/following.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('following'); +export default db.get('following'); diff --git a/src/api/models/like.ts b/src/api/models/like.ts index 7c571b91c..301ef7c75 100644 --- a/src/api/models/like.ts +++ b/src/api/models/like.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('likes'); +export default db.get('likes'); diff --git a/src/api/models/messaging-history.ts b/src/api/models/messaging-history.ts index a06a7dd38..9d96d996d 100644 --- a/src/api/models/messaging-history.ts +++ b/src/api/models/messaging-history.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('messaging_histories'); +export default db.get('messaging_histories'); diff --git a/src/api/models/messaging-message.ts b/src/api/models/messaging-message.ts index 1e6865d45..498186e4c 100644 --- a/src/api/models/messaging-message.ts +++ b/src/api/models/messaging-message.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('messaging_messages'); +export default db.get('messaging_messages'); diff --git a/src/api/models/notification.ts b/src/api/models/notification.ts index b53db4f0b..6ec7c53ee 100644 --- a/src/api/models/notification.ts +++ b/src/api/models/notification.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('notifications'); +export default db.get('notifications'); diff --git a/src/api/models/post.ts b/src/api/models/post.ts index 04468dd2a..97dc9d648 100644 --- a/src/api/models/post.ts +++ b/src/api/models/post.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('posts'); +export default db.get('posts'); diff --git a/src/api/models/signin.ts b/src/api/models/signin.ts index 151a0359e..11e6bf06b 100644 --- a/src/api/models/signin.ts +++ b/src/api/models/signin.ts @@ -1,3 +1,3 @@ import db from '../../db/mongodb'; -export default db.collection('signin'); +export default db.get('signin'); diff --git a/src/api/models/user.ts b/src/api/models/user.ts index 5645d3856..25b7999ba 100644 --- a/src/api/models/user.ts +++ b/src/api/models/user.ts @@ -1,9 +1,9 @@ import db from '../../db/mongodb'; -const collection = db.collection('users'); +const collection = db.get('users'); -collection.createIndex('username'); -collection.createIndex('token'); +(collection as any).index('username'); // fuck type definition +(collection as any).index('token'); // fuck type definition export default collection; diff --git a/src/api/private/signup.ts b/src/api/private/signup.ts index 34e98db28..1eb6abfe9 100644 --- a/src/api/private/signup.ts +++ b/src/api/private/signup.ts @@ -55,7 +55,7 @@ export default async (req: express.Request, res: express.Response) => { const secret = '!' + rndstr('a-zA-Z0-9', 32); // Create account - const inserted = await User.insert({ + const account = await User.insert({ token: secret, avatar_id: null, banner_id: null, @@ -77,8 +77,6 @@ export default async (req: express.Request, res: express.Response) => { username_lower: username.toLowerCase() }); - const account = inserted.ops[0]; - // Response res.send(await serialize(account)); diff --git a/src/db/mongodb.ts b/src/db/mongodb.ts index ea810dba0..6ee7f4534 100644 --- a/src/db/mongodb.ts +++ b/src/db/mongodb.ts @@ -1,4 +1,4 @@ -const mongo = require('mongoskin'); +import * as mongo from 'monk'; import config from '../conf'; @@ -6,6 +6,6 @@ const uri = config.mongodb.user && config.mongodb.pass ? `mongodb://${config.mongodb.user}:${config.mongodb.pass}@${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}` : `mongodb://${config.mongodb.host}:${config.mongodb.port}/${config.mongodb.db}`; -const db = mongo.db(uri, { native_parser: true }); +const db = mongo(uri); export default db;