Improve API definitions
This commit is contained in:
		
							parent
							
								
									c29f912461
								
							
						
					
					
						commit
						3aece449e4
					
				
					 15 changed files with 136 additions and 34 deletions
				
			
		| 
						 | 
				
			
			@ -21,3 +21,20 @@
 | 
			
		|||
 | 
			
		||||
	> .host
 | 
			
		||||
		opacity 0.7
 | 
			
		||||
 | 
			
		||||
#stability
 | 
			
		||||
	padding 8px 12px
 | 
			
		||||
	color #fff
 | 
			
		||||
	border-radius 4px
 | 
			
		||||
 | 
			
		||||
	&.deprecated
 | 
			
		||||
		background #f42443
 | 
			
		||||
 | 
			
		||||
	&.experimental
 | 
			
		||||
		background #f2781a
 | 
			
		||||
 | 
			
		||||
	&.stable
 | 
			
		||||
		background #3dcc90
 | 
			
		||||
 | 
			
		||||
	> b
 | 
			
		||||
		margin-left 4px
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,11 @@ block main
 | 
			
		|||
			| /
 | 
			
		||||
		span.path= endpointUrl.path
 | 
			
		||||
 | 
			
		||||
	- var stability = endpoint.stability || 'experimental';
 | 
			
		||||
	p#stability(class=stability)
 | 
			
		||||
		| Stability:
 | 
			
		||||
		b= stability
 | 
			
		||||
 | 
			
		||||
	if endpoint.desc
 | 
			
		||||
		p#desc= endpoint.desc[lang] || endpoint.desc['ja-JP']
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@ import * as path from 'path';
 | 
			
		|||
import * as glob from 'glob';
 | 
			
		||||
 | 
			
		||||
export interface IEndpointMeta {
 | 
			
		||||
	stability?: 'deprecated' | 'experimental' | 'stable';
 | 
			
		||||
 | 
			
		||||
	desc?: any;
 | 
			
		||||
 | 
			
		||||
	params?: any;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,8 +3,11 @@ const ms = require('ms');
 | 
			
		|||
import User, { pack, ILocalUser } from '../../../../models/user';
 | 
			
		||||
import Following from '../../../../models/following';
 | 
			
		||||
import create from '../../../../services/following/create';
 | 
			
		||||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定したユーザーをフォローします。',
 | 
			
		||||
		'en-US': 'Follow a user.'
 | 
			
		||||
| 
						 | 
				
			
			@ -17,24 +20,32 @@ export const meta = {
 | 
			
		|||
 | 
			
		||||
	requireCredential: true,
 | 
			
		||||
 | 
			
		||||
	kind: 'following-write'
 | 
			
		||||
	kind: 'following-write',
 | 
			
		||||
 | 
			
		||||
	params: {
 | 
			
		||||
		userId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象のユーザーのID',
 | 
			
		||||
				'en-US': 'Target user ID'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	const [ps, psErr] = getParams(meta, params);
 | 
			
		||||
	if (psErr) return rej(psErr);
 | 
			
		||||
 | 
			
		||||
	const follower = user;
 | 
			
		||||
 | 
			
		||||
	// Get 'userId' parameter
 | 
			
		||||
	const [userId, userIdErr] = $.type(ID).get(params.userId);
 | 
			
		||||
	if (userIdErr) return rej('invalid userId param');
 | 
			
		||||
 | 
			
		||||
	// 自分自身
 | 
			
		||||
	if (user._id.equals(userId)) {
 | 
			
		||||
	if (user._id.equals(ps.userId)) {
 | 
			
		||||
		return rej('followee is yourself');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get followee
 | 
			
		||||
	const followee = await User.findOne({
 | 
			
		||||
		_id: userId
 | 
			
		||||
		_id: ps.userId
 | 
			
		||||
	}, {
 | 
			
		||||
		fields: {
 | 
			
		||||
			data: false,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,8 +3,11 @@ const ms = require('ms');
 | 
			
		|||
import User, { pack, ILocalUser } from '../../../../models/user';
 | 
			
		||||
import Following from '../../../../models/following';
 | 
			
		||||
import deleteFollowing from '../../../../services/following/delete';
 | 
			
		||||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定したユーザーのフォローを解除します。',
 | 
			
		||||
		'en-US': 'Unfollow a user.'
 | 
			
		||||
| 
						 | 
				
			
			@ -17,24 +20,32 @@ export const meta = {
 | 
			
		|||
 | 
			
		||||
	requireCredential: true,
 | 
			
		||||
 | 
			
		||||
	kind: 'following-write'
 | 
			
		||||
	kind: 'following-write',
 | 
			
		||||
 | 
			
		||||
	params: {
 | 
			
		||||
		userId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象のユーザーのID',
 | 
			
		||||
				'en-US': 'Target user ID'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	const [ps, psErr] = getParams(meta, params);
 | 
			
		||||
	if (psErr) return rej(psErr);
 | 
			
		||||
 | 
			
		||||
	const follower = user;
 | 
			
		||||
 | 
			
		||||
	// Get 'userId' parameter
 | 
			
		||||
	const [userId, userIdErr] = $.type(ID).get(params.userId);
 | 
			
		||||
	if (userIdErr) return rej('invalid userId param');
 | 
			
		||||
 | 
			
		||||
	// Check if the followee is yourself
 | 
			
		||||
	if (user._id.equals(userId)) {
 | 
			
		||||
	if (user._id.equals(ps.userId)) {
 | 
			
		||||
		return rej('followee is yourself');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get followee
 | 
			
		||||
	const followee = await User.findOne({
 | 
			
		||||
		_id: userId
 | 
			
		||||
		_id: ps.userId
 | 
			
		||||
	}, {
 | 
			
		||||
		fields: {
 | 
			
		||||
			data: false,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@ import User, { pack, ILocalUser } from '../../../models/user';
 | 
			
		|||
import { IApp } from '../../../models/app';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '自分のアカウント情報を取得します。'
 | 
			
		||||
	},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@ import { addPinned } from '../../../../services/i/pin';
 | 
			
		|||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿をピン留めします。'
 | 
			
		||||
	},
 | 
			
		||||
| 
						 | 
				
			
			@ -16,7 +18,8 @@ export const meta = {
 | 
			
		|||
	params: {
 | 
			
		||||
		noteId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象の投稿のID'
 | 
			
		||||
				'ja-JP': '対象の投稿のID',
 | 
			
		||||
				'en-US': 'Target note ID'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@ import { removePinned } from '../../../../services/i/pin';
 | 
			
		|||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿のピン留めを解除します。'
 | 
			
		||||
	},
 | 
			
		||||
| 
						 | 
				
			
			@ -16,7 +18,8 @@ export const meta = {
 | 
			
		|||
	params: {
 | 
			
		||||
		noteId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象の投稿のID'
 | 
			
		||||
				'ja-JP': '対象の投稿のID',
 | 
			
		||||
				'en-US': 'Target note ID'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,8 @@ const pkg = require('../../../../package.json');
 | 
			
		|||
const client = require('../../../../built/client/meta.json');
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': 'インスタンス情報を取得します。',
 | 
			
		||||
		'en-US': 'Get the information of this instance.'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,8 @@ import { IApp } from '../../../../models/app';
 | 
			
		|||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '投稿します。'
 | 
			
		||||
	},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,11 @@ import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
 | 
			
		|||
import Note from '../../../../models/note';
 | 
			
		||||
import deleteNote from '../../../../services/note/delete';
 | 
			
		||||
import User, { ILocalUser } from '../../../../models/user';
 | 
			
		||||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿を削除します。',
 | 
			
		||||
		'en-US': 'Delete a note.'
 | 
			
		||||
| 
						 | 
				
			
			@ -11,17 +14,25 @@ export const meta = {
 | 
			
		|||
 | 
			
		||||
	requireCredential: true,
 | 
			
		||||
 | 
			
		||||
	kind: 'note-write'
 | 
			
		||||
	kind: 'note-write',
 | 
			
		||||
 | 
			
		||||
	params: {
 | 
			
		||||
		noteId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象の投稿のID',
 | 
			
		||||
				'en-US': 'Target note ID.'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	// Get 'noteId' parameter
 | 
			
		||||
	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
	const [ps, psErr] = getParams(meta, params);
 | 
			
		||||
	if (psErr) return rej(psErr);
 | 
			
		||||
 | 
			
		||||
	// Fetch note
 | 
			
		||||
	const note = await Note.findOne({
 | 
			
		||||
		_id: noteId
 | 
			
		||||
		_id: ps.noteId
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	if (note === null) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@ import { ILocalUser } from '../../../../../models/user';
 | 
			
		|||
import getParams from '../../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿をお気に入りに登録します。',
 | 
			
		||||
		'en-US': 'Favorite a note.'
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +19,8 @@ export const meta = {
 | 
			
		|||
	params: {
 | 
			
		||||
		noteId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象の投稿のID'
 | 
			
		||||
				'ja-JP': '対象の投稿のID',
 | 
			
		||||
				'en-US': 'Target note ID.'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,11 @@ import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
 | 
			
		|||
import Favorite from '../../../../../models/favorite';
 | 
			
		||||
import Note from '../../../../../models/note';
 | 
			
		||||
import { ILocalUser } from '../../../../../models/user';
 | 
			
		||||
import getParams from '../../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿のお気に入りを解除します。',
 | 
			
		||||
		'en-US': 'Unfavorite a note.'
 | 
			
		||||
| 
						 | 
				
			
			@ -11,17 +14,25 @@ export const meta = {
 | 
			
		|||
 | 
			
		||||
	requireCredential: true,
 | 
			
		||||
 | 
			
		||||
	kind: 'favorite-write'
 | 
			
		||||
	kind: 'favorite-write',
 | 
			
		||||
 | 
			
		||||
	params: {
 | 
			
		||||
		noteId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象の投稿のID',
 | 
			
		||||
				'en-US': 'Target note ID.'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	// Get 'noteId' parameter
 | 
			
		||||
	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
	const [ps, psErr] = getParams(meta, params);
 | 
			
		||||
	if (psErr) return rej(psErr);
 | 
			
		||||
 | 
			
		||||
	// Get favoritee
 | 
			
		||||
	const note = await Note.findOne({
 | 
			
		||||
		_id: noteId
 | 
			
		||||
		_id: ps.noteId
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	if (note === null) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,8 @@ import { ILocalUser } from '../../../../../models/user';
 | 
			
		|||
import getParams from '../../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿にリアクションします。',
 | 
			
		||||
		'en-US': 'React to a note.'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,18 +1,35 @@
 | 
			
		|||
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
 | 
			
		||||
import Note, { pack } from '../../../../models/note';
 | 
			
		||||
import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	stability: 'stable',
 | 
			
		||||
 | 
			
		||||
	desc: {
 | 
			
		||||
		'ja-JP': '指定した投稿を取得します。',
 | 
			
		||||
		'en-US': 'Get a note.'
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	requireCredential: false,
 | 
			
		||||
 | 
			
		||||
	params: {
 | 
			
		||||
		noteId: $.type(ID).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				'ja-JP': '対象の投稿のID',
 | 
			
		||||
				'en-US': 'Target note ID.'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Show a note
 | 
			
		||||
 */
 | 
			
		||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	// Get 'noteId' parameter
 | 
			
		||||
	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
	const [ps, psErr] = getParams(meta, params);
 | 
			
		||||
	if (psErr) return rej(psErr);
 | 
			
		||||
 | 
			
		||||
	// Get note
 | 
			
		||||
	const note = await Note.findOne({
 | 
			
		||||
		_id: noteId
 | 
			
		||||
		_id: ps.noteId
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	if (note === null) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue