Skip to content

Commit e2d7a59

Browse files
committed
Use apprt-fetch instead of apprt-request.
This is required for compatibility with map.apps 4.20.0.
1 parent 29a6261 commit e2d7a59

3 files changed

Lines changed: 31 additions & 16 deletions

File tree

src/main/js/bundles/mapapps-github-manager/BundleDetailsController.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
* limitations under the License.
1515
*/
1616
import Hash from "ct/Hash";
17-
import apprt_request from "apprt-request";
17+
import { apprtFetch, apprtFetchJson } from "apprt-fetch";
1818
import { replace } from "apprt-core/string-replace";
19+
import { sourceId } from "source-info!";
20+
import { loggerForName } from "apprt-core/Logger";
21+
const LOG = loggerForName(sourceId);
1922

2023
export default class BundleDetailsController {
2124
// injected
@@ -117,8 +120,8 @@ export default class BundleDetailsController {
117120
async _lookupAvailableTags(repositoryName) {
118121
const tagsUrl = "https://api.github.com/repos/conterra/" + repositoryName + "/releases";
119122
try {
120-
const response = await apprt_request(tagsUrl, { jsonp: true });
121-
const releases = response.data.filter((release) => !release.name.includes("SNAPSHOT"));
123+
const data = await apprtFetchJson(tagsUrl);
124+
const releases = data.filter((release) => !release.name.includes("SNAPSHOT"));
122125
releases.sort((a, b) =>
123126
b.name.replace(/\d+/g, (n) => +n + 100000).localeCompare(a.name.replace(/\d+/g, (n) => +n + 100000))
124127
);
@@ -191,10 +194,10 @@ export default class BundleDetailsController {
191194
}
192195
}
193196

194-
_downloadArchive(url) {
195-
return apprt_request(url, {
196-
handleAs: "blob"
197-
});
197+
async _downloadArchive(url) {
198+
// Currently throws a CORS error (from GitHub) and then uses the map.apps proxy.
199+
const response = await apprtFetch(url, { checkStatus: true });
200+
return await response.blob();
198201
}
199202

200203
async _uploadBundle(blob, itemName) {
@@ -205,8 +208,10 @@ export default class BundleDetailsController {
205208
formData.append("file", blob, fileName);
206209
formData.append("f", "json");
207210
try {
208-
await apprt_request.post(url, {
209-
data: formData
211+
await apprtFetch(url, {
212+
method: "POST",
213+
body: formData,
214+
checkStatus: true
210215
});
211216
this.buttonWidget.set("disabled", false);
212217
this.buttonWidget.set("iconClass", "icon-sign-success");
@@ -216,6 +221,7 @@ export default class BundleDetailsController {
216221
this.detailWindow.close();
217222
}, 1500);
218223
} catch (e) {
224+
LOG.error("Failed to upload bundle", e);
219225
this.detailWindow.set("content", this.i18n.integrationFailed);
220226
}
221227
}

src/main/js/bundles/mapapps-github-manager/BundleStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import { AsyncInMemoryStore } from "store-api/InMemoryStore";
1717
import TypeFormat from "ct/util/TypeFormat";
18-
import apprt_request from "apprt-request";
18+
import { apprtFetchJson } from "apprt-fetch";
1919
import stringEscape from "apprt-core/string-escape";
2020

2121
export default class BundleStoreFactory {
@@ -49,8 +49,8 @@ async function fetchBundlesFromGitHub(target, user, topic) {
4949
}
5050
url = url + "&per_page=100";
5151
try {
52-
const data = await apprt_request(url, {
53-
useProxy: false,
52+
const data = await apprtFetchJson(url, {
53+
proxyMode: "force-off",
5454
headers: {
5555
Accept: "application/vnd.github.mercy-preview+json"
5656
}

src/main/js/bundles/mapapps-github-manager/manifest.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dataform": "^4.17.0",
1717
"dataview": "^4.17.0",
1818
"apprt-vue": "^4.17.0",
19-
"apprt-request": "^4.17.0",
19+
"apprt-fetch": "^4.17.0",
2020
"apprt-core": "^4.17.0",
2121
"apprt-vuetify": "^4.17.0",
2222
"store-api": "^4.17.0"
@@ -111,7 +111,10 @@
111111
{
112112
"name": "GithubBundlesDataView",
113113
"impl": "dataview/DataView",
114-
"provides": ["dijit.Widget", "mapapps-github-manager.GithubBundlesDataView"],
114+
"provides": [
115+
"dijit.Widget",
116+
"mapapps-github-manager.GithubBundlesDataView"
117+
],
115118
"propertiesConstructor": true,
116119
"properties": {
117120
"id": "githubBundlesDataView",
@@ -181,7 +184,10 @@
181184
{
182185
"name": "BundlesDataViewController",
183186
"impl": "dataview/DataViewController",
184-
"provides": ["ct.framework.api.EventHandler", "mapapps-github-manager.BundlesDataViewController"],
187+
"provides": [
188+
"ct.framework.api.EventHandler",
189+
"mapapps-github-manager.BundlesDataViewController"
190+
],
185191
"properties": {
186192
"Event-Topics": [
187193
{
@@ -217,7 +223,10 @@
217223
},
218224
{
219225
"name": "BundleDetailsController",
220-
"provides": ["ct.framework.api.EventHandler", "mapapps-github-manager.BundleDetailsController"],
226+
"provides": [
227+
"ct.framework.api.EventHandler",
228+
"mapapps-github-manager.BundleDetailsController"
229+
],
221230
"properties": {
222231
"uploadTarget": "@@applicationURL.noscheme@@/resources/jsregistry/upload",
223232
"Event-Topics": [

0 commit comments

Comments
 (0)