Skip to content

Commit

Permalink
support upload from url
Browse files Browse the repository at this point in the history
  • Loading branch information
maple3142 committed Oct 7, 2019
1 parent 8127bd6 commit d8b60a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
54 changes: 33 additions & 21 deletions worker/dist/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1172,20 +1172,40 @@ self.props = {
});
}

var tok = path.split('/');
var name = tok.pop();
var parent = tok.join('/');
var rootId = request.searchParams.get('rootId') || self.props.defaultRootId;
return _await$1(gd.uploadByPath(parent, name, request.body, rootId), function (_gd$uploadByPath) {
return new Response(JSON.stringify(_gd$uploadByPath), {
headers: {
'Content-Type': 'application/json'
}
var url = request.searchParams.get('url');
var fileBody;
return _invoke(function () {
if (url) {
return _await$1(fetch(url), function (_fetch) {
fileBody = _fetch.body;
});
} else {
fileBody = request.body;
}
}, function () {
var tok = path.split('/');
var name = tok.pop();
var parent = tok.join('/');
var rootId = request.searchParams.get('rootId') || self.props.defaultRootId;
return _await$1(gd.uploadByPath(parent, name, fileBody, rootId), function (_gd$uploadByPath) {
return new Response(JSON.stringify(_gd$uploadByPath), {
headers: {
'Content-Type': 'application/json'
}
});
});
});
});

function _empty() {}
function _invoke(body, then) {
var result = body();

if (result && result.then) {
return result.then(then);
}

return then(result);
}

var onPost = _async(function (request) {
var path = request.pathname;
Expand Down Expand Up @@ -1228,13 +1248,7 @@ self.props = {
}
});

function _invokeIgnored(body) {
var result = body();

if (result && result.then) {
return result.then(_empty);
}
}
function _empty() {}

var onGet = _async(function (request) {
var path = request.pathname;
Expand Down Expand Up @@ -1293,14 +1307,12 @@ self.props = {
}
});

function _invoke(body, then) {
function _invokeIgnored(body) {
var result = body();

if (result && result.then) {
return result.then(then);
return result.then(_empty);
}

return then(result);
}

var gd = new GoogleDrive(self.props);
Expand Down
9 changes: 8 additions & 1 deletion worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,18 @@ async function onPut(request) {
status: 405
})
}
const url = request.searchParams.get('url')
let fileBody
if (url) {
fileBody = (await fetch(url)).body
} else {
fileBody = request.body
}
const tok = path.split('/')
const name = tok.pop()
const parent = tok.join('/')
const rootId = request.searchParams.get('rootId') || self.props.defaultRootId
return new Response(JSON.stringify(await gd.uploadByPath(parent, name, request.body, rootId)), {
return new Response(JSON.stringify(await gd.uploadByPath(parent, name, fileBody, rootId)), {
headers: {
'Content-Type': 'application/json'
}
Expand Down

0 comments on commit d8b60a7

Please sign in to comment.