Refactor searching
This commit is contained in:
parent
87649b5a3a
commit
bbcbe8d871
9 changed files with 155 additions and 122 deletions
29
lib/lookup.js
Normal file
29
lib/lookup.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
var path = require('path');
|
||||
|
||||
var services = [];
|
||||
|
||||
require("fs").readdirSync(path.join(__dirname, "services")).forEach(function(file) {
|
||||
var service = require(path.join(__dirname, "services", file));
|
||||
if (service.search) {
|
||||
services.push(service);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = function(url) {
|
||||
|
||||
var matchedService;
|
||||
services.some(function(service) {
|
||||
matchedService = service.match(url) ? service : null;
|
||||
return matchedService;
|
||||
});
|
||||
|
||||
if (matchedService) {
|
||||
return matchedService.parseUrl(url).timeout(10000).then(function(result) {
|
||||
return matchedService.lookupId(result.id, result.type).then(function(item) {
|
||||
return item;
|
||||
});
|
||||
});
|
||||
}
|
||||
return false;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue