Compare commits

...

25 Commits

Author SHA1 Message Date
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
37 changed files with 185 additions and 236 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

@ -7,7 +7,8 @@ If you encounter any problems with updating, please try the following:
11.0.0
----------
* データベースがMongoDBからPostgreSQLに変更されました
* **データベースが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

@ -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.7",
"version": "11.0.0-beta.12",
"codename": "daybreak",
"repository": {
"type": "git",

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

@ -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,11 +10,8 @@ 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';

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 getRandom() {
return counter.toString(36).padStart(2, '0').substr(2);
}
export function genAid(date: Date): string {
counter++;
return getTime(date.getTime()) + getRandom();
}

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

@ -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

@ -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}`, renderError(err)))
.on('error', (error) => deliverLogger.error(`error ${error}`, renderError(error)))
.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'}`, renderError(err)))
.on('error', (error) => inboxLogger.error(`error ${error}`, renderError(error)))
.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

@ -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 '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()) {

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

@ -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

@ -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

@ -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';
@ -109,7 +109,7 @@ export default async (ctx: Koa.BaseContext) => {
createdAt: new Date(),
username: username,
usernameLower: username.toLowerCase(),
host: host ? toPuny(host) : null,
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

@ -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,7 +22,6 @@ module.exports = (server: http.Server) => {
let ev: EventEmitter;
if (config.redis) {
// Connect to Redis
const subscriber = redis.createClient(
config.redis.port, config.redis.host);
@ -42,9 +40,6 @@ module.exports = (server: http.Server) => {
subscriber.unsubscribe();
subscriber.quit();
});
} else {
ev = new Xev();
}
const main = new MainStreamConnection(connection, ev, user, app);

View File

@ -8,7 +8,7 @@ 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';
@ -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,34 +1,20 @@
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({
redis.publish('misskey', JSON.stringify({
channel: channel,
message: message
}));
}
}
public publishMainStream = (userId: User['id'], type: string, value?: any): void => {
this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value);

View File

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