Compare commits

...

51 Commits

Author SHA1 Message Date
7e0d8dd4d7 11.0.0-beta.14 2019-04-14 12:00:49 +09:00
146fb23d7d Fix bug 2019-04-14 11:59:23 +09:00
61455ffe29 Fix bug 2019-04-14 11:58:10 +09:00
c267baafdc Fix bug 2019-04-14 11:56:37 +09:00
42248a306a Better error handling 2019-04-14 11:53:47 +09:00
694ec7ebe1 Fix bug 2019-04-14 11:50:31 +09:00
e3b3f8fac1 Better error handling 2019-04-14 04:17:24 +09:00
b390363b25 Update CHANGELOG.md 2019-04-14 02:44:49 +09:00
f6f8cdbcf2 11.0.0-beta.13 2019-04-14 02:36:21 +09:00
f46f53b8a3 Refactor 2019-04-14 02:36:00 +09:00
a2fcae4383 Fix bug 2019-04-14 02:33:50 +09:00
483f043768 11.0.0-beta.12 2019-04-14 02:24:27 +09:00
f8e0f4f21f Fix bug 2019-04-14 02:21:57 +09:00
9c3613e96d Improve error handling 2019-04-14 02:19:59 +09:00
d9cacdc86d Update meid.ts 2019-04-14 01:47:46 +09:00
aa3d2deeaa Add meid 2019-04-14 01:40:29 +09:00
e64912545a Update id generation methods 2019-04-14 01:08:26 +09:00
b247be80cc 11.0.0-beta.11 2019-04-13 20:02:47 +09:00
343f2f1f33 Fix bug 2019-04-13 20:02:31 +09:00
2d590df900 Clean up 2019-04-13 20:01:32 +09:00
ba56b2b9fd Update CHANGELOG.md 2019-04-13 19:40:03 +09:00
bf472b0c5e refactor 2019-04-13 19:36:57 +09:00
f7961f34c5 Update CHANGELOG.md 2019-04-13 19:23:32 +09:00
e369031a28 Redis必須に 2019-04-13 19:19:32 +09:00
186d7bbfd9 Fix bug 2019-04-13 19:08:41 +09:00
60a11f8da5 11.0.0-beta.10 2019-04-13 18:58:48 +09:00
1181fcdceb Fix bug 2019-04-13 18:58:29 +09:00
8cb9852058 リプライ先をエラー時に無視すると本来は投票なのに投票じゃないと扱われおかしくなるのでエラーにするように 2019-04-13 18:45:07 +09:00
53d46d1cbe Fix error 2019-04-13 18:23:32 +09:00
275e1c8de9 Refactor 2019-04-13 18:17:27 +09:00
d46eca4c87 Refactor 2019-04-13 18:14:32 +09:00
2927fb1597 11.0.0-beta.9 2019-04-13 17:27:17 +09:00
8c72e011d2 Fix bug 2019-04-13 17:26:38 +09:00
69662e24c3 Fix bug 2019-04-13 17:24:56 +09:00
96099ffe98 11.0.0-beta.8 2019-04-13 16:55:13 +09:00
ae16b45c11 Fix bug 2019-04-13 16:54:21 +09:00
cfee87d3ef 11.0.0-beta.7 2019-04-13 15:18:27 +09:00
5fcf5bc635 Fix bug 2019-04-13 15:18:12 +09:00
14bcb813cc Update migrate.ts 2019-04-13 15:09:16 +09:00
6af19794b6 11.0.0-beta.6 2019-04-13 15:03:56 +09:00
8316186695 Clean packed responses 2019-04-13 15:02:15 +09:00
85d3023cd5 Clean packed responses 2019-04-13 14:55:59 +09:00
78414dee29 Add note 2019-04-13 14:45:51 +09:00
084135141f typo 2019-04-13 14:37:45 +09:00
467a21f028 Update CONTRIBUTING.md 2019-04-13 14:36:35 +09:00
6e284c44d6 Update CONTRIBUTING.md 2019-04-13 14:34:34 +09:00
daf9a449e8 Update CONTRIBUTING.md 2019-04-13 14:31:05 +09:00
960268fd33 typo 2019-04-13 14:17:50 +09:00
8c331da315 Fix bug 2019-04-13 14:11:15 +09:00
b0d626d862 Update CONTRIBUTING.md 2019-04-13 14:04:29 +09:00
a51fbd7316 Suppress errors 2019-04-13 04:00:02 +09:00
67 changed files with 326 additions and 320 deletions

View File

@ -65,10 +65,10 @@ db:
# ┌─────────────────────┐
#───┘ Redis configuration └─────────────────────────────────────
#redis:
# host: localhost
# port: 6379
# pass: example-pass
redis:
host: localhost
port: 6379
#pass: example-pass
# ┌─────────────────────────────┐
#───┘ Elasticsearch configuration └─────────────────────────────
@ -127,28 +127,12 @@ drive:
# change it according to your preferences.
# Available methods:
# aid1 ... Use AID for ID generation (with random 1 char)
# aid2 ... Use AID for ID generation (with random 2 chars)
# aid3 ... Use AID for ID generation (with random 3 chars)
# aid4 ... Use AID for ID generation (with random 4 chars)
# ulid ... Use ulid for ID generation
# objectid ... This is left for backward compatibility.
# aid ... Short, Millisecond accuracy
# meid ... Similar to ObjectID, Millisecond accuracy
# ulid ... Millisecond accuracy
# objectid ... This is left for backward compatibility
# AID(n) is the original ID generation method.
# The trailing n represents the number of random characters that
# will be suffixed.
# The larger n is the safer. If n is small, the possibility of
# collision at the same time increases, but there are also
# advantages such as shortening of the URL.
# ULID: Universally Unique Lexicographically Sortable Identifier.
# for more details: https://github.com/ulid/spec
# * Normally, AID should be sufficient.
# ObjectID is the method used in previous versions of Misskey.
# * Choose this if you are migrating from a previous Misskey.
id: 'aid2'
id: 'aid'
# ┌─────────────────────┐
#───┘ Other configuration └─────────────────────────────────────

View File

@ -5,9 +5,10 @@ If you encounter any problems with updating, please try the following:
1. `npm run clean` or `npm run cleanall`
2. Retry update (Don't forget `npm i`)
11.0.0
----------
* データベースがMongoDBからPostgreSQLに変更されました
11.0.0 (daybreak)
-----------------
* **データベースがMongoDBからPostgreSQLに変更されました**
* **Redisが必須に**
* アカウントを完全に削除できるように
* ミュート/ブロック時にそのユーザーの投稿のウォッチをすべて解除するように
* フォロー申請数が実際より1すくなくなる問題を修正
@ -19,6 +20,15 @@ If you encounter any problems with updating, please try the following:
### APIの破壊的変更
* v10時点で deprecated だったパラメータなどを削除
* ユーザーリストの title が name に
* リバーシの対局の`settings`プロパティがなくなり、その中にあったプロパティがすべて上の階層に
* 例えば`game.settings.map``game.map`になる
### 既知の問題
* アプリが作成できない
* 依存ライブラリの問題と思わるため、対応が難しい
### Migration
coming soon...
10.100.0
----------

View File

@ -130,6 +130,40 @@ const users = userIds.length > 0 ? await Users.find({
}) : [];
```
### 配列のインデックス in SQL
SQLでは配列のインデックスは**1始まり**。
`[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く
### `undefined`にご用心
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
### 簡素な`undefined`チェック
データベースからレコードを取得するときに、プログラムの流れ的に(ほぼ)絶対`undefined`にはならない場合でも、`undefined`チェックしないとTypeScriptに怒られます。
でもいちいち複数行を費やして、発生するはずのない`undefined`をチェックするのも面倒なので、`ensure`というユーティリティ関数を用意しています。
例えば、
``` ts
const user = await Users.findOne(userId);
// この時点で user の型は User | undefined
if (user == null) {
throw 'missing user';
}
// この時点で user の型は User
```
という処理を`ensure`を使うと
``` ts
const user = await Users.findOne(userId).then(ensure);
// この時点で user の型は User
```
という風に書けます。
もちろん`ensure`内部でエラーを握りつぶすようなことはしておらず、万が一`undefined`だった場合はPromiseがRejectされ後続の処理は実行されません。
``` ts
const user = await Users.findOne(userId).then(ensure);
// 万が一 Users.findOne の結果が undefined だったら、ensure でエラーが発生するので
// この行に到達することは無い
// なので、.then(ensure) は
// if (user == null) {
// throw 'missing user';
// }
// の糖衣構文のような扱いです
```

View File

@ -24,18 +24,13 @@ Please install and setup these softwares:
#### Dependencies :package:
* **[Node.js](https://nodejs.org/en/)** >= 11.7.0
* **[PostgreSQL](https://www.postgresql.org/)** >= 10
* **[Redis](https://redis.io/)**
##### Optional
* [Redis](https://redis.io/)
* Redis is optional, but we strongly recommended to install it
* [Elasticsearch](https://www.elastic.co/) - required to enable the search feature
* [FFmpeg](https://www.ffmpeg.org/)
*3.* Setup PostgreSQL
----------------------------------------------------------------
:)
*4.* Install Misskey
*3.* Install Misskey
----------------------------------------------------------------
1. `su - misskey` Connect to misskey user.
2. `git clone -b master git://github.com/syuilo/misskey.git` Clone the misskey repo from master branch.
@ -43,12 +38,12 @@ Please install and setup these softwares:
4. `git checkout $(git tag -l | grep -Ev -- '-(rc|alpha)\.[0-9]+$' | sort -V | tail -n 1)` Checkout to the [latest release](https://github.com/syuilo/misskey/releases/latest)
5. `npm install` Install misskey dependencies.
*5.* Configure Misskey
*4.* Configure Misskey
----------------------------------------------------------------
1. `cp .config/example.yml .config/default.yml` Copy the `.config/example.yml` and rename it to `default.yml`.
2. Edit `default.yml`
*6.* Build Misskey
*5.* Build Misskey
----------------------------------------------------------------
Build misskey with the following:
@ -64,13 +59,13 @@ If you're still encountering errors about some modules, use node-gyp:
3. `node-gyp build`
4. `NODE_ENV=production npm run build`
*7.* Init DB
*6.* Init DB
----------------------------------------------------------------
``` shell
npm run init
```
*8.* That is it.
*7.* That is it.
----------------------------------------------------------------
Well done! Now, you have an environment that run to Misskey.

View File

@ -24,18 +24,13 @@ Installez les paquets suivants :
#### Dépendences :package:
* **[Node.js](https://nodejs.org/en/)** >= 11.7.0
* **[PostgreSQL](https://www.postgresql.org/)** >= 10
* **[Redis](https://redis.io/)**
##### Optionnels
* [Redis](https://redis.io/)
* Redis est optionnel mais nous vous recommandons vivement de l'installer
* [Elasticsearch](https://www.elastic.co/) - requis pour pouvoir activer la fonctionnalité de recherche
* [FFmpeg](https://www.ffmpeg.org/)
*3.* Paramètrage de PostgreSQL
----------------------------------------------------------------
:)
*4.* Installation de Misskey
*3.* Installation de Misskey
----------------------------------------------------------------
1. `su - misskey` Basculez vers l'utilisateur misskey.
2. `git clone -b master git://github.com/syuilo/misskey.git` Clonez la branche master du dépôt misskey.
@ -43,12 +38,12 @@ Installez les paquets suivants :
4. `git checkout $(git tag -l | grep -Ev -- '-(rc|alpha)\.[0-9]+$' | sort -V | tail -n 1)` Checkout sur le tag de la [version la plus récente](https://github.com/syuilo/misskey/releases/latest)
5. `npm install` Installez les dépendances de misskey.
*5.* Création du fichier de configuration
*4.* Création du fichier de configuration
----------------------------------------------------------------
1. `cp .config/example.yml .config/default.yml` Copiez le fichier `.config/example.yml` et renommez-le`default.yml`.
2. Editez le fichier `default.yml`
*6.* Construction de Misskey
*5.* Construction de Misskey
----------------------------------------------------------------
Construisez Misskey comme ceci :
@ -64,7 +59,7 @@ Si vous rencontrez des erreurs concernant certains modules, utilisez node-gyp:
3. `node-gyp build`
4. `NODE_ENV=production npm run build`
*7.* C'est tout.
*6.* C'est tout.
----------------------------------------------------------------
Excellent ! Maintenant, vous avez un environnement prêt pour lancer Misskey

View File

@ -24,25 +24,14 @@ adduser --disabled-password --disabled-login misskey
#### 依存関係 :package:
* **[Node.js](https://nodejs.org/en/)** (11.7.0以上)
* **[PostgreSQL](https://www.postgresql.org/)** (10以上)
* **[Redis](https://redis.io/)**
##### オプション
* [Redis](https://redis.io/)
* Redisはオプションですが、インストールすることを強く推奨します。
* インストールしなくていいのは、あなたのインスタンスが自分専用のときだけとお考えください。
* 具体的には、Redisをインストールしないと、次の事が出来なくなります:
* Misskeyプロセスを複数起動しての負荷分散
* レートリミット
* ジョブキュー
* Twitter連携
* [Elasticsearch](https://www.elastic.co/)
* 検索機能を有効にするためにはインストールが必要です。
* [FFmpeg](https://www.ffmpeg.org/)
*3.* PostgreSQLの設定
----------------------------------------------------------------
:)
*4.* Misskeyのインストール
*3.* Misskeyのインストール
----------------------------------------------------------------
1. `su - misskey` misskeyユーザーを使用
2. `git clone -b master git://github.com/syuilo/misskey.git` masterブランチからMisskeyレポジトリをクローン
@ -50,12 +39,12 @@ adduser --disabled-password --disabled-login misskey
4. `git checkout $(git tag -l | grep -Ev -- '-(rc|alpha)\.[0-9]+$' | sort -V | tail -n 1)` [最新のリリース](https://github.com/syuilo/misskey/releases/latest)を確認
5. `npm install` Misskeyの依存パッケージをインストール
*5.* 設定ファイルを作成する
*4.* 設定ファイルを作成する
----------------------------------------------------------------
1. `cp .config/example.yml .config/default.yml` `.config/example.yml`をコピーし名前を`default.yml`にする。
2. `default.yml` を編集する。
*6.* Misskeyのビルド
*5.* Misskeyのビルド
----------------------------------------------------------------
次のコマンドでMisskeyをビルドしてください:
@ -70,13 +59,13 @@ Debianをお使いであれば、`build-essential`パッケージをインスト
3. `node-gyp build`
4. `NODE_ENV=production npm run build`
*7.* データベースを初期化
*6.* データベースを初期化
----------------------------------------------------------------
``` shell
npm run init
```
*8.* 以上です!
*7.* 以上です!
----------------------------------------------------------------
お疲れ様でした。これでMisskeyを動かす準備は整いました。

View File

@ -1,7 +1,7 @@
{
"name": "misskey",
"author": "syuilo <i@syuilo.com>",
"version": "11.0.0-beta.5",
"version": "11.0.0-beta.14",
"codename": "daybreak",
"repository": {
"type": "git",

View File

@ -28,7 +28,7 @@ export default class MiOS extends EventEmitter {
};
public get instanceName() {
return this.meta ? this.meta.data.name : 'Misskey';
return this.meta ? (this.meta.data.name || 'Misskey') : 'Misskey';
}
private isMetaFetching = false;

View File

@ -1,7 +1,7 @@
import * as redis from 'redis';
import config from '../config';
export default config.redis ? redis.createClient(
export default redis.createClient(
config.redis.port,
config.redis.host,
{
@ -9,4 +9,4 @@ export default config.redis ? redis.createClient(
prefix: config.redis.prefix,
db: config.redis.db || 0
}
) : null;
);

View File

@ -24,9 +24,14 @@ import { UserPublickey } from './models/entities/user-publickey';
import { UserKeypair } from './models/entities/user-keypair';
import { extractPublic } from './crypto_key';
import { Emoji } from './models/entities/emoji';
import { toPuny } from './misc/convert-host';
import { toPuny as _toPuny } from './misc/convert-host';
import { UserProfile } from './models/entities/user-profile';
function toPuny(x: string | null): string | null {
if (x == null) return null;
return _toPuny(x);
}
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;

View File

@ -1,26 +0,0 @@
// AID
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さnの[ランダムな文字列]
const CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
const TIME2000 = 946684800000;
function getTime(time: number) {
time = time - TIME2000;
if (time < 0) time = 0;
return time.toString(36);
}
function getRandom(length: number) {
let str = '';
for (let i = 0; i < length; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
}
return str;
}
export function genAid(date: Date, rand: number): string {
return getTime(date.getTime()).padStart(8, CHARS[0]) + getRandom(rand);
}

View File

@ -1,26 +0,0 @@
// AID(Cheep)
// 長さ6の[2000年1月1日からの経過秒をbase36でエンコードしたもの] + 長さ3の[ランダムな文字列]
const CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
const TIME2000 = 946684800000;
function getTime(time: number) {
time = time - TIME2000;
if (time < 0) time = 0;
time = Math.floor(time / 1000);
return time.toString(36);
}
function getRandom() {
let str = '';
for (let i = 0; i < 3; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
}
return str;
}
export function genAidc(date: Date): string {
return getTime(date.getTime()).padStart(6, CHARS[0]) + getRandom();
}

View File

@ -19,3 +19,8 @@ export function extractDbHost(uri: string) {
export function toPuny(host: string) {
return toASCII(host.toLowerCase());
}
export function toPunyNullable(host: string | null | undefined): string | null {
if (host == null) return null;
return toASCII(host.toLowerCase());
}

View File

@ -1,7 +1,7 @@
import { ulid } from 'ulid';
import { genAid } from './aid';
import { genAidc } from './aidc';
import { genObjectId } from './object-id';
import { genAid } from './id/aid';
import { genMeid } from './id/meid';
import { genObjectId } from './id/object-id';
import config from '../config';
const metohd = config.id.toLowerCase();
@ -10,13 +10,10 @@ export function genId(date?: Date): string {
if (!date || (date > new Date())) date = new Date();
switch (metohd) {
case 'aidc': return genAidc(date);
case 'aid1': return genAid(date, 1);
case 'aid2': return genAid(date, 2);
case 'aid3': return genAid(date, 3);
case 'aid4': return genAid(date, 4);
case 'aid': return genAid(date);
case 'meid': return genMeid(date);
case 'ulid': return ulid(date.getTime());
case 'objectid': return genObjectId(date);
default: throw 'unknown id generation method';
default: throw new Error('unknown id generation method');
}
}

23
src/misc/id/aid.ts Normal file
View File

@ -0,0 +1,23 @@
// AID
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ2の[ノイズ文字列]
import * as cluster from 'cluster';
const TIME2000 = 946684800000;
let counter = process.pid + (cluster.isMaster ? 0 : cluster.worker.id);
function getTime(time: number) {
time = time - TIME2000;
if (time < 0) time = 0;
return time.toString(36).padStart(8, '0');
}
function getNoise() {
return counter.toString(36).padStart(2, '0').slice(-2);
}
export function genAid(date: Date): string {
counter++;
return getTime(date.getTime()) + getNoise();
}

26
src/misc/id/meid.ts Normal file
View File

@ -0,0 +1,26 @@
const CHARS = '0123456789abcdef';
function getTime(time: number) {
if (time < 0) time = 0;
if (time === 0) {
return CHARS[0];
}
time += 0x800000000000;
return time.toString(16).padStart(12, CHARS[0]);
}
function getRandom() {
let str = '';
for (let i = 0; i < 12; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
}
return str;
}
export function genMeid(date: Date): string {
return 'f' + getTime(date.getTime()) + getRandom();
}

View File

@ -8,7 +8,7 @@ function getTime(time: number) {
time = Math.floor(time / 1000);
return time.toString(16);
return time.toString(16).padStart(8, CHARS[0]);
}
function getRandom() {

View File

@ -20,7 +20,7 @@ export async function getFallbackReaction(): Promise<string> {
return meta.useStarForReactionFallback ? 'star' : 'like';
}
export async function toDbReaction(reaction: string, enableEmoji = true): Promise<string> {
export async function toDbReaction(reaction?: string | null, enableEmoji = true): Promise<string> {
if (reaction == null) return await getFallbackReaction();
// 既存の文字列リアクションはそのまま

View File

@ -19,11 +19,15 @@ export class AuthSession {
})
public token: string;
@Column(id())
@Column({
...id(),
nullable: true
})
public userId: User['id'];
@ManyToOne(type => User, {
onDelete: 'CASCADE'
onDelete: 'CASCADE',
nullable: true
})
@JoinColumn()
public user: User | null;

View File

@ -148,7 +148,7 @@ export class NoteRepository extends Repository<Note> {
return reaction.reaction;
}
return null;
return undefined;
}
let text = note.text;
@ -162,15 +162,15 @@ export class NoteRepository extends Repository<Note> {
const packed = await rap({
id: note.id,
createdAt: note.createdAt,
app: note.appId ? Apps.pack(note.appId) : null,
app: note.appId ? Apps.pack(note.appId) : undefined,
userId: note.userId,
user: Users.pack(note.user || note.userId, meId),
text: text,
cw: note.cw,
visibility: note.visibility,
localOnly: note.localOnly,
visibleUserIds: note.visibleUserIds,
viaMobile: note.viaMobile,
localOnly: note.localOnly || undefined,
visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined,
viaMobile: note.viaMobile || undefined,
renoteCount: note.renoteCount,
repliesCount: note.repliesCount,
reactions: note.reactions,
@ -188,13 +188,13 @@ export class NoteRepository extends Repository<Note> {
...(opts.detail ? {
reply: note.replyId ? this.pack(note.replyId, meId, {
detail: false
}) : null,
}) : undefined,
renote: note.renoteId ? this.pack(note.renoteId, meId, {
detail: true
}) : null,
}) : undefined,
poll: note.hasPoll ? populatePoll() : null,
poll: note.hasPoll ? populatePoll() : undefined,
...(meId ? {
myReaction: populateMyReaction()

View File

@ -1,6 +1,7 @@
import { EntityRepository, Repository } from 'typeorm';
import { UserList } from '../entities/user-list';
import { ensure } from '../../prelude/ensure';
import { UserListJoinings } from '..';
@EntityRepository(UserList)
export class UserListRepository extends Repository<UserList> {
@ -9,9 +10,14 @@ export class UserListRepository extends Repository<UserList> {
) {
const userList = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
const users = await UserListJoinings.find({
userListId: userList.id
});
return {
id: userList.id,
name: userList.name
name: userList.name,
userIds: users.map(x => x.userId)
};
}
}

View File

@ -89,13 +89,11 @@ export class UserRepository extends Repository<User> {
username: user.username,
host: user.host,
avatarUrl: user.avatarUrl,
bannerUrl: user.bannerUrl,
avatarColor: user.avatarColor,
bannerColor: user.bannerColor,
isAdmin: user.isAdmin,
isBot: user.isBot,
isCat: user.isCat,
isVerified: user.isVerified,
isAdmin: user.isAdmin || undefined,
isBot: user.isBot || undefined,
isCat: user.isCat || undefined,
isVerified: user.isVerified || undefined,
// カスタム絵文字添付
emojis: user.emojis.length > 0 ? Emojis.find({
@ -121,6 +119,9 @@ export class UserRepository extends Repository<User> {
url: profile!.url,
createdAt: user.createdAt,
updatedAt: user.updatedAt,
bannerUrl: user.bannerUrl,
bannerColor: user.bannerColor,
isLocked: user.isLocked,
description: profile!.description,
location: profile!.location,
birthday: profile!.birthday,

View File

@ -1,6 +1,9 @@
/**
* 値が null または undefined の場合はエラーを発生させ、そうでない場合は値をそのまま返します
*/
export function ensure<T>(x: T): NonNullable<T> {
if (x == null) {
throw 'ぬるぽ';
throw new Error('ぬるぽ');
} else {
return x!;
}

View File

@ -23,6 +23,14 @@ function initializeQueue(name: string) {
});
}
function renderError(e: Error): any {
return {
stack: e.stack,
message: e.message,
name: e.name
};
}
export const deliverQueue = initializeQueue('deliver');
export const inboxQueue = initializeQueue('inbox');
export const dbQueue = initializeQueue('db');
@ -34,16 +42,16 @@ deliverQueue
.on('waiting', (jobId) => deliverLogger.debug(`waiting id=${jobId}`))
.on('active', (job) => deliverLogger.debug(`active id=${job.id} to=${job.data.to}`))
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`))
.on('failed', (job, err) => deliverLogger.warn(`failed(${err}) id=${job.id} to=${job.data.to}`))
.on('error', (error) => deliverLogger.error(`error ${error}`))
.on('failed', (job, err) => deliverLogger.warn(`failed(${err}) id=${job.id} to=${job.data.to}`, { job, e: renderError(err) }))
.on('error', (job: any, err: Error) => deliverLogger.error(`error ${err}`, { job, e: renderError(err) }))
.on('stalled', (job) => deliverLogger.warn(`stalled id=${job.id} to=${job.data.to}`));
inboxQueue
.on('waiting', (jobId) => inboxLogger.debug(`waiting id=${jobId}`))
.on('active', (job) => inboxLogger.debug(`active id=${job.id}`))
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) id=${job.id}`))
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`))
.on('error', (error) => inboxLogger.error(`error ${error}`))
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`, { job, e: renderError(err) }))
.on('error', (job: any, err: Error) => inboxLogger.error(`error ${err}`, { job, e: renderError(err) }))
.on('stalled', (job) => inboxLogger.warn(`stalled id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`));
export function deliver(user: ILocalUser, content: any, to: any) {

View File

@ -12,7 +12,7 @@ import { Instances, Users, UserPublickeys } from '../../models';
import { instanceChart } from '../../services/chart';
import { UserPublickey } from '../../models/entities/user-publickey';
import fetchMeta from '../../misc/fetch-meta';
import { toPuny } from '../../misc/convert-host';
import { toPuny, toPunyNullable } from '../../misc/convert-host';
import { validActor } from '../../remote/activitypub/type';
import { ensure } from '../../prelude/ensure';
@ -36,7 +36,7 @@ export default async (job: Bull.Job): Promise<void> => {
if (keyIdLower.startsWith('acct:')) {
const acct = parseAcct(keyIdLower.slice('acct:'.length));
const host = acct.host ? toPuny(acct.host) : null;
const host = toPunyNullable(acct.host);
const username = toPuny(acct.username);
if (host === null) {

View File

@ -6,7 +6,7 @@ import { Users } from '../../../../models';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
if (!id.startsWith(config.url + '/')) {
return;

View File

@ -9,7 +9,7 @@ const logger = apLogger;
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
const uri = activity.id || activity;

View File

@ -6,7 +6,7 @@ import { Users } from '../../../models';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
if (!id.startsWith(config.url + '/')) {
return;

View File

@ -5,7 +5,7 @@ import { Notes } from '../../../models';
export default async (actor: IRemoteUser, activity: ILike) => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
// Transform:
// https://misskey.ex/notes/xxxx to

View File

@ -6,7 +6,7 @@ import { Users } from '../../../../models';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
if (!id.startsWith(config.url + '/')) {
return;

View File

@ -9,7 +9,7 @@ const logger = apLogger;
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
const uri = activity.id || activity;

View File

@ -7,7 +7,7 @@ import { Users, FollowRequests, Followings } from '../../../../models';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
if (!id.startsWith(config.url + '/')) {
return;

View File

@ -8,13 +8,13 @@ import { Notes } from '../../../../models';
*/
export default async (actor: IRemoteUser, activity: ILike): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
if (id == null) throw 'missing id';
if (id == null) throw new Error('missing id');
const noteId = id.split('/').pop();
const note = await Notes.findOne(noteId);
if (note == null) {
throw 'note not found';
throw new Error('note not found');
}
await deleteReaction(actor, note);

View File

@ -32,7 +32,7 @@ const logger = apLogger;
*/
export async function fetchNote(value: string | IObject, resolver?: Resolver): Promise<Note | null> {
const uri = typeof value == 'string' ? value : value.id;
if (uri == null) throw 'missing uri';
if (uri == null) throw new Error('missing uri');
// URIがこのサーバーを指しているならデータベースからフェッチ
if (uri.startsWith(config.url + '/')) {
@ -67,7 +67,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
value: value,
object: object
});
throw 'invalid note';
throw new Error('invalid note');
}
const note: INote = object;
@ -81,7 +81,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
// 投稿者が凍結されていたらスキップ
if (actor.isSuspended) {
throw 'actor has been suspended';
throw new Error('actor has been suspended');
}
//#region Visibility
@ -120,13 +120,15 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
: [];
// リプライ
const reply: Note | undefined | null = note.inReplyTo
? await resolveNote(note.inReplyTo, resolver).catch(e => {
// 4xxの場合はリプライしてないことにする
if (e.statusCode >= 400 && e.statusCode < 500) {
logger.warn(`Ignored inReplyTo ${note.inReplyTo} - ${e.statusCode} `);
return null;
const reply: Note | null = note.inReplyTo
? await resolveNote(note.inReplyTo, resolver).then(x => {
if (x == null) {
logger.warn(`Specified inReplyTo, but nout found`);
throw new Error('inReplyTo not found');
} else {
return x;
}
}).catch(e => {
logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`);
throw e;
})
@ -150,11 +152,11 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
const cw = note.summary === '' ? null : note.summary;
// テキストのパース
const text = note._misskey_content || fromHtml(note.content);
const text = note._misskey_content || (note.content ? fromHtml(note.content) : null);
// vote
if (reply && reply.hasPoll) {
const poll = await Polls.findOne({ noteId: reply.id }).then(ensure);
const poll = await Polls.findOne(reply.id).then(ensure);
const tryCreateVote = async (name: string, index: number): Promise<null> => {
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
@ -228,7 +230,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
*/
export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise<Note | null> {
const uri = typeof value == 'string' ? value : value.id;
if (uri == null) throw 'missing uri';
if (uri == null) throw new Error('missing uri');
// ブロックしてたら中断
// TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく
@ -250,7 +252,7 @@ export async function resolveNote(value: string | IObject, resolver?: Resolver):
if (e.name === 'duplicated') {
return fetchNote(uri).then(note => {
if (note == null) {
throw 'something happened';
throw new Error('something happened');
} else {
return note;
}

View File

@ -88,7 +88,7 @@ function validatePerson(x: any, uri: string) {
* Misskeyに対象のPersonが登録されていればそれを返します。
*/
export async function fetchPerson(uri: string, resolver?: Resolver): Promise<User | null> {
if (typeof uri !== 'string') throw 'uri is not string';
if (typeof uri !== 'string') throw new Error('uri is not string');
// URIがこのサーバーを指しているならデータベースからフェッチ
if (uri.startsWith(config.url + '/')) {
@ -111,7 +111,7 @@ export async function fetchPerson(uri: string, resolver?: Resolver): Promise<Use
* Personを作成します。
*/
export async function createPerson(uri: string, resolver?: Resolver): Promise<User> {
if (typeof uri !== 'string') throw 'uri is not string';
if (typeof uri !== 'string') throw new Error('uri is not string');
if (resolver == null) resolver = new Resolver();
@ -256,7 +256,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
* @param hint Hint of Person object (この値が正当なPersonの場合、Remote resolveをせずに更新に利用します)
*/
export async function updatePerson(uri: string, resolver?: Resolver | null, hint?: object): Promise<void> {
if (typeof uri !== 'string') throw 'uri is not string';
if (typeof uri !== 'string') throw new Error('uri is not string');
// URIがこのサーバーを指しているならスキップ
if (uri.startsWith(config.url + '/')) {
@ -380,7 +380,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
* リモートサーバーからフェッチしてMisskeyに登録しそれを返します。
*/
export async function resolvePerson(uri: string, resolver?: Resolver): Promise<User> {
if (typeof uri !== 'string') throw 'uri is not string';
if (typeof uri !== 'string') throw new Error('uri is not string');
//#region このサーバーに既に登録されていたらそれを返す
const exist = await fetchPerson(uri);

View File

@ -11,7 +11,7 @@ export async function extractPollFromQuestion(source: string | IQuestion): Promi
const expiresAt = question.endTime ? new Date(question.endTime) : null;
if (multiple && !question.anyOf) {
throw 'invalid question';
throw new Error('invalid question');
}
const choices = question[multiple ? 'anyOf' : 'oneOf']!
@ -37,14 +37,14 @@ export async function updateQuestion(value: any) {
const uri = typeof value == 'string' ? value : value.id;
// URIがこのサーバーを指しているならスキップ
if (uri.startsWith(config.url + '/')) throw 'uri points local';
if (uri.startsWith(config.url + '/')) throw new Error('uri points local');
//#region このサーバーに既に登録されているか
const note = await Notes.findOne({ uri });
if (note == null) throw 'Question is not registed';
if (note == null) throw new Error('Question is not registed');
const poll = await Polls.findOne({ noteId: note.id });
if (poll == null) throw 'Question is not registed';
if (poll == null) throw new Error('Question is not registed');
//#endregion
// resolve new Question object
@ -52,7 +52,7 @@ export async function updateQuestion(value: any) {
const question = await resolver.resolve(value) as IQuestion;
apLogger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);
if (question.type !== 'Question') throw 'object is not a Question';
if (question.type !== 'Question') throw new Error('object is not a Question');
const apChoices = question.oneOf || question.anyOf;

View File

@ -12,7 +12,7 @@ export interface IObject {
attachment?: any[];
inReplyTo?: any;
replies?: ICollection;
content: string;
content?: string;
name?: string;
startTime?: Date;
endTime?: Date;
@ -44,16 +44,16 @@ export interface IOrderedCollection extends IObject {
export interface INote extends IObject {
type: 'Note' | 'Question';
_misskey_content: string;
_misskey_quote: string;
_misskey_question: string;
_misskey_content?: string;
_misskey_quote?: string;
_misskey_question?: string;
}
export interface IQuestion extends IObject {
type: 'Note' | 'Question';
_misskey_content: string;
_misskey_quote: string;
_misskey_question: string;
_misskey_content?: string;
_misskey_quote?: string;
_misskey_question?: string;
oneOf?: IQuestionChoice[];
anyOf?: IQuestionChoice[];
endTime?: Date;
@ -129,7 +129,7 @@ export interface IRemove extends IActivity {
export interface ILike extends IActivity {
type: 'Like';
_misskey_reaction: string;
_misskey_reaction?: string;
}
export interface IAnnounce extends IActivity {

View File

@ -17,7 +17,7 @@ export async function resolveUser(username: string, host: string | null, option?
logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null }).then(u => {
if (u == null) {
throw 'user not found';
throw new Error('user not found');
} else {
return u;
}
@ -30,7 +30,7 @@ export async function resolveUser(username: string, host: string | null, option?
logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null }).then(u => {
if (u == null) {
throw 'user not found';
throw new Error('user not found');
} else {
return u;
}
@ -78,7 +78,7 @@ export async function resolveUser(username: string, host: string | null, option?
logger.info(`return resynced remote user: ${acctLower}`);
return await Users.findOne({ uri: self.href }).then(u => {
if (u == null) {
throw 'user not found';
throw new Error('user not found');
} else {
return u;
}

View File

@ -14,7 +14,7 @@ export default async (token: string): Promise<[User | null | undefined, App | nu
.findOne({ token });
if (user == null) {
throw 'user not found';
throw new Error('user not found');
}
return [user, null];
@ -24,7 +24,7 @@ export default async (token: string): Promise<[User | null | undefined, App | nu
});
if (accessToken == null) {
throw 'invalid signature';
throw new Error('invalid signature');
}
const app = await Apps

View File

@ -36,7 +36,7 @@ export async function getRemoteUser(userId: User['id']) {
const user = await getUser(userId);
if (!Users.isRemoteUser(user)) {
throw 'user is not a remote user';
throw new Error('user is not a remote user');
}
return user;
@ -49,7 +49,7 @@ export async function getLocalUser(userId: User['id']) {
const user = await getUser(userId);
if (!Users.isLocalUser(user)) {
throw 'user is not a local user';
throw new Error('user is not a local user');
}
return user;

View File

@ -1,7 +1,7 @@
import $ from 'cafy';
import define from '../../../define';
import { Emojis } from '../../../../../models';
import { toPuny } from '../../../../../misc/convert-host';
import { toPunyNullable } from '../../../../../misc/convert-host';
export const meta = {
desc: {
@ -23,7 +23,7 @@ export const meta = {
export default define(meta, async (ps) => {
const emojis = await Emojis.find({
host: ps.host ? toPuny(ps.host) : null
host: toPunyNullable(ps.host)
});
return emojis.map(e => ({

View File

@ -34,7 +34,7 @@ export default define(meta, async (ps) => {
if (ps.domain) {
const whiteDomains = ps.domain.split(' ').filter(x => !x.startsWith('-'));
const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-'));
const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-')).map(x => x.substr(1));
if (whiteDomains.length > 0) {
query.andWhere(new Brackets(qb => {
@ -53,11 +53,17 @@ export default define(meta, async (ps) => {
if (blackDomains.length > 0) {
query.andWhere(new Brackets(qb => {
for (const blackDomain of blackDomains) {
const subDomains = blackDomain.split('.');
let i = 0;
for (const subDomain of blackDomain.split('.')) {
for (const subDomain of subDomains) {
const p = `blackSubDomain_${subDomain}_${i}`;
// SQL is 1 based, so we need '+ 1'
qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain });
if (i === subDomains.length - 1) {
// SQL is 1 based, so we need '+ 1'
qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain });
} else {
// SQL is 1 based, so we need '+ 1'
qb.andWhere(`log.domain[${i + 1}] = :${p}`, { [p]: subDomain });
}
i++;
}
}

View File

@ -38,7 +38,7 @@ export default define(meta, async (ps, user) => {
const app = await Apps.save({
id: genId(),
createdAt: new Date(),
userId: user && user.id,
userId: user ? user.id : null,
name: ps.name,
description: ps.description,
permission: ps.permission,

View File

@ -71,6 +71,4 @@ export default define(meta, async (ps, user) => {
await AuthSessions.update(session.id, {
userId: user.id
});
return;
});

View File

@ -76,12 +76,12 @@ export default define(meta, async (ps, user) => {
user: meta.smtpUser,
pass: meta.smtpPass
} : undefined
});
} as any);
const link = `${config.url}/verify-email/${code}`;
transporter.sendMail({
from: meta.email,
from: meta.email!,
to: ps.email,
subject: meta.name || 'Misskey',
text: `To verify email, please click this link: ${link}`

View File

@ -35,6 +35,7 @@ export default define(meta, async (ps, user) => {
const day = 1000 * 60 * 60 * 24 * 3; // 3日前まで
const query = Notes.createQueryBuilder('note')
.where('note.userHost IS NULL')
.andWhere(`note.createdAt > :date`, { date: new Date(Date.now() - day) })
.andWhere(`note.visibility = 'public'`)
.leftJoinAndSelect('note.user', 'user');

View File

@ -124,7 +124,7 @@ export default define(meta, async (ps, user) => {
// Increment votes count
const index = ps.choice + 1; // In SQL, array index is 1 based
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE "noteId" = '${poll.noteId}'`);
publishNoteStream(note.id, 'pollVoted', {
choice: ps.choice,

View File

@ -4,7 +4,7 @@ import define from '../../define';
import { ApiError } from '../../error';
import { Users, Followings } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { toPuny } from '../../../../misc/convert-host';
import { toPunyNullable } from '../../../../misc/convert-host';
export const meta = {
desc: {
@ -66,7 +66,7 @@ export const meta = {
export default define(meta, async (ps, me) => {
const user = await Users.findOne(ps.userId != null
? { id: ps.userId }
: { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) });
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
if (user == null) {
throw new ApiError(meta.errors.noSuchUser);

View File

@ -4,7 +4,7 @@ import define from '../../define';
import { ApiError } from '../../error';
import { Users, Followings } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { toPuny } from '../../../../misc/convert-host';
import { toPunyNullable } from '../../../../misc/convert-host';
export const meta = {
desc: {
@ -66,7 +66,7 @@ export const meta = {
export default define(meta, async (ps, me) => {
const user = await Users.findOne(ps.userId != null
? { id: ps.userId }
: { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) });
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
if (user == null) {
throw new ApiError(meta.errors.noSuchUser);

View File

@ -8,12 +8,6 @@ import Logger from '../../services/logger';
const logger = new Logger('limiter');
export default (endpoint: IEndpoint, user: User) => new Promise((ok, reject) => {
// Redisがインストールされてない場合は常に許可
if (limiterDB == null) {
ok();
return;
}
const limitation = endpoint.meta.limit!;
const key = limitation.hasOwnProperty('key')

View File

@ -10,7 +10,7 @@ import { genId } from '../../../misc/gen-id';
import { usersChart } from '../../../services/chart';
import { User } from '../../../models/entities/user';
import { UserKeypair } from '../../../models/entities/user-keypair';
import { toPuny } from '../../../misc/convert-host';
import { toPunyNullable } from '../../../misc/convert-host';
import { UserProfile } from '../../../models/entities/user-profile';
import { getConnection } from 'typeorm';
@ -36,7 +36,7 @@ export default async (ctx: Koa.BaseContext) => {
const username = body['username'];
const password = body['password'];
const host = process.env.NODE_ENV === 'test' ? (body['host'] || null) : null;
const host: string | null = process.env.NODE_ENV === 'test' ? (body['host'] || null) : null;
const invitationCode = body['invitationCode'];
if (instance && instance.disableRegistration) {
@ -96,7 +96,7 @@ export default async (ctx: Koa.BaseContext) => {
cipher: undefined,
passphrase: undefined
}
}, (e, publicKey, privateKey) =>
} as any, (e, publicKey, privateKey) =>
e ? j(e) : s([publicKey, privateKey])
));
@ -109,7 +109,7 @@ export default async (ctx: Koa.BaseContext) => {
createdAt: new Date(),
username: username,
usernameLower: username.toLowerCase(),
host: toPuny(host),
host: toPunyNullable(host),
token: secret,
isAdmin: config.autoAdmin && usersCount === 0,
}));

View File

@ -83,8 +83,6 @@ async function getOAuth2() {
}
router.get('/connect/discord', async ctx => {
if (redis == null) return;
if (!compareOrigin(ctx)) {
ctx.throw(400, 'invalid origin');
return;
@ -110,8 +108,6 @@ router.get('/connect/discord', async ctx => {
});
router.get('/signin/discord', async ctx => {
if (redis == null) return;
const sessid = uuid();
const params = {
@ -138,8 +134,6 @@ router.get('/signin/discord', async ctx => {
});
router.get('/dc/cb', async ctx => {
if (redis == null) return;
const userToken = getUserToken(ctx);
const oauth2 = await getOAuth2();
@ -160,7 +154,7 @@ router.get('/dc/cb', async ctx => {
}
const { redirect_uri, state } = await new Promise<any>((res, rej) => {
redis!.get(sessid, async (_, state) => {
redis.get(sessid, async (_, state) => {
res(JSON.parse(state));
});
});
@ -241,7 +235,7 @@ router.get('/dc/cb', async ctx => {
}
const { redirect_uri, state } = await new Promise<any>((res, rej) => {
redis!.get(userToken, async (_, state) => {
redis.get(userToken, async (_, state) => {
res(JSON.parse(state));
});
});

View File

@ -80,8 +80,6 @@ async function getOath2() {
}
router.get('/connect/github', async ctx => {
if (redis == null) return;
if (!compareOrigin(ctx)) {
ctx.throw(400, 'invalid origin');
return;
@ -106,8 +104,6 @@ router.get('/connect/github', async ctx => {
});
router.get('/signin/github', async ctx => {
if (redis == null) return;
const sessid = uuid();
const params = {
@ -133,8 +129,6 @@ router.get('/signin/github', async ctx => {
});
router.get('/gh/cb', async ctx => {
if (redis == null) return;
const userToken = getUserToken(ctx);
const oauth2 = await getOath2();
@ -155,7 +149,7 @@ router.get('/gh/cb', async ctx => {
}
const { redirect_uri, state } = await new Promise<any>((res, rej) => {
redis!.get(sessid, async (_, state) => {
redis.get(sessid, async (_, state) => {
res(JSON.parse(state));
});
});
@ -222,7 +216,7 @@ router.get('/gh/cb', async ctx => {
}
const { redirect_uri, state } = await new Promise<any>((res, rej) => {
redis!.get(userToken, async (_, state) => {
redis.get(userToken, async (_, state) => {
res(JSON.parse(state));
});
});

View File

@ -79,8 +79,6 @@ async function getTwAuth() {
}
router.get('/connect/twitter', async ctx => {
if (redis == null) return;
if (!compareOrigin(ctx)) {
ctx.throw(400, 'invalid origin');
return;
@ -99,8 +97,6 @@ router.get('/connect/twitter', async ctx => {
});
router.get('/signin/twitter', async ctx => {
if (redis == null) return;
const twAuth = await getTwAuth();
const twCtx = await twAuth!.begin();
@ -122,8 +118,6 @@ router.get('/signin/twitter', async ctx => {
});
router.get('/tw/cb', async ctx => {
if (redis == null) return;
const userToken = getUserToken(ctx);
const twAuth = await getTwAuth();
@ -137,7 +131,7 @@ router.get('/tw/cb', async ctx => {
}
const get = new Promise<any>((res, rej) => {
redis!.get(sessid, async (_, twCtx) => {
redis.get(sessid, async (_, twCtx) => {
res(twCtx);
});
});
@ -170,7 +164,7 @@ router.get('/tw/cb', async ctx => {
}
const get = new Promise<any>((res, rej) => {
redis!.get(userToken, async (_, twCtx) => {
redis.get(userToken, async (_, twCtx) => {
res(twCtx);
});
});

View File

@ -43,7 +43,7 @@ export default class extends Channel {
if (this.user == null) return;
const game = await ReversiGames.findOne(this.gameId!);
if (game == null) throw 'game not found';
if (game == null) throw new Error('game not found');
if (game.isStarted) return;
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
@ -67,7 +67,7 @@ export default class extends Channel {
if (this.user == null) return;
const game = await ReversiGames.findOne(this.gameId!);
if (game == null) throw 'game not found';
if (game == null) throw new Error('game not found');
if (game.isStarted) return;
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
@ -91,7 +91,7 @@ export default class extends Channel {
if (this.user == null) return;
const game = await ReversiGames.findOne(this.gameId!);
if (game == null) throw 'game not found';
if (game == null) throw new Error('game not found');
if (game.isStarted) return;
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
@ -135,7 +135,7 @@ export default class extends Channel {
if (this.user == null) return;
const game = await ReversiGames.findOne(this.gameId!);
if (game == null) throw 'game not found';
if (game == null) throw new Error('game not found');
if (game.isStarted) return;
@ -237,7 +237,7 @@ export default class extends Channel {
if (this.user == null) return;
const game = await ReversiGames.findOne(this.gameId!);
if (game == null) throw 'game not found';
if (game == null) throw new Error('game not found');
if (!game.isStarted) return;
if (game.isEnded) return;
@ -304,7 +304,7 @@ export default class extends Channel {
@autobind
private async check(crc32: string) {
const game = await ReversiGames.findOne(this.gameId!);
if (game == null) throw 'game not found';
if (game == null) throw new Error('game not found');
if (!game.isStarted) return;

View File

@ -1,7 +1,6 @@
import * as http from 'http';
import * as websocket from 'websocket';
import * as redis from 'redis';
import Xev from 'xev';
import MainStreamConnection from './stream';
import { ParsedUrlQuery } from 'querystring';
@ -23,28 +22,24 @@ module.exports = (server: http.Server) => {
let ev: EventEmitter;
if (config.redis) {
// Connect to Redis
const subscriber = redis.createClient(
config.redis.port, config.redis.host);
// Connect to Redis
const subscriber = redis.createClient(
config.redis.port, config.redis.host);
subscriber.subscribe('misskey');
subscriber.subscribe('misskey');
ev = new EventEmitter();
ev = new EventEmitter();
subscriber.on('message', async (_, data) => {
const obj = JSON.parse(data);
subscriber.on('message', async (_, data) => {
const obj = JSON.parse(data);
ev.emit(obj.channel, obj.message);
});
ev.emit(obj.channel, obj.message);
});
connection.once('close', () => {
subscriber.unsubscribe();
subscriber.quit();
});
} else {
ev = new Xev();
}
connection.once('close', () => {
subscriber.unsubscribe();
subscriber.quit();
});
const main = new MainStreamConnection(connection, ev, user, app);

View File

@ -201,13 +201,20 @@ async function upload(key: string, stream: fs.ReadStream | Buffer, type: string,
}
async function deleteOldFile(user: IRemoteUser) {
const oldFile = await DriveFiles.createQueryBuilder()
.select('file')
.where('file.id != :avatarId', { avatarId: user.avatarId })
.andWhere('file.id != :bannerId', { bannerId: user.bannerId })
.andWhere('file.userId = :userId', { userId: user.id })
.orderBy('file.id', 'DESC')
.getOne();
const q = DriveFiles.createQueryBuilder('file')
.where('file.userId = :userId', { userId: user.id });
if (user.avatarId) {
q.andWhere('file.id != :avatarId', { avatarId: user.avatarId });
}
if (user.bannerId) {
q.andWhere('file.id != :bannerId', { bannerId: user.bannerId })
}
q.orderBy('file.id', 'DESC');
const oldFile = await q.getOne();
if (oldFile) {
delFile(oldFile, true);
@ -297,7 +304,7 @@ export default async function(
// If usage limit exceeded
if (usage + size > driveCapacity) {
if (Users.isLocalUser(user)) {
throw 'no-free-space';
throw new Error('no-free-space');
} else {
// (アバターまたはバナーを含まず)最も古いファイルを削除する
deleteOldFile(user as IRemoteUser);
@ -316,7 +323,7 @@ export default async function(
userId: user.id
});
if (driveFolder == null) throw 'folder-not-found';
if (driveFolder == null) throw new Error('folder-not-found');
return driveFolder;
};

View File

@ -78,7 +78,7 @@ export async function removePinned(user: User, noteId: Note['id']) {
export async function deliverPinnedChange(userId: User['id'], noteId: Note['id'], isAddition: boolean) {
const user = await Users.findOne(userId);
if (user == null) throw 'user not found';
if (user == null) throw new Error('user not found');
if (!Users.isLocalUser(user)) return;

View File

@ -7,7 +7,7 @@ import { renderPerson } from '../../remote/activitypub/renderer/person';
export async function publishToFollowers(userId: User['id']) {
const user = await Users.findOne(userId);
if (user == null) throw 'user not found';
if (user == null) throw new Error('user not found');
const followers = await Followings.find({
followeeId: user.id

View File

@ -175,7 +175,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
}
if (data.visibility == 'specified') {
if (data.visibleUsers == null) throw 'invalid param';
if (data.visibleUsers == null) throw new Error('invalid param');
for (const u of data.visibleUsers) {
if (!mentionedUsers.some(x => x.id === u.id)) {
@ -214,7 +214,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
// 未読通知を作成
if (data.visibility == 'specified') {
if (data.visibleUsers == null) throw 'invalid param';
if (data.visibleUsers == null) throw new Error('invalid param');
for (const u of data.visibleUsers) {
insertNoteUnread(u, note, true);
@ -428,7 +428,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri
console.error(e);
throw 'something happened';
throw new Error('something happened');
}
}

View File

@ -7,10 +7,10 @@ import { Note } from '../../../models/entities/note';
export async function deliverQuestionUpdate(noteId: Note['id']) {
const note = await Notes.findOne(noteId);
if (note == null) throw 'note not found';
if (note == null) throw new Error('note not found');
const user = await Users.findOne(note.userId);
if (user == null) throw 'note not found';
if (user == null) throw new Error('note not found');
const followers = await Followings.find({
followeeId: user.id

View File

@ -8,9 +8,9 @@ import { genId } from '../../../misc/gen-id';
import { createNotification } from '../../create-notification';
export default async function(user: User, note: Note, choice: number) {
const poll = await Polls.findOne({ noteId: note.id });
const poll = await Polls.findOne(note.id);
if (poll == null) throw 'poll not found';
if (poll == null) throw new Error('poll not found');
// Check whether is valid choice
if (poll.choices[choice] == null) throw new Error('invalid choice param');
@ -40,7 +40,7 @@ export default async function(user: User, note: Note, choice: number) {
// Increment votes count
const index = choice + 1; // In SQL, array index is 1 based
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE "noteId" = '${poll.noteId}'`);
publishNoteStream(note.id, 'pollVoted', {
choice: choice,

View File

@ -16,7 +16,7 @@ import { NoteReaction } from '../../../models/entities/note-reaction';
import { createNotification } from '../../create-notification';
import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-error';
export default async (user: User, note: Note, reaction: string) => {
export default async (user: User, note: Note, reaction?: string) => {
// Myself
if (note.userId === user.id) {
throw new IdentifiableError('2d8e7297-1873-4c00-8404-792c68d7bef0', 'cannot react to my note');

View File

@ -1,33 +1,19 @@
import redis from '../db/redis';
import Xev from 'xev';
import { User } from '../models/entities/user';
import { Note } from '../models/entities/note';
import { UserList } from '../models/entities/user-list';
import { ReversiGame } from '../models/entities/games/reversi/game';
class Publisher {
private ev: Xev | null = null;
constructor() {
// Redisがインストールされてないときはプロセス間通信を使う
if (redis == null) {
this.ev = new Xev();
}
}
private publish = (channel: string, type: string | null, value?: any): void => {
const message = type == null ? value : value == null ?
{ type: type, body: null } :
{ type: type, body: value };
if (this.ev) {
this.ev.emit(channel, message);
} else {
redis!.publish('misskey', JSON.stringify({
channel: channel,
message: message
}));
}
redis.publish('misskey', JSON.stringify({
channel: channel,
message: message
}));
}
public publishMainStream = (userId: User['id'], type: string, value?: any): void => {

View File

@ -63,7 +63,9 @@ export async function updateHashtag(user: User, tag: string, isUserAttached = fa
}
}
q.execute();
if (Object.keys(set).length > 0) {
q.execute();
}
} else {
if (isUserAttached) {
Hashtags.save({

View File

@ -18,8 +18,8 @@ const args = process.argv.slice(2);
const name = args[0];
const url = args[1];
if (!name) throw 'require name';
if (!url) throw 'require url';
if (!name) throw new Error('require name');
if (!url) throw new Error('require url');
main(name, url).then(() => {
console.log('success');

View File

@ -15,7 +15,7 @@ async function main(username: string, headers?: string[]) {
usernameLower: username.toLowerCase(),
});
if (user == null) throw 'User not found';
if (user == null) throw new Error('User not found');
const history = await Signins.find({
userId: user.id