2024-09-11 03:16:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const urlPattern = require('url-pattern');
|
|
|
|
|
|
|
|
const hosts = [{
|
|
|
|
method: 'imgurImage',
|
|
|
|
pattern: new urlPattern('http(s)\\://(i.)imgur.com/:id(.:ext)(?:num)')
|
|
|
|
}, {
|
|
|
|
method: 'imgurAlbum',
|
|
|
|
pattern: new urlPattern('http(s)\\://imgur.com/:type/:id')
|
2024-09-11 03:16:53 +00:00
|
|
|
}, {
|
|
|
|
method: 'gfycat',
|
|
|
|
pattern: new urlPattern('http(s)\\://(:server.)gfycat.com/:id(.:ext)')
|
2024-09-11 03:16:53 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
module.exports = function dissectLink(url) {
|
|
|
|
return hosts.reduce((acc, host) => {
|
|
|
|
if(acc) {
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
const match = host.pattern.match(url);
|
|
|
|
|
|
|
|
if(match) {
|
|
|
|
return Object.assign(match, {
|
|
|
|
url: url,
|
|
|
|
method: host.method
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}, null);
|
|
|
|
};
|