mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-03-22 03:53:35 +00:00
Resolve conflicts
This commit is contained in:
@@ -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,27 +76,27 @@ 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) {
|
||||
delete _app.secret;
|
||||
}
|
||||
|
||||
_app.icon_url = _app.icon != null
|
||||
_app.iconUrl = _app.icon != null
|
||||
? `${config.drive_url}/${_app.icon}`
|
||||
: `${config.drive_url}/app-default.jpg`;
|
||||
|
||||
if (me) {
|
||||
// 既に連携しているか
|
||||
const exist = await AccessToken.count({
|
||||
app_id: _app.id,
|
||||
user_id: me,
|
||||
appId: _app.id,
|
||||
userId: me,
|
||||
}, {
|
||||
limit: 1
|
||||
});
|
||||
|
||||
_app.is_authorized = exist === 1;
|
||||
_app.isAuthorized = exist === 1;
|
||||
}
|
||||
|
||||
resolve(_app);
|
||||
|
||||
@@ -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,13 @@
|
||||
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;
|
||||
channelId: 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,12 +62,12 @@ export const pack = (
|
||||
if (me) {
|
||||
//#region Watchしているかどうか
|
||||
const watch = await Watching.findOne({
|
||||
user_id: meId,
|
||||
channel_id: _channel.id,
|
||||
deleted_at: { $exists: false }
|
||||
userId: meId,
|
||||
channelId: _channel.id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
_channel.is_watching = watch !== null;
|
||||
_channel.isWatching = watch !== null;
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
_folder.foldersCount = childFoldersCount;
|
||||
_folder.filesCount = 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<IFavorite>('favorites');
|
||||
export default Favorites;
|
||||
|
||||
export type IFavorite = {
|
||||
_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;
|
||||
};
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import db from '../../../db/mongodb';
|
||||
|
||||
export default db.get('messaging_histories') as any; // fuck type definition
|
||||
const MessagingHistory = db.get<IMessagingHistory>('messagingHistories');
|
||||
export default MessagingHistory;
|
||||
|
||||
export type IMessagingHistory = {
|
||||
_id: mongo.ObjectID;
|
||||
updatedAt: Date;
|
||||
userId: mongo.ObjectID;
|
||||
partnerId: mongo.ObjectID;
|
||||
messageId: mongo.ObjectID;
|
||||
};
|
||||
|
||||
@@ -5,16 +5,17 @@ import { pack as packFile } from './drive-file';
|
||||
import db from '../../../db/mongodb';
|
||||
import parse from '../common/text';
|
||||
|
||||
const MessagingMessage = db.get<IMessagingMessage>('messaging_messages');
|
||||
const MessagingMessage = db.get<IMessagingMessage>('messagingMessages');
|
||||
export default MessagingMessage;
|
||||
|
||||
export interface IMessagingMessage {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
createdAt: Date;
|
||||
text: string;
|
||||
user_id: mongo.ObjectID;
|
||||
recipient_id: mongo.ObjectID;
|
||||
is_read: boolean;
|
||||
userId: mongo.ObjectID;
|
||||
recipientId: mongo.ObjectID;
|
||||
isRead: boolean;
|
||||
fileId: mongo.ObjectID;
|
||||
}
|
||||
|
||||
export function isValidText(text: string): boolean {
|
||||
@@ -65,16 +66,16 @@ export const pack = (
|
||||
}
|
||||
|
||||
// Populate user
|
||||
_message.user = await packUser(_message.user_id, me);
|
||||
_message.user = await packUser(_message.userId, me);
|
||||
|
||||
if (_message.file_id) {
|
||||
if (_message.fileId) {
|
||||
// Populate file
|
||||
_message.file = await packFile(_message.file_id);
|
||||
_message.file = await packFile(_message.fileId);
|
||||
}
|
||||
|
||||
if (opts.populateRecipient) {
|
||||
// Populate recipient
|
||||
_message.recipient = await packUser(_message.recipient_id, me);
|
||||
_message.recipient = await packUser(_message.recipientId, me);
|
||||
}
|
||||
|
||||
resolve(_message);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import db from '../../../db/mongodb';
|
||||
|
||||
export default db.get('meta') as any; // fuck type definition
|
||||
const Meta = db.get<IMeta>('meta');
|
||||
export default Meta;
|
||||
|
||||
export type IMeta = {
|
||||
top_image: string;
|
||||
broadcasts: any[];
|
||||
};
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import db from '../../../db/mongodb';
|
||||
|
||||
export default db.get('mute') as any; // fuck type definition
|
||||
const Mute = db.get<IMute>('mute');
|
||||
export default Mute;
|
||||
|
||||
export interface IMute {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
deletedAt: Date;
|
||||
muterId: mongo.ObjectID;
|
||||
muteeId: mongo.ObjectID;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export default Notification;
|
||||
|
||||
export interface INotification {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
createdAt: Date;
|
||||
|
||||
/**
|
||||
* 通知の受信者
|
||||
@@ -19,7 +19,7 @@ export interface INotification {
|
||||
/**
|
||||
* 通知の受信者
|
||||
*/
|
||||
notifiee_id: mongo.ObjectID;
|
||||
notifieeId: mongo.ObjectID;
|
||||
|
||||
/**
|
||||
* イニシエータ(initiator)、Origin。通知を行う原因となったユーザー
|
||||
@@ -29,7 +29,7 @@ export interface INotification {
|
||||
/**
|
||||
* イニシエータ(initiator)、Origin。通知を行う原因となったユーザー
|
||||
*/
|
||||
notifier_id: mongo.ObjectID;
|
||||
notifierId: mongo.ObjectID;
|
||||
|
||||
/**
|
||||
* 通知の種類。
|
||||
@@ -46,7 +46,7 @@ export interface INotification {
|
||||
/**
|
||||
* 通知が読まれたかどうか
|
||||
*/
|
||||
is_read: Boolean;
|
||||
isRead: Boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,15 +75,15 @@ export const pack = (notification: any) => new Promise<any>(async (resolve, reje
|
||||
_notification.id = _notification._id;
|
||||
delete _notification._id;
|
||||
|
||||
// Rename notifier_id to user_id
|
||||
_notification.user_id = _notification.notifier_id;
|
||||
delete _notification.notifier_id;
|
||||
// Rename notifierId to userId
|
||||
_notification.userId = _notification.notifierId;
|
||||
delete _notification.notifierId;
|
||||
|
||||
const me = _notification.notifiee_id;
|
||||
delete _notification.notifiee_id;
|
||||
const me = _notification.notifieeId;
|
||||
delete _notification.notifieeId;
|
||||
|
||||
// Populate notifier
|
||||
_notification.user = await packUser(_notification.user_id, me);
|
||||
_notification.user = await packUser(_notification.userId, me);
|
||||
|
||||
switch (_notification.type) {
|
||||
case 'follow':
|
||||
@@ -96,7 +96,7 @@ export const pack = (notification: any) => new Promise<any>(async (resolve, reje
|
||||
case 'reaction':
|
||||
case 'poll_vote':
|
||||
// Populate post
|
||||
_notification.post = await packPost(_notification.post_id, me);
|
||||
_notification.post = await packPost(_notification.postId, me);
|
||||
break;
|
||||
default:
|
||||
console.error(`Unknown type: ${_notification.type}`);
|
||||
|
||||
@@ -3,17 +3,17 @@ import deepcopy = require('deepcopy');
|
||||
import db from '../../../db/mongodb';
|
||||
import { IUser, pack as packUser } from './user';
|
||||
|
||||
const Game = db.get<IGame>('othello_games');
|
||||
export default Game;
|
||||
const OthelloGame = db.get<IOthelloGame>('othelloGames');
|
||||
export default OthelloGame;
|
||||
|
||||
export interface IGame {
|
||||
export interface IOthelloGame {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
started_at: Date;
|
||||
user1_id: mongo.ObjectID;
|
||||
user2_id: mongo.ObjectID;
|
||||
user1_accepted: boolean;
|
||||
user2_accepted: boolean;
|
||||
createdAt: Date;
|
||||
startedAt: Date;
|
||||
user1Id: mongo.ObjectID;
|
||||
user2Id: mongo.ObjectID;
|
||||
user1Accepted: boolean;
|
||||
user2Accepted: boolean;
|
||||
|
||||
/**
|
||||
* どちらのプレイヤーが先行(黒)か
|
||||
@@ -22,9 +22,9 @@ export interface IGame {
|
||||
*/
|
||||
black: number;
|
||||
|
||||
is_started: boolean;
|
||||
is_ended: boolean;
|
||||
winner_id: mongo.ObjectID;
|
||||
isStarted: boolean;
|
||||
isEnded: boolean;
|
||||
winnerId: mongo.ObjectID;
|
||||
logs: Array<{
|
||||
at: Date;
|
||||
color: boolean;
|
||||
@@ -33,9 +33,9 @@ export interface IGame {
|
||||
settings: {
|
||||
map: string[];
|
||||
bw: string | number;
|
||||
is_llotheo: boolean;
|
||||
can_put_everywhere: boolean;
|
||||
looped_board: boolean;
|
||||
isLlotheo: boolean;
|
||||
canPutEverywhere: boolean;
|
||||
loopedBoard: boolean;
|
||||
};
|
||||
form1: any;
|
||||
form2: any;
|
||||
@@ -62,11 +62,11 @@ export const pack = (
|
||||
|
||||
// Populate the game if 'game' is ID
|
||||
if (mongo.ObjectID.prototype.isPrototypeOf(game)) {
|
||||
_game = await Game.findOne({
|
||||
_game = await OthelloGame.findOne({
|
||||
_id: game
|
||||
});
|
||||
} else if (typeof game === 'string') {
|
||||
_game = await Game.findOne({
|
||||
_game = await OthelloGame.findOne({
|
||||
_id: new mongo.ObjectID(game)
|
||||
});
|
||||
} else {
|
||||
@@ -97,10 +97,10 @@ export const pack = (
|
||||
}
|
||||
|
||||
// Populate user
|
||||
_game.user1 = await packUser(_game.user1_id, meId);
|
||||
_game.user2 = await packUser(_game.user2_id, meId);
|
||||
if (_game.winner_id) {
|
||||
_game.winner = await packUser(_game.winner_id, meId);
|
||||
_game.user1 = await packUser(_game.user1Id, meId);
|
||||
_game.user2 = await packUser(_game.user2Id, meId);
|
||||
if (_game.winnerId) {
|
||||
_game.winner = await packUser(_game.winnerId, meId);
|
||||
} else {
|
||||
_game.winner = null;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ import deepcopy = require('deepcopy');
|
||||
import db from '../../../db/mongodb';
|
||||
import { IUser, pack as packUser } from './user';
|
||||
|
||||
const Matching = db.get<IMatching>('othello_matchings');
|
||||
const Matching = db.get<IMatching>('othelloMatchings');
|
||||
export default Matching;
|
||||
|
||||
export interface IMatching {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
parent_id: mongo.ObjectID;
|
||||
child_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
parentId: mongo.ObjectID;
|
||||
childId: mongo.ObjectID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,8 +37,8 @@ export const pack = (
|
||||
delete _matching._id;
|
||||
|
||||
// Populate user
|
||||
_matching.parent = await packUser(_matching.parent_id, meId);
|
||||
_matching.child = await packUser(_matching.child_id, meId);
|
||||
_matching.parent = await packUser(_matching.parentId, meId);
|
||||
_matching.child = await packUser(_matching.childId, meId);
|
||||
|
||||
resolve(_matching);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
<<<<<<< HEAD:src/server/api/models/poll-vote.ts
|
||||
import db from '../../../db/mongodb';
|
||||
=======
|
||||
import * as mongo from 'mongodb';
|
||||
import db from '../../db/mongodb';
|
||||
>>>>>>> refs/remotes/origin/master:src/api/models/poll-vote.ts
|
||||
|
||||
export default db.get('poll_votes') as any; // fuck type definition
|
||||
const PollVote = db.get<IPollVote>('pollVotes');
|
||||
export default PollVote;
|
||||
|
||||
export interface IPollVote {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
userId: mongo.ObjectID;
|
||||
postId: mongo.ObjectID;
|
||||
choice: number;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@ import db from '../../../db/mongodb';
|
||||
import Reaction from './post-reaction';
|
||||
import { pack as packUser } from './user';
|
||||
|
||||
const PostReaction = db.get<IPostReaction>('post_reactions');
|
||||
const PostReaction = db.get<IPostReaction>('postReactions');
|
||||
export default PostReaction;
|
||||
|
||||
export interface IPostReaction {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
deleted_at: Date;
|
||||
createdAt: Date;
|
||||
deletedAt: Date;
|
||||
postId: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
reaction: string;
|
||||
}
|
||||
|
||||
@@ -45,7 +47,7 @@ export const pack = (
|
||||
delete _reaction._id;
|
||||
|
||||
// Populate user
|
||||
_reaction.user = await packUser(_reaction.user_id, me);
|
||||
_reaction.user = await packUser(_reaction.userId, me);
|
||||
|
||||
resolve(_reaction);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import db from '../../../db/mongodb';
|
||||
|
||||
export default db.get('post_watching') as any; // fuck type definition
|
||||
const PostWatching = db.get<IPostWatching>('postWatching');
|
||||
export default PostWatching;
|
||||
|
||||
export interface IPostWatching {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
userId: mongo.ObjectID;
|
||||
postId: mongo.ObjectID;
|
||||
}
|
||||
|
||||
@@ -20,18 +20,20 @@ export function isValidText(text: string): boolean {
|
||||
|
||||
export type IPost = {
|
||||
_id: mongo.ObjectID;
|
||||
channel_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
media_ids: mongo.ObjectID[];
|
||||
reply_id: mongo.ObjectID;
|
||||
repost_id: mongo.ObjectID;
|
||||
channelId: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
mediaIds: mongo.ObjectID[];
|
||||
replyId: mongo.ObjectID;
|
||||
repostId: mongo.ObjectID;
|
||||
poll: any; // todo
|
||||
text: string;
|
||||
user_id: mongo.ObjectID;
|
||||
app_id: mongo.ObjectID;
|
||||
category: string;
|
||||
is_category_verified: boolean;
|
||||
via_mobile: boolean;
|
||||
userId: mongo.ObjectID;
|
||||
appId: mongo.ObjectID;
|
||||
viaMobile: boolean;
|
||||
repostCount: number;
|
||||
repliesCount: number;
|
||||
reactionCounts: any;
|
||||
mentions: mongo.ObjectID[];
|
||||
geo: {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
@@ -102,21 +104,21 @@ export const pack = async (
|
||||
}
|
||||
|
||||
// Populate user
|
||||
_post.user = packUser(_post.user_id, meId);
|
||||
_post.user = packUser(_post.userId, meId);
|
||||
|
||||
// Populate app
|
||||
if (_post.app_id) {
|
||||
_post.app = packApp(_post.app_id);
|
||||
if (_post.appId) {
|
||||
_post.app = packApp(_post.appId);
|
||||
}
|
||||
|
||||
// Populate channel
|
||||
if (_post.channel_id) {
|
||||
_post.channel = packChannel(_post.channel_id);
|
||||
if (_post.channelId) {
|
||||
_post.channel = packChannel(_post.channelId);
|
||||
}
|
||||
|
||||
// Populate media
|
||||
if (_post.media_ids) {
|
||||
_post.media = Promise.all(_post.media_ids.map(fileId =>
|
||||
if (_post.mediaIds) {
|
||||
_post.media = Promise.all(_post.mediaIds.map(fileId =>
|
||||
packFile(fileId)
|
||||
));
|
||||
}
|
||||
@@ -126,7 +128,7 @@ export const pack = async (
|
||||
// Get previous post info
|
||||
_post.prev = (async () => {
|
||||
const prev = await Post.findOne({
|
||||
user_id: _post.user_id,
|
||||
userId: _post.userId,
|
||||
_id: {
|
||||
$lt: id
|
||||
}
|
||||
@@ -144,7 +146,7 @@ export const pack = async (
|
||||
// Get next post info
|
||||
_post.next = (async () => {
|
||||
const next = await Post.findOne({
|
||||
user_id: _post.user_id,
|
||||
userId: _post.userId,
|
||||
_id: {
|
||||
$gt: id
|
||||
}
|
||||
@@ -159,16 +161,16 @@ export const pack = async (
|
||||
return next ? next._id : null;
|
||||
})();
|
||||
|
||||
if (_post.reply_id) {
|
||||
if (_post.replyId) {
|
||||
// Populate reply to post
|
||||
_post.reply = pack(_post.reply_id, meId, {
|
||||
_post.reply = pack(_post.replyId, meId, {
|
||||
detail: false
|
||||
});
|
||||
}
|
||||
|
||||
if (_post.repost_id) {
|
||||
if (_post.repostId) {
|
||||
// Populate repost
|
||||
_post.repost = pack(_post.repost_id, meId, {
|
||||
_post.repost = pack(_post.repostId, meId, {
|
||||
detail: _post.text == null
|
||||
});
|
||||
}
|
||||
@@ -178,15 +180,15 @@ export const pack = async (
|
||||
_post.poll = (async (poll) => {
|
||||
const vote = await Vote
|
||||
.findOne({
|
||||
user_id: meId,
|
||||
post_id: id
|
||||
userId: meId,
|
||||
postId: id
|
||||
});
|
||||
|
||||
if (vote != null) {
|
||||
const myChoice = poll.choices
|
||||
.filter(c => c.id == vote.choice)[0];
|
||||
|
||||
myChoice.is_voted = true;
|
||||
myChoice.isVoted = true;
|
||||
}
|
||||
|
||||
return poll;
|
||||
@@ -195,12 +197,12 @@ export const pack = async (
|
||||
|
||||
// Fetch my reaction
|
||||
if (meId) {
|
||||
_post.my_reaction = (async () => {
|
||||
_post.myReaction = (async () => {
|
||||
const reaction = await Reaction
|
||||
.findOne({
|
||||
user_id: meId,
|
||||
post_id: id,
|
||||
deleted_at: { $exists: false }
|
||||
userId: meId,
|
||||
postId: id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (reaction) {
|
||||
|
||||
@@ -7,6 +7,11 @@ export default Signin;
|
||||
|
||||
export interface ISignin {
|
||||
_id: mongo.ObjectID;
|
||||
createdAt: Date;
|
||||
userId: mongo.ObjectID;
|
||||
ip: string;
|
||||
headers: any;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import db from '../../../db/mongodb';
|
||||
|
||||
export default db.get('sw_subscriptions') as any; // fuck type definition
|
||||
const SwSubscription = db.get<ISwSubscription>('swSubscriptions');
|
||||
export default SwSubscription;
|
||||
|
||||
export interface ISwSubscription {
|
||||
_id: mongo.ObjectID;
|
||||
userId: mongo.ObjectID;
|
||||
endpoint: string;
|
||||
auth: string;
|
||||
publickey: string;
|
||||
}
|
||||
|
||||
@@ -46,25 +46,26 @@ export type ILocalAccount = {
|
||||
password: string;
|
||||
token: string;
|
||||
twitter: {
|
||||
access_token: string;
|
||||
access_token_secret: string;
|
||||
user_id: string;
|
||||
screen_name: string;
|
||||
accessToken: string;
|
||||
accessTokenSecret: string;
|
||||
userId: string;
|
||||
screenName: string;
|
||||
};
|
||||
line: {
|
||||
user_id: string;
|
||||
userId: string;
|
||||
};
|
||||
profile: {
|
||||
location: string;
|
||||
birthday: string; // 'YYYY-MM-DD'
|
||||
tags: string[];
|
||||
};
|
||||
last_used_at: Date;
|
||||
is_bot: boolean;
|
||||
is_pro: boolean;
|
||||
two_factor_secret: string;
|
||||
two_factor_enabled: boolean;
|
||||
client_settings: any;
|
||||
lastUsedAt: Date;
|
||||
isBot: boolean;
|
||||
isPro: boolean;
|
||||
twoFactorSecret: string;
|
||||
twoFactorEnabled: boolean;
|
||||
twoFactorTempSecret: string;
|
||||
clientSettings: any;
|
||||
settings: any;
|
||||
};
|
||||
|
||||
@@ -74,33 +75,33 @@ export type IRemoteAccount = {
|
||||
|
||||
export type IUser = {
|
||||
_id: mongo.ObjectID;
|
||||
created_at: Date;
|
||||
deleted_at: Date;
|
||||
followers_count: number;
|
||||
following_count: number;
|
||||
createdAt: Date;
|
||||
deletedAt: Date;
|
||||
followersCount: number;
|
||||
followingCount: number;
|
||||
name: string;
|
||||
posts_count: number;
|
||||
drive_capacity: number;
|
||||
postsCount: number;
|
||||
driveCapacity: number;
|
||||
username: string;
|
||||
username_lower: string;
|
||||
avatar_id: mongo.ObjectID;
|
||||
banner_id: mongo.ObjectID;
|
||||
usernameLower: string;
|
||||
avatarId: mongo.ObjectID;
|
||||
bannerId: mongo.ObjectID;
|
||||
data: any;
|
||||
description: string;
|
||||
latest_post: IPost;
|
||||
pinned_post_id: mongo.ObjectID;
|
||||
is_suspended: boolean;
|
||||
latestPost: IPost;
|
||||
pinnedPostId: mongo.ObjectID;
|
||||
isSuspended: boolean;
|
||||
keywords: string[];
|
||||
host: string;
|
||||
host_lower: string;
|
||||
hostLower: string;
|
||||
account: ILocalAccount | IRemoteAccount;
|
||||
};
|
||||
|
||||
export function init(user): IUser {
|
||||
user._id = new mongo.ObjectID(user._id);
|
||||
user.avatar_id = new mongo.ObjectID(user.avatar_id);
|
||||
user.banner_id = new mongo.ObjectID(user.banner_id);
|
||||
user.pinned_post_id = new mongo.ObjectID(user.pinned_post_id);
|
||||
user.avatarId = new mongo.ObjectID(user.avatarId);
|
||||
user.bannerId = new mongo.ObjectID(user.bannerId);
|
||||
user.pinnedPostId = new mongo.ObjectID(user.pinnedPostId);
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ export const pack = (
|
||||
const fields = opts.detail ? {
|
||||
} : {
|
||||
'account.settings': false,
|
||||
'account.client_settings': false,
|
||||
'account.clientSettings': false,
|
||||
'account.profile': false,
|
||||
'account.keywords': false,
|
||||
'account.domains': false
|
||||
@@ -166,19 +167,19 @@ export const pack = (
|
||||
delete _user._id;
|
||||
|
||||
// Remove needless properties
|
||||
delete _user.latest_post;
|
||||
delete _user.latestPost;
|
||||
|
||||
if (!_user.host) {
|
||||
// Remove private properties
|
||||
delete _user.account.keypair;
|
||||
delete _user.account.password;
|
||||
delete _user.account.token;
|
||||
delete _user.account.two_factor_temp_secret;
|
||||
delete _user.account.two_factor_secret;
|
||||
delete _user.username_lower;
|
||||
delete _user.account.twoFactorTempSecret;
|
||||
delete _user.account.twoFactorSecret;
|
||||
delete _user.usernameLower;
|
||||
if (_user.account.twitter) {
|
||||
delete _user.account.twitter.access_token;
|
||||
delete _user.account.twitter.access_token_secret;
|
||||
delete _user.account.twitter.accessToken;
|
||||
delete _user.account.twitter.accessTokenSecret;
|
||||
}
|
||||
delete _user.account.line;
|
||||
|
||||
@@ -186,65 +187,65 @@ export const pack = (
|
||||
if (!opts.includeSecrets) {
|
||||
delete _user.account.email;
|
||||
delete _user.account.settings;
|
||||
delete _user.account.client_settings;
|
||||
delete _user.account.clientSettings;
|
||||
}
|
||||
|
||||
if (!opts.detail) {
|
||||
delete _user.account.two_factor_enabled;
|
||||
delete _user.account.twoFactorEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
_user.avatar_url = _user.avatar_id != null
|
||||
? `${config.drive_url}/${_user.avatar_id}`
|
||||
_user.avatarUrl = _user.avatarId != null
|
||||
? `${config.drive_url}/${_user.avatarId}`
|
||||
: `${config.drive_url}/default-avatar.jpg`;
|
||||
|
||||
_user.banner_url = _user.banner_id != null
|
||||
? `${config.drive_url}/${_user.banner_id}`
|
||||
_user.bannerUrl = _user.bannerId != null
|
||||
? `${config.drive_url}/${_user.bannerId}`
|
||||
: null;
|
||||
|
||||
if (!meId || !meId.equals(_user.id) || !opts.detail) {
|
||||
delete _user.avatar_id;
|
||||
delete _user.banner_id;
|
||||
delete _user.avatarId;
|
||||
delete _user.bannerId;
|
||||
|
||||
delete _user.drive_capacity;
|
||||
delete _user.driveCapacity;
|
||||
}
|
||||
|
||||
if (meId && !meId.equals(_user.id)) {
|
||||
// Whether the user is following
|
||||
_user.is_following = (async () => {
|
||||
_user.isFollowing = (async () => {
|
||||
const follow = await Following.findOne({
|
||||
follower_id: meId,
|
||||
followee_id: _user.id,
|
||||
deleted_at: { $exists: false }
|
||||
followerId: meId,
|
||||
followeeId: _user.id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
return follow !== null;
|
||||
})();
|
||||
|
||||
// Whether the user is followed
|
||||
_user.is_followed = (async () => {
|
||||
_user.isFollowed = (async () => {
|
||||
const follow2 = await Following.findOne({
|
||||
follower_id: _user.id,
|
||||
followee_id: meId,
|
||||
deleted_at: { $exists: false }
|
||||
followerId: _user.id,
|
||||
followeeId: meId,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
return follow2 !== null;
|
||||
})();
|
||||
|
||||
// Whether the user is muted
|
||||
_user.is_muted = (async () => {
|
||||
_user.isMuted = (async () => {
|
||||
const mute = await Mute.findOne({
|
||||
muter_id: meId,
|
||||
mutee_id: _user.id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: meId,
|
||||
muteeId: _user.id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
return mute !== null;
|
||||
})();
|
||||
}
|
||||
|
||||
if (opts.detail) {
|
||||
if (_user.pinned_post_id) {
|
||||
if (_user.pinnedPostId) {
|
||||
// Populate pinned post
|
||||
_user.pinned_post = packPost(_user.pinned_post_id, meId, {
|
||||
_user.pinnedPost = packPost(_user.pinnedPostId, meId, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
@@ -253,17 +254,17 @@ export const pack = (
|
||||
const myFollowingIds = await getFriends(meId);
|
||||
|
||||
// Get following you know count
|
||||
_user.following_you_know_count = Following.count({
|
||||
followee_id: { $in: myFollowingIds },
|
||||
follower_id: _user.id,
|
||||
deleted_at: { $exists: false }
|
||||
_user.followingYouKnowCount = Following.count({
|
||||
followeeId: { $in: myFollowingIds },
|
||||
followerId: _user.id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
// Get followers you know count
|
||||
_user.followers_you_know_count = Following.count({
|
||||
followee_id: _user.id,
|
||||
follower_id: { $in: myFollowingIds },
|
||||
deleted_at: { $exists: false }
|
||||
_user.followersYouKnowCount = Following.count({
|
||||
followeeId: _user.id,
|
||||
followerId: { $in: myFollowingIds },
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -322,7 +323,7 @@ export const packForAp = (
|
||||
"name": _user.name,
|
||||
"summary": _user.description,
|
||||
"icon": [
|
||||
`${config.drive_url}/${_user.avatar_id}`
|
||||
`${config.drive_url}/${_user.avatarId}`
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user