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