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",
"_inBundle": false,
"_integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"_location": "/axios",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"type": "range",
"registry": true,
"raw": "axios",
"raw": "axios@^0.18.0",
"name": "axios",
"escapedName": "axios",
"rawSpec": "",
"rawSpec": "^0.18.0",
"saveSpec": null,
"fetchSpec": "latest"
"fetchSpec": "^0.18.0"
},
"_requiredBy": [
"#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",
"_spec": "axios",
"_where": "D:\\Desktop\\smartshopperNodeReworkFirebase",
"_spec": "axios@^0.18.0",
"_where": "D:\\5CHITM\\Diplomarbeit\\repos\\SmartShopper\\express-server",
"author": {
"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.
## Browserify Usage
## Browser Usage
Due to the way `XMLHttpRequest` works, the `browserify` versions of `http` and `https` already follow redirects.
If you are *only* targeting the browser, then this library has little value for you. If you want to write cross
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:
Due to the way the browser works,
the `http` and `https` browser equivalents perform redirects by default.
By requiring `follow-redirects` this way:
```javascript
var http = require('follow-redirects/http');
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:
```javascript
"browser": {
```json
{
"follow-redirects/http" : "http",
"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
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
[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 = url.URL;
var http = require("http");
var https = require("https");
var assert = require("assert");
@ -23,6 +24,8 @@ function RedirectableRequest(options, responseCallback) {
Writable.call(this);
options.headers = options.headers || {};
this._options = options;
this._ended = false;
this._ending = false;
this._redirectCount = 0;
this._redirects = [];
this._requestBodyLength = 0;
@ -69,6 +72,11 @@ RedirectableRequest.prototype = Object.create(Writable.prototype);
// Writes buffered data to the current native request
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
if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
throw new Error("data should be a string, Buffer or Uint8Array");
@ -111,11 +119,20 @@ RedirectableRequest.prototype.end = function (data, encoding, callback) {
encoding = null;
}
// Write data and end
// Write data if needed and end
if (!data) {
this._ended = this._ending = true;
this._currentRequest.end(null, null, callback);
}
else {
var self = this;
var currentRequest = this._currentRequest;
this.write(data || "", encoding, function () {
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
@ -183,15 +200,30 @@ RedirectableRequest.prototype._performRequest = function () {
if (this._isRedirect) {
// Write the request entity and end.
var i = 0;
var self = this;
var buffers = this._requestBodyBuffers;
(function writeNext() {
if (i < buffers.length) {
(function writeNext(error) {
// Only write if this request has not been redirected yet
/* istanbul ignore else */
if (request === self._currentRequest) {
// Report any write errors
/* istanbul ignore if */
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);
}
else {
}
// 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;
if (location && this._options.followRedirects !== false &&
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
// in cyclical redirections (i.e., "infinite" redirection loops).
if (++this._redirectCount > this._options.maxRedirects) {
@ -289,27 +326,46 @@ function wrap(protocols) {
var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
// Executes a request, following redirects
wrappedProtocol.request = function (options, callback) {
if (typeof options === "string") {
options = url.parse(options);
options.maxRedirects = exports.maxRedirects;
wrappedProtocol.request = function (input, options, callback) {
// Parse parameters
if (typeof input === "string") {
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 {
callback = options;
options = input;
input = { protocol: protocol };
}
if (typeof options === "function") {
callback = options;
options = null;
}
// Set defaults
options = Object.assign({
protocol: protocol,
maxRedirects: exports.maxRedirects,
maxBodyLength: exports.maxBodyLength,
}, options);
}
}, input, options);
options.nativeProtocols = nativeProtocols;
assert.equal(options.protocol, protocol, "protocol mismatch");
debug("options", options);
return new RedirectableRequest(options, callback);
};
// Executes a GET request, following redirects
wrappedProtocol.get = function (options, callback) {
var request = wrappedProtocol.request(options, callback);
wrappedProtocol.get = function (input, options, callback) {
var request = wrappedProtocol.request(input, options, callback);
request.end();
return request;
};
@ -317,6 +373,29 @@ function wrap(protocols) {
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
module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap;

View File

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

View File

@ -660,7 +660,7 @@
},
"axios": {
"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=",
"requires": {
"follow-redirects": "^1.3.0",
@ -1271,9 +1271,9 @@
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz",
"integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==",
"requires": {
"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() {
//initialize all modals
$('.modal').modal();
$('.materialboxed').materialbox();
if ($(window).width() > 600) {
//large
$(".col").css("height", "100%");
}
else {
//small
$(".col").css("height", "50%");
}
$("#modal1").modal("open");
$(".btnanalyze").click(function() {
analyzeUploaded();
});
//AJAX
// Initialize Firebase
@ -24,15 +34,17 @@ var 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) {
$.ajax({
type: "POST",
url: "/dones",
data:{
idtoken: idtoken,
sl_id: "BplQ5lFU",
billcontent: "fsfs"
sl_id: id,
billcontent: text
},
success(result){
console.log(result);
@ -45,7 +57,8 @@ function movePurchases() {
}
$(".test").click(function() {
movePurchases();
//movePurchases();
getAllShoppinglists();
});
function analyzeUploaded() {
@ -60,7 +73,7 @@ function analyzeUploaded() {
loading = false;
$(".output").text(result.text);
$('#modal1').modal("open");
movePurchases();
movePurchases(result.text);
$(".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;

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 {
background-color: rgb(44, 44, 44);
background-color: #ff5722 ;
height: 100%;
border-radius: 30px;
max-height: 100%;
}
.opt2 {
background-color: rgb(44, 44, 44);
background-color: #03a9f4;
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);
try {
res.status(200).send("Done");
res.status(200).send(await postgres.moveDoneItems(uid, req.body.sl_id, req.body.billcontent));
}
catch(err) {

View File

@ -3,16 +3,25 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Scan Purchases automatically</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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://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-->
<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 -->
<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 -->
<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>
<body>
<div class="cont row container z-depth-4">
<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>
<div class="progress grey lighten-1">
<div class="determinate green accent-4" style="width: 0%"></div>
<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>
<ul class="collection with-header">
<li class="collection-header"><h4>Choose List</h4></li>
<li class="collection-item"><div>Test<a class="secondary-content"><i class="material-icons">send</i></a></div></li>
</ul>
</div>
<div class="col s12 m6 l6 opt2 waves-effect waves-dark">
<!-- Modal Upload -->
<div id="modal-upload" class="modal">
<div class="modal-content">
<h4>Choose Image</h4>
<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>
<img class="materialboxed" id="blah" src="#" alt="your image" />
</div>
<div class="modal-footer">
<a class="modal-close waves-effect waves-red btn-flat">Cancel</a>
<a class="modal-close waves-effect waves-green btn-flat btnanalyze">Continue</a>
<center><i class="material-icons ico">camera</i></center>
</div>
</div>
<!-- Modal Upload -->
<!-- Modal Structure -->
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Result</h4>
<p class="output"></p>
<h4>Choose Shoppinglist</h4>
<div class="collection output">
</div>
</div>
<div class="modal-footer">
<a class="modal-close waves-effect waves-green btn-flat">Ok</a>
<a href="/dash" class="modal-close waves-effect waves-red btn-flat">Return to Dashboard</a>
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Continue</a>
</div>
</div>
<script src="/ocrscan/cam.js"></script>
<script src="/ocrscan/ocrscan.js"></script>
<script src="/ocrscan/fileuploads.js"></script>
</body>
</html>