forked from FoundKeyGang/FoundKey
NEW FEATURE: Add url upload
This commit is contained in:
parent
616cad9768
commit
f004673ea5
5 changed files with 95 additions and 13 deletions
|
@ -83,6 +83,7 @@
|
||||||
"crypto": "0.0.3",
|
"crypto": "0.0.3",
|
||||||
"debug": "2.6.1",
|
"debug": "2.6.1",
|
||||||
"deepcopy": "0.6.3",
|
"deepcopy": "0.6.3",
|
||||||
|
"download": "5.0.3",
|
||||||
"elasticsearch": "12.1.3",
|
"elasticsearch": "12.1.3",
|
||||||
"escape-html": "1.0.3",
|
"escape-html": "1.0.3",
|
||||||
"escape-regexp": "0.0.1",
|
"escape-regexp": "0.0.1",
|
||||||
|
|
|
@ -58,6 +58,7 @@ export default [
|
||||||
{ name: 'drive/stream', shouldBeSignin: true, kind: 'drive-read' },
|
{ name: 'drive/stream', shouldBeSignin: true, kind: 'drive-read' },
|
||||||
{ name: 'drive/files', shouldBeSignin: true, kind: 'drive-read' },
|
{ name: 'drive/files', shouldBeSignin: true, kind: 'drive-read' },
|
||||||
{ name: 'drive/files/create', shouldBeSignin: true, limitDuration: hour, limitMax: 100, withFile: true, kind: 'drive-write' },
|
{ name: 'drive/files/create', shouldBeSignin: true, limitDuration: hour, limitMax: 100, withFile: true, kind: 'drive-write' },
|
||||||
|
{ name: 'drive/files/upload_from_url', shouldBeSignin: true, limitDuration: hour, limitMax: 10, kind: 'drive-write' },
|
||||||
{ name: 'drive/files/show', shouldBeSignin: true, kind: 'drive-read' },
|
{ name: 'drive/files/show', shouldBeSignin: true, kind: 'drive-read' },
|
||||||
{ name: 'drive/files/find', shouldBeSignin: true, kind: 'drive-read' },
|
{ name: 'drive/files/find', shouldBeSignin: true, kind: 'drive-read' },
|
||||||
{ name: 'drive/files/delete', shouldBeSignin: true, kind: 'drive-write' },
|
{ name: 'drive/files/delete', shouldBeSignin: true, kind: 'drive-write' },
|
||||||
|
|
55
src/api/endpoints/drive/files/upload_from_url.js
Normal file
55
src/api/endpoints/drive/files/upload_from_url.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module dependencies
|
||||||
|
*/
|
||||||
|
import * as URL from 'url';
|
||||||
|
const download = require('download');
|
||||||
|
import * as mongo from 'mongodb';
|
||||||
|
import File from '../../../models/drive-file';
|
||||||
|
import { validateFileName } from '../../../models/drive-file';
|
||||||
|
import User from '../../../models/user';
|
||||||
|
import serialize from '../../../serializers/drive-file';
|
||||||
|
import create from '../../../common/add-file-to-drive';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a file from a URL
|
||||||
|
*
|
||||||
|
* @param {Object} params
|
||||||
|
* @param {Object} user
|
||||||
|
* @return {Promise<object>}
|
||||||
|
*/
|
||||||
|
module.exports = (params, user) =>
|
||||||
|
new Promise(async (res, rej) =>
|
||||||
|
{
|
||||||
|
// Get 'url' parameter
|
||||||
|
const url = params.url;
|
||||||
|
if (url == null) {
|
||||||
|
return rej('url is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
let name = URL.parse(url).pathname.split('/').pop();
|
||||||
|
if (!validateFileName(name)) {
|
||||||
|
name = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 'folder_id' parameter
|
||||||
|
let folder = params.folder_id;
|
||||||
|
if (folder === undefined || folder === null) {
|
||||||
|
folder = null;
|
||||||
|
} else {
|
||||||
|
folder = new mongo.ObjectID(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download file
|
||||||
|
const data = await download(url);
|
||||||
|
|
||||||
|
// Create file
|
||||||
|
const driveFile = await create(user, data, name, null, folder);
|
||||||
|
|
||||||
|
// Serialize
|
||||||
|
const fileObj = await serialize(driveFile);
|
||||||
|
|
||||||
|
// Response
|
||||||
|
res(fileObj);
|
||||||
|
});
|
|
@ -7,6 +7,9 @@
|
||||||
<li onclick={ parent.upload }>
|
<li onclick={ parent.upload }>
|
||||||
<p><i class="fa fa-upload"></i>ファイルをアップロード</p>
|
<p><i class="fa fa-upload"></i>ファイルをアップロード</p>
|
||||||
</li>
|
</li>
|
||||||
|
<li onclick={ parent.urlUpload }>
|
||||||
|
<p><i class="fa fa-cloud-upload"></i>URLからアップロード</p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</mk-contextmenu>
|
</mk-contextmenu>
|
||||||
<script>
|
<script>
|
||||||
|
@ -27,5 +30,9 @@
|
||||||
@upload = ~>
|
@upload = ~>
|
||||||
@browser.select-local-file!
|
@browser.select-local-file!
|
||||||
@refs.ctx.close!
|
@refs.ctx.close!
|
||||||
|
|
||||||
|
@url-upload = ~>
|
||||||
|
@browser.url-upload!
|
||||||
|
@refs.ctx.close!
|
||||||
</script>
|
</script>
|
||||||
</mk-drive-browser-base-contextmenu>
|
</mk-drive-browser-base-contextmenu>
|
||||||
|
|
|
@ -455,6 +455,24 @@
|
||||||
@select-local-file = ~>
|
@select-local-file = ~>
|
||||||
@refs.file-input.click!
|
@refs.file-input.click!
|
||||||
|
|
||||||
|
@url-upload = ~>
|
||||||
|
url <~ @input-dialog do
|
||||||
|
'URLアップロード'
|
||||||
|
'アップロードしたいファイルのURL'
|
||||||
|
null
|
||||||
|
|
||||||
|
if url? and url != ''
|
||||||
|
@api \drive/files/upload_from_url do
|
||||||
|
url: url
|
||||||
|
folder_id: if @folder? then @folder.id else undefined
|
||||||
|
|
||||||
|
@dialog do
|
||||||
|
'<i class="fa fa-check"></i>アップロードをリクエストしました'
|
||||||
|
'アップロードが完了するまで時間がかかる場合があります。'
|
||||||
|
[
|
||||||
|
text: \OK
|
||||||
|
]
|
||||||
|
|
||||||
@create-folder = ~>
|
@create-folder = ~>
|
||||||
name <~ @input-dialog do
|
name <~ @input-dialog do
|
||||||
'フォルダー作成'
|
'フォルダー作成'
|
||||||
|
|
Loading…
Reference in a new issue