[mastodon-client] handle user & note URLs in search
This commit is contained in:
parent
770e8bdf6d
commit
42ac4510eb
2 changed files with 53 additions and 0 deletions
|
@ -42,6 +42,7 @@ export function apiSearchMastodon(router: Router): void {
|
||||||
!type || type === "hashtags"
|
!type || type === "hashtags"
|
||||||
? await client.search(query.q, "hashtags", query)
|
? await client.search(query.q, "hashtags", query)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
accounts:
|
accounts:
|
||||||
acct?.data?.accounts.map((account) => convertAccount(account)) ?? [],
|
acct?.data?.accounts.map((account) => convertAccount(account)) ?? [],
|
||||||
|
|
|
@ -2395,6 +2395,32 @@ export default class Misskey implements MegalodonInterface {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'accounts': {
|
case 'accounts': {
|
||||||
|
if (q.startsWith("http://") || q.startsWith("https://")) {
|
||||||
|
return this.client.post('/api/ap/show', {uri: q}).then(async res => {
|
||||||
|
if (res.status != 200 || res.data.type != 'User') {
|
||||||
|
res.status = 200;
|
||||||
|
res.statusText = "OK";
|
||||||
|
res.data = {
|
||||||
|
accounts: [],
|
||||||
|
statuses: [],
|
||||||
|
hashtags: []
|
||||||
|
};
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const account = await this.converter.userDetail(res.data.object as MisskeyAPI.Entity.UserDetail, this.baseUrlToHost(this.baseUrl));
|
||||||
|
|
||||||
|
return {
|
||||||
|
...res,
|
||||||
|
data: {
|
||||||
|
accounts: options?.max_id && options?.max_id >= account.id ? [] : [account],
|
||||||
|
statuses: [],
|
||||||
|
hashtags: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
let params = {
|
let params = {
|
||||||
query: q
|
query: q
|
||||||
}
|
}
|
||||||
|
@ -2468,6 +2494,32 @@ export default class Misskey implements MegalodonInterface {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
case 'statuses': {
|
case 'statuses': {
|
||||||
|
if (q.startsWith("http://") || q.startsWith("https://")) {
|
||||||
|
return this.client.post('/api/ap/show', {uri: q}).then(async res => {
|
||||||
|
if (res.status != 200 || res.data.type != 'Note') {
|
||||||
|
res.status = 200;
|
||||||
|
res.statusText = "OK";
|
||||||
|
res.data = {
|
||||||
|
accounts: [],
|
||||||
|
statuses: [],
|
||||||
|
hashtags: []
|
||||||
|
};
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
const post = await this.noteWithDetails(res.data.object as MisskeyAPI.Entity.Note, this.baseUrlToHost(this.baseUrl), accountCache);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...res,
|
||||||
|
data: {
|
||||||
|
accounts: [],
|
||||||
|
statuses: options?.max_id && options.max_id >= post.id ? [] : [post],
|
||||||
|
hashtags: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
let params = {
|
let params = {
|
||||||
query: q
|
query: q
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue