1.0.4 • Published 1 year ago

@binarycortex/link-metadata v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Description

Link-Metadata used to get metadata from internet URLs (htmls, images, media..). It also returns security policy information (Cross-Origin Resource Sharing, Content Security Policy) and checks them with Google Safe Browsing (Web Risk).

Installation

$ npm install @binarycortex/link-metadata

Usage

Link-Metadata is TypeScript-friendly and comes with both CommonJS and ESM module support.

const lmd = require('@binarycortex/link-metadata');

or

import lmd from '@binarycortex/link-metadata';

First, create a new user if you don't have one:

const firstName = 'name';
const lastName = 'surname';
const email = 'email@some.com';
const username = 'username';
const password = 'password';

const reply = await lmd.createUser(firstName, lastName,
    email, username, password);

console.log(reply);

Second, log in and create a new access key. If you already have one you don't need to login, just use the key.

const response = await lmd.login(username, password);

if (response.error) {
    console.error(response.error);
    return;
}

const key = response.accessKey;

Getting a metadata for the given URL:

const metadata = await lmd.getMetadata(url, key);

API

login(username, password)

Used to get first instance of access key. Returns KeyResponse:

interface AccessKey {
    accessId: string;
    accessSecret: string;
}

interface KeyResponse {
    username?: string;
    accessKey?: AccessKey;
    error?: string;
}

If an error occurs, it is returned in the corresponding field.

createKey(key)

Issue a new key (using current). All keys are the same in terms of functionality, there is no 'primary' key. You may create as much keys as you want. Returns KeyResponse.

getKeys(key)

List all available keys. Returns KeysResponse:

interface KeysResponse {
    username?: string;
    accessKeys?: AccessKey[];
    error?: string;
}

revokeKey(key)

Revokes a key (the one that passed in argument). Useful when a key becomes compromised. Returns a string.

getMetadata(url, key)

To obtain metadata for the URL. Needs an access key (token) to be provided. Returns MetadataResponse structure.

interface MetadataResponse {
    url: string; // The original request url
    status: number | null; // Request status code. Null in cases where url is invlaid and the like. Never make the network request

    type: string | null; // The type of the content. This should be a static list (enum). This may be base on
    // the file such as video. Or more specific like article/book/etc. Full list to be determined.
    contentType: string | null; // HTML mime time from the http request
    contentEncoding: string | null; // HTML content encoding from the http request

    audio: Audio | null; // If the file is an audio file, audio details will be here.
    file: File | null; // If the file is not any of the other supported types, what details we have will be here.
    html: HTML | null; // If the file is an html file, html details will be here.
    image: Image | null; // If the file is an image file, image details will be here.
    video: Video | null; // If the file is an video file, video details will be here.
    xml: XML | null; // If the file is an xml file, xml details will be here.

    // errors
    error: number | null; // Number indicates there was an error and is the error code
    reason: string | null; // Reason string for error
    warnings: string[] | null; // A list of warnings/errors while processing. See [Warnings](#warnings) section for some examples

    // Web Risk
    googleSafeBrowsing: GoogleSafeBrowsing | null;
}

reportBadData(url, reason)

Reports issues with the metadata (not sufficient, irrelevant, etc). The report should consist of the url of issue and an optional reason message. This helps us to get feedback and improve our service.

const response = await lmd.reportBadData('https://www.youtube.com/watch?v=2mNwZHcoW_o', 'wrong language');
1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago