mirror of
https://github.com/zadam/trilium.git
synced 2026-01-05 23:19:56 +01:00
Add multi-branch prefix editing support (#7598)
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user