[API] Improve drive/files/upload_from_url

This commit is contained in:
syuilo 2018-11-07 12:12:43 +09:00
parent 0068dc30d3
commit 665fa7f2aa
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
2 changed files with 28 additions and 4 deletions

View File

@ -11,7 +11,7 @@ export const meta = {
limit: { limit: {
duration: ms('1hour'), duration: ms('1hour'),
max: 10 max: 60
}, },
requireCredential: true, requireCredential: true,
@ -29,9 +29,26 @@ export const meta = {
default: null as any as any, default: null as any as any,
transform: transform transform: transform
}, },
isSensitive: {
validator: $.bool.optional,
default: false,
desc: {
'ja-JP': 'このメディアが「閲覧注意」(NSFW)かどうか',
'en-US': 'Whether this media is NSFW'
}
},
force: {
validator: $.bool.optional,
default: false,
desc: {
'ja-JP': 'true にすると、同じハッシュを持つファイルが既にアップロードされていても強制的にファイルを作成します。',
}
}
} }
}; };
export default define(meta, (ps, user) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
res(pack(await uploadFromUrl(ps.url, user, ps.folderId))); res(pack(await uploadFromUrl(ps.url, user, ps.folderId, null, ps.isSensitive, ps.force)));
})); }));

View File

@ -14,7 +14,14 @@ import fetchMeta from '../../misc/fetch-meta';
const log = debug('misskey:drive:upload-from-url'); const log = debug('misskey:drive:upload-from-url');
export default async (url: string, user: IUser, folderId: mongodb.ObjectID = null, uri: string = null, sensitive = false): Promise<IDriveFile> => { export default async (
url: string,
user: IUser,
folderId: mongodb.ObjectID = null,
uri: string = null,
sensitive = false,
force = false
): Promise<IDriveFile> => {
log(`REQUESTED: ${url}`); log(`REQUESTED: ${url}`);
let name = URL.parse(url).pathname.split('/').pop(); let name = URL.parse(url).pathname.split('/').pop();
@ -76,7 +83,7 @@ export default async (url: string, user: IUser, folderId: mongodb.ObjectID = nul
let error; let error;
try { try {
driveFile = await create(user, path, name, null, folderId, false, !instance.cacheRemoteFiles, url, uri, sensitive); driveFile = await create(user, path, name, null, folderId, force, !instance.cacheRemoteFiles, url, uri, sensitive);
log(`got: ${driveFile._id}`); log(`got: ${driveFile._id}`);
} catch (e) { } catch (e) {
error = e; error = e;