Compare commits
17 Commits
11.0.0-bet
...
11.0.0-bet
Author | SHA1 | Date | |
---|---|---|---|
![]() |
96099ffe98 | ||
![]() |
ae16b45c11 | ||
![]() |
cfee87d3ef | ||
![]() |
5fcf5bc635 | ||
![]() |
14bcb813cc | ||
![]() |
6af19794b6 | ||
![]() |
8316186695 | ||
![]() |
85d3023cd5 | ||
![]() |
78414dee29 | ||
![]() |
084135141f | ||
![]() |
467a21f028 | ||
![]() |
6e284c44d6 | ||
![]() |
daf9a449e8 | ||
![]() |
960268fd33 | ||
![]() |
8c331da315 | ||
![]() |
b0d626d862 | ||
![]() |
a51fbd7316 |
@@ -130,6 +130,40 @@ const users = userIds.length > 0 ? await Users.find({
|
|||||||
}) : [];
|
}) : [];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 配列のインデックス in SQL
|
||||||
|
SQLでは配列のインデックスは**1始まり**。
|
||||||
|
`[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く
|
||||||
|
|
||||||
### `undefined`にご用心
|
### `undefined`にご用心
|
||||||
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
||||||
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
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';
|
||||||
|
// }
|
||||||
|
// の糖衣構文のような扱いです
|
||||||
|
```
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "11.0.0-beta.5",
|
"version": "11.0.0-beta.8",
|
||||||
"codename": "daybreak",
|
"codename": "daybreak",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@@ -24,9 +24,14 @@ import { UserPublickey } from './models/entities/user-publickey';
|
|||||||
import { UserKeypair } from './models/entities/user-keypair';
|
import { UserKeypair } from './models/entities/user-keypair';
|
||||||
import { extractPublic } from './crypto_key';
|
import { extractPublic } from './crypto_key';
|
||||||
import { Emoji } from './models/entities/emoji';
|
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';
|
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 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;
|
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
|
||||||
|
|
||||||
|
@@ -19,3 +19,8 @@ export function extractDbHost(uri: string) {
|
|||||||
export function toPuny(host: string) {
|
export function toPuny(host: string) {
|
||||||
return toASCII(host.toLowerCase());
|
return toASCII(host.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toPunyNullable(host: string | null | undefined): string | null {
|
||||||
|
if (host == null) return null;
|
||||||
|
return toASCII(host.toLowerCase());
|
||||||
|
}
|
||||||
|
@@ -148,7 +148,7 @@ export class NoteRepository extends Repository<Note> {
|
|||||||
return reaction.reaction;
|
return reaction.reaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = note.text;
|
let text = note.text;
|
||||||
@@ -162,15 +162,15 @@ export class NoteRepository extends Repository<Note> {
|
|||||||
const packed = await rap({
|
const packed = await rap({
|
||||||
id: note.id,
|
id: note.id,
|
||||||
createdAt: note.createdAt,
|
createdAt: note.createdAt,
|
||||||
app: note.appId ? Apps.pack(note.appId) : null,
|
app: note.appId ? Apps.pack(note.appId) : undefined,
|
||||||
userId: note.userId,
|
userId: note.userId,
|
||||||
user: Users.pack(note.user || note.userId, meId),
|
user: Users.pack(note.user || note.userId, meId),
|
||||||
text: text,
|
text: text,
|
||||||
cw: note.cw,
|
cw: note.cw,
|
||||||
visibility: note.visibility,
|
visibility: note.visibility,
|
||||||
localOnly: note.localOnly,
|
localOnly: note.localOnly || undefined,
|
||||||
visibleUserIds: note.visibleUserIds,
|
visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined,
|
||||||
viaMobile: note.viaMobile,
|
viaMobile: note.viaMobile || undefined,
|
||||||
renoteCount: note.renoteCount,
|
renoteCount: note.renoteCount,
|
||||||
repliesCount: note.repliesCount,
|
repliesCount: note.repliesCount,
|
||||||
reactions: note.reactions,
|
reactions: note.reactions,
|
||||||
@@ -188,13 +188,13 @@ export class NoteRepository extends Repository<Note> {
|
|||||||
...(opts.detail ? {
|
...(opts.detail ? {
|
||||||
reply: note.replyId ? this.pack(note.replyId, meId, {
|
reply: note.replyId ? this.pack(note.replyId, meId, {
|
||||||
detail: false
|
detail: false
|
||||||
}) : null,
|
}) : undefined,
|
||||||
|
|
||||||
renote: note.renoteId ? this.pack(note.renoteId, meId, {
|
renote: note.renoteId ? this.pack(note.renoteId, meId, {
|
||||||
detail: true
|
detail: true
|
||||||
}) : null,
|
}) : undefined,
|
||||||
|
|
||||||
poll: note.hasPoll ? populatePoll() : null,
|
poll: note.hasPoll ? populatePoll() : undefined,
|
||||||
|
|
||||||
...(meId ? {
|
...(meId ? {
|
||||||
myReaction: populateMyReaction()
|
myReaction: populateMyReaction()
|
||||||
|
@@ -89,13 +89,11 @@ export class UserRepository extends Repository<User> {
|
|||||||
username: user.username,
|
username: user.username,
|
||||||
host: user.host,
|
host: user.host,
|
||||||
avatarUrl: user.avatarUrl,
|
avatarUrl: user.avatarUrl,
|
||||||
bannerUrl: user.bannerUrl,
|
|
||||||
avatarColor: user.avatarColor,
|
avatarColor: user.avatarColor,
|
||||||
bannerColor: user.bannerColor,
|
isAdmin: user.isAdmin || undefined,
|
||||||
isAdmin: user.isAdmin,
|
isBot: user.isBot || undefined,
|
||||||
isBot: user.isBot,
|
isCat: user.isCat || undefined,
|
||||||
isCat: user.isCat,
|
isVerified: user.isVerified || undefined,
|
||||||
isVerified: user.isVerified,
|
|
||||||
|
|
||||||
// カスタム絵文字添付
|
// カスタム絵文字添付
|
||||||
emojis: user.emojis.length > 0 ? Emojis.find({
|
emojis: user.emojis.length > 0 ? Emojis.find({
|
||||||
@@ -121,6 +119,8 @@ export class UserRepository extends Repository<User> {
|
|||||||
url: profile!.url,
|
url: profile!.url,
|
||||||
createdAt: user.createdAt,
|
createdAt: user.createdAt,
|
||||||
updatedAt: user.updatedAt,
|
updatedAt: user.updatedAt,
|
||||||
|
bannerUrl: user.bannerUrl,
|
||||||
|
bannerColor: user.bannerColor,
|
||||||
description: profile!.description,
|
description: profile!.description,
|
||||||
location: profile!.location,
|
location: profile!.location,
|
||||||
birthday: profile!.birthday,
|
birthday: profile!.birthday,
|
||||||
|
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* 値が null または undefined の場合はエラーを発生させ、そうでない場合は値をそのまま返します
|
||||||
|
*/
|
||||||
export function ensure<T>(x: T): NonNullable<T> {
|
export function ensure<T>(x: T): NonNullable<T> {
|
||||||
if (x == null) {
|
if (x == null) {
|
||||||
throw 'ぬるぽ';
|
throw 'ぬるぽ';
|
||||||
|
@@ -12,7 +12,7 @@ import { Instances, Users, UserPublickeys } from '../../models';
|
|||||||
import { instanceChart } from '../../services/chart';
|
import { instanceChart } from '../../services/chart';
|
||||||
import { UserPublickey } from '../../models/entities/user-publickey';
|
import { UserPublickey } from '../../models/entities/user-publickey';
|
||||||
import fetchMeta from '../../misc/fetch-meta';
|
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 { validActor } from '../../remote/activitypub/type';
|
||||||
import { ensure } from '../../prelude/ensure';
|
import { ensure } from '../../prelude/ensure';
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
|||||||
|
|
||||||
if (keyIdLower.startsWith('acct:')) {
|
if (keyIdLower.startsWith('acct:')) {
|
||||||
const acct = parseAcct(keyIdLower.slice('acct:'.length));
|
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);
|
const username = toPuny(acct.username);
|
||||||
|
|
||||||
if (host === null) {
|
if (host === null) {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { Emojis } from '../../../../../models';
|
import { Emojis } from '../../../../../models';
|
||||||
import { toPuny } from '../../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@@ -23,7 +23,7 @@ export const meta = {
|
|||||||
|
|
||||||
export default define(meta, async (ps) => {
|
export default define(meta, async (ps) => {
|
||||||
const emojis = await Emojis.find({
|
const emojis = await Emojis.find({
|
||||||
host: ps.host ? toPuny(ps.host) : null
|
host: toPunyNullable(ps.host)
|
||||||
});
|
});
|
||||||
|
|
||||||
return emojis.map(e => ({
|
return emojis.map(e => ({
|
||||||
|
@@ -34,7 +34,7 @@ export default define(meta, async (ps) => {
|
|||||||
|
|
||||||
if (ps.domain) {
|
if (ps.domain) {
|
||||||
const whiteDomains = ps.domain.split(' ').filter(x => !x.startsWith('-'));
|
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) {
|
if (whiteDomains.length > 0) {
|
||||||
query.andWhere(new Brackets(qb => {
|
query.andWhere(new Brackets(qb => {
|
||||||
@@ -53,11 +53,17 @@ export default define(meta, async (ps) => {
|
|||||||
if (blackDomains.length > 0) {
|
if (blackDomains.length > 0) {
|
||||||
query.andWhere(new Brackets(qb => {
|
query.andWhere(new Brackets(qb => {
|
||||||
for (const blackDomain of blackDomains) {
|
for (const blackDomain of blackDomains) {
|
||||||
|
const subDomains = blackDomain.split('.');
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const subDomain of blackDomain.split('.')) {
|
for (const subDomain of subDomains) {
|
||||||
const p = `blackSubDomain_${subDomain}_${i}`;
|
const p = `blackSubDomain_${subDomain}_${i}`;
|
||||||
// SQL is 1 based, so we need '+ 1'
|
if (i === subDomains.length - 1) {
|
||||||
qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain });
|
// 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++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,12 +76,12 @@ export default define(meta, async (ps, user) => {
|
|||||||
user: meta.smtpUser,
|
user: meta.smtpUser,
|
||||||
pass: meta.smtpPass
|
pass: meta.smtpPass
|
||||||
} : undefined
|
} : undefined
|
||||||
});
|
} as any);
|
||||||
|
|
||||||
const link = `${config.url}/verify-email/${code}`;
|
const link = `${config.url}/verify-email/${code}`;
|
||||||
|
|
||||||
transporter.sendMail({
|
transporter.sendMail({
|
||||||
from: meta.email,
|
from: meta.email!,
|
||||||
to: ps.email,
|
to: ps.email,
|
||||||
subject: meta.name || 'Misskey',
|
subject: meta.name || 'Misskey',
|
||||||
text: `To verify email, please click this link: ${link}`
|
text: `To verify email, please click this link: ${link}`
|
||||||
|
@@ -4,7 +4,7 @@ import define from '../../define';
|
|||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { Users, Followings } from '../../../../models';
|
import { Users, Followings } from '../../../../models';
|
||||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||||
import { toPuny } from '../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@@ -66,7 +66,7 @@ export const meta = {
|
|||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
const user = await Users.findOne(ps.userId != null
|
const user = await Users.findOne(ps.userId != null
|
||||||
? { id: ps.userId }
|
? { id: ps.userId }
|
||||||
: { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) });
|
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
throw new ApiError(meta.errors.noSuchUser);
|
||||||
|
@@ -4,7 +4,7 @@ import define from '../../define';
|
|||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { Users, Followings } from '../../../../models';
|
import { Users, Followings } from '../../../../models';
|
||||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||||
import { toPuny } from '../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@@ -66,7 +66,7 @@ export const meta = {
|
|||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
const user = await Users.findOne(ps.userId != null
|
const user = await Users.findOne(ps.userId != null
|
||||||
? { id: ps.userId }
|
? { id: ps.userId }
|
||||||
: { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) });
|
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
throw new ApiError(meta.errors.noSuchUser);
|
||||||
|
@@ -10,7 +10,7 @@ import { genId } from '../../../misc/gen-id';
|
|||||||
import { usersChart } from '../../../services/chart';
|
import { usersChart } from '../../../services/chart';
|
||||||
import { User } from '../../../models/entities/user';
|
import { User } from '../../../models/entities/user';
|
||||||
import { UserKeypair } from '../../../models/entities/user-keypair';
|
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 { UserProfile } from '../../../models/entities/user-profile';
|
||||||
import { getConnection } from 'typeorm';
|
import { getConnection } from 'typeorm';
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ export default async (ctx: Koa.BaseContext) => {
|
|||||||
|
|
||||||
const username = body['username'];
|
const username = body['username'];
|
||||||
const password = body['password'];
|
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'];
|
const invitationCode = body['invitationCode'];
|
||||||
|
|
||||||
if (instance && instance.disableRegistration) {
|
if (instance && instance.disableRegistration) {
|
||||||
@@ -96,7 +96,7 @@ export default async (ctx: Koa.BaseContext) => {
|
|||||||
cipher: undefined,
|
cipher: undefined,
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
}
|
}
|
||||||
}, (e, publicKey, privateKey) =>
|
} as any, (e, publicKey, privateKey) =>
|
||||||
e ? j(e) : s([publicKey, privateKey])
|
e ? j(e) : s([publicKey, privateKey])
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ export default async (ctx: Koa.BaseContext) => {
|
|||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
username: username,
|
username: username,
|
||||||
usernameLower: username.toLowerCase(),
|
usernameLower: username.toLowerCase(),
|
||||||
host: toPuny(host),
|
host: toPunyNullable(host),
|
||||||
token: secret,
|
token: secret,
|
||||||
isAdmin: config.autoAdmin && usersCount === 0,
|
isAdmin: config.autoAdmin && usersCount === 0,
|
||||||
}));
|
}));
|
||||||
|
Reference in New Issue
Block a user