<commit_before>import * as Router from 'koa-router';
import User from '../../models/user';
import { toASCII } from 'punycode';
import config from '../../config';
import Meta from '../../models/meta';
import { ObjectID } from 'bson';
import Emoji from '../../models/emoji';
import { toMastodonEmojis } from '../../models/mastodon/emoji';
const pkg = require('../../../package.json');

// Init router
const router = new Router();

router.get('/v1/custom_emojis', async ctx => ctx.body =
	(await Emoji.find({ host: null }, {
		fields: {
			_id: false
		}
	})).map(toMastodonEmojis));

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;
	const emojis = (await Emoji.find({ host: null }, {
		fields: {
			_id: false
		}
	})).map(toMastodonEmojis);

	ctx.body = {
		uri: config.hostname,
		title: meta.name || 'Misskey',
		description: meta.description || '',
		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,
			emojis: emojis,
			moved: null,
			fields: null
		}
	};
});

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;<commit_msg>Separate commits<commit_after>import * as Router from 'koa-router';
import User from '../../models/user';
import { toASCII } from 'punycode';
import config from '../../config';
import Meta from '../../models/meta';
import { ObjectID } from 'bson';
import Emoji from '../../models/emoji';
const pkg = require('../../../package.json');

// Init router
const router = new Router();

router.get('/v1/custom_emojis', async ctx => ctx.body =
	await Emoji.find({ host: null }, {
		fields: {
			_id: false
		}
	}));

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;

	ctx.body = {
		uri: config.hostname,
		title: meta.name || 'Misskey',
		description: meta.description || '',
		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,
			emojis: [],
			moved: null,
			fields: null
		}
	};
});

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;
{'fraction_non_alphanumeric': 0.16256548658517225, 'fraction_numerical': 0.004445150023813304, 'mean_word_length': 3.790874524714829, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1331034', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2098, 'n_words': 506}