Skip to content

Commit d8b60a7

Browse files
committed
support upload from url
1 parent 8127bd6 commit d8b60a7

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

worker/dist/worker.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,20 +1172,40 @@ self.props = {
11721172
});
11731173
}
11741174

1175-
var tok = path.split('/');
1176-
var name = tok.pop();
1177-
var parent = tok.join('/');
1178-
var rootId = request.searchParams.get('rootId') || self.props.defaultRootId;
1179-
return _await$1(gd.uploadByPath(parent, name, request.body, rootId), function (_gd$uploadByPath) {
1180-
return new Response(JSON.stringify(_gd$uploadByPath), {
1181-
headers: {
1182-
'Content-Type': 'application/json'
1183-
}
1175+
var url = request.searchParams.get('url');
1176+
var fileBody;
1177+
return _invoke(function () {
1178+
if (url) {
1179+
return _await$1(fetch(url), function (_fetch) {
1180+
fileBody = _fetch.body;
1181+
});
1182+
} else {
1183+
fileBody = request.body;
1184+
}
1185+
}, function () {
1186+
var tok = path.split('/');
1187+
var name = tok.pop();
1188+
var parent = tok.join('/');
1189+
var rootId = request.searchParams.get('rootId') || self.props.defaultRootId;
1190+
return _await$1(gd.uploadByPath(parent, name, fileBody, rootId), function (_gd$uploadByPath) {
1191+
return new Response(JSON.stringify(_gd$uploadByPath), {
1192+
headers: {
1193+
'Content-Type': 'application/json'
1194+
}
1195+
});
11841196
});
11851197
});
11861198
});
11871199

1188-
function _empty() {}
1200+
function _invoke(body, then) {
1201+
var result = body();
1202+
1203+
if (result && result.then) {
1204+
return result.then(then);
1205+
}
1206+
1207+
return then(result);
1208+
}
11891209

11901210
var onPost = _async(function (request) {
11911211
var path = request.pathname;
@@ -1228,13 +1248,7 @@ self.props = {
12281248
}
12291249
});
12301250

1231-
function _invokeIgnored(body) {
1232-
var result = body();
1233-
1234-
if (result && result.then) {
1235-
return result.then(_empty);
1236-
}
1237-
}
1251+
function _empty() {}
12381252

12391253
var onGet = _async(function (request) {
12401254
var path = request.pathname;
@@ -1293,14 +1307,12 @@ self.props = {
12931307
}
12941308
});
12951309

1296-
function _invoke(body, then) {
1310+
function _invokeIgnored(body) {
12971311
var result = body();
12981312

12991313
if (result && result.then) {
1300-
return result.then(then);
1314+
return result.then(_empty);
13011315
}
1302-
1303-
return then(result);
13041316
}
13051317

13061318
var gd = new GoogleDrive(self.props);

worker/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,18 @@ async function onPut(request) {
9696
status: 405
9797
})
9898
}
99+
const url = request.searchParams.get('url')
100+
let fileBody
101+
if (url) {
102+
fileBody = (await fetch(url)).body
103+
} else {
104+
fileBody = request.body
105+
}
99106
const tok = path.split('/')
100107
const name = tok.pop()
101108
const parent = tok.join('/')
102109
const rootId = request.searchParams.get('rootId') || self.props.defaultRootId
103-
return new Response(JSON.stringify(await gd.uploadByPath(parent, name, request.body, rootId)), {
110+
return new Response(JSON.stringify(await gd.uploadByPath(parent, name, fileBody, rootId)), {
104111
headers: {
105112
'Content-Type': 'application/json'
106113
}

0 commit comments

Comments
 (0)