yumechi-no-kuni/src/server/api/endpoints/drive/files/upload_from_url.ts

38 lines
867 B
TypeScript
Raw Normal View History

2018-11-01 13:32:24 -05:00
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
2018-07-16 14:36:44 -05:00
const ms = require('ms');
2018-03-29 06:32:18 -05:00
import { pack } from '../../../../../models/drive-file';
2018-04-07 14:02:12 -05:00
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
2018-11-01 23:47:44 -05:00
import define from '../../../define';
2017-02-16 14:46:14 -06:00
2018-07-16 14:36:44 -05:00
export const meta = {
desc: {
2018-08-28 16:59:43 -05:00
'ja-JP': 'ドライブに指定されたURLに存在するファイルをアップロードします。'
2018-07-16 14:36:44 -05:00
},
limit: {
duration: ms('1hour'),
max: 10
},
requireCredential: true,
2018-11-01 13:32:24 -05:00
kind: 'drive-write',
params: {
url: {
// TODO: Validate this url
validator: $.str,
},
folderId: {
validator: $.type(ID).optional.nullable,
default: null as any as any,
transform: transform
},
}
2018-07-16 14:36:44 -05:00
};
2018-11-01 23:47:44 -05:00
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
res(pack(await uploadFromUrl(ps.url, user, ps.folderId)));
}));