Skip to content

Commit

Permalink
solve multi-requests on the fly bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Geraldine GEOFFROY authored and Geraldine GEOFFROY committed Oct 12, 2019
1 parent e03340b commit 3d9d7eb
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 50 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sudoctoolkit",
"productName": "SudocToolkit",
"version": "1.0.0",
"version": "1.1.0",
"description": "Utiliser les web services de l'Abes sans être développeur",
"author": "Géraldine Geoffroy",
"main": "main.js",
Expand All @@ -24,6 +24,7 @@
"jquery": "^3.4.1",
"progress-stream": "^2.0.0",
"request": "^2.88.0",
"requestretry": "^4.0.2",
"underscore": "^1.9.1",
"update-electron-app": "^1.5.0"
}
Expand Down
135 changes: 86 additions & 49 deletions renderer-process/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const electron = require('electron')
const dialog = electron.remote.dialog
const BrowserWindow = electron.remote.BrowserWindow
const path = require('path')
const request = require('request')
const request = require('requestretry')
const childProcess = require('child_process')

const fs = require('fs')
Expand Down Expand Up @@ -105,17 +105,13 @@ var str = progress({
getValue(record[chooseKey].toString()).then(
function(val) {
record = filterTypes(record,arrColumns)
console.log(record)
if(val === undefined) {record[columnResultName]="2 ou +"}
else {
record[columnResultName]=val
}
callback(null, record)
},
function(error) {
record = filterTypes(record,arrColumns)
record[columnResultName]="0"
callback(null, record)
}
}
)
})
)
Expand Down Expand Up @@ -185,62 +181,103 @@ var str = progress({
return result;
}
//sudoc web services
function getValue(id){
function getValue(id){
return new Promise(function(resolve, reject){
switch(selectedOption) {
case "isbn2ppncount":
request('https://www.sudoc.fr/services/isbn2ppn/'+id+'&format=text/json', function (error, response, body) {
try {
if(Array.isArray(JSON.parse(body).sudoc.query.result)) {
resolve(JSON.parse(body).sudoc.query.result.length);}
else {
resolve("1");
}
} catch(e) {
reject(e);
request({
url: 'https://www.sudoc.fr/services/isbn2ppn/'+id+'&format=text/json',
json: true,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, function(err, response, body){
if (response) {
if(Array.isArray(body.sudoc.query.result)) {
resolve(body.sudoc.query.result.length)
}
else {
resolve("1")
}
}
});
else {
resolve("0")
}
})
break;
case "isbn2ppn":
request('https://www.sudoc.fr/services/isbn2ppn/'+id+'&format=text/json', function (error, response, body) {
try {
resolve(JSON.parse(body).sudoc.query.result.ppn)
} catch(e) {
reject(e);
}
});
request({
url: 'https://www.sudoc.fr/services/isbn2ppn/'+id+'&format=text/json',
json: true,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, function(err, response, body){
if (response) {
resolve(body.sudoc.query.result.ppn)
}
else {
resolve("0")
}
})
break;
case "issn2ppn":
request('https://www.sudoc.fr/services/issn2ppn/'+id+'&format=text/json', function (error, response, body) {
try {
resolve(JSON.parse(body).sudoc.query.result.ppn)
} catch(e) {
reject(e);
}
});
request({
url: 'https://www.sudoc.fr/services/issn2ppn/'+id+'&format=text/json',
json: true,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, function(err, response, body){
if (response) {
resolve(body.sudoc.query.result.ppn)
}
else {
resolve("0")
}
})
break;
case "merged":
request('https://www.sudoc.fr/services/merged/'+id+'&format=text/json', function (error, response, body) {
try {
resolve(JSON.parse(body).sudoc.query.result.ppn);
} catch(e) {
reject(e);
request({
url: 'https://www.sudoc.fr/services/merged/'+id+'&format=text/json',
json: true,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, function(err, response, body){
if (response) {
if(!body.sudoc) {
resolve("0")
}
else {
resolve(body.sudoc.query.result.ppn)
}
}
});
else {
resolve("0")
}
})
break;
case "multiwhere":
request('https://www.sudoc.fr/services/multiwhere/'+id+'&format=text/json', function (error, response, body) {
console.log(JSON.parse(body))
try {
if(Array.isArray(JSON.parse(body).sudoc.query.result.library)) {
resolve(JSON.parse(body).sudoc.query.result.library.length);}
else {
resolve("1");
}
} catch(e) {
reject(e);
request({
url: 'https://www.sudoc.fr/services/multiwhere/'+id+'&format=text/json',
json: true,
maxAttempts: 5,
retryDelay: 5000,
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, function(err, response, body){
if (response) {
if(Array.isArray(body.sudoc.query.result.library)) {
resolve(body.sudoc.query.result.library.length)
}
else {
resolve("1")
}
}
});
else {
resolve("0")
}
});
break;
}
});
Expand Down

0 comments on commit 3d9d7eb

Please sign in to comment.