Add wildcard and regex modes to Bulk Rename

Plain-text substring matching couldn't handle a batch of
slightly-different patterns (e.g. several release-group suffixes) in
one pass. Add a match-type selector: wildcard (shell-style */?) for
the common case, and full regex (with backreferences in the
replacement) for anything more precise. Invalid regex is caught and
reported inline instead of failing the request.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-24 11:45:52 -04:00
co-authored by Claude Sonnet 5
parent 49b68b8e51
commit bcd1734c94
3 changed files with 100 additions and 17 deletions
+33 -4
View File
@@ -117,6 +117,12 @@
font-size: 0.92em;
margin: 0 0 14px;
}
.section-desc code {
background: var(--bg-tertiary);
border-radius: 4px;
padding: 1px 5px;
font-family: monospace;
}
.text-input {
flex: 1;
min-width: 160px;
@@ -515,9 +521,14 @@
</div>
<h2 class="section-title">{{ icons.icon('pencil', 18) }} Bulk Rename</h2>
<p class="section-desc">Find and replace text across every course/folder name in the library at once - handy for stripping a release-group suffix off a batch of downloads.</p>
<p class="section-desc">Find and replace text across every course/folder name in the library at once - handy for stripping a release-group suffix off a batch of downloads. Wildcard or regex mode can match several slightly-different patterns in one pass, e.g. <code>.BOOKWARE*</code> catching <code>.BOOKWARE-GETH</code>, <code>.BOOKWARE-BOOKTIME</code>, <code>.BOOKWARE-BLZiSO</code>, etc. at once.</p>
<div class="card">
<div class="toolbar" style="margin-bottom: 10px;">
<select id="bulk-rename-mode" class="text-input" style="flex: 0 0 auto; min-width: 130px;" onchange="updateBulkRenamePlaceholder()">
<option value="plain">Plain text</option>
<option value="wildcard">Wildcard (*, ?)</option>
<option value="regex">Regex</option>
</select>
<input type="text" id="bulk-rename-find" class="text-input" placeholder="Find (e.g. .BOOKWARE-LERNSTUF)">
<input type="text" id="bulk-rename-replace" class="text-input" placeholder="Replace with (blank to remove)">
<button class="btn" onclick="previewBulkRename()">Preview</button>
@@ -824,9 +835,21 @@
// ---- Bulk rename: find/replace across every course/folder name ----
let bulkRenameMatches = [];
const BULK_RENAME_PLACEHOLDERS = {
plain: 'Find (e.g. .BOOKWARE-LERNSTUF)',
wildcard: 'Find (e.g. .BOOKWARE*)',
regex: String.raw`Find (e.g. \.BOOKWARE-\w+)`,
};
function updateBulkRenamePlaceholder() {
const mode = document.getElementById('bulk-rename-mode').value;
document.getElementById('bulk-rename-find').placeholder = BULK_RENAME_PLACEHOLDERS[mode] || BULK_RENAME_PLACEHOLDERS.plain;
}
function previewBulkRename() {
const pattern = document.getElementById('bulk-rename-find').value;
const replacement = document.getElementById('bulk-rename-replace').value;
const mode = document.getElementById('bulk-rename-mode').value;
const status = document.getElementById('bulk-rename-status');
const preview = document.getElementById('bulk-rename-preview');
preview.innerHTML = '';
@@ -837,9 +860,15 @@
}
status.style.color = 'var(--text-muted)';
status.textContent = 'Searching...';
fetch(`/api/bulk-rename/preview?pattern=${encodeURIComponent(pattern)}&replacement=${encodeURIComponent(replacement)}`)
.then(r => r.json())
.then(data => {
fetch(`/api/bulk-rename/preview?pattern=${encodeURIComponent(pattern)}&replacement=${encodeURIComponent(replacement)}&mode=${encodeURIComponent(mode)}`)
.then(r => r.json().then(data => ({ ok: r.ok, data })))
.then(({ ok, data }) => {
if (!ok) {
status.style.color = 'var(--error)';
status.textContent = data.error || 'Invalid pattern.';
bulkRenameMatches = [];
return;
}
bulkRenameMatches = data.matches || [];
renderBulkRenamePreview();
})