From 1b9f49f687befc463bacedbcf98b255179f37dfa Mon Sep 17 00:00:00 2001 From: Ben Letchford Date: Thu, 23 Jan 2020 11:40:05 +1100 Subject: [PATCH] Detect plain text files and assign them an extension of .txt instead of defaulting to octet-stream --- package.json | 2 +- src/client/index.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 263c3cb..8b7f6e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wetty", - "version": "1.3.0", + "version": "1.3.1", "description": "WeTTY = Web + TTY. Terminal access in browser over http/https", "homepage": "https://github.com/butlerx/wetty", "repository": { diff --git a/src/client/index.ts b/src/client/index.ts index 454f038..432fd7a 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -99,6 +99,12 @@ socket.on('connect', () => { mimeType = typeData.mime; fileExt = typeData.ext; } + // Check if the buffer is ASCII + // Ref: https://stackoverflow.com/a/14313213 + else if (/^[\x00-\x7F]*$/.test(fileCharacters)) { // eslint-disable-line no-control-regex + mimeType = 'text/plain'; + fileExt = 'txt'; + } const fileName = `file-${new Date() .toISOString() .split('.')[0]