Commit 3add7a8f authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Move handleDataURLRead code outside the promise

parent 5f872cc2
...@@ -17,11 +17,8 @@ ...@@ -17,11 +17,8 @@
}); });
} }
function getOrientation(blob, callback) { function handleDataURLRead(data_url) {
var fr = new FileReader(); var view = new DataView(data_url),
return new RSVP.Promise(function waitFormDataURLRead(resolve, reject) {
fr.addEventListener("load", function handleDataURLRead(evt) {
var view = new DataView(evt.target.result),
length = view.byteLength, length = view.byteLength,
offset = 2, offset = 2,
marker, marker,
...@@ -30,18 +27,18 @@ ...@@ -30,18 +27,18 @@
i; i;
if (view.getUint16(0, false) !== 0xFFD8) { if (view.getUint16(0, false) !== 0xFFD8) {
return resolve(-2); return -2;
} }
while (offset < length) { while (offset < length) {
if (view.getUint16(offset + 2, false) <= 8) { if (view.getUint16(offset + 2, false) <= 8) {
return resolve(-1); return -1;
} }
marker = view.getUint16(offset, false); marker = view.getUint16(offset, false);
offset += 2; offset += 2;
if (marker === 0xFFE1) { if (marker === 0xFFE1) {
offset += 2; offset += 2;
if (view.getUint32(offset, false) !== 0x45786966) { if (view.getUint32(offset, false) !== 0x45786966) {
return resolve(-1); return -1;
} }
offset += 6; offset += 6;
little = view.getUint16(offset, false) === 0x4949; little = view.getUint16(offset, false) === 0x4949;
...@@ -50,7 +47,7 @@ ...@@ -50,7 +47,7 @@
offset += 2; offset += 2;
for (i = 0; i < tags; i = i + 1) { for (i = 0; i < tags; i = i + 1) {
if (view.getUint16(offset + (i * 12), little) === 0x0112) { if (view.getUint16(offset + (i * 12), little) === 0x0112) {
return resolve(view.getUint16(offset + (i * 12) + 8, little)); return view.getUint16(offset + (i * 12) + 8, little);
} }
} }
continue; continue;
...@@ -59,7 +56,14 @@ ...@@ -59,7 +56,14 @@
} }
offset += view.getUint16(offset, false); offset += view.getUint16(offset, false);
} }
return resolve(-1); return -1;
}
function getOrientation(blob, callback) {
var fr = new FileReader();
return new RSVP.Promise(function waitFormDataURLRead(resolve, reject) {
fr.addEventListener("load", function onload(evt) {
resolve(handleDataURLRead(evt.target.result));
}); });
fr.addEventListener("error", reject); fr.addEventListener("error", reject);
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>982.16570.34450.716</string> </value> <value> <string>982.16659.47570.45977</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1583145490.98</float> <float>1583149298.17</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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