|
@@ -44,33 +44,26 @@ class RestFormApi {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async upload(content, url) {
|
|
async upload(content, url) {
|
|
|
-
|
|
|
|
|
this.controller = new AbortController();
|
|
this.controller = new AbortController();
|
|
|
- try {
|
|
|
|
|
- const blob = new Blob([content], { type: "text/html" });
|
|
|
|
|
- const file = new File([blob], "SingleFile.html", { type: "text/html" });
|
|
|
|
|
- let formData = new FormData();
|
|
|
|
|
- if (this.fileFieldName) {
|
|
|
|
|
- formData.append(this.fileFieldName, file);
|
|
|
|
|
- }
|
|
|
|
|
- if (this.urlFieldName) {
|
|
|
|
|
- formData.append(this.urlFieldName, url);
|
|
|
|
|
- }
|
|
|
|
|
- const response = await fetch(this.restApiUrl, {
|
|
|
|
|
- method: "POST",
|
|
|
|
|
- body: formData,
|
|
|
|
|
- headers: this.headers,
|
|
|
|
|
- signal: this.controller.signal
|
|
|
|
|
- });
|
|
|
|
|
- if ([200, 201].includes(response.status)) {
|
|
|
|
|
- // do something with the data?
|
|
|
|
|
- const data = await response.json();
|
|
|
|
|
- } else {
|
|
|
|
|
- throw new Error(await response.text());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const blob = new Blob([content], { type: "text/html" });
|
|
|
|
|
+ const file = new File([blob], "SingleFile.html", { type: "text/html" });
|
|
|
|
|
+ let formData = new FormData();
|
|
|
|
|
+ if (this.fileFieldName) {
|
|
|
|
|
+ formData.append(this.fileFieldName, file);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.urlFieldName) {
|
|
|
|
|
+ formData.append(this.urlFieldName, url);
|
|
|
}
|
|
}
|
|
|
- catch (e) {
|
|
|
|
|
- throw new Error(e);
|
|
|
|
|
|
|
+ const response = await fetch(this.restApiUrl, {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ body: formData,
|
|
|
|
|
+ headers: this.headers,
|
|
|
|
|
+ signal: this.controller.signal
|
|
|
|
|
+ });
|
|
|
|
|
+ if ([200, 201].includes(response.status)) {
|
|
|
|
|
+ return response.json();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error(await response.text());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|