2018-10-16 08:55:55 +09:00
|
|
|
import * as Router from 'koa-router';
|
2018-11-05 13:38:50 +09:00
|
|
|
import User from '../../../models/user';
|
2018-10-16 08:55:55 +09:00
|
|
|
import { toASCII } from 'punycode';
|
2018-11-05 13:38:50 +09:00
|
|
|
import config from '../../../config';
|
|
|
|
import Meta from '../../../models/meta';
|
2018-10-31 02:17:54 +09:00
|
|
|
import { ObjectID } from 'bson';
|
2018-11-05 13:38:50 +09:00
|
|
|
import Emoji from '../../../models/emoji';
|
|
|
|
import { toMastodonEmojis } from './emoji';
|
2018-11-05 13:46:46 +09:00
|
|
|
const pkg = require('../../../../package.json');
|
2018-10-16 08:55:55 +09:00
|
|
|
|
|
|
|
// Init router
|
|
|
|
const router = new Router();
|
|
|
|
|
2018-11-05 10:45:57 +09:00
|
|
|
router.get('/v1/custom_emojis', async ctx => ctx.body =
|
2018-11-05 11:57:17 +09:00
|
|
|
(await Emoji.find({ host: null }, {
|
2018-11-05 10:45:57 +09:00
|
|
|
fields: {
|
|
|
|
_id: false
|
|
|
|
}
|
2018-11-05 11:58:41 +09:00
|
|
|
})).map(x => toMastodonEmojis(x)));
|
2018-10-31 02:17:54 +09:00
|
|
|
|
|
|
|
router.get('/v1/instance', async ctx => { // TODO: This is a temporary implementation. Consider creating helper methods!
|
|
|
|
const meta = await Meta.findOne() || {};
|
|
|
|
const { originalNotesCount, originalUsersCount } = meta.stats || {
|
|
|
|
originalNotesCount: 0,
|
|
|
|
originalUsersCount: 0
|
|
|
|
};
|
|
|
|
const domains = await User.distinct('host', { host: { $ne: null } }) as any as [] || [];
|
|
|
|
const maintainer = await User.findOne({ isAdmin: true }) || {
|
|
|
|
_id: ObjectID.createFromTime(0),
|
|
|
|
username: '', // TODO: Consider making this better!
|
|
|
|
host: config.host,
|
|
|
|
name: '',
|
|
|
|
isLocked: false,
|
|
|
|
isBot: false,
|
|
|
|
createdAt: new Date(0),
|
|
|
|
description: '',
|
|
|
|
avatarUrl: '',
|
|
|
|
bannerUrl: '',
|
|
|
|
followersCount: 0,
|
|
|
|
followingCount: 0,
|
|
|
|
notesCount: 0
|
|
|
|
};
|
|
|
|
const acct = maintainer.host ? `${maintainer.username}@${maintainer.host}` : maintainer.username;
|
2018-11-05 11:57:17 +09:00
|
|
|
const emojis = (await Emoji.find({ host: null }, {
|
|
|
|
fields: {
|
|
|
|
_id: false
|
|
|
|
}
|
|
|
|
})).map(toMastodonEmojis);
|
2018-10-31 02:17:54 +09:00
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
uri: config.hostname,
|
2018-11-04 23:00:43 +09:00
|
|
|
title: meta.name || 'Misskey',
|
|
|
|
description: meta.description || '',
|
2018-10-31 02:17:54 +09:00
|
|
|
email: config.maintainer.email || config.maintainer.url.startsWith('mailto:') ? config.maintainer.url.slice(7) : '',
|
|
|
|
version: `0.0.0:compatible:misskey:${pkg.version}`, // TODO: How to tell about that this is an api for compatibility?
|
|
|
|
thumbnail: meta.bannerUrl,
|
|
|
|
/*
|
|
|
|
urls: {
|
|
|
|
streaming_api: config.ws_url + '/mastodon' // TODO: Implement compatible streaming API
|
|
|
|
}, */
|
|
|
|
stats: {
|
|
|
|
user_count: originalUsersCount,
|
|
|
|
status_count: originalNotesCount,
|
|
|
|
domain_count: domains.length
|
|
|
|
},
|
|
|
|
languages: config.languages || [ 'ja' ],
|
|
|
|
contact_account: {
|
|
|
|
id: maintainer._id,
|
|
|
|
username: maintainer.username,
|
|
|
|
acct: acct,
|
|
|
|
display_name: maintainer.name || '',
|
|
|
|
locked: maintainer.isLocked,
|
|
|
|
bot: maintainer.isBot,
|
|
|
|
created_at: maintainer.createdAt,
|
|
|
|
note: maintainer.description,
|
|
|
|
url: `${config.url}/@${acct}`,
|
|
|
|
avatar: maintainer.avatarUrl || '',
|
|
|
|
/*
|
|
|
|
avatar_static: maintainer.avatarUrl || '', // TODO: Implement static avatar url (ensure non-animated GIF)
|
|
|
|
*/
|
|
|
|
header: maintainer.bannerUrl || '',
|
|
|
|
/*
|
|
|
|
header_static: maintainer.bannerUrl || '', // TODO: Implement static header url (ensure non-animated GIF)
|
|
|
|
*/
|
|
|
|
followers_count: maintainer.followersCount,
|
|
|
|
following_count: maintainer.followingCount,
|
|
|
|
statuses_count: maintainer.notesCount,
|
2018-11-05 11:57:17 +09:00
|
|
|
emojis: emojis,
|
2018-10-31 02:17:54 +09:00
|
|
|
moved: null,
|
|
|
|
fields: null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-10-16 08:55:55 +09:00
|
|
|
router.get('/v1/instance/peers', async ctx => {
|
|
|
|
const peers = await User.distinct('host', { host: { $ne: null } }) as any as string[];
|
|
|
|
const punyCodes = peers.map(peer => toASCII(peer));
|
|
|
|
ctx.body = punyCodes;
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|