n8n
Version:
n8n Workflow Automation Tool
27 lines • 915 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UniqueFilenameAllocator = void 0;
const slug_utils_1 = require("./slug.utils");
class UniqueFilenameAllocator {
constructor(baseDir, fallback) {
this.baseDir = baseDir;
this.fallback = fallback;
this.used = new Set();
}
allocate(name) {
const base = `${this.baseDir}/${(0, slug_utils_1.generateSlug)(name, this.fallback)}`;
if (!this.used.has(base)) {
this.used.add(base);
return base;
}
for (let suffix = 2;; suffix++) {
const candidate = `${base}-${suffix}`;
if (!this.used.has(candidate)) {
this.used.add(candidate);
return candidate;
}
}
}
}
exports.UniqueFilenameAllocator = UniqueFilenameAllocator;
//# sourceMappingURL=unique-filename-allocator.js.map