Constructor
new LinkService(optsopt)
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
<optional> |
Options for initializing the serice. Properties
|
Methods
getExamples() → {Array.<ExampleURL>}
Gather an array of example URLs from all the registered resolvers, for use in populating a selection field in a testing client.
Returns:
List of URLs.
- Type
- Array.<ExampleURL>
normalizeURL(url, base) → {URL}
Normalize a URL. This method is used by the LinkService to normalize all URLs that it encounters. Normalization helps ensure better cache hit rates and lets the service work with a degree of garbage input.
This method can be overwritten for custom behavior, and
by default it just calls the normalizeURL
method
from utilities.
Parameters:
Name | Type | Description |
---|---|---|
url |
String | URL | The URL to normalize |
base |
URL | A base URL to use to build an absolute URL, if the input URL is relative. |
Returns:
A normalized URL
- Type
- URL
pickResolver(url) → {Resolver}
Pick the best resolver to handle a given URL from the list of
known Resolver
instances. This also caches the
decision in a LRU cache to speed up subsequent URLs from
the same domain.
Parameters:
Name | Type | Description |
---|---|---|
url |
String | URL | The URL to pick a resolver for. If this is a String, it will be run through |
Returns:
The resolver instance to use for processing.
- Type
- Resolver
proxyImage(url, sizeopt) → {String}
Create a URL for passing an image through a proxy, used to avoid leaking end-user IP addresses and to perform sanity checks on the contents of the image.
Currently, this method is written to generate URLs for the https://github.com/willnorris/imageproxy project, as that's what FrankerFaceZ is using.
This returns null
if no image_proxy_host
is set in
options as end-user security should be the default. If you
really, really want to pass URLs through unmodified this
must be set to LinkService.ALLOW_UNSAFE_IMAGES
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
String | URL | The URL to proxy. |
||
size |
Number |
<optional> |
324
|
The size parameter to pass to the proxy server. |
Returns:
The proxied image URL, or null
if no proxy server is configured.
- Type
- String
registerDefaultResolvers()
Register all of the default resolvers that come packaged with the LinkService. A list of those resolvers can be found at https://github.com/FrankerFaceZ/link-service/tree/master/lib/resolvers
registerResolver(resolver) → {Resolver}
Register a new Resolver
with the LinkService. If a
class is passed, an instance will be created automatically.
Note: Registering a resolver has the side effect of clearing the domain cache.
Parameters:
Name | Type | Description |
---|---|---|
resolver |
Resolver | The resolver to register. |
Returns:
The registered resolver.
- Type
- Resolver
registerSafetyCheck(checker) → {SafetyCheck}
Register a new SafetyCheck
with the LinkService.
If a class is passed, an instance will be created
automatically.
Parameters:
Name | Type | Description |
---|---|---|
checker |
SafetyCheck | The safety check to register. |
Returns:
The registered safety check.
- Type
- SafetyCheck
registerShortenerCheck(checker) → {ShortenerCheck}
Register a new ShortenerCheck
with the LinkService.
If a class is passed, an instance will be created
automatically.
Parameters:
Name | Type | Description |
---|---|---|
checker |
ShortenerCheck | The shortener check to register. |
Returns:
The registered shortener check.
- Type
- ShortenerCheck
(async) resolve(url) → {Object}
Normalize a URL and use Resolver
instances to retrieve metadata
for the URL, keeping track of redirects and looking up SafeBrowsing
records on all URLs. Essentially: the heart of the service.
Returns a response, as in: responses
Parameters:
Name | Type | Description |
---|---|---|
url |
String | URL | The URL to resolve. |
Returns:
The metadata to be sent to clients.
- Type
- Object