diff --git a/src/App.js b/src/App.js index 1f66f7b..6aafd77 100644 --- a/src/App.js +++ b/src/App.js @@ -17,14 +17,10 @@ async function loadFromBytebin(id) { const resp = await fetch('https://bytebin.lucko.me/' + id); if (resp.ok) { const content = await resp.text(); - const { type, subtype: subType } = parseContentType(resp.headers.get('content-type')); + const type = parseLanguageFromContentType(resp.headers.get('content-type')); document.title = 'paste | ' + id; - if (type === 'text' && languageIds.includes(subType.toLowerCase())) { - return { ok: true, content, type: subType.toLowerCase() }; - } else { - return { ok: true, content }; - } + return { ok: true, content, type }; } else { return { ok: false }; } @@ -33,6 +29,16 @@ async function loadFromBytebin(id) { } } +function parseLanguageFromContentType(contentType) { + const { type, subtype: subType } = parseContentType(contentType); + if (type === 'application' && subType === 'json') { + return 'json'; + } + if (type === 'text' && languageIds.includes(subType.toLowerCase())) { + return subType.toLowerCase(); + } +} + const INITIAL = Symbol(); const LOADING = Symbol(); const LOADED = Symbol(); diff --git a/src/components/EditorControls.js b/src/components/EditorControls.js index af9db66..77b0866 100644 --- a/src/components/EditorControls.js +++ b/src/components/EditorControls.js @@ -147,10 +147,18 @@ const MenuButton = ({ label, ids, value, setValue }) => { ) } +function langaugeToContentType(language) { + if (language === 'json') { + return 'application/json'; + } else { + return 'text/' + language; + } +} + async function saveToBytebin(code, language) { try { const compressed = gzip(code); - const contentType = 'text/' + language; + const contentType = langaugeToContentType(language); const resp = await fetch('https://bytebin.lucko.me/post', { method: 'POST',