diff --git a/apps/client/src/services/server.ts b/apps/client/src/services/server.ts index e15e3ba88..8207f18ff 100644 --- a/apps/client/src/services/server.ts +++ b/apps/client/src/services/server.ts @@ -58,8 +58,11 @@ async function getWithSilentNotFound(url: string, componentId?: string) { return await call("GET", url, componentId, { silentNotFound: true }); } -async function get(url: string, componentId?: string) { - return await call("GET", url, componentId); +/** + * @param raw if `true`, the value will be returned as a string instead of a JavaScript object if JSON, XMLDocument if XML, etc. + */ +async function get(url: string, componentId?: string, raw?: boolean) { + return await call("GET", url, componentId, { raw }); } async function post(url: string, data?: unknown, componentId?: string) { @@ -102,6 +105,8 @@ let maxKnownEntityChangeId = 0; interface CallOptions { data?: unknown; silentNotFound?: boolean; + // If `true`, the value will be returned as a string instead of a JavaScript object if JSON, XMLDocument if XML, etc. + raw?: boolean; } async function call(method: string, url: string, componentId?: string, options: CallOptions = {}) { @@ -132,7 +137,7 @@ async function call(method: string, url: string, componentId?: string, option }); })) as any; } else { - resp = await ajax(url, method, data, headers, !!options.silentNotFound); + resp = await ajax(url, method, data, headers, !!options.silentNotFound, options.raw); } const maxEntityChangeIdStr = resp.headers["trilium-max-entity-change-id"]; @@ -144,7 +149,10 @@ async function call(method: string, url: string, componentId?: string, option return resp.body as T; } -function ajax(url: string, method: string, data: unknown, headers: Headers, silentNotFound: boolean): Promise { +/** + * @param raw if `true`, the value will be returned as a string instead of a JavaScript object if JSON, XMLDocument if XML, etc. + */ +function ajax(url: string, method: string, data: unknown, headers: Headers, silentNotFound: boolean, raw?: boolean): Promise { return new Promise((res, rej) => { const options: JQueryAjaxSettings = { url: window.glob.baseApiUrl + url, @@ -186,6 +194,10 @@ function ajax(url: string, method: string, data: unknown, headers: Headers, sile } }; + if (raw) { + options.dataType = "text"; + } + if (data) { try { options.data = JSON.stringify(data); diff --git a/apps/client/src/widgets/type_widgets/geo_map.ts b/apps/client/src/widgets/type_widgets/geo_map.ts index bf7433572..bd4d3af57 100644 --- a/apps/client/src/widgets/type_widgets/geo_map.ts +++ b/apps/client/src/widgets/type_widgets/geo_map.ts @@ -224,13 +224,12 @@ export default class GeoMapTypeWidget extends TypeWidget { this.gpxLoaded = true; } - const xmlResponse = await server.get(`notes/${note.noteId}/open`); + const xmlResponse = await server.get(`notes/${note.noteId}/open`, undefined, true); let stringResponse: string; if (xmlResponse instanceof Uint8Array) { stringResponse = new TextDecoder().decode(xmlResponse); } else { - // TODO: This is not very efficient as it's probably a string response that is parsed and then converted back to string and parsed again. - stringResponse = new XMLSerializer().serializeToString(xmlResponse) + stringResponse = xmlResponse; } const track = new this.L.GPX(stringResponse, {});