Refactoring, Clean up and bug fixes

This commit is contained in:
syuilo
2018-11-02 03:32:24 +09:00
parent b4b9e76c8d
commit 931bdc6aac
108 changed files with 1722 additions and 1539 deletions

View File

@ -1,4 +1,4 @@
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import getHostLower from '../../common/get-host-lower';
import Note, { packMany } from '../../../../models/note';
import User, { ILocalUser } from '../../../../models/user';
@ -11,100 +11,118 @@ export const meta = {
},
params: {
userId: $.type(ID).optional.note({
userId: {
validator: $.type(ID).optional,
transform: transform,
desc: {
'ja-JP': 'ユーザーID'
}
}),
},
username: $.str.optional.note({
username: {
validator: $.str.optional,
desc: {
'ja-JP': 'ユーザー名'
}
}),
},
host: $.str.optional.note({
}),
host: {
validator: $.str.optional,
},
includeReplies: $.bool.optional.note({
includeReplies: {
validator: $.bool.optional,
default: true,
desc: {
'ja-JP': 'リプライを含めるか否か'
}
}),
},
limit: $.num.optional.range(1, 100).note({
limit: {
validator: $.num.optional.range(1, 100),
default: 10,
desc: {
'ja-JP': '最大数'
}
}),
},
sinceId: $.type(ID).optional.note({
sinceId: {
validator: $.type(ID).optional,
transform: transform,
desc: {
'ja-JP': '指定すると、この投稿を基点としてより新しい投稿を取得します'
}
}),
},
untilId: $.type(ID).optional.note({
untilId: {
validator: $.type(ID).optional,
transform: transform,
desc: {
'ja-JP': '指定すると、この投稿を基点としてより古い投稿を取得します'
}
}),
},
sinceDate: $.num.optional.note({
sinceDate: {
validator: $.num.optional,
desc: {
'ja-JP': '指定した時間を基点としてより新しい投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
}
}),
},
untilDate: $.num.optional.note({
untilDate: {
validator: $.num.optional,
desc: {
'ja-JP': '指定した時間を基点としてより古い投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
}
}),
},
includeMyRenotes: $.bool.optional.note({
includeMyRenotes: {
validator: $.bool.optional,
default: true,
desc: {
'ja-JP': '自分の行ったRenoteを含めるかどうか'
}
}),
},
includeRenotedMyNotes: $.bool.optional.note({
includeRenotedMyNotes: {
validator: $.bool.optional,
default: true,
desc: {
'ja-JP': 'Renoteされた自分の投稿を含めるかどうか'
}
}),
},
includeLocalRenotes: $.bool.optional.note({
includeLocalRenotes: {
validator: $.bool.optional,
default: true,
desc: {
'ja-JP': 'Renoteされたローカルの投稿を含めるかどうか'
}
}),
},
withFiles: $.bool.optional.note({
withFiles: {
validator: $.bool.optional,
default: false,
desc: {
'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します'
}
}),
},
mediaOnly: $.bool.optional.note({
mediaOnly: {
validator: $.bool.optional,
default: false,
desc: {
'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
}
}),
},
fileType: $.arr($.str).optional.note({
fileType: {
validator: $.arr($.str).optional,
desc: {
'ja-JP': '指定された種類のファイルが添付された投稿のみを取得します'
}
}),
},
}
};
@ -121,7 +139,7 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
const q = ps.userId !== undefined
const q = ps.userId != null
? { _id: ps.userId }
: { usernameLower: ps.username.toLowerCase(), host: getHostLower(ps.host) } ;