Skip to content

Commit

Permalink
Fix Surrey; Sutton has moved to LUCi (#29)
Browse files Browse the repository at this point in the history
* West Sussex moved to Arena v7

* Haringey move to Enterprise

* East Lothian has moved to Spydus

* Falkirk has moved to Spydus

* North Lincolnshire move to Arena v7

* Southampton has removed individual libraries

* Fix Surrey and Sutton
  • Loading branch information
cpwood committed Feb 3, 2023
1 parent 5e1d8b0 commit a82c35b
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 12 deletions.
116 changes: 116 additions & 0 deletions connectors/luci.js
@@ -0,0 +1,116 @@
const request = require('superagent');
const common = require('./common');

console.log('luci connector loading...')

/**
* Gets the object representing the service
* @param {object} service
*/
exports.getService = (service) => common.getService(service)

getLibrariesInternal = async function (service) {
const agent = request.agent()
const response = {
libraries: []
};

try {
let resp = await agent.get(`${service.Url}bookshelf`).timeout(20000);
const frontEndId = /\/_next\/static\/([^\/]+)\/_buildManifest.js/gm.exec(resp.text)[1];

resp = await agent.get(`${service.Url}_next/data/${frontEndId}/user/register.json`).timeout(20000);
const libraries = resp.body.pageProps.patronFields.find(x => x.code == 'patron_homeLocation').optionList;

for(let library of libraries) {
response.libraries.push({
name: library.value.trim(),
code: library.key.trim()
});
}

} catch (e) {
response.exception = e
}

return response
}

/**
* Gets the libraries in the service based upon possible search and filters within the library catalogue
* @param {object} service
*/
exports.getLibraries = async function (service) {
const responseLibraries = common.initialiseGetLibrariesResponse(service)
const libs = await getLibrariesInternal(service);

responseLibraries.exception = libs.exception;
responseLibraries.libraries = libs.libraries.map(x => x.name)

return common.endResponse(responseLibraries)
}

/**
* Retrieves the availability summary of an ISBN by library
* @param {string} isbn
* @param {object} service
*/
exports.searchByISBN = async function (isbn, service) {
const responseHoldings = common.initialiseSearchByISBNResponse(service)

try {
const agent = request.agent();
let resp = await agent.get(`${service.Url}bookshelf`).timeout(20000);

const appId = /\?appid=([a-f0-9\-]+)/gm.exec(resp.text)[1];

resp = await agent
.post(`${service.Url}api/manifestations/searchresult`)
.send({
searchTerm: isbn,
searchTarget: '',
searchField: '',
sortField: 'any',
searchLimit: '196',
offset: 0,
facets: [
{
Name: 'LANGUAGE',
Selected: ['ENG']
}
],
count: 40
})
.set('Content-Type', 'application/json')
.set('solus-app-id', appId)
.timeout(20000);


const result = resp.body.records.find(x => x.isbnList.includes(isbn));

if (!result || result.eContent)
return common.endResponse(responseHoldings);

responseHoldings.id = result.recordID;
responseHoldings.url = `${service.Url}manifestations/${result.recordID}`;

resp = await agent.get(`${service.Url}api/record?id=${result.recordID}&source=ILSWS`).timeout(20000);
let libraries = resp.body.data.copies.map(x => x.location.locationName);

// Get unique library values.
libraries = libraries.filter((v, i, s) => s.indexOf(v) === i);

for (let library of libraries) {
responseHoldings.availability.push({
library,
available: resp.body.data.copies.filter(x => x.location.locationName == library && x.available).length,
unavailable: resp.body.data.copies.filter(x => x.location.locationName == library && !x.available).length
});
}
}
catch(e) {
responseHoldings.exception = e
}

return common.endResponse(responseHoldings)
}
11 changes: 3 additions & 8 deletions data/data.json
Expand Up @@ -1545,19 +1545,14 @@
"Available"
],
"TitleDetailUrl": "search/detailnonmodal.detail.detailavailabilityaccordions:lookuptitleinfo/ent:[ITEMID]/ILS/0/true/true",
"Url": "https://llc.ent.sirsidynix.net.uk/client/en_GB/sutton/",
"Url": "https://tlc.ent.sirsidynix.net.uk/client/en_GB/surrey/",
"LibraryNameFilter": "Surrey"
},
{
"Name": "Sutton",
"Code": "E09000029",
"Type": "enterprise",
"Available": [
"Available"
],
"TitleDetailUrl": "search/detailnonmodal.detail.detailavailabilityaccordions:lookuptitleinfo/ent:[ITEMID]/ILS/0/true/true",
"Url": "https://llc.ent.sirsidynix.net.uk/client/en_GB/sutton/",
"LibraryNameFilter": "Sutton"
"Type": "luci",
"Url": "https://libraries.sutton.gov.uk/"
},
{
"Name": "Abertawe - Swansea",
Expand Down
1 change: 0 additions & 1 deletion tests/enterprise.test.js
Expand Up @@ -63,7 +63,6 @@ test('E10000028 - Staffordshire', async () => await index.runTest('Staffordshire
test('S12000030 - Stirling', async () => await index.runTest('Stirling'), 300000);
test('E08000024 - Sunderland', async () => await index.runTest('Sunderland'), 300000);
test('E10000030 - Surrey', async () => await index.runTest('Surrey'), 300000);
test('E09000029 - Sutton', async () => await index.runTest('Sutton'), 300000);
test('W06000011 - Abertawe - Swansea', async () => await index.runTest('Abertawe - Swansea'), 300000);
test('E06000034 - Thurrock', async () => await index.runTest('Thurrock'), 300000);
test('W06000020 - Tor-faen - Torfaen', async () => await index.runTest('Tor-faen - Torfaen'), 300000);
Expand Down
2 changes: 2 additions & 0 deletions tests/index.js
Expand Up @@ -2,6 +2,8 @@ const index = require('../index');
const tests = require('./tests.json');

const librariesIgnoreList = [
// Only has "All Locations" option
'Southampton'
];

exports.runTest = async (service) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/luci.test.js
@@ -0,0 +1,3 @@
const index = require('.');

test('E09000029 - Sutton', async () => await index.runTest('Sutton'), 300000);
6 changes: 3 additions & 3 deletions tests/tests.json
Expand Up @@ -1757,9 +1757,9 @@
"Name": "Sutton",
"ISBNs": [
"9780747532743",
"9780141187761",
"9780141439518",
"9780521618748",
"9781405807043",
"9781405862462",
"9781904271338",
"9780007371464"
]
},
Expand Down

0 comments on commit a82c35b

Please sign in to comment.