@argdown/node
Version:
Async Argdown application for node.js
35 lines • 1.28 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.imageUtils = void 0;
const axios_1 = __importDefault(require("axios"));
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const process_1 = __importDefault(require("process"));
exports.imageUtils = {
getImage: async (imagePath, baseDir = "") => {
let buffer;
if (imagePath.startsWith("https:")) {
buffer = await exports.imageUtils.getRemoteImage(imagePath);
}
else {
try {
const resolvedPath = path_1.default.resolve(baseDir || process_1.default.cwd(), imagePath);
buffer = await fs_1.promises.readFile(resolvedPath);
}
catch (err) {
buffer = await exports.imageUtils.getRemoteImage(imagePath);
}
}
return buffer;
},
getRemoteImage: async (path) => {
const response = await axios_1.default.get(path, {
responseType: "arraybuffer"
});
return Buffer.from(response.data, "binary");
}
};
//# sourceMappingURL=utils.js.map