Add multi-branch prefix editing support (#7598)

This commit is contained in:
Elian Doran
2025-11-04 19:17:31 +02:00
committed by GitHub
7 changed files with 145 additions and 25 deletions

View File

@@ -270,6 +270,38 @@ function setPrefix(req: Request) {
branch.save();
}
function setPrefixBatch(req: Request) {
const { branchIds, prefix } = req.body;
if (!Array.isArray(branchIds)) {
throw new ValidationError("branchIds must be an array");
}
// Validate that prefix is a string or null/undefined to prevent prototype pollution
if (prefix !== null && prefix !== undefined && typeof prefix !== 'string') {
throw new ValidationError("prefix must be a string or null");
}
const normalizedPrefix = utils.isEmptyOrWhitespace(prefix) ? null : prefix;
let updatedCount = 0;
for (const branchId of branchIds) {
const branch = becca.getBranch(branchId);
if (branch) {
branch.prefix = normalizedPrefix;
branch.save();
updatedCount++;
} else {
log.info(`Branch ${branchId} not found, skipping prefix update`);
}
}
return {
success: true,
count: updatedCount
};
}
export default {
moveBranchToParent,
moveBranchBeforeNote,
@@ -277,5 +309,6 @@ export default {
setExpanded,
setExpandedForSubtree,
deleteBranch,
setPrefix
setPrefix,
setPrefixBatch
};

View File

@@ -154,6 +154,7 @@ function register(app: express.Application) {
apiRoute(PUT, "/api/branches/:branchId/expanded-subtree/:expanded", branchesApiRoute.setExpandedForSubtree);
apiRoute(DEL, "/api/branches/:branchId", branchesApiRoute.deleteBranch);
apiRoute(PUT, "/api/branches/:branchId/set-prefix", branchesApiRoute.setPrefix);
apiRoute(PUT, "/api/branches/set-prefix-batch", branchesApiRoute.setPrefixBatch);
apiRoute(GET, "/api/notes/:noteId/attachments", attachmentsApiRoute.getAttachments);
apiRoute(PST, "/api/notes/:noteId/attachments", attachmentsApiRoute.saveAttachment);