mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-05 08:14:12 +09:00
Resolve #2623
This commit is contained in:
@ -2,6 +2,7 @@ import $ from 'cafy';
|
||||
import Vote from '../../../../../models/poll-vote';
|
||||
import Note, { pack } from '../../../../../models/note';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -10,16 +11,23 @@ export const meta = {
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
params: {
|
||||
limit: {
|
||||
validator: $.num.optional.range(1, 100),
|
||||
default: 10
|
||||
},
|
||||
|
||||
offset: {
|
||||
validator: $.num.optional.min(0),
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
// Get votes
|
||||
const votes = await Vote.find({
|
||||
@ -46,14 +54,14 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
$ne: null
|
||||
}
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
limit: ps.limit,
|
||||
skip: ps.offset,
|
||||
sort: {
|
||||
_id: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(notes.map(async note =>
|
||||
await pack(note, user, { detail: true }))));
|
||||
res(await Promise.all(notes.map(note => pack(note, user, {
|
||||
detail: true
|
||||
}))));
|
||||
});
|
||||
|
@ -4,19 +4,36 @@ import Note from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import { packMany } from '../../../../models/note';
|
||||
import es from '../../../../db/elasticsearch';
|
||||
import getParams from '../../get-params';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
'ja-JP': '投稿を検索します。',
|
||||
'en-US': 'Search notes.'
|
||||
},
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
query: {
|
||||
validator: $.str
|
||||
},
|
||||
|
||||
limit: {
|
||||
validator: $.num.optional.range(1, 100),
|
||||
default: 10
|
||||
},
|
||||
|
||||
offset: {
|
||||
validator: $.num.optional.min(0),
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||
// Get 'query' parameter
|
||||
const [query, queryError] = $.str.get(params.query);
|
||||
if (queryError) return rej('invalid query param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
if (es == null) return rej('searching not available');
|
||||
|
||||
@ -24,12 +41,12 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
|
||||
index: 'misskey',
|
||||
type: 'note',
|
||||
body: {
|
||||
size: limit,
|
||||
from: offset,
|
||||
size: ps.limit,
|
||||
from: ps.offset,
|
||||
query: {
|
||||
simple_query_string: {
|
||||
fields: ['text'],
|
||||
query: query,
|
||||
query: ps.query,
|
||||
default_operator: 'and'
|
||||
}
|
||||
},
|
||||
|
@ -1,76 +0,0 @@
|
||||
const ms = require('ms');
|
||||
import $ from 'cafy';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
'ja-JP': '人気の投稿の一覧を取得します。',
|
||||
'en-US': 'Get trend notes.'
|
||||
},
|
||||
|
||||
requireCredential: true
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'offset' parameter
|
||||
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
// Get 'reply' parameter
|
||||
const [reply, replyErr] = $.bool.optional.get(params.reply);
|
||||
if (replyErr) return rej('invalid reply param');
|
||||
|
||||
// Get 'renote' parameter
|
||||
const [renote, renoteErr] = $.bool.optional.get(params.renote);
|
||||
if (renoteErr) return rej('invalid renote param');
|
||||
|
||||
// Get 'media' parameter
|
||||
const [media, mediaErr] = $.bool.optional.get(params.media);
|
||||
if (mediaErr) return rej('invalid media param');
|
||||
|
||||
// Get 'poll' parameter
|
||||
const [poll, pollErr] = $.bool.optional.get(params.poll);
|
||||
if (pollErr) return rej('invalid poll param');
|
||||
|
||||
const query = {
|
||||
_id: { $gte: new Date(Date.now() - ms('1days')) },
|
||||
renoteCount: { $gt: 0 },
|
||||
'_user.host': null
|
||||
} as any;
|
||||
|
||||
if (reply != undefined) {
|
||||
query.replyId = reply ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (renote != undefined) {
|
||||
query.renoteId = renote ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (media != undefined) {
|
||||
query.fileIds = media ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (poll != undefined) {
|
||||
query.poll = poll ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
// Issue query
|
||||
const notes = await Note
|
||||
.find(query, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
sort: {
|
||||
renoteCount: -1,
|
||||
_id: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(notes.map(async note =>
|
||||
await pack(note, user, { detail: true }))));
|
||||
});
|
Reference in New Issue
Block a user