✌️
This commit is contained in:
parent
b2223c19e1
commit
aff76a57c0
3 changed files with 39 additions and 3 deletions
|
@ -46,6 +46,10 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
const [media = null, mediaErr] = $(params.media).optional.nullable.boolean().$;
|
const [media = null, mediaErr] = $(params.media).optional.nullable.boolean().$;
|
||||||
if (mediaErr) return rej('invalid media param');
|
if (mediaErr) return rej('invalid media param');
|
||||||
|
|
||||||
|
// Get 'poll' parameter
|
||||||
|
const [poll = null, pollErr] = $(params.poll).optional.nullable.boolean().$;
|
||||||
|
if (pollErr) return rej('invalid poll param');
|
||||||
|
|
||||||
// Get 'since_date' parameter
|
// Get 'since_date' parameter
|
||||||
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
|
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
|
||||||
if (sinceDateErr) throw 'invalid since_date param';
|
if (sinceDateErr) throw 'invalid since_date param';
|
||||||
|
@ -76,11 +80,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
// If Elasticsearch is available, search by it
|
// If Elasticsearch is available, search by it
|
||||||
// If not, search by MongoDB
|
// If not, search by MongoDB
|
||||||
(config.elasticsearch.enable ? byElasticsearch : byNative)
|
(config.elasticsearch.enable ? byElasticsearch : byNative)
|
||||||
(res, rej, me, text, user, following, reply, repost, media, sinceDate, untilDate, offset, limit);
|
(res, rej, me, text, user, following, reply, repost, media, poll, sinceDate, untilDate, offset, limit);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Search by MongoDB
|
// Search by MongoDB
|
||||||
async function byNative(res, rej, me, text, userId, following, reply, repost, media, sinceDate, untilDate, offset, max) {
|
async function byNative(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
|
||||||
const q: any = {
|
const q: any = {
|
||||||
$and: []
|
$and: []
|
||||||
};
|
};
|
||||||
|
@ -175,6 +179,27 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (poll != null) {
|
||||||
|
if (poll) {
|
||||||
|
push({
|
||||||
|
poll: {
|
||||||
|
$exists: true,
|
||||||
|
$ne: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
push({
|
||||||
|
$or: [{
|
||||||
|
poll: {
|
||||||
|
$exists: false
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
poll: null
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sinceDate) {
|
if (sinceDate) {
|
||||||
push({
|
push({
|
||||||
created_at: {
|
created_at: {
|
||||||
|
@ -207,7 +232,7 @@ async function byNative(res, rej, me, text, userId, following, reply, repost, me
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search by Elasticsearch
|
// Search by Elasticsearch
|
||||||
async function byElasticsearch(res, rej, me, text, userId, following, reply, repost, media, sinceDate, untilDate, offset, max) {
|
async function byElasticsearch(res, rej, me, text, userId, following, reply, repost, media, poll, sinceDate, untilDate, offset, max) {
|
||||||
const es = require('../../db/elasticsearch');
|
const es = require('../../db/elasticsearch');
|
||||||
|
|
||||||
es.search({
|
es.search({
|
||||||
|
|
|
@ -22,6 +22,9 @@ export default function(qs: string) {
|
||||||
case 'media':
|
case 'media':
|
||||||
q['media'] = value == 'null' ? null : value == 'true';
|
q['media'] = value == 'null' ? null : value == 'true';
|
||||||
break;
|
break;
|
||||||
|
case 'poll':
|
||||||
|
q['poll'] = value == 'null' ? null : value == 'true';
|
||||||
|
break;
|
||||||
case 'until':
|
case 'until':
|
||||||
case 'since':
|
case 'since':
|
||||||
// YYYY-MM-DD
|
// YYYY-MM-DD
|
||||||
|
|
|
@ -53,6 +53,14 @@ section
|
||||||
| false ... メディアが添付されていない投稿に限定。
|
| false ... メディアが添付されていない投稿に限定。
|
||||||
br
|
br
|
||||||
| null ... 特に限定しない(デフォルト)
|
| null ... 特に限定しない(デフォルト)
|
||||||
|
tr
|
||||||
|
td poll
|
||||||
|
td
|
||||||
|
| true ... 投票が添付されている投稿に限定。
|
||||||
|
br
|
||||||
|
| false ... 投票が添付されていない投稿に限定。
|
||||||
|
br
|
||||||
|
| null ... 特に限定しない(デフォルト)
|
||||||
tr
|
tr
|
||||||
td until
|
td until
|
||||||
td 上限の日時。(YYYY-MM-DD)
|
td 上限の日時。(YYYY-MM-DD)
|
||||||
|
|
Loading…
Reference in a new issue