2018-11-02 03:32:24 +09:00
|
|
|
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
2018-10-02 16:27:36 +09:00
|
|
|
import { ILocalUser } from '../../../../models/user';
|
2018-03-29 20:32:18 +09:00
|
|
|
import { pack } from '../../../../models/user';
|
2018-10-02 16:27:36 +09:00
|
|
|
import { addPinned } from '../../../../services/i/pin';
|
2018-09-24 16:26:12 +09:00
|
|
|
import getParams from '../../get-params';
|
|
|
|
|
|
|
|
export const meta = {
|
2018-10-22 05:16:27 +09:00
|
|
|
stability: 'stable',
|
|
|
|
|
2018-09-24 16:26:12 +09:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '指定した投稿をピン留めします。'
|
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'account-write',
|
|
|
|
|
|
|
|
params: {
|
2018-11-02 03:32:24 +09:00
|
|
|
noteId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
2018-09-24 16:26:12 +09:00
|
|
|
desc: {
|
2018-10-22 05:16:27 +09:00
|
|
|
'ja-JP': '対象の投稿のID',
|
|
|
|
'en-US': 'Target note ID'
|
2018-09-24 16:26:12 +09:00
|
|
|
}
|
2018-11-02 03:32:24 +09:00
|
|
|
}
|
2018-09-24 16:26:12 +09:00
|
|
|
}
|
|
|
|
};
|
2017-08-30 17:31:39 +09:00
|
|
|
|
2018-07-06 02:58:29 +09:00
|
|
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
2018-09-24 16:26:12 +09:00
|
|
|
const [ps, psErr] = getParams(meta, params);
|
|
|
|
if (psErr) return rej(psErr);
|
2017-08-30 17:31:39 +09:00
|
|
|
|
2018-10-02 16:27:36 +09:00
|
|
|
// Processing
|
|
|
|
try {
|
|
|
|
await addPinned(user, ps.noteId);
|
|
|
|
} catch (e) {
|
|
|
|
return rej(e.message);
|
2018-09-24 16:26:12 +09:00
|
|
|
}
|
|
|
|
|
2018-10-02 16:27:36 +09:00
|
|
|
// Serialize
|
2018-02-02 08:21:30 +09:00
|
|
|
const iObj = await pack(user, user, {
|
2017-08-30 17:31:39 +09:00
|
|
|
detail: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Send response
|
|
|
|
res(iObj);
|
|
|
|
});
|