41 lines
999 B
TypeScript
41 lines
999 B
TypeScript
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
|
const ms = require('ms');
|
|
import { pack } from '../../../../../models/drive-file';
|
|
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
|
import { ILocalUser } from '../../../../../models/user';
|
|
import getParams from '../../../get-params';
|
|
|
|
export const meta = {
|
|
desc: {
|
|
'ja-JP': 'ドライブに指定されたURLに存在するファイルをアップロードします。'
|
|
},
|
|
|
|
limit: {
|
|
duration: ms('1hour'),
|
|
max: 10
|
|
},
|
|
|
|
requireCredential: true,
|
|
|
|
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
|
|
},
|
|
}
|
|
};
|
|
|
|
export default async (params: any, user: ILocalUser): Promise<any> => {
|
|
const [ps, psErr] = getParams(meta, params);
|
|
if (psErr) throw psErr;
|
|
|
|
return pack(await uploadFromUrl(ps.url, user, ps.folderId));
|
|
};
|