@imgproxy/imgproxy-node
Version:
Official node url-builder lib for imgproxy - fast and secure standalone server for resizing and converting remote images
32 lines (31 loc) • 1.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bufferToBase64_js_1 = __importDefault(require("./bufferToBase64.js"));
const getEncryptPair_js_1 = __importDefault(require("./getEncryptPair.js"));
const getEncryptedUrl_js_1 = __importDefault(require("./getEncryptedUrl.js"));
const normalizeUrl = ({ url, encryptKey, encryptIV, }) => {
const changedUrl = {
value: typeof url === "string" ? url : url.value,
type: (typeof url === "string" ? "base64" : url.displayAs) || "base64",
};
//encoded url to base64
if (changedUrl.type === "base64") {
changedUrl.value = (0, bufferToBase64_js_1.default)(Buffer.from(changedUrl.value));
}
//encrypting url
if (changedUrl.type === "encrypted") {
if (!encryptKey) {
throw new Error("You should provide encryptKey if you want to use encrypted url type");
}
const encKey = (0, getEncryptPair_js_1.default)(encryptKey, encryptIV);
if (encKey) {
changedUrl.value = (0, getEncryptedUrl_js_1.default)(changedUrl.value, encKey);
changedUrl.type = "encrypted";
}
}
return changedUrl;
};
exports.default = normalizeUrl;