ocr design update

This commit is contained in:
LukasNowy 2019-01-28 19:53:40 +01:00
parent c8fe9b045a
commit 2179eecb3d
10 changed files with 1849 additions and 165 deletions

View File

@ -1,28 +1,33 @@
{ {
"_from": "axios", "_from": "axios@^0.18.0",
"_id": "axios@0.18.0", "_id": "axios@0.18.0",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", "_integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"_location": "/axios", "_location": "/axios",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "tag", "type": "range",
"registry": true, "registry": true,
"raw": "axios", "raw": "axios@^0.18.0",
"name": "axios", "name": "axios",
"escapedName": "axios", "escapedName": "axios",
"rawSpec": "", "rawSpec": "^0.18.0",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "latest" "fetchSpec": "^0.18.0"
}, },
"_requiredBy": [ "_requiredBy": [
"#USER", "#USER",
"/" "/",
"/gcp-metadata",
"/google-auth-library",
"/google-auto-auth/gcp-metadata",
"/google-auto-auth/google-auth-library",
"/gtoken"
], ],
"_resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz", "_resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"_shasum": "32d53e4851efdc0a11993b6cd000789d70c05102", "_shasum": "32d53e4851efdc0a11993b6cd000789d70c05102",
"_spec": "axios", "_spec": "axios@^0.18.0",
"_where": "D:\\Desktop\\smartshopperNodeReworkFirebase", "_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server",
"author": { "author": {
"name": "Matt Zabriskie" "name": "Matt Zabriskie"
}, },

View File

@ -96,42 +96,26 @@ var followRedirects = require('follow-redirects').wrap({
Such custom protocols only need an implementation of the `request` method. Such custom protocols only need an implementation of the `request` method.
## Browserify Usage ## Browser Usage
Due to the way `XMLHttpRequest` works, the `browserify` versions of `http` and `https` already follow redirects. Due to the way the browser works,
If you are *only* targeting the browser, then this library has little value for you. If you want to write cross the `http` and `https` browser equivalents perform redirects by default.
platform code for node and the browser, `follow-redirects` provides a great solution for making the native node
modules behave the same as they do in browserified builds in the browser. To avoid bundling unnecessary code
you should tell browserify to swap out `follow-redirects` with the standard modules when bundling.
To make this easier, you need to change how you require the modules:
By requiring `follow-redirects` this way:
```javascript ```javascript
var http = require('follow-redirects/http'); var http = require('follow-redirects/http');
var https = require('follow-redirects/https'); var https = require('follow-redirects/https');
``` ```
you can easily tell webpack and friends to replace
`follow-redirect` by the built-in versions:
You can then replace `follow-redirects` in your browserify configuration like so: ```json
{
```javascript
"browser": {
"follow-redirects/http" : "http", "follow-redirects/http" : "http",
"follow-redirects/https" : "https" "follow-redirects/https" : "https"
} }
``` ```
The `browserify-http` module has not kept pace with node development, and no long behaves identically to the native
module when running in the browser. If you are experiencing problems, you may want to check out
[browserify-http-2](https://www.npmjs.com/package/http-browserify-2). It is more actively maintained and
attempts to address a few of the shortcomings of `browserify-http`. In that case, your browserify config should
look something like this:
```javascript
"browser": {
"follow-redirects/http" : "browserify-http-2/http",
"follow-redirects/https" : "browserify-http-2/https"
}
```
## Contributing ## Contributing
Pull Requests are always welcome. Please [file an issue](https://github.com/follow-redirects/follow-redirects/issues) Pull Requests are always welcome. Please [file an issue](https://github.com/follow-redirects/follow-redirects/issues)
@ -152,4 +136,4 @@ Pull Requests are always welcome. Please [file an issue](https://github.com/foll
## License ## License
[https://github.com/follow-redirects/follow-redirects/blob/master/LICENSE](MIT License) [MIT License](https://github.com/follow-redirects/follow-redirects/blob/master/LICENSE)

View File

@ -1,4 +1,5 @@
var url = require("url"); var url = require("url");
var URL = url.URL;
var http = require("http"); var http = require("http");
var https = require("https"); var https = require("https");
var assert = require("assert"); var assert = require("assert");
@ -23,6 +24,8 @@ function RedirectableRequest(options, responseCallback) {
Writable.call(this); Writable.call(this);
options.headers = options.headers || {}; options.headers = options.headers || {};
this._options = options; this._options = options;
this._ended = false;
this._ending = false;
this._redirectCount = 0; this._redirectCount = 0;
this._redirects = []; this._redirects = [];
this._requestBodyLength = 0; this._requestBodyLength = 0;
@ -69,6 +72,11 @@ RedirectableRequest.prototype = Object.create(Writable.prototype);
// Writes buffered data to the current native request // Writes buffered data to the current native request
RedirectableRequest.prototype.write = function (data, encoding, callback) { RedirectableRequest.prototype.write = function (data, encoding, callback) {
// Writing is not allowed if end has been called
if (this._ending) {
throw new Error("write after end");
}
// Validate input and shift parameters if necessary // Validate input and shift parameters if necessary
if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) { if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
throw new Error("data should be a string, Buffer or Uint8Array"); throw new Error("data should be a string, Buffer or Uint8Array");
@ -111,11 +119,20 @@ RedirectableRequest.prototype.end = function (data, encoding, callback) {
encoding = null; encoding = null;
} }
// Write data and end // Write data if needed and end
var currentRequest = this._currentRequest; if (!data) {
this.write(data || "", encoding, function () { this._ended = this._ending = true;
currentRequest.end(null, null, callback); this._currentRequest.end(null, null, callback);
}); }
else {
var self = this;
var currentRequest = this._currentRequest;
this.write(data, encoding, function () {
self._ended = true;
currentRequest.end(null, null, callback);
});
this._ending = true;
}
}; };
// Sets a header value on the current native request // Sets a header value on the current native request
@ -183,14 +200,29 @@ RedirectableRequest.prototype._performRequest = function () {
if (this._isRedirect) { if (this._isRedirect) {
// Write the request entity and end. // Write the request entity and end.
var i = 0; var i = 0;
var self = this;
var buffers = this._requestBodyBuffers; var buffers = this._requestBodyBuffers;
(function writeNext() { (function writeNext(error) {
if (i < buffers.length) { // Only write if this request has not been redirected yet
var buffer = buffers[i++]; /* istanbul ignore else */
request.write(buffer.data, buffer.encoding, writeNext); if (request === self._currentRequest) {
} // Report any write errors
else { /* istanbul ignore if */
request.end(); if (error) {
self.emit("error", error);
}
// Write the next buffer if there are still left
else if (i < buffers.length) {
var buffer = buffers[i++];
/* istanbul ignore else */
if (!request.finished) {
request.write(buffer.data, buffer.encoding, writeNext);
}
}
// End the request if `end` has been called on us
else if (self._ended) {
request.end();
}
} }
}()); }());
} }
@ -216,6 +248,11 @@ RedirectableRequest.prototype._processResponse = function (response) {
var location = response.headers.location; var location = response.headers.location;
if (location && this._options.followRedirects !== false && if (location && this._options.followRedirects !== false &&
response.statusCode >= 300 && response.statusCode < 400) { response.statusCode >= 300 && response.statusCode < 400) {
// Abort the current request
this._currentRequest.removeAllListeners();
this._currentRequest.on("error", noop);
this._currentRequest.abort();
// RFC7231§6.4: A client SHOULD detect and intervene // RFC7231§6.4: A client SHOULD detect and intervene
// in cyclical redirections (i.e., "infinite" redirection loops). // in cyclical redirections (i.e., "infinite" redirection loops).
if (++this._redirectCount > this._options.maxRedirects) { if (++this._redirectCount > this._options.maxRedirects) {
@ -289,27 +326,46 @@ function wrap(protocols) {
var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol); var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
// Executes a request, following redirects // Executes a request, following redirects
wrappedProtocol.request = function (options, callback) { wrappedProtocol.request = function (input, options, callback) {
if (typeof options === "string") { // Parse parameters
options = url.parse(options); if (typeof input === "string") {
options.maxRedirects = exports.maxRedirects; var urlStr = input;
try {
input = urlToOptions(new URL(urlStr));
}
catch (err) {
/* istanbul ignore next */
input = url.parse(urlStr);
}
}
else if (URL && (input instanceof URL)) {
input = urlToOptions(input);
} }
else { else {
options = Object.assign({ callback = options;
protocol: protocol, options = input;
maxRedirects: exports.maxRedirects, input = { protocol: protocol };
maxBodyLength: exports.maxBodyLength,
}, options);
} }
if (typeof options === "function") {
callback = options;
options = null;
}
// Set defaults
options = Object.assign({
maxRedirects: exports.maxRedirects,
maxBodyLength: exports.maxBodyLength,
}, input, options);
options.nativeProtocols = nativeProtocols; options.nativeProtocols = nativeProtocols;
assert.equal(options.protocol, protocol, "protocol mismatch"); assert.equal(options.protocol, protocol, "protocol mismatch");
debug("options", options); debug("options", options);
return new RedirectableRequest(options, callback); return new RedirectableRequest(options, callback);
}; };
// Executes a GET request, following redirects // Executes a GET request, following redirects
wrappedProtocol.get = function (options, callback) { wrappedProtocol.get = function (input, options, callback) {
var request = wrappedProtocol.request(options, callback); var request = wrappedProtocol.request(input, options, callback);
request.end(); request.end();
return request; return request;
}; };
@ -317,6 +373,29 @@ function wrap(protocols) {
return exports; return exports;
} }
/* istanbul ignore next */
function noop() { /* empty */ }
// from https://github.com/nodejs/node/blob/master/lib/internal/url.js
function urlToOptions(urlObject) {
var options = {
protocol: urlObject.protocol,
hostname: urlObject.hostname.startsWith("[") ?
/* istanbul ignore next */
urlObject.hostname.slice(1, -1) :
urlObject.hostname,
hash: urlObject.hash,
search: urlObject.search,
pathname: urlObject.pathname,
path: urlObject.pathname + urlObject.search,
href: urlObject.href,
};
if (urlObject.port !== "") {
options.port = Number(urlObject.port);
}
return options;
}
// Exports // Exports
module.exports = wrap({ http: http, https: https }); module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap; module.exports.wrap = wrap;

View File

@ -1,8 +1,8 @@
{ {
"_from": "follow-redirects@^1.3.0", "_from": "follow-redirects@^1.3.0",
"_id": "follow-redirects@1.5.10", "_id": "follow-redirects@1.6.1",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", "_integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==",
"_location": "/follow-redirects", "_location": "/follow-redirects",
"_phantomChildren": { "_phantomChildren": {
"ms": "2.0.0" "ms": "2.0.0"
@ -20,10 +20,10 @@
"_requiredBy": [ "_requiredBy": [
"/axios" "/axios"
], ],
"_resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", "_resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz",
"_shasum": "7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a", "_shasum": "514973c44b5757368bad8bddfe52f81f015c94cb",
"_spec": "follow-redirects@^1.3.0", "_spec": "follow-redirects@^1.3.0",
"_where": "D:\\Desktop\\smartshopperNodeReworkFirebase\\node_modules\\axios", "_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server\\node_modules\\axios",
"author": { "author": {
"name": "Ruben Verborgh", "name": "Ruben Verborgh",
"email": "ruben@verborgh.org", "email": "ruben@verborgh.org",
@ -61,10 +61,7 @@
"node": ">=4.0" "node": ">=4.0"
}, },
"files": [ "files": [
"index.js", "*.js"
"create.js",
"http.js",
"https.js"
], ],
"homepage": "https://github.com/follow-redirects/follow-redirects", "homepage": "https://github.com/follow-redirects/follow-redirects",
"keywords": [ "keywords": [
@ -94,5 +91,5 @@
"mocha": "nyc mocha", "mocha": "nyc mocha",
"test": "npm run lint && npm run mocha" "test": "npm run lint && npm run mocha"
}, },
"version": "1.5.10" "version": "1.6.1"
} }

View File

@ -660,7 +660,7 @@
}, },
"axios": { "axios": {
"version": "0.18.0", "version": "0.18.0",
"resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": { "requires": {
"follow-redirects": "^1.3.0", "follow-redirects": "^1.3.0",
@ -1271,9 +1271,9 @@
} }
}, },
"follow-redirects": { "follow-redirects": {
"version": "1.5.10", "version": "1.6.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", "integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==",
"requires": { "requires": {
"debug": "=3.1.0" "debug": "=3.1.0"
}, },

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,25 @@
var id;
$(document).ready(function() { $(document).ready(function() {
//initialize all modals //initialize all modals
$('.modal').modal(); $('.modal').modal();
$('.materialboxed').materialbox(); $('.materialboxed').materialbox();
if ($(window).width() > 600) {
//large
$(".col").css("height", "100%");
}
else {
//small
$(".col").css("height", "50%");
}
$("#modal1").modal("open");
$(".btnanalyze").click(function() { $(".btnanalyze").click(function() {
analyzeUploaded(); analyzeUploaded();
}); });
//AJAX //AJAX
// Initialize Firebase // Initialize Firebase
@ -24,15 +34,17 @@ var config = {
firebase.initializeApp(config); firebase.initializeApp(config);
function movePurchases() { getAllShoppinglists();
function movePurchases(text) {
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) { firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/dones", url: "/dones",
data:{ data:{
idtoken: idtoken, idtoken: idtoken,
sl_id: "BplQ5lFU", sl_id: id,
billcontent: "fsfs" billcontent: text
}, },
success(result){ success(result){
console.log(result); console.log(result);
@ -45,7 +57,8 @@ function movePurchases() {
} }
$(".test").click(function() { $(".test").click(function() {
movePurchases(); //movePurchases();
getAllShoppinglists();
}); });
function analyzeUploaded() { function analyzeUploaded() {
@ -60,7 +73,7 @@ function analyzeUploaded() {
loading = false; loading = false;
$(".output").text(result.text); $(".output").text(result.text);
$('#modal1').modal("open"); $('#modal1').modal("open");
movePurchases(); movePurchases(result.text);
$(".determinate").css("width", "0%"); $(".determinate").css("width", "0%");
}); });
} }
@ -74,6 +87,36 @@ function updateProgress(percent) {
} }
function getAllShoppinglists() {
firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) {
$.ajax({
type: "GET",
url: "/myshoppinglists",
data:{
idtoken: idtoken,
},
success(data){
for(let item of data) {
$(".output").append("<a id='" + item.sl_id +"' class='collection-item'>" + item.name + "</a>")
}
},
error(err){
console.error("Error: " + err);
}
});
}).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}});
}
$(document).on("click", ".collection-item", function() {
id = $(this).closest("a").attr("id");
$(".active").removeClass("active");
$(this).addClass("active");
});
}); });
var loading = false; var loading = false;

View File

@ -1,36 +1,35 @@
html, body {
height: 100%;
margin: 0;
background-color: #90caf9;
}
#video {
width: 100%;
}
#canvas {
width: 100%;
}
.cont {
margin-top: 3%;
height: 100%;
border-radius: 30px;
background-color: rgb(44, 44, 44);
}
.opt1 { .opt1 {
background-color: rgb(44, 44, 44); background-color: #ff5722 ;
height: 100%; height: 100%;
border-radius: 30px; max-height: 100%;
} }
.opt2 { .opt2 {
background-color: rgb(44, 44, 44); background-color: #03a9f4;
height: 100%; height: 100%;
border-radius: 30px; max-height: 100%;
} }
.blah { .row {
height: 100%;
max-height: 100%;
}
html, body {
height: 100%;
margin: 0;
max-height: 100%;
overflow: hidden;
}
.ico {
color: white;
font-size: 50vmin;
-ms-transform: translateY(50%);
transform: translateY(50%);
}
.collection .collection-item.active {
/* background-color: #00c853; */
} }

View File

@ -441,7 +441,7 @@ router.post("/dones", async function(req, res, next) {
console.log("So andere sachen: ", req.body.name, req.body.description); console.log("So andere sachen: ", req.body.name, req.body.description);
try { try {
res.status(200).send("Done"); res.status(200).send(await postgres.moveDoneItems(uid, req.body.sl_id, req.body.billcontent));
} }
catch(err) { catch(err) {

View File

@ -3,16 +3,25 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scan Purchases automatically</title> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://www.gstatic.com/firebasejs/5.7.0/firebase.js"></script> <script src="https://www.gstatic.com/firebasejs/5.7.0/firebase.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="/ocrscan/axios.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src='https://cdn.jsdelivr.net/gh/naptha/tesseract.js@v1.0.14/dist/tesseract.min.js'></script>
<!--Import Google Icon Font--> <!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src='https://cdn.jsdelivr.net/gh/naptha/tesseract.js@v1.0.14/dist/tesseract.min.js'></script> <!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Compiled and minified CSS --> <!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
@ -20,74 +29,39 @@
<!-- Compiled and minified JavaScript --> <!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<link rel="stylesheet" href="/ocrscan/style.css"> <link rel="stylesheet" href="ocrscan/style.css">
</head> </head>
<body> <body>
<div class="row">
<div class="col s12 m6 l6 opt1 waves-effect waves-dark" >
<center><i class="material-icons ico" >file_upload</i></center>
</div>
<div class="cont row container z-depth-4"> <div class="col s12 m6 l6 opt2 waves-effect waves-dark">
<button data-target="modal-upload" class="btn modal-trigger">Upload Image</button>
<button data-target="modal-upload" class="btn modal-trigger">Make Image</button>
<button class="test">Tessst</button> <center><i class="material-icons ico">camera</i></center>
</div>
<div class="progress grey lighten-1">
<div class="determinate green accent-4" style="width: 0%"></div>
</div> </div>
<ul class="collection with-header"> <!-- Modal Structure -->
<li class="collection-header"><h4>Choose List</h4></li> <div id="modal1" class="modal">
<li class="collection-item"><div>Test<a class="secondary-content"><i class="material-icons">send</i></a></div></li>
</ul>
</div>
<!-- Modal Upload -->
<div id="modal-upload" class="modal">
<div class="modal-content"> <div class="modal-content">
<h4>Choose Image</h4> <h4>Choose Shoppinglist</h4>
<div class="collection output">
<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input type='file' onchange="readURL(this);" />
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload one or more files">
</div>
</div> </div>
<img class="materialboxed" id="blah" src="#" alt="your image" />
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a class="modal-close waves-effect waves-red btn-flat">Cancel</a> <a href="/dash" class="modal-close waves-effect waves-red btn-flat">Return to Dashboard</a>
<a class="modal-close waves-effect waves-green btn-flat btnanalyze">Continue</a> <a href="#!" class="modal-close waves-effect waves-green btn-flat">Continue</a>
</div> </div>
</div> </div>
<script src="/ocrscan/cam.js"></script>
<script src="/ocrscan/ocrscan.js"></script>
<!-- Modal Upload --> <script src="/ocrscan/fileuploads.js"></script>
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Result</h4>
<p class="output"></p>
</div>
<div class="modal-footer">
<a class="modal-close waves-effect waves-green btn-flat">Ok</a>
</div>
</div>
<script src="/ocrscan/cam.js"></script>
<script src="/ocrscan/ocrscan.js"></script>
<script src="/ocrscan/fileuploads.js"></script>
</body> </body>
</html> </html>