mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 03:17:38 -07:00
[mastodon-client] GET /v1/custom_emoji
This commit is contained in:
parent
5f0d140bbe
commit
fb7713c424
3 changed files with 33 additions and 10 deletions
|
@ -7,7 +7,7 @@ export class EmojiConverter {
|
|||
static_url: e.url,
|
||||
url: e.url,
|
||||
visible_in_picker: true,
|
||||
category: "unknown", //FIXME - e.category
|
||||
category: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,11 @@ import { convertId, IdType } from "@/misc/convert-id.js";
|
|||
|
||||
export function setupEndpointsMisc(router: Router): void {
|
||||
router.get("/v1/custom_emojis", async (ctx) => {
|
||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||
const accessTokens = ctx.request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
try {
|
||||
const data = await client.getInstanceCustomEmojis();
|
||||
ctx.body = data.data;
|
||||
ctx.body = await MiscHelpers.getCustomEmoji();
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
ctx.status = 401;
|
||||
ctx.body = e.response.data;
|
||||
ctx.status = 500;
|
||||
ctx.body = { error: e.message };
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import config from "@/config/index.js";
|
||||
import { FILE_TYPE_BROWSERSAFE, MAX_NOTE_TEXT_LENGTH } from "@/const.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { AnnouncementReads, Announcements, Instances, Notes, Users } from "@/models/index.js";
|
||||
import { AnnouncementReads, Announcements, Emojis, Instances, Notes, Users } from "@/models/index.js";
|
||||
import { IsNull } from "typeorm";
|
||||
import { awaitAll } from "@/prelude/await-all.js";
|
||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||
|
@ -16,6 +16,8 @@ import { UserHelpers } from "@/server/api/mastodon/helpers/user.js";
|
|||
import { generateMutedUserQueryForUsers } from "@/server/api/common/generate-muted-user-query.js";
|
||||
import { generateBlockQueryForUsers } from "@/server/api/common/generate-block-query.js";
|
||||
import { uniqBy } from "@/prelude/array.js";
|
||||
import { EmojiConverter } from "@/server/api/mastodon/converters/emoji.js";
|
||||
import { populateEmojis } from "@/misc/populate-emojis.js";
|
||||
|
||||
export class MiscHelpers {
|
||||
public static async getInstance(): Promise<MastodonEntity.Instance> {
|
||||
|
@ -175,4 +177,30 @@ export class MiscHelpers {
|
|||
|
||||
return Promise.all(results).then(p => uniqBy(p.flat(), (x: MastodonEntity.SuggestedAccount) => x.account.id).slice(0, limit));
|
||||
}
|
||||
|
||||
public static async getCustomEmoji() {
|
||||
return Emojis.find({
|
||||
where: {
|
||||
host: IsNull(),
|
||||
},
|
||||
order: {
|
||||
category: "ASC",
|
||||
name: "ASC",
|
||||
},
|
||||
cache: {
|
||||
id: "meta_emojis",
|
||||
milliseconds: 3600000, // 1 hour
|
||||
}}
|
||||
)
|
||||
.then(dbRes => populateEmojis(dbRes.map(p => p.name), null)
|
||||
.then(p => p.map(x => EmojiConverter.encode(x))
|
||||
.map(x => {
|
||||
return {
|
||||
...x,
|
||||
category: dbRes.find(y => y.name === x.shortcode)?.category ?? null
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue