From 7ffbd375e264457f074b9e4f87a83e87dd1eff9b Mon Sep 17 00:00:00 2001 From: Antoine Hurard <50317271+AntoineRelief@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:42:13 +0800 Subject: [PATCH] Revert "refactor: application scss endpoint now using text/plain (#2467)" This reverts commit 48868fe0cfc7f51c9627591912a293d8583fba65. --- .../application/application.service.ts | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/libs/shared/src/lib/services/application/application.service.ts b/libs/shared/src/lib/services/application/application.service.ts index 12f67fa2dd..4679dae458 100644 --- a/libs/shared/src/lib/services/application/application.service.ts +++ b/libs/shared/src/lib/services/application/application.service.ts @@ -1951,42 +1951,46 @@ export class ApplicationService { const path = `style/application/${application?.id}`; const headers = new HttpHeaders({ // eslint-disable-next-line @typescript-eslint/naming-convention - 'Content-Type': 'text/plain', + 'Content-Type': 'application/json', }); return firstValueFrom( - this.restService.get(path, { responseType: 'text', headers }) + this.restService.get(path, { responseType: 'blob', headers }) ) .then(async (res) => { - const styleFromFile = res; - const scss = styleFromFile as string; - this.customStyle = this.document.createElement('style'); - await firstValueFrom( - this.restService.post( - 'style/scss-to-css', - { scss }, - { responseType: 'text' } + if (res.type === 'application/octet-stream') { + const styleFromFile = await res.text(); + const scss = styleFromFile as string; + this.customStyle = this.document.createElement('style'); + await firstValueFrom( + this.restService.post( + 'style/scss-to-css', + { scss }, + { responseType: 'text' } + ) ) - ) - .then((css) => { - if (this.customStyle) { - this.customStyle.innerText = css; - // Add stylesheet to shadow root instead of document head - if (this.shadowDomService.isShadowRoot) { - this.shadowDomService.currentHost.appendChild(this.customStyle); - } else { - this.document - .getElementsByTagName('head')[0] - .appendChild(this.customStyle); + .then((css) => { + if (this.customStyle) { + this.customStyle.innerText = css; + // Add stylesheet to shadow root instead of document head + if (this.shadowDomService.isShadowRoot) { + this.shadowDomService.currentHost.appendChild( + this.customStyle + ); + } else { + this.document + .getElementsByTagName('head')[0] + .appendChild(this.customStyle); + } } - } - }) - .catch(() => { - if (this.customStyle) { - this.customStyle.innerText = styleFromFile; - } - }); + }) + .catch(() => { + if (this.customStyle) { + this.customStyle.innerText = styleFromFile; + } + }); - this.rawCustomStyle = styleFromFile; + this.rawCustomStyle = styleFromFile; + } }) .catch((err) => { console.error(err);