openblox
Version:
Roblox API Wrapper For Both Classic And OpenCloud APIs.
53 lines (52 loc) • 2.47 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var parseDeepLink_exports = {};
__export(parseDeepLink_exports, {
deepLinkParse: () => deepLinkParse
});
module.exports = __toCommonJS(parseDeepLink_exports);
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
const placeIdsRegex = /placeId=([0-9]+)(?:.*placeId=([0-9]+))?/;
const launchDataRegex = /launchData=([^&]+)(?:.*launchData=([^&]+))?/;
const parseLaunchData = (launchData, decodeBase64) => {
if (!launchData) return null;
launchData = decodeURIComponent(launchData);
if (decodeBase64 === void 0 || decodeBase64) {
if (decodeBase64 || base64Regex.test(launchData)) launchData = atob(launchData);
}
try {
return JSON.parse(launchData);
} catch {
return launchData;
}
};
const deepLinkParse = (deepLink, decodeBase64) => {
const decodedDeepLink = deepLink.replaceAll("%3D", "=");
const placeIdsExec = placeIdsRegex.exec(decodedDeepLink);
const firstPlaceId = placeIdsExec?.[1], secondPlaceId = placeIdsExec?.[2];
const placeIds = [typeof firstPlaceId === "string" ? firstPlaceId : null, typeof secondPlaceId === "string" ? secondPlaceId : null].filter((e) => e);
const launchDataExec = launchDataRegex.exec(decodedDeepLink);
const firstLaunchData = launchDataExec?.[1], secondLaunchData = launchDataExec?.[2];
const launchData = [typeof firstLaunchData === "string" ? firstLaunchData : null, typeof secondLaunchData === "string" ? secondLaunchData : null];
return placeIds.map((placeId, idx) => ({ placeId, launchData: parseLaunchData(launchData[idx], decodeBase64) }));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
deepLinkParse
});
;