From a0e583ee4eebe37db4011a99b65d0d60db324054 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 27 Apr 2019 00:25:09 +0200 Subject: api now fetches url --- client/app.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'client/app.js') diff --git a/client/app.js b/client/app.js index cadafef..d18a5aa 100644 --- a/client/app.js +++ b/client/app.js @@ -4,9 +4,10 @@ import UploadImage from './lib/uploadImage.component' import { post } from './util' const initialState = { - 'image': null, - 'res': null, - 'loading': false, + image: null, + url: "", + res: null, + loading: false, } export default class PhashApp extends Component { @@ -35,6 +36,19 @@ export default class PhashApp extends Component { submit() { const { url } = this.state if (!url || url.indexOf('http') !== 0) return + this.setState({ image: url, loading: true }) + + const fd = new FormData() + fd.append('url', url) + post('/api/v1/match', fd) + .then(res => { + console.log(res) + this.setState({ res, loading: false }) + }) + .catch(err => { + console.log(err) + this.setState({ loading: false }) + }) } render() { @@ -108,10 +122,11 @@ export default class PhashApp extends Component { ) } - const { ext, phash, score, sha256 } = closest_match + const { phash, score, sha256, url} = closest_match return (
- Closest match: {sha256}{'.'}{ext}
+
+ Closest match: {sha256}
Score: {score}
Phash: {phash.toString(16)}
-- cgit v1.2.3-70-g09d2