UNPKG

@zeeko/nx-remotecache-minio

Version:
47 lines (46 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const minio_1 = require("minio"); const nx_remotecache_custom_1 = require("nx-remotecache-custom"); const ENV_URL = "NXCACHE_MINIO_URL"; const ENV_ACCESS_KEY = "NXCACHE_MINIO_ACCESS_KEY"; const ENV_SECRET_KEY = "NXCACHE_MINIO_SECRET_KEY"; const ENV_BUCKET = "NXCACHE_MINIO_BUCKET"; const ENV_REGION = "NXCACHE_MINIO_REGION"; const ENV_PATH_STYLE = "NXCACHE_MINIO_PATH_STYLE"; const getEnv = (key) => process.env[key]; function getClient(options) { var _a, _b, _c, _d; const url = new URL((_a = getEnv(ENV_URL)) !== null && _a !== void 0 ? _a : options.url); const pathStyle = getEnv(ENV_PATH_STYLE); return new minio_1.Client({ port: parseInt(url.port), endPoint: url.hostname, useSSL: url.protocol === "https:", accessKey: (_b = getEnv(ENV_ACCESS_KEY)) !== null && _b !== void 0 ? _b : options.accessKey, secretKey: (_c = getEnv(ENV_SECRET_KEY)) !== null && _c !== void 0 ? _c : options.secretKey, region: (_d = getEnv(ENV_REGION)) !== null && _d !== void 0 ? _d : options.region, pathStyle: pathStyle ? pathStyle.toLowerCase() === "true" : options.pathStyle }); } const runner = (0, nx_remotecache_custom_1.createCustomRunner)(async (options) => { var _a; (0, nx_remotecache_custom_1.initEnv)(options); const client = getClient(options); const bucket = (_a = getEnv(ENV_BUCKET)) !== null && _a !== void 0 ? _a : options.bucket; return { name: "Minio Storage", fileExists: async (filename) => { try { const result = await client.statObject(bucket, filename); return !!result; } catch (_) { return false; } }, retrieveFile: (filename) => client.getObject(bucket, filename), storeFile: (filename, stream) => client.putObject(bucket, filename, stream) }; }); exports.default = runner;