mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-10-31 21:44:12 +00:00 
			
		
		
		
	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 | 	> .host | ||||||
| 		opacity 0.7 | 		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 | 		span.path= endpointUrl.path | ||||||
| 
 | 
 | ||||||
|  | 	- var stability = endpoint.stability || 'experimental'; | ||||||
|  | 	p#stability(class=stability) | ||||||
|  | 		| Stability: | ||||||
|  | 		b= stability | ||||||
|  | 
 | ||||||
| 	if endpoint.desc | 	if endpoint.desc | ||||||
| 		p#desc= endpoint.desc[lang] || endpoint.desc['ja-JP'] | 		p#desc= endpoint.desc[lang] || endpoint.desc['ja-JP'] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,8 @@ import * as path from 'path'; | ||||||
| import * as glob from 'glob'; | import * as glob from 'glob'; | ||||||
| 
 | 
 | ||||||
| export interface IEndpointMeta { | export interface IEndpointMeta { | ||||||
|  | 	stability?: 'deprecated' | 'experimental' | 'stable'; | ||||||
|  | 
 | ||||||
| 	desc?: any; | 	desc?: any; | ||||||
| 
 | 
 | ||||||
| 	params?: any; | 	params?: any; | ||||||
|  |  | ||||||
|  | @ -3,8 +3,11 @@ const ms = require('ms'); | ||||||
| import User, { pack, ILocalUser } from '../../../../models/user'; | import User, { pack, ILocalUser } from '../../../../models/user'; | ||||||
| import Following from '../../../../models/following'; | import Following from '../../../../models/following'; | ||||||
| import create from '../../../../services/following/create'; | import create from '../../../../services/following/create'; | ||||||
|  | import getParams from '../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定したユーザーをフォローします。', | 		'ja-JP': '指定したユーザーをフォローします。', | ||||||
| 		'en-US': 'Follow a user.' | 		'en-US': 'Follow a user.' | ||||||
|  | @ -17,24 +20,32 @@ export const meta = { | ||||||
| 
 | 
 | ||||||
| 	requireCredential: true, | 	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) => { | 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; | 	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'); | 		return rej('followee is yourself'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Get followee
 | 	// Get followee
 | ||||||
| 	const followee = await User.findOne({ | 	const followee = await User.findOne({ | ||||||
| 		_id: userId | 		_id: ps.userId | ||||||
| 	}, { | 	}, { | ||||||
| 		fields: { | 		fields: { | ||||||
| 			data: false, | 			data: false, | ||||||
|  |  | ||||||
|  | @ -3,8 +3,11 @@ const ms = require('ms'); | ||||||
| import User, { pack, ILocalUser } from '../../../../models/user'; | import User, { pack, ILocalUser } from '../../../../models/user'; | ||||||
| import Following from '../../../../models/following'; | import Following from '../../../../models/following'; | ||||||
| import deleteFollowing from '../../../../services/following/delete'; | import deleteFollowing from '../../../../services/following/delete'; | ||||||
|  | import getParams from '../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定したユーザーのフォローを解除します。', | 		'ja-JP': '指定したユーザーのフォローを解除します。', | ||||||
| 		'en-US': 'Unfollow a user.' | 		'en-US': 'Unfollow a user.' | ||||||
|  | @ -17,24 +20,32 @@ export const meta = { | ||||||
| 
 | 
 | ||||||
| 	requireCredential: true, | 	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) => { | 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; | 	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
 | 	// Check if the followee is yourself
 | ||||||
| 	if (user._id.equals(userId)) { | 	if (user._id.equals(ps.userId)) { | ||||||
| 		return rej('followee is yourself'); | 		return rej('followee is yourself'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Get followee
 | 	// Get followee
 | ||||||
| 	const followee = await User.findOne({ | 	const followee = await User.findOne({ | ||||||
| 		_id: userId | 		_id: ps.userId | ||||||
| 	}, { | 	}, { | ||||||
| 		fields: { | 		fields: { | ||||||
| 			data: false, | 			data: false, | ||||||
|  |  | ||||||
|  | @ -2,6 +2,8 @@ import User, { pack, ILocalUser } from '../../../models/user'; | ||||||
| import { IApp } from '../../../models/app'; | import { IApp } from '../../../models/app'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '自分のアカウント情報を取得します。' | 		'ja-JP': '自分のアカウント情報を取得します。' | ||||||
| 	}, | 	}, | ||||||
|  |  | ||||||
|  | @ -5,6 +5,8 @@ import { addPinned } from '../../../../services/i/pin'; | ||||||
| import getParams from '../../get-params'; | import getParams from '../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定した投稿をピン留めします。' | 		'ja-JP': '指定した投稿をピン留めします。' | ||||||
| 	}, | 	}, | ||||||
|  | @ -16,7 +18,8 @@ export const meta = { | ||||||
| 	params: { | 	params: { | ||||||
| 		noteId: $.type(ID).note({ | 		noteId: $.type(ID).note({ | ||||||
| 			desc: { | 			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'; | import getParams from '../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定した投稿のピン留めを解除します。' | 		'ja-JP': '指定した投稿のピン留めを解除します。' | ||||||
| 	}, | 	}, | ||||||
|  | @ -16,7 +18,8 @@ export const meta = { | ||||||
| 	params: { | 	params: { | ||||||
| 		noteId: $.type(ID).note({ | 		noteId: $.type(ID).note({ | ||||||
| 			desc: { | 			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'); | const client = require('../../../../built/client/meta.json'); | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': 'インスタンス情報を取得します。', | 		'ja-JP': 'インスタンス情報を取得します。', | ||||||
| 		'en-US': 'Get the information of this instance.' | 		'en-US': 'Get the information of this instance.' | ||||||
|  |  | ||||||
|  | @ -8,6 +8,8 @@ import { IApp } from '../../../../models/app'; | ||||||
| import getParams from '../../get-params'; | import getParams from '../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '投稿します。' | 		'ja-JP': '投稿します。' | ||||||
| 	}, | 	}, | ||||||
|  |  | ||||||
|  | @ -2,8 +2,11 @@ import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; | ||||||
| import Note from '../../../../models/note'; | import Note from '../../../../models/note'; | ||||||
| import deleteNote from '../../../../services/note/delete'; | import deleteNote from '../../../../services/note/delete'; | ||||||
| import User, { ILocalUser } from '../../../../models/user'; | import User, { ILocalUser } from '../../../../models/user'; | ||||||
|  | import getParams from '../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定した投稿を削除します。', | 		'ja-JP': '指定した投稿を削除します。', | ||||||
| 		'en-US': 'Delete a note.' | 		'en-US': 'Delete a note.' | ||||||
|  | @ -11,17 +14,25 @@ export const meta = { | ||||||
| 
 | 
 | ||||||
| 	requireCredential: true, | 	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) => { | export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { | ||||||
| 	// Get 'noteId' parameter
 | 	const [ps, psErr] = getParams(meta, params); | ||||||
| 	const [noteId, noteIdErr] = $.type(ID).get(params.noteId); | 	if (psErr) return rej(psErr); | ||||||
| 	if (noteIdErr) return rej('invalid noteId param'); |  | ||||||
| 
 | 
 | ||||||
| 	// Fetch note
 | 	// Fetch note
 | ||||||
| 	const note = await Note.findOne({ | 	const note = await Note.findOne({ | ||||||
| 		_id: noteId | 		_id: ps.noteId | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	if (note === null) { | 	if (note === null) { | ||||||
|  |  | ||||||
|  | @ -5,6 +5,8 @@ import { ILocalUser } from '../../../../../models/user'; | ||||||
| import getParams from '../../../get-params'; | import getParams from '../../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定した投稿をお気に入りに登録します。', | 		'ja-JP': '指定した投稿をお気に入りに登録します。', | ||||||
| 		'en-US': 'Favorite a note.' | 		'en-US': 'Favorite a note.' | ||||||
|  | @ -17,7 +19,8 @@ export const meta = { | ||||||
| 	params: { | 	params: { | ||||||
| 		noteId: $.type(ID).note({ | 		noteId: $.type(ID).note({ | ||||||
| 			desc: { | 			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 Favorite from '../../../../../models/favorite'; | ||||||
| import Note from '../../../../../models/note'; | import Note from '../../../../../models/note'; | ||||||
| import { ILocalUser } from '../../../../../models/user'; | import { ILocalUser } from '../../../../../models/user'; | ||||||
|  | import getParams from '../../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定した投稿のお気に入りを解除します。', | 		'ja-JP': '指定した投稿のお気に入りを解除します。', | ||||||
| 		'en-US': 'Unfavorite a note.' | 		'en-US': 'Unfavorite a note.' | ||||||
|  | @ -11,17 +14,25 @@ export const meta = { | ||||||
| 
 | 
 | ||||||
| 	requireCredential: true, | 	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) => { | export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { | ||||||
| 	// Get 'noteId' parameter
 | 	const [ps, psErr] = getParams(meta, params); | ||||||
| 	const [noteId, noteIdErr] = $.type(ID).get(params.noteId); | 	if (psErr) return rej(psErr); | ||||||
| 	if (noteIdErr) return rej('invalid noteId param'); |  | ||||||
| 
 | 
 | ||||||
| 	// Get favoritee
 | 	// Get favoritee
 | ||||||
| 	const note = await Note.findOne({ | 	const note = await Note.findOne({ | ||||||
| 		_id: noteId | 		_id: ps.noteId | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	if (note === null) { | 	if (note === null) { | ||||||
|  |  | ||||||
|  | @ -6,6 +6,8 @@ import { ILocalUser } from '../../../../../models/user'; | ||||||
| import getParams from '../../../get-params'; | import getParams from '../../../get-params'; | ||||||
| 
 | 
 | ||||||
| export const meta = { | export const meta = { | ||||||
|  | 	stability: 'stable', | ||||||
|  | 
 | ||||||
| 	desc: { | 	desc: { | ||||||
| 		'ja-JP': '指定した投稿にリアクションします。', | 		'ja-JP': '指定した投稿にリアクションします。', | ||||||
| 		'en-US': 'React to a note.' | 		'en-US': 'React to a note.' | ||||||
|  |  | ||||||
|  | @ -1,18 +1,35 @@ | ||||||
| import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; | import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; | ||||||
| import Note, { pack } from '../../../../models/note'; | import Note, { pack } from '../../../../models/note'; | ||||||
| import { ILocalUser } from '../../../../models/user'; | 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) => { | export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { | ||||||
| 	// Get 'noteId' parameter
 | 	const [ps, psErr] = getParams(meta, params); | ||||||
| 	const [noteId, noteIdErr] = $.type(ID).get(params.noteId); | 	if (psErr) return rej(psErr); | ||||||
| 	if (noteIdErr) return rej('invalid noteId param'); |  | ||||||
| 
 | 
 | ||||||
| 	// Get note
 | 	// Get note
 | ||||||
| 	const note = await Note.findOne({ | 	const note = await Note.findOne({ | ||||||
| 		_id: noteId | 		_id: ps.noteId | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	if (note === null) { | 	if (note === null) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue