tav-media
Version:
Cross platform media editing framework
39 lines (38 loc) • 1.13 kB
JavaScript
import { parseClipAssetPath } from '../utils/clip-asset-path';
/**
* Utils for HTTP request.
*/
/* eslint-disable no-param-reassign */
export class Http {
/**
* Get the absolute url of a relative url.
* @param clipAssetPath The relative path of the asset.
* @returns Full url of the asset.
*/
static getUrl(clipAssetPath) {
const { assetPath } = parseClipAssetPath(clipAssetPath);
if (assetPath.indexOf('://') >= 0 || assetPath.indexOf('//') === 0) {
return assetPath;
}
return this.baseUrl + assetPath;
}
/**
* Send a Fetch request.
* @param input The url or Request object to fetch.
* @param init The RequestInit object to modify the request.
* @returns The Fetch API Response object.
*/
static fetch(input, init) {
if (typeof (input) === 'string') {
input = this.getUrl(input);
}
else {
input = Object.assign({ url: this.getUrl(input.url) }, input);
}
return fetch(input, init);
}
}
/**
* Set the base url of the assets.
*/
Http.baseUrl = './';