Commit b043a615 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Use External Mimetype library to identify mimetypes properly

parent 097e1705
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<script src="../lib/renderjs.js" type="text/javascript"></script> <script src="../lib/renderjs.js" type="text/javascript"></script>
<script src="../lib/jszip.js" type="text/javascript"></script> <script src="../lib/jszip.js" type="text/javascript"></script>
<script src="../lib/FileSaver.js" type="text/javascript"></script> <script src="../lib/FileSaver.js" type="text/javascript"></script>
<script src="../lib/mimetype.js" type="text/javascript"></script>
<script src="../lib/webtorrent.min.js" type="text/javascript"></script> <script src="../lib/webtorrent.min.js" type="text/javascript"></script>
<script src="./gadget_global.js" type="text/javascript"></script> <script src="./gadget_global.js" type="text/javascript"></script>
......
/*global window, rJS, loopEventListener, RSVP, console, document, saveAs, WebTorrent, /*global window, rJS, loopEventListener, RSVP, console, document, saveAs, WebTorrent,
File, setInterval, clearInterval*/ File, setInterval, clearInterval, mimeType*/
/*jslint nomen: true, indent: 2, maxerr: 3*/ /*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, loopEventListener, JSZip, FileSaver, WebTorrent) { (function (window, rJS, loopEventListener, JSZip, FileSaver, WebTorrent,
mimeType) {
"use strict"; "use strict";
function getExtension(url) { function getExtension(url) {
...@@ -260,16 +261,10 @@ ...@@ -260,16 +261,10 @@
return zipEntry.async('blob'); return zipEntry.async('blob');
}) })
.push(function (result) { .push(function (result) {
if (end_url.endsWith(".js")) { var guessed_type = mimeType.lookup(
// This is a ugly hack as mimetype needs to be correct for JS end_url, false, "application/octet-stream"
result = result.slice(0, result.size, "application/javascript"); );
} else if (end_url.endsWith(".html")) { result = result.slice(0, result.size, guessed_type);
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html");
} else if (end_url.endsWith(".css")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/css");
}
return gadget.crib_sw_put(end_url, {blob: result}); return gadget.crib_sw_put(end_url, {blob: result});
}) })
); );
...@@ -282,6 +277,9 @@ ...@@ -282,6 +277,9 @@
}) })
.push(function () { .push(function () {
logFunction(gadget, "Loaded " + url_number + " files at " + Date()); logFunction(gadget, "Loaded " + url_number + " files at " + Date());
}, function (e) {
console.error(e);
logFunction(gadget, "ERROR:</br>" + e.toString());
}); });
} }
...@@ -367,4 +365,4 @@ ...@@ -367,4 +365,4 @@
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}); });
}(window, rJS, loopEventListener, JSZip, FileSaver, WebTorrent)); }(window, rJS, loopEventListener, JSZip, FileSaver, WebTorrent, mimeType));
\ No newline at end of file \ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<script src="../lib/rsvp.js"></script> <script src="../lib/rsvp.js"></script>
<script src="../lib/renderjs.js"></script> <script src="../lib/renderjs.js"></script>
<script src="../lib/jszip.js" type="text/javascript"></script> <script src="../lib/jszip.js" type="text/javascript"></script>
<script src="../lib/mimetype.js" type="text/javascript"></script>
<script src="./gadget_landing_cribjs.js"></script> <script src="./gadget_landing_cribjs.js"></script>
</head> </head>
<body> <body>
......
/*jslint browser: true, indent: 2, maxlen: 80*/ /*jslint browser: true, indent: 2, maxlen: 80*/
/*globals RSVP, rJS, /*globals RSVP, rJS,
location, console, fetch, Promise*/ location, console, fetch, Promise*/
(function (window, document, RSVP, rJS, location, console, JSZip) { (function (window, document, RSVP, rJS, location, console, JSZip, mimeType) {
"use strict"; "use strict";
function getExtension(url) { function getExtension(url) {
...@@ -38,16 +38,10 @@ ...@@ -38,16 +38,10 @@
return zipEntry.async('blob'); return zipEntry.async('blob');
}) })
.push(function (result) { .push(function (result) {
if (end_url.endsWith(".js")) { var guessed_type = mimeType.lookup(
// This is a ugly hack as mimetype needs to be correct for JS end_url, false, "application/octet-stream"
result = result.slice(0, result.size, "application/javascript"); );
} else if (end_url.endsWith(".html")) { result = result.slice(0, result.size, guessed_type);
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/html");
} else if (end_url.endsWith(".css")) {
// This is a ugly hack as mimetype needs to be correct for JS
result = result.slice(0, result.size, "text/css");
}
return gadget.crib_sw_put(end_url, {blob: result}); return gadget.crib_sw_put(end_url, {blob: result});
}) })
); );
...@@ -113,4 +107,4 @@ ...@@ -113,4 +107,4 @@
return this.getSetting(argument_list[0], argument_list[1]); return this.getSetting(argument_list[0], argument_list[1]);
}); });
}(window, document, RSVP, rJS, location, console, JSZip)); }(window, document, RSVP, rJS, location, console, JSZip, mimeType));
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment