Skip to content

Commit

Permalink
Mastodonインスタンス名を取得するように
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Jul 15, 2020
1 parent a7f9754 commit 45a8b04
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/services/update-instanceinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,25 @@ export async function UpdateInstanceinfo(instance: IInstance, request?: InboxReq
export async function fetchInstanceinfo(host: string) {
const info = await fetchNodeinfo(host).catch(() => null);

if (!info) {
const mastodon = await fetchMastodonInstance(host);
return {
softwareName: 'mastodon',
softwareVersion: mastodon.version,
};
let name = info?.metadata?.nodeName || info?.metadata?.name || null;
let description = info?.metadata?.nodeDescription || info?.metadata?.description || null;
const maintainerName = info?.metadata?.maintainer?.name || null;
let maintainerEmail = info?.metadata?.maintainer?.email || null;

// fetch Mastodon API
if (!name) {
const mastodon = await fetchMastodonInstance(toApHost(host)!).catch(() => {});
if (mastodon) {
name = mastodon.title;
description = mastodon.description;
maintainerEmail = mastodon.email;
}
}

// additional metadatas
const name = info.metadata ? (info.metadata.nodeName || info.metadata.name || null) : null;
const description = info.metadata ? (info.metadata.nodeDescription || info.metadata.description || null) : null;
const maintainerName = info.metadata ? info.metadata.maintainer ? (info.metadata.maintainer.name || null) : null : null;
const maintainerEmail = info.metadata ? info.metadata.maintainer ? (info.metadata.maintainer.email || null) : null : null;

return {
softwareName: info.software.name,
softwareVersion: info.software.version,
openRegistrations: info.openRegistrations,
softwareName: info?.software?.name,
softwareVersion: info?.software?.version,
openRegistrations: info?.openRegistrations,
name,
description,
maintainerName,
Expand Down

0 comments on commit 45a8b04

Please sign in to comment.