2015-06-03 21:45:54 -07:00
|
|
|
import path from 'path';
|
|
|
|
import fs from 'fs';
|
2015-01-06 12:58:57 +00:00
|
|
|
|
|
|
|
var services = [];
|
|
|
|
|
2015-06-03 21:45:54 -07:00
|
|
|
fs.readdirSync(path.join(__dirname, 'services')).forEach(function(file) {
|
2015-08-20 23:22:57 +01:00
|
|
|
const service = require(path.join(__dirname, 'services', file));
|
2015-01-06 12:58:57 +00:00
|
|
|
if (service.search) {
|
|
|
|
services.push(service);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-14 00:18:48 +01:00
|
|
|
export default async function (url) {
|
2015-08-20 23:22:57 +01:00
|
|
|
let matchedService;
|
|
|
|
for (let service of services) {
|
2017-07-20 14:31:07 +01:00
|
|
|
matchedService = service.match(url);
|
2015-08-20 23:22:57 +01:00
|
|
|
if (matchedService) {
|
2018-04-14 00:18:48 +01:00
|
|
|
const result = await service.parseUrl(url);
|
|
|
|
return await service.lookupId(result.id, result.type);
|
2015-08-20 23:22:57 +01:00
|
|
|
}
|
2015-01-06 12:58:57 +00:00
|
|
|
}
|
|
|
|
};
|