forked from FoundKeyGang/FoundKey
wip
This commit is contained in:
parent
3c553ba674
commit
0cc5ca598a
12 changed files with 166 additions and 43 deletions
|
@ -1,8 +1,16 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
const collection = db.get('access_tokens');
|
||||
const AccessToken = db.get<IAccessTokens>('accessTokens');
|
||||
AccessToken.createIndex('token');
|
||||
AccessToken.createIndex('hash');
|
||||
export default AccessToken;
|
||||
|
||||
(collection as any).createIndex('token'); // fuck type definition
|
||||
(collection as any).createIndex('hash'); // fuck type definition
|
||||
|
||||
export default collection as any; // fuck type definition
|
||||
export type IAccessTokens = {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
appId: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
token: string;
|
||||
hash: string;
|
||||
};
|
||||
|
|
|
@ -5,16 +5,22 @@ import db from '../../db/mongodb';
|
|||
import config from '../../conf';
|
||||
|
||||
const App = db.get<IApp>('apps');
|
||||
App.createIndex('name_id');
|
||||
App.createIndex('name_id_lower');
|
||||
App.createIndex('nameId');
|
||||
App.createIndex('nameIdLower');
|
||||
App.createIndex('secret');
|
||||
export default App;
|
||||
|
||||
export type IApp = {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
user_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
userId: mongo.ObjectID;
|
||||
secret: string;
|
||||
name: string;
|
||||
nameId: string;
|
||||
nameIdLower: string;
|
||||
description: string;
|
||||
permission: string;
|
||||
callbackUrl: string;
|
||||
};
|
||||
|
||||
export function isValidNameId(nameId: string): boolean {
|
||||
|
@ -70,7 +76,7 @@ export const pack = (
|
|||
_app.id = _app._id;
|
||||
delete _app._id;
|
||||
|
||||
delete _app.name_id_lower;
|
||||
delete _app.nameIdLower;
|
||||
|
||||
// Visible by only owner
|
||||
if (!opts.includeSecret) {
|
||||
|
@ -84,8 +90,8 @@ export const pack = (
|
|||
if (me) {
|
||||
// 既に連携しているか
|
||||
const exist = await AccessToken.count({
|
||||
app_id: _app.id,
|
||||
user_id: me,
|
||||
appId: _app.id,
|
||||
userId: me,
|
||||
}, {
|
||||
limit: 1
|
||||
});
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.get('appdata') as any; // fuck type definition
|
|
@ -3,11 +3,15 @@ import deepcopy = require('deepcopy');
|
|||
import db from '../../db/mongodb';
|
||||
import { pack as packApp } from './app';
|
||||
|
||||
const AuthSession = db.get('auth_sessions');
|
||||
const AuthSession = db.get<IAuthSession>('authSessions');
|
||||
export default AuthSession;
|
||||
|
||||
export interface IAuthSession {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
appId: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
token: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +28,6 @@ export const pack = (
|
|||
let _session: any;
|
||||
|
||||
// TODO: Populate session if it ID
|
||||
|
||||
_session = deepcopy(session);
|
||||
|
||||
// Me
|
||||
|
@ -39,7 +42,7 @@ export const pack = (
|
|||
delete _session._id;
|
||||
|
||||
// Populate app
|
||||
_session.app = await packApp(_session.app_id, me);
|
||||
_session.app = await packApp(_session.appId, me);
|
||||
|
||||
resolve(_session);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
import * as mongo from 'mongodb';
|
||||
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.get('channel_watching') as any; // fuck type definition
|
||||
const ChannelWatching = db.get<IChannelWatching>('channelWatching');
|
||||
export default ChannelWatching;
|
||||
|
||||
export interface IChannelWatching {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
deletedAt: Date;
|
||||
channel_id: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ export default Channel;
|
|||
|
||||
export type IChannel = {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
createdAt: Date;
|
||||
title: string;
|
||||
user_id: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
index: number;
|
||||
watchingCount: number;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -47,7 +48,7 @@ export const pack = (
|
|||
delete _channel._id;
|
||||
|
||||
// Remove needless properties
|
||||
delete _channel.user_id;
|
||||
delete _channel.userId;
|
||||
|
||||
// Me
|
||||
const meId: mongo.ObjectID = me
|
||||
|
@ -61,9 +62,9 @@ export const pack = (
|
|||
if (me) {
|
||||
//#region Watchしているかどうか
|
||||
const watch = await Watching.findOne({
|
||||
user_id: meId,
|
||||
userId: meId,
|
||||
channel_id: _channel.id,
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
_channel.is_watching = watch !== null;
|
||||
|
|
|
@ -4,14 +4,14 @@ import { pack as packFolder } from './drive-folder';
|
|||
import config from '../../conf';
|
||||
import monkDb, { nativeDbConn } from '../../db/mongodb';
|
||||
|
||||
const DriveFile = monkDb.get<IDriveFile>('drive_files.files');
|
||||
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
||||
|
||||
export default DriveFile;
|
||||
|
||||
const getGridFSBucket = async (): Promise<mongodb.GridFSBucket> => {
|
||||
const db = await nativeDbConn();
|
||||
const bucket = new mongodb.GridFSBucket(db, {
|
||||
bucketName: 'drive_files'
|
||||
bucketName: 'driveFiles'
|
||||
});
|
||||
return bucket;
|
||||
};
|
||||
|
@ -26,8 +26,8 @@ export type IDriveFile = {
|
|||
contentType: string;
|
||||
metadata: {
|
||||
properties: any;
|
||||
user_id: mongodb.ObjectID;
|
||||
folder_id: mongodb.ObjectID;
|
||||
userId: mongodb.ObjectID;
|
||||
folderId: mongodb.ObjectID;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -79,7 +79,7 @@ export const pack = (
|
|||
let _target: any = {};
|
||||
|
||||
_target.id = _file._id;
|
||||
_target.created_at = _file.uploadDate;
|
||||
_target.createdAt = _file.uploadDate;
|
||||
_target.name = _file.filename;
|
||||
_target.type = _file.contentType;
|
||||
_target.datasize = _file.length;
|
||||
|
@ -92,9 +92,9 @@ export const pack = (
|
|||
if (_target.properties == null) _target.properties = {};
|
||||
|
||||
if (opts.detail) {
|
||||
if (_target.folder_id) {
|
||||
if (_target.folderId) {
|
||||
// Populate folder
|
||||
_target.folder = await packFolder(_target.folder_id, {
|
||||
_target.folder = await packFolder(_target.folderId, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ export default DriveFolder;
|
|||
|
||||
export type IDriveFolder = {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
createdAt: Date;
|
||||
name: string;
|
||||
user_id: mongo.ObjectID;
|
||||
parent_id: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
parentId: mongo.ObjectID;
|
||||
};
|
||||
|
||||
export function isValidFolderName(name: string): boolean {
|
||||
|
@ -55,20 +55,20 @@ export const pack = (
|
|||
|
||||
if (opts.detail) {
|
||||
const childFoldersCount = await DriveFolder.count({
|
||||
parent_id: _folder.id
|
||||
parentId: _folder.id
|
||||
});
|
||||
|
||||
const childFilesCount = await DriveFile.count({
|
||||
'metadata.folder_id': _folder.id
|
||||
'metadata.folderId': _folder.id
|
||||
});
|
||||
|
||||
_folder.folders_count = childFoldersCount;
|
||||
_folder.files_count = childFilesCount;
|
||||
}
|
||||
|
||||
if (opts.detail && _folder.parent_id) {
|
||||
if (opts.detail && _folder.parentId) {
|
||||
// Populate parent folder
|
||||
_folder.parent = await pack(_folder.parent_id, {
|
||||
_folder.parent = await pack(_folder.parentId, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.get('drive_tags') as any; // fuck type definition
|
|
@ -1,3 +1,12 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.get('favorites') as any; // fuck type definition
|
||||
const Favorites = db.get<IFavorites>('favorites');
|
||||
export default Favorites;
|
||||
|
||||
export type IFavorites = {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
userId: mongo.ObjectID;
|
||||
postId: mongo.ObjectID;
|
||||
};
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import db from '../../db/mongodb';
|
||||
|
||||
export default db.get('following') as any; // fuck type definition
|
||||
const Following = db.get<IFollowing>('following');
|
||||
export default Following;
|
||||
|
||||
export type IFollowing = {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
deletedAt: Date;
|
||||
followeeId: mongo.ObjectID;
|
||||
followerId: mongo.ObjectID;
|
||||
};
|
||||
|
|
81
tools/migration/shell.camel-case.js
Normal file
81
tools/migration/shell.camel-case.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
db.access_tokens.renameCollection('accessTokens');
|
||||
db.accessTokens.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
app_id: 'appId',
|
||||
user_id: 'userId',
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.apps.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
user_id: 'userId',
|
||||
name_id: 'nameId',
|
||||
name_id_lower: 'nameIdLower',
|
||||
callback_url: 'callbackUrl',
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.auth_sessions.renameCollection('authSessions');
|
||||
db.authSessions.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
app_id: 'appId',
|
||||
user_id: 'userId',
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.channel_watching.renameCollection('channelWatching');
|
||||
db.channelWatching.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
deleted_at: 'deletedAt',
|
||||
channel_id: 'channelId',
|
||||
user_id: 'userId',
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.channels.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
user_id: 'userId',
|
||||
watching_count: 'watchingCount'
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.drive_files.files.renameCollection('driveFiles.files');
|
||||
db.drive_files.chunks.renameCollection('driveFiles.chunks');
|
||||
db.driveFiles.files.update({}, {
|
||||
$rename: {
|
||||
'metadata.user_id': 'metadata.userId',
|
||||
'metadata.folder_id': 'metadata.folderId',
|
||||
'metadata.properties.average_color': 'metadata.properties.avgColor'
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.drive_folders.renameCollection('driveFolders');
|
||||
db.driveFolders.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
user_id: 'userId',
|
||||
parent_id: 'parentId',
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.favorites.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
user_id: 'userId',
|
||||
post_id: 'postId',
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
db.following.update({}, {
|
||||
$rename: {
|
||||
created_at: 'createdAt',
|
||||
deleted_at: 'deletedAt',
|
||||
followee_id: 'followeeId',
|
||||
follower_id: 'followerId',
|
||||
}
|
||||
}, false, true);
|
Loading…
Reference in a new issue