v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
@@ -113,23 +113,6 @@ export const meta = {
|
||||
}
|
||||
},
|
||||
|
||||
geo: {
|
||||
validator: $.optional.nullable.obj({
|
||||
coordinates: $.arr().length(2)
|
||||
.item(0, $.num.range(-180, 180))
|
||||
.item(1, $.num.range(-90, 90)),
|
||||
altitude: $.nullable.num,
|
||||
accuracy: $.nullable.num,
|
||||
altitudeAccuracy: $.nullable.num,
|
||||
heading: $.nullable.num.range(0, 360),
|
||||
speed: $.nullable.num
|
||||
}).strict(),
|
||||
desc: {
|
||||
'ja-JP': '位置情報'
|
||||
},
|
||||
ref: 'geo'
|
||||
},
|
||||
|
||||
fileIds: {
|
||||
validator: $.optional.arr($.type(ID)).unique().range(1, 4),
|
||||
desc: {
|
||||
@@ -308,7 +291,6 @@ export default define(meta, async (ps, user, app) => {
|
||||
apMentions: ps.noExtractMentions ? [] : undefined,
|
||||
apHashtags: ps.noExtractHashtags ? [] : undefined,
|
||||
apEmojis: ps.noExtractEmojis ? [] : undefined,
|
||||
geo: ps.geo
|
||||
});
|
||||
|
||||
return {
|
||||
|
@@ -15,12 +15,17 @@ export const meta = {
|
||||
|
||||
params: {
|
||||
limit: {
|
||||
validator: $.optional.num.range(1, 30),
|
||||
validator: $.optional.num.range(1, 100),
|
||||
default: 10,
|
||||
desc: {
|
||||
'ja-JP': '最大数'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
offset: {
|
||||
validator: $.optional.num.min(0),
|
||||
default: 0
|
||||
},
|
||||
},
|
||||
|
||||
res: {
|
||||
@@ -35,6 +40,7 @@ export const meta = {
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
const max = 30;
|
||||
const day = 1000 * 60 * 60 * 24 * 3; // 3日前まで
|
||||
|
||||
const query = Notes.createQueryBuilder('note')
|
||||
@@ -46,7 +52,14 @@ export default define(meta, async (ps, user) => {
|
||||
|
||||
if (user) generateMuteQuery(query, user);
|
||||
|
||||
const notes = await query.orderBy('note.score', 'DESC').take(ps.limit!).getMany();
|
||||
let notes = await query
|
||||
.orderBy('note.score', 'DESC')
|
||||
.take(max)
|
||||
.getMany();
|
||||
|
||||
notes.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
||||
|
||||
notes = notes.slice(ps.offset, ps.offset + ps.limit);
|
||||
|
||||
return await Notes.packMany(notes, user);
|
||||
});
|
||||
|
@@ -1,11 +1,13 @@
|
||||
import $ from 'cafy';
|
||||
import es from '../../../../db/elasticsearch';
|
||||
import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
import { Notes } from '../../../../models';
|
||||
import { In } from 'typeorm';
|
||||
import { ID } from '../../../../misc/cafy-id';
|
||||
import config from '../../../../config';
|
||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
|
||||
import { generateMuteQuery } from '../../common/generate-mute-query';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@@ -22,16 +24,19 @@ export const meta = {
|
||||
validator: $.str
|
||||
},
|
||||
|
||||
sinceId: {
|
||||
validator: $.optional.type(ID),
|
||||
},
|
||||
|
||||
untilId: {
|
||||
validator: $.optional.type(ID),
|
||||
},
|
||||
|
||||
limit: {
|
||||
validator: $.optional.num.range(1, 100),
|
||||
default: 10
|
||||
},
|
||||
|
||||
offset: {
|
||||
validator: $.optional.num.min(0),
|
||||
default: 0
|
||||
},
|
||||
|
||||
host: {
|
||||
validator: $.optional.nullable.str,
|
||||
default: undefined
|
||||
@@ -54,74 +59,80 @@ export const meta = {
|
||||
},
|
||||
|
||||
errors: {
|
||||
searchingNotAvailable: {
|
||||
message: 'Searching not available.',
|
||||
code: 'SEARCHING_NOT_AVAILABLE',
|
||||
id: '7ee9c119-16a1-479f-a6fd-6fab00ed946f'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, me) => {
|
||||
if (es == null) throw new ApiError(meta.errors.searchingNotAvailable);
|
||||
if (es == null) {
|
||||
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
||||
.andWhere('note.text ILIKE :q', { q: `%${ps.query}%` })
|
||||
.leftJoinAndSelect('note.user', 'user');
|
||||
|
||||
const userQuery = ps.userId != null ? [{
|
||||
term: {
|
||||
userId: ps.userId
|
||||
}
|
||||
}] : [];
|
||||
generateVisibilityQuery(query, me);
|
||||
if (me) generateMuteQuery(query, me);
|
||||
|
||||
const hostQuery = ps.userId == null ?
|
||||
ps.host === null ? [{
|
||||
bool: {
|
||||
must_not: {
|
||||
exists: {
|
||||
field: 'userHost'
|
||||
const notes = await query.take(ps.limit!).getMany();
|
||||
|
||||
return await Notes.packMany(notes, me);
|
||||
} else {
|
||||
const userQuery = ps.userId != null ? [{
|
||||
term: {
|
||||
userId: ps.userId
|
||||
}
|
||||
}] : [];
|
||||
|
||||
const hostQuery = ps.userId == null ?
|
||||
ps.host === null ? [{
|
||||
bool: {
|
||||
must_not: {
|
||||
exists: {
|
||||
field: 'userHost'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}] : ps.host !== undefined ? [{
|
||||
term: {
|
||||
userHost: ps.host
|
||||
}
|
||||
}] : []
|
||||
: [];
|
||||
|
||||
const result = await es.search({
|
||||
index: config.elasticsearch.index || 'misskey_note',
|
||||
body: {
|
||||
size: ps.limit!,
|
||||
from: ps.offset,
|
||||
query: {
|
||||
bool: {
|
||||
must: [{
|
||||
simple_query_string: {
|
||||
fields: ['text'],
|
||||
query: ps.query.toLowerCase(),
|
||||
default_operator: 'and'
|
||||
},
|
||||
}, ...hostQuery, ...userQuery]
|
||||
}] : ps.host !== undefined ? [{
|
||||
term: {
|
||||
userHost: ps.host
|
||||
}
|
||||
}] : []
|
||||
: [];
|
||||
|
||||
const result = await es.search({
|
||||
index: config.elasticsearch.index || 'misskey_note',
|
||||
body: {
|
||||
size: ps.limit!,
|
||||
from: ps.offset,
|
||||
query: {
|
||||
bool: {
|
||||
must: [{
|
||||
simple_query_string: {
|
||||
fields: ['text'],
|
||||
query: ps.query.toLowerCase(),
|
||||
default_operator: 'and'
|
||||
},
|
||||
}, ...hostQuery, ...userQuery]
|
||||
}
|
||||
},
|
||||
sort: [{
|
||||
_doc: 'desc'
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
const hits = result.body.hits.hits.map((hit: any) => hit._id);
|
||||
|
||||
if (hits.length === 0) return [];
|
||||
|
||||
// Fetch found notes
|
||||
const notes = await Notes.find({
|
||||
where: {
|
||||
id: In(hits)
|
||||
},
|
||||
sort: [{
|
||||
_doc: 'desc'
|
||||
}]
|
||||
}
|
||||
});
|
||||
order: {
|
||||
id: -1
|
||||
}
|
||||
});
|
||||
|
||||
const hits = result.body.hits.hits.map((hit: any) => hit._id);
|
||||
|
||||
if (hits.length === 0) return [];
|
||||
|
||||
// Fetch found notes
|
||||
const notes = await Notes.find({
|
||||
where: {
|
||||
id: In(hits)
|
||||
},
|
||||
order: {
|
||||
id: -1
|
||||
}
|
||||
});
|
||||
|
||||
return await Notes.packMany(notes, me);
|
||||
return await Notes.packMany(notes, me);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user