diff --git a/src/api/index.ts b/src/api/index.ts index 1ba3aacb..2d0763e6 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -647,9 +647,10 @@ export class AtelierAPI { name: string, scope: vscode.Uri | string, mtime?: number, - storageOnly: boolean = false + storageOnly = false, + forceBinary = false ): Promise> { - let params, headers; + const params: Record = {}; name = this.transformNameIfCsp(name); if ( this.config.apiVersion >= 4 && @@ -663,17 +664,19 @@ export class AtelierAPI { ) .get("multilineMethodArgs") ) { - params = { format: "udl-multiline" }; - } else { - params = {}; - } - if (storageOnly) { - params["storageOnly"] = "1"; - } - if (mtime && mtime > 0) { - headers = { "IF-NONE-MATCH": new Date(mtime).toISOString().replace(/T|Z/g, " ").trim() }; + params.format = "udl-multiline"; } - return this.request(1, "GET", `${this.ns}/doc/${name}`, null, params, headers); + if (storageOnly) params.storageOnly = "1"; + if (forceBinary) params.binary = "1"; + return this.request( + 1, + "GET", + `${this.ns}/doc/${name}`, + null, + params, + // headers + mtime && mtime > 0 ? { "IF-NONE-MATCH": new Date(mtime).toISOString().replace(/T|Z/g, " ").trim() } : undefined + ); } // api v1+ diff --git a/src/providers/FileSystemProvider/FileSystemProvider.ts b/src/providers/FileSystemProvider/FileSystemProvider.ts index 709d03f4..30e3b518 100644 --- a/src/providers/FileSystemProvider/FileSystemProvider.ts +++ b/src/providers/FileSystemProvider/FileSystemProvider.ts @@ -1,6 +1,5 @@ import * as path from "path"; import * as vscode from "vscode"; -import { isText } from "istextorbinary"; import { AtelierAPI } from "../../api"; import { fireOtherStudioAction, OtherStudioAction } from "../../commands/studio"; import { isfsConfig, projectContentsFromUri, studioOpenDialogFromURI } from "../../utils/FileProviderUtil"; @@ -541,7 +540,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider { .then( async (entry: File) => { const contentBuffer = Buffer.from(content); - const putContent = isText(uri.path.split("/").pop(), contentBuffer) + const putContent = !csp // Web app files must always be written as raw bytes ? { content: new TextDecoder().decode(content).split(/\r?\n/), enc: false, @@ -579,15 +578,6 @@ export class FileSystemProvider implements vscode.FileSystemProvider { update = true; } } - if ( - csp && - !putContent.enc && - putContent.content.length > 1 && - putContent.content[putContent.content.length - 1] == "" - ) { - // Avoid appending a blank line on every save, which would cause a web app file to grow each time - putContent.content.pop(); - } // By the time we get here VS Code's built-in conflict resolution mechanism will already have interacted with the user. // Therefore, it's safe to ignore any conflicts. return api @@ -1075,7 +1065,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider { const fileName = isfsDocumentName(uri, csp); const api = new AtelierAPI(uri); return api - .getDoc(fileName, uri, cachedFile?.mtime) + .getDoc(fileName, uri, cachedFile?.mtime, undefined, csp) // Web app files must always be read as raw bytes .then((data) => data.result) .then( ({ ts, content }) =>