deepinfra
Version:
Official API wrapper for DeepInfra
32 lines (31 loc) • 1.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormDataUtils = void 0;
const form_data_1 = __importDefault(require("form-data"));
const read_stream_1 = require("../../lib/utils/read-stream");
exports.FormDataUtils = {
/**
* Prepare form data from the given data object
* @param data - The data object to be converted to form data.
* @param blobKeys - The keys of the data object that contain binary data.
* @returns A FormData object.
* @throws {Error} If the binary data is invalid.
*
*/
async prepareFormData(data, blobKeys = []) {
const formData = new form_data_1.default();
for (const [key, value] of Object.entries(data)) {
if (blobKeys.includes(key)) {
const readStream = await read_stream_1.ReadStreamUtils.getReadStream(value);
formData.append(key, readStream);
}
else {
formData.append(key, JSON.stringify(value));
}
}
return formData;
},
};