bluejoyq

add api connection

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