jointrashposs/assets/js/mi/io-meta.ts
かっこかり 1f2b1aa58b
(Add) Tools: MFM Preview (#2)
* wip

* (add) mfm preview

* (fix) iroiro

* (Fix) build error

* (fix) something
2023-09-26 21:57:26 +09:00

33 lines
1.0 KiB
TypeScript

import * as Misskey from 'misskey-js';
export const getIOMeta = async (): Promise<Misskey.entities.LiteInstanceMetadata> => {
if (!process.client) {
return {};
}
if (!sessionStorage.getItem('miHub_io_meta')) {
const meta = await fetch('https://misskey.io/api/meta');
const metaText = await meta.text();
sessionStorage.setItem('miHub_io_meta', metaText);
return JSON.parse(metaText);
} else {
return JSON.parse(sessionStorage.getItem('miHub_io_meta') ?? '');
}
}
export const getIOEmoji = async (): Promise<{ emojis: Misskey.entities.CustomEmoji[] }> => {
if (!process.client) {
return { emojis: [] };
}
if (!localStorage.getItem('miHub_io_emoji')) {
const emoji = await fetch('https://misskey.io/api/emojis');
const emojiText = await emoji.text();
localStorage.setItem('miHub_io_emoji', emojiText);
return JSON.parse(emojiText);
} else {
return JSON.parse(localStorage.getItem('miHub_io_emoji') ?? '');
}
}