Comparing version 2.8.0 to 2.9.0
# Changelog | ||
## [2.9.0] | ||
### Added | ||
- Support for downloading skylinks with paths (either pre-encoded in the skylink, or with the `path` parameter not encoded). | ||
- Support for returning skylinks from `getSkylinkUrl` and `downloadFile` in subdomain form. | ||
- Added `includePath`, `onlyPath`, and `fromSubdomain` options to `parseSkylink`, allowing getting the path with/without the skylink as well as parsing skylinks in base32 subdomain form. | ||
### Changed | ||
- Fixed bug in `getJSON` where fetching an inexistent entry would cause an error. | ||
## [2.8.0] | ||
@@ -4,0 +16,0 @@ |
@@ -67,2 +67,4 @@ "use strict"; | ||
url = utils_1.makeUrl(this.portalUrl, config.endpointPath, (_a = config.extraPath) !== null && _a !== void 0 ? _a : ""); | ||
} | ||
if (config.query) { | ||
url = utils_1.addUrlQuery(url, config.query); | ||
@@ -83,3 +85,5 @@ } | ||
}, | ||
timeout: config.timeout | ||
timeout: config.timeout, | ||
maxContentLength: Infinity, | ||
maxBodyLength: Infinity | ||
}); | ||
@@ -86,0 +90,0 @@ }; |
import { SkynetClient } from "./client"; | ||
/** | ||
* Initiates a download of the content of the skylink within the browser. | ||
* @param {string} skylink - 46 character skylink. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param skylink - 46 character skylink, possibly followed by a path or query parameters. Note that the skylink will not be encoded, so if your path might contain special characters, consider using `customOptions.path`. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [customOptions.endpointPath="/"] - The relative URL path of the portal endpoint to contact. | ||
* @param {string} [customOptions.path=""] - A path to append to the skylink, e.g. `dir1/dir2/file`. A Unix-style path is expected. Each path component will be URL-encoded. | ||
* @param {Object} [customOptions.query={}] - A query object to convert to a query parameter string and append to the URL. | ||
* @param {boolean} [customOptions.subdomain=false] - Whether to return the final skylink in subdomain format. | ||
* @returns {string} - The full URL that was used. | ||
*/ | ||
export declare function downloadFile(this: SkynetClient, skylink: string, customOptions?: any): void; | ||
export declare function downloadFile(this: SkynetClient, skylink: string, customOptions?: any): string; | ||
/** | ||
* Initiates a download of the content of the skylink at the Handshake domain. | ||
* @param {string} domain - Handshake domain. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param domain - Handshake domain. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [customOptions.endpointPath="/hns"] - The relative URL path of the portal endpoint to contact. | ||
* @param {Object} [customOptions.query] - A query object to convert to a query parameter string and append to the URL. | ||
* @param {boolean} [customOptions.subdomain=false] - Whether to return the final URL with the HNS domain as a subdomain. | ||
* @returns {string} - The full URL that was used. | ||
*/ | ||
export declare function downloadFileHns(this: SkynetClient, domain: string, customOptions?: any): Promise<void>; | ||
export declare function getSkylinkUrl(this: SkynetClient, skylink: string, customOptions?: any): string; | ||
export declare function downloadFileHns(this: SkynetClient, domain: string, customOptions?: any): Promise<string>; | ||
export declare function getSkylinkUrl(this: SkynetClient, skylinkStr: string, customOptions?: any): string; | ||
export declare function getHnsUrl(this: SkynetClient, domain: string, customOptions?: any): string; | ||
@@ -24,20 +29,23 @@ export declare function getHnsresUrl(this: SkynetClient, domain: string, customOptions?: any): string; | ||
* Opens the content of the skylink within the browser. | ||
* @param {string} skylink - 46 character skylink. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param skylink - 46 character skylink. | ||
* @param [customOptions={}] - Additional settings that can optionally be set.. See `downloadFile` for the full list. | ||
* @param {string} [customOptions.endpointPath="/"] - The relative URL path of the portal endpoint to contact. | ||
* @returns - The full URL that was used. | ||
*/ | ||
export declare function openFile(this: SkynetClient, skylink: string, customOptions?: {}): void; | ||
export declare function openFile(this: SkynetClient, skylink: string, customOptions?: {}): string; | ||
/** | ||
* Opens the content of the skylink from the given Handshake domain within the browser. | ||
* @param {string} domain - Handshake domain. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param domain - Handshake domain. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. See `downloadFileHns` for the full list. | ||
* @param {string} [customOptions.endpointPath="/hns"] - The relative URL path of the portal endpoint to contact. | ||
* @returns {string} - The full URL that was used. | ||
*/ | ||
export declare function openFileHns(this: SkynetClient, domain: string, customOptions?: {}): Promise<void>; | ||
export declare function openFileHns(this: SkynetClient, domain: string, customOptions?: {}): Promise<string>; | ||
/** | ||
* @param {string} domain - Handshake resolver domain. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param domain - Handshake resolver domain. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [customOptions.endpointPath="/hnsres"] - The relative URL path of the portal endpoint to contact. | ||
* @param {Object} [customOptions.query] - A query object to convert to a query parameter string and append to the URL. | ||
*/ | ||
export declare function resolveHns(this: SkynetClient, domain: string, customOptions?: {}): Promise<any>; | ||
//# sourceMappingURL=download.d.ts.map |
@@ -57,6 +57,9 @@ "use strict"; | ||
* Initiates a download of the content of the skylink within the browser. | ||
* @param {string} skylink - 46 character skylink. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param skylink - 46 character skylink, possibly followed by a path or query parameters. Note that the skylink will not be encoded, so if your path might contain special characters, consider using `customOptions.path`. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [customOptions.endpointPath="/"] - The relative URL path of the portal endpoint to contact. | ||
* @param {string} [customOptions.path=""] - A path to append to the skylink, e.g. `dir1/dir2/file`. A Unix-style path is expected. Each path component will be URL-encoded. | ||
* @param {Object} [customOptions.query={}] - A query object to convert to a query parameter string and append to the URL. | ||
* @param {boolean} [customOptions.subdomain=false] - Whether to return the final skylink in subdomain format. | ||
* @returns {string} - The full URL that was used. | ||
*/ | ||
@@ -69,2 +72,3 @@ function downloadFile(skylink, customOptions) { | ||
window.location.assign(url); | ||
return url; | ||
} | ||
@@ -74,6 +78,8 @@ exports.downloadFile = downloadFile; | ||
* Initiates a download of the content of the skylink at the Handshake domain. | ||
* @param {string} domain - Handshake domain. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param domain - Handshake domain. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [customOptions.endpointPath="/hns"] - The relative URL path of the portal endpoint to contact. | ||
* @param {Object} [customOptions.query] - A query object to convert to a query parameter string and append to the URL. | ||
* @param {boolean} [customOptions.subdomain=false] - Whether to return the final URL with the HNS domain as a subdomain. | ||
* @returns {string} - The full URL that was used. | ||
*/ | ||
@@ -89,3 +95,3 @@ function downloadFileHns(domain, customOptions) { | ||
window.location.assign(url); | ||
return [2 /*return*/]; | ||
return [2 /*return*/, url]; | ||
}); | ||
@@ -95,13 +101,50 @@ }); | ||
exports.downloadFileHns = downloadFileHns; | ||
function getSkylinkUrl(skylink, customOptions) { | ||
function getSkylinkUrl(skylinkStr, customOptions) { | ||
var _a; | ||
if (customOptions === void 0) { customOptions = {}; } | ||
var opts = __assign(__assign(__assign({}, defaultDownloadOptions), this.customOptions), customOptions); | ||
var query = opts.download ? { attachment: true } : {}; | ||
skylink = utils_1.parseSkylink(skylink); | ||
var query = (_a = opts.query) !== null && _a !== void 0 ? _a : {}; | ||
if (opts.download) { | ||
query.attachment = true; | ||
} | ||
// URL-encode the path. | ||
var path = ""; | ||
if (opts.path) { | ||
if (typeof opts.path !== "string") { | ||
throw new Error("opts.path has to be a string, " + typeof opts.path + " provided"); | ||
} | ||
// Encode each element of the path separately and join them. | ||
// | ||
// Don't use encodeURI because it does not encode characters such as '?' | ||
// etc. These are allowed as filenames on Skynet and should be encoded so | ||
// they are not treated as URL separators. | ||
path = opts.path | ||
.split("/") | ||
.map(function (element) { return encodeURIComponent(element); }) | ||
.join("/"); | ||
} | ||
// TODO: fix subdomain + includePath | ||
var url; | ||
if (opts.subdomain) { | ||
// Get the path from the skylink. | ||
var skylinkPath = utils_1.parseSkylink(skylinkStr, { onlyPath: true }); | ||
// Get just the skylink. | ||
var skylink = utils_1.parseSkylink(skylinkStr); | ||
if (skylink === null) { | ||
throw new Error("Could not get skylink out of input '" + skylinkStr + "'"); | ||
} | ||
// Convert the skylink (without the path) to base32. | ||
skylink = utils_1.convertSkylinkToBase32(skylink); | ||
url = utils_1.addSubdomain(this.portalUrl, skylink); | ||
url = utils_1.makeUrl(url, skylinkPath, path); | ||
} | ||
var url = opts.subdomain | ||
? utils_1.addSubdomain(this.portalUrl, skylink) | ||
: utils_1.makeUrl(this.portalUrl, opts.endpointPath, skylink); | ||
else { | ||
// Get the skylink including the path. | ||
var skylink = utils_1.parseSkylink(skylinkStr, { includePath: true }); | ||
if (skylink === null) { | ||
throw new Error("Could not get skylink out of input '" + skylinkStr + "'"); | ||
} | ||
// Add additional path if passed in. | ||
url = utils_1.makeUrl(this.portalUrl, opts.endpointPath, skylink, path); | ||
} | ||
return utils_1.addUrlQuery(url, query); | ||
@@ -111,5 +154,9 @@ } | ||
function getHnsUrl(domain, customOptions) { | ||
var _a; | ||
if (customOptions === void 0) { customOptions = {}; } | ||
var opts = __assign(__assign(__assign({}, defaultDownloadHnsOptions), this.customOptions), customOptions); | ||
var query = opts.download ? { attachment: true } : {}; | ||
var query = (_a = opts.query) !== null && _a !== void 0 ? _a : {}; | ||
if (opts.download) { | ||
query.attachment = true; | ||
} | ||
domain = utils_1.trimUriPrefix(domain, utils_1.uriHandshakePrefix); | ||
@@ -156,5 +203,6 @@ var url = opts.subdomain | ||
* Opens the content of the skylink within the browser. | ||
* @param {string} skylink - 46 character skylink. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param skylink - 46 character skylink. | ||
* @param [customOptions={}] - Additional settings that can optionally be set.. See `downloadFile` for the full list. | ||
* @param {string} [customOptions.endpointPath="/"] - The relative URL path of the portal endpoint to contact. | ||
* @returns - The full URL that was used. | ||
*/ | ||
@@ -166,2 +214,3 @@ function openFile(skylink, customOptions) { | ||
window.open(url, "_blank"); | ||
return url; | ||
} | ||
@@ -171,5 +220,6 @@ exports.openFile = openFile; | ||
* Opens the content of the skylink from the given Handshake domain within the browser. | ||
* @param {string} domain - Handshake domain. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param domain - Handshake domain. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. See `downloadFileHns` for the full list. | ||
* @param {string} [customOptions.endpointPath="/hns"] - The relative URL path of the portal endpoint to contact. | ||
* @returns {string} - The full URL that was used. | ||
*/ | ||
@@ -185,3 +235,3 @@ function openFileHns(domain, customOptions) { | ||
window.open(url, "_blank"); | ||
return [2 /*return*/]; | ||
return [2 /*return*/, url]; | ||
}); | ||
@@ -192,5 +242,6 @@ }); | ||
/** | ||
* @param {string} domain - Handshake resolver domain. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param domain - Handshake resolver domain. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [customOptions.endpointPath="/hnsres"] - The relative URL path of the portal endpoint to contact. | ||
* @param {Object} [customOptions.query] - A query object to convert to a query parameter string and append to the URL. | ||
*/ | ||
@@ -197,0 +248,0 @@ function resolveHns(domain, customOptions) { |
@@ -67,3 +67,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var opts, publicKeyBuffer, response, err_1, entry; | ||
var opts, publicKeyBuffer, response, err_1, signedEntry; | ||
return __generator(this, function (_a) { | ||
@@ -92,3 +92,3 @@ switch (_a.label) { | ||
} | ||
entry = { | ||
signedEntry = { | ||
entry: { | ||
@@ -102,6 +102,6 @@ datakey: dataKey, | ||
}; | ||
if (entry && | ||
if (signedEntry && | ||
!node_forge_1.pki.ed25519.verify({ | ||
message: crypto_1.hashRegistryEntry(entry.entry), | ||
signature: entry.signature, | ||
message: crypto_1.hashRegistryEntry(signedEntry.entry), | ||
signature: signedEntry.signature, | ||
publicKey: publicKeyBuffer | ||
@@ -111,3 +111,3 @@ })) { | ||
} | ||
return [2 /*return*/, entry]; | ||
return [2 /*return*/, signedEntry]; | ||
} | ||
@@ -114,0 +114,0 @@ }); |
@@ -71,11 +71,11 @@ "use strict"; | ||
case 1: | ||
entry = _a.sent(); | ||
entry = (_a.sent()).entry; | ||
if (entry === null) { | ||
return [2 /*return*/, null]; | ||
} | ||
skylink = utils_1.parseSkylink(entry.entry.data); | ||
skylink = utils_1.parseSkylink(entry.data); | ||
return [4 /*yield*/, this.executeRequest(__assign(__assign({}, opts), { method: "get", url: this.getSkylinkUrl(skylink) }))]; | ||
case 2: | ||
response = _a.sent(); | ||
return [2 /*return*/, { data: response.data, revision: entry.entry.revision }]; | ||
return [2 /*return*/, { data: response.data, revision: entry.revision }]; | ||
} | ||
@@ -82,0 +82,0 @@ }); |
@@ -6,2 +6,3 @@ import { SkynetClient, CustomClientOptions } from "./client"; | ||
customFilename?: string; | ||
query?: Record<string, unknown>; | ||
} & CustomClientOptions; | ||
@@ -12,5 +13,5 @@ export declare function uploadFile(this: SkynetClient, file: File, customOptions?: CustomUploadOptions): Promise<string>; | ||
* Uploads a local directory to Skynet. | ||
* @param {Object} directory - File objects to upload, indexed by their path strings. | ||
* @param {string} filename - The name of the directory. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param directory - File objects to upload, indexed by their path strings. | ||
* @param filename - The name of the directory. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [config.APIKey] - Authentication password to use. | ||
@@ -21,6 +22,3 @@ * @param {string} [config.customUserAgent=""] - Custom user agent header to set. | ||
* @param {string} [customOptions.portalDirectoryfilefieldname="files[]"] - The fieldName for directory files on the portal. | ||
* @returns {Object} data - The returned data. | ||
* @returns {string} data.skylink - The returned skylink. | ||
* @returns {string} data.merkleroot - The hash that is encoded into the skylink. | ||
* @returns {number} data.bitfield - The bitfield that gets encoded into the skylink. | ||
* @returns skylink - The returned skylink. | ||
*/ | ||
@@ -27,0 +25,0 @@ export declare function uploadDirectory(this: SkynetClient, directory: any, filename: string, customOptions?: CustomUploadOptions): Promise<string>; |
@@ -93,5 +93,5 @@ "use strict"; | ||
* Uploads a local directory to Skynet. | ||
* @param {Object} directory - File objects to upload, indexed by their path strings. | ||
* @param {string} filename - The name of the directory. | ||
* @param {Object} [customOptions={}] - Additional settings that can optionally be set. | ||
* @param directory - File objects to upload, indexed by their path strings. | ||
* @param filename - The name of the directory. | ||
* @param [customOptions={}] - Additional settings that can optionally be set. | ||
* @param {string} [config.APIKey] - Authentication password to use. | ||
@@ -102,6 +102,3 @@ * @param {string} [config.customUserAgent=""] - Custom user agent header to set. | ||
* @param {string} [customOptions.portalDirectoryfilefieldname="files[]"] - The fieldName for directory files on the portal. | ||
* @returns {Object} data - The returned data. | ||
* @returns {string} data.skylink - The returned skylink. | ||
* @returns {string} data.merkleroot - The hash that is encoded into the skylink. | ||
* @returns {number} data.bitfield - The bitfield that gets encoded into the skylink. | ||
* @returns skylink - The returned skylink. | ||
*/ | ||
@@ -108,0 +105,0 @@ function uploadDirectory(directory, filename, customOptions) { |
@@ -22,8 +22,11 @@ export declare const defaultSkynetPortalUrl = "https://siasky.net"; | ||
/** | ||
* Parses the given string for a base64 skylink, or base32 if opts.subdomain is given. | ||
* Parses the given string for a base64 skylink, or base32 if opts.fromSubdomain is given. | ||
* @param skylinkStr - plain skylink, skylink with URI prefix, or URL with skylink as the first path element. | ||
* @param [opts={}] - Additional settings that can optionally be set. | ||
* @param [opts.subdomain=false] - Whether to parse the skylink as a base32 subdomain in a URL. | ||
* @param [opts.onlyPath=false] - Whether to parse out just the path, e.g. /foo/bar. Will still return null if the string does not contain a skylink. | ||
* @param [opts.includePath=false] - Whether to include the path after the skylink. | ||
* @param [opts.fromSubdomain=false] - Whether to parse the skylink as a base32 subdomain in a URL. | ||
*/ | ||
export declare function parseSkylink(skylinkStr: string, opts?: any): string; | ||
export declare function trimForwardSlash(str: string): string; | ||
export declare function trimUriPrefix(str: string, prefix: string): string; | ||
@@ -30,0 +33,0 @@ export declare function randomNumber(low: number, high: number): number; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
@@ -13,3 +24,3 @@ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
exports.__esModule = true; | ||
exports.getFileMimeType = exports.readData = exports.toHexString = exports.hexToUint8Array = exports.stringToUint8Array = exports.randomNumber = exports.trimUriPrefix = exports.parseSkylink = exports.makeUrl = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultPortalUrl = exports.defaultOptions = exports.convertSkylinkToBase32 = exports.addUrlQuery = exports.addSubdomain = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0; | ||
exports.getFileMimeType = exports.readData = exports.toHexString = exports.hexToUint8Array = exports.stringToUint8Array = exports.randomNumber = exports.trimUriPrefix = exports.trimForwardSlash = exports.parseSkylink = exports.makeUrl = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultPortalUrl = exports.defaultOptions = exports.convertSkylinkToBase32 = exports.addUrlQuery = exports.addSubdomain = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0; | ||
var base64_js_1 = __importDefault(require("base64-js")); | ||
@@ -38,3 +49,7 @@ var base32_encode_1 = __importDefault(require("base32-encode")); | ||
function addUrlQuery(url, query) { | ||
var parsed = url_parse_1["default"](url); | ||
var parsed = url_parse_1["default"](url, true); | ||
if (parsed.query) { | ||
// Combine the desired query params with the already existing ones. | ||
query = __assign(__assign({}, parsed.query), query); | ||
} | ||
parsed.set("query", query); | ||
@@ -96,10 +111,13 @@ return parsed.toString(); | ||
var SKYLINK_DIRECT_REGEX = new RegExp("^" + SKYLINK_MATCHER + "$"); | ||
var SKYLINK_PATHNAME_REGEX = new RegExp("^/?" + SKYLINK_MATCHER + "(/.*)?$"); | ||
var SKYLINK_PATHNAME_REGEX = new RegExp("^/?" + SKYLINK_MATCHER + "((/.*)?)$"); | ||
var SKYLINK_SUBDOMAIN_REGEX = new RegExp("^" + SKYLINK_MATCHER_SUBDOMAIN + "(\\..*)?$"); | ||
var SKYLINK_REGEXP_MATCH_POSITION = 1; | ||
var SKYLINK_DIRECT_MATCH_POSITION = 1; | ||
var SKYLINK_PATH_MATCH_POSITION = 2; | ||
/** | ||
* Parses the given string for a base64 skylink, or base32 if opts.subdomain is given. | ||
* Parses the given string for a base64 skylink, or base32 if opts.fromSubdomain is given. | ||
* @param skylinkStr - plain skylink, skylink with URI prefix, or URL with skylink as the first path element. | ||
* @param [opts={}] - Additional settings that can optionally be set. | ||
* @param [opts.subdomain=false] - Whether to parse the skylink as a base32 subdomain in a URL. | ||
* @param [opts.onlyPath=false] - Whether to parse out just the path, e.g. /foo/bar. Will still return null if the string does not contain a skylink. | ||
* @param [opts.includePath=false] - Whether to include the path after the skylink. | ||
* @param [opts.fromSubdomain=false] - Whether to parse the skylink as a base32 subdomain in a URL. | ||
*/ | ||
@@ -110,4 +128,8 @@ function parseSkylink(skylinkStr, opts) { | ||
throw new Error("Skylink has to be a string, " + typeof skylinkStr + " provided"); | ||
if (opts.subdomain) { | ||
return parseSkylinkBase32(skylinkStr); | ||
if (opts.includePath && opts.onlyPath) | ||
throw new Error("The includePath and onlyPath options cannot both be set"); | ||
if (opts.includePath && opts.fromSubdomain) | ||
throw new Error("The includePath and fromSubdomain options cannot both be set"); | ||
if (opts.fromSubdomain) { | ||
return parseSkylinkBase32(skylinkStr, opts); | ||
} | ||
@@ -120,23 +142,60 @@ // Check for skylink prefixed with sia: or sia:// and extract it. | ||
var matchDirect = skylinkStr.match(SKYLINK_DIRECT_REGEX); | ||
if (matchDirect) | ||
return matchDirect[SKYLINK_REGEXP_MATCH_POSITION]; | ||
if (matchDirect) { | ||
if (opts.onlyPath) { | ||
return ""; | ||
} | ||
return matchDirect[SKYLINK_DIRECT_MATCH_POSITION]; | ||
} | ||
// Check for skylink passed in an url and extract it. | ||
// Example: https://siasky.net/XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg | ||
// Example: https://bg06v2tidkir84hg0s1s4t97jaeoaa1jse1svrad657u070c9calq4g.siasky.net (if opts.subdomain = true) | ||
// Pass empty object as second param to disable using location as base url when parsing in browser. | ||
// Example: https://bg06v2tidkir84hg0s1s4t97jaeoaa1jse1svrad657u070c9calq4g.siasky.net (if opts.fromSubdomain = true) | ||
// Pass empty object as second param to disable using location as base url | ||
// when parsing in browser. | ||
var parsed = url_parse_1["default"](skylinkStr, {}); | ||
var matchPathname = parsed.pathname.match(SKYLINK_PATHNAME_REGEX); | ||
if (matchPathname) | ||
return matchPathname[SKYLINK_REGEXP_MATCH_POSITION]; | ||
return null; | ||
var skylinkAndPath = trimSuffix(parsed.pathname, "/"); | ||
var matchPathname = skylinkAndPath.match(SKYLINK_PATHNAME_REGEX); | ||
if (!matchPathname) | ||
return null; | ||
var path = matchPathname[SKYLINK_PATH_MATCH_POSITION]; | ||
if (path == "/") | ||
path = ""; | ||
if (opts.includePath) | ||
return trimForwardSlash(skylinkAndPath); | ||
else if (opts.onlyPath) | ||
return path; | ||
else | ||
return matchPathname[SKYLINK_DIRECT_MATCH_POSITION]; | ||
} | ||
exports.parseSkylink = parseSkylink; | ||
function parseSkylinkBase32(skylinkStr) { | ||
// Pass empty object as second param to disable using location as base url when parsing in browser. | ||
function parseSkylinkBase32(skylinkStr, opts) { | ||
if (opts === void 0) { opts = {}; } | ||
// Pass empty object as second param to disable using location as base url | ||
// when parsing in browser. | ||
var parsed = url_parse_1["default"](skylinkStr, {}); | ||
// Check if the hostname contains a skylink subdomain. | ||
var matchHostname = parsed.hostname.match(SKYLINK_SUBDOMAIN_REGEX); | ||
if (matchHostname) | ||
return matchHostname[SKYLINK_REGEXP_MATCH_POSITION]; | ||
if (matchHostname) { | ||
if (opts.onlyPath) { | ||
return parsed.pathname; | ||
} | ||
return matchHostname[SKYLINK_DIRECT_MATCH_POSITION]; | ||
} | ||
return null; | ||
} | ||
function trimForwardSlash(str) { | ||
return trimPrefix(trimSuffix(str, "/"), "/"); | ||
} | ||
exports.trimForwardSlash = trimForwardSlash; | ||
function trimPrefix(str, prefix) { | ||
while (str.startsWith(prefix)) { | ||
str = str.slice(prefix.length); | ||
} | ||
return str; | ||
} | ||
function trimSuffix(str, suffix) { | ||
while (str.endsWith(suffix)) { | ||
str = str.substring(0, str.length - suffix.length); | ||
} | ||
return str; | ||
} | ||
function trimUriPrefix(str, prefix) { | ||
@@ -143,0 +202,0 @@ var longPrefix = prefix + "//"; |
{ | ||
"name": "skynet-js", | ||
"version": "2.8.0", | ||
"version": "2.9.0", | ||
"description": "Sia Skynet Javascript Client", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94190
1517