From 665fa7f2aa80a726f36f834d14ecac8eaff3f944 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Wed, 7 Nov 2018 12:12:43 +0900
Subject: [PATCH] [API] Improve drive/files/upload_from_url

---
 .../endpoints/drive/files/upload_from_url.ts  | 21 +++++++++++++++++--
 src/services/drive/upload-from-url.ts         | 11 ++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/server/api/endpoints/drive/files/upload_from_url.ts b/src/server/api/endpoints/drive/files/upload_from_url.ts
index cacb96fa3..a8faab1d7 100644
--- a/src/server/api/endpoints/drive/files/upload_from_url.ts
+++ b/src/server/api/endpoints/drive/files/upload_from_url.ts
@@ -11,7 +11,7 @@ export const meta = {
 
 	limit: {
 		duration: ms('1hour'),
-		max: 10
+		max: 60
 	},
 
 	requireCredential: true,
@@ -29,9 +29,26 @@ export const meta = {
 			default: null as any as any,
 			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) => {
-	res(pack(await uploadFromUrl(ps.url, user, ps.folderId)));
+	res(pack(await uploadFromUrl(ps.url, user, ps.folderId, null, ps.isSensitive, ps.force)));
 }));
diff --git a/src/services/drive/upload-from-url.ts b/src/services/drive/upload-from-url.ts
index 96e258c98..fa37615a9 100644
--- a/src/services/drive/upload-from-url.ts
+++ b/src/services/drive/upload-from-url.ts
@@ -14,7 +14,14 @@ import fetchMeta from '../../misc/fetch-meta';
 
 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}`);
 
 	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;
 
 	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}`);
 	} catch (e) {
 		error = e;