bluejoyq

add api connection

...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
2 "devToolsPort": 19002, 2 "devToolsPort": 19002,
3 "expoServerPort": 19000, 3 "expoServerPort": 19000,
4 "packagerPort": 19001, 4 "packagerPort": 19001,
5 - "packagerPid": 30352, 5 + "packagerPid": 14964,
6 "expoServerNgrokUrl": "https://s4-47j.anonymous.searchguide.exp.direct", 6 "expoServerNgrokUrl": "https://s4-47j.anonymous.searchguide.exp.direct",
7 "packagerNgrokUrl": "https://packager.s4-47j.anonymous.searchguide.exp.direct", 7 "packagerNgrokUrl": "https://packager.s4-47j.anonymous.searchguide.exp.direct",
8 - "ngrokPid": 19368 8 + "ngrokPid": 3788
9 } 9 }
......
1 +const axios = require('axios')
2 +const filter = require('./filter')
3 +
4 +export const SendToApi = async(searchdata) => {
5 + console.log(searchdata)
6 + return new Promise((resolve,reject) => {
7 + let isBlank_reg = "/\s\g"
8 + if(searchdata=== "" || searchdata.length > 30 ){
9 + resolve(JSON.stringify({ "return_code" : -1, "error_code": "검색 단어를 확인해 주세요!" }));
10 + } else{
11 + axios(
12 + {
13 + headers: {
14 + "Accept": "application/json",
15 + "Content-Type": "application/json",
16 + },
17 + url: 'http://1.201.142.118:80/api/cliConnection',
18 + data: {
19 + data:{
20 + text: searchdata.replace(/\s{1,}/g,' ')
21 + }
22 + },
23 + method: "POST",
24 + }
25 + )
26 + .then((response)=>{
27 + resolve(JSON.stringify(filter(response.data)))
28 + })
29 + .catch(error => {
30 + console.error(error);
31 + });
32 + }
33 + setTimeout( () => {
34 + try {
35 + throw new Error( "ERROR" );
36 + }
37 + catch (err) {
38 + resolve(JSON.stringify({ "return_code" : -1, "error_code" : err.message }));
39 + return false;
40 + }},10000)
41 + })
42 +}
...\ No newline at end of file ...\ No newline at end of file
1 +const specificURL = [ 'naver.com', 'google.com', 'namu.wiki', 'facebook.com', 'ko.wikipedia.org','youtube.com' ];
2 +
3 +export default filter = (JSONdata) => {
4 + JSONdata.return_data.searchResults.sort( ( a, b ) => {
5 + return a.confidence > b.confidence ? -1 : a.confidence < b.confidence ? 1 : 0;
6 + })
7 + slicedata = Object.keys( JSONdata.return_data.searchResults ).slice( 0, 10 ).reduce( (result, key ) => {
8 + result[ key ] = JSONdata.return_data.searchResults[ key ]
9 + return result
10 + }, {} );
11 +
12 + let tempResult = Object.values( slicedata );
13 + tempResult.forEach( ( data ) => {
14 + if( data.title.length > 14 ) {
15 + data.title = data.title.slice( 0, 15 ) + "..";
16 + }
17 + if( data.passage.length > 125 ) {
18 + data.passage = data.passage.slice( 0, 125 ) + "..";
19 + }
20 + specificURL.forEach( ( url ) => {
21 + if( data.url.indexOf( url ) !== -1 ) {
22 + data.site = url;
23 + }
24 + });
25 + if( !data.site ) {
26 + data.site = "etc";
27 + }
28 + });
29 + return ( {...JSONdata, return_data: { ...JSONdata.return_data, searchResults: tempResult } } );
30 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -5717,6 +5717,11 @@ ...@@ -5717,6 +5717,11 @@
5717 "react-is": "^16.9.0" 5717 "react-is": "^16.9.0"
5718 } 5718 }
5719 }, 5719 },
5720 + "react-thunk": {
5721 + "version": "1.0.0",
5722 + "resolved": "https://registry.npmjs.org/react-thunk/-/react-thunk-1.0.0.tgz",
5723 + "integrity": "sha1-eYE9R/MRR+ga7oQe1edqnj6ryLE="
5724 + },
5720 "react-timer-mixin": { 5725 "react-timer-mixin": {
5721 "version": "0.13.4", 5726 "version": "0.13.4",
5722 "resolved": "https://registry.npmjs.org/react-timer-mixin/-/react-timer-mixin-0.13.4.tgz", 5727 "resolved": "https://registry.npmjs.org/react-timer-mixin/-/react-timer-mixin-0.13.4.tgz",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
26 "react-navigation-material-bottom-tabs": "^2.1.5", 26 "react-navigation-material-bottom-tabs": "^2.1.5",
27 "react-navigation-tabs": "^2.5.6", 27 "react-navigation-tabs": "^2.5.6",
28 "react-redux": "^7.1.3", 28 "react-redux": "^7.1.3",
29 + "react-thunk": "^1.0.0",
29 "redux": "^4.0.4" 30 "redux": "^4.0.4"
30 }, 31 },
31 "devDependencies": { 32 "devDependencies": {
......
...@@ -6,7 +6,7 @@ export const change = (text) => ({ ...@@ -6,7 +6,7 @@ export const change = (text) => ({
6 text, 6 text,
7 }) 7 })
8 8
9 -export const submit = (text) => ({ 9 +export const submit = (text) => (dispatch) => ({
10 type: CHANGE, 10 type: CHANGE,
11 text, 11 text,
12 }) 12 })
......