mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	rename attachment
This commit is contained in:
		
							parent
							
								
									2ebbc33081
								
							
						
					
					
						commit
						34c642a49a
					
				@ -26,12 +26,14 @@ const TPL = `
 | 
				
			|||||||
    </style>
 | 
					    </style>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <button type="button" data-toggle="dropdown" aria-haspopup="true" 
 | 
					    <button type="button" data-toggle="dropdown" aria-haspopup="true" 
 | 
				
			||||||
        aria-expanded="false" class="icon-action icon-action-always-border bx bx-dots-vertical-rounded"></button>
 | 
					        aria-expanded="false" class="icon-action icon-action-always-border bx bx-dots-vertical-rounded"
 | 
				
			||||||
 | 
					        style="position: relative; top: 5px;"></button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <div class="dropdown-menu dropdown-menu-right">
 | 
					    <div class="dropdown-menu dropdown-menu-right">
 | 
				
			||||||
        <a data-trigger-command="openAttachment" class="dropdown-item"
 | 
					        <a data-trigger-command="openAttachment" class="dropdown-item"
 | 
				
			||||||
            title="File will be open in an external application and watched for changes. You'll then be able to upload the modified version back to Trilium.">Open externally</a>
 | 
					            title="File will be open in an external application and watched for changes. You'll then be able to upload the modified version back to Trilium.">Open externally</a>
 | 
				
			||||||
        <a data-trigger-command="downloadAttachment" class="dropdown-item">Download</a>
 | 
					        <a data-trigger-command="downloadAttachment" class="dropdown-item">Download</a>
 | 
				
			||||||
 | 
					        <a data-trigger-command="renameAttachment" class="dropdown-item">Rename attachment</a>
 | 
				
			||||||
        <a data-trigger-command="uploadNewAttachmentRevision" class="dropdown-item">Upload new revision</a>
 | 
					        <a data-trigger-command="uploadNewAttachmentRevision" class="dropdown-item">Upload new revision</a>
 | 
				
			||||||
        <a data-trigger-command="copyAttachmentLinkToClipboard" class="dropdown-item">Copy link to clipboard</a>
 | 
					        <a data-trigger-command="copyAttachmentLinkToClipboard" class="dropdown-item">Copy link to clipboard</a>
 | 
				
			||||||
        <a data-trigger-command="convertAttachmentIntoNote" class="dropdown-item">Convert attachment into note</a>
 | 
					        <a data-trigger-command="convertAttachmentIntoNote" class="dropdown-item">Convert attachment into note</a>
 | 
				
			||||||
@ -129,4 +131,18 @@ export default class AttachmentActionsWidget extends BasicWidget {
 | 
				
			|||||||
        await ws.waitForMaxKnownEntityChangeId();
 | 
					        await ws.waitForMaxKnownEntityChangeId();
 | 
				
			||||||
        await appContext.tabManager.getActiveContext().setNote(newNote.noteId);
 | 
					        await appContext.tabManager.getActiveContext().setNote(newNote.noteId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async renameAttachmentCommand() {
 | 
				
			||||||
 | 
					        const attachmentTitle = await dialogService.prompt({
 | 
				
			||||||
 | 
					            title: "Rename attachment",
 | 
				
			||||||
 | 
					            message: "Please enter new attachment's name",
 | 
				
			||||||
 | 
					            defaultValue: this.attachment.title
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!attachmentTitle?.trim()) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await server.put(`attachments/${this.attachmentId}/rename`, {title: attachmentTitle});
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -14,8 +14,8 @@ const TPL = `
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        .attachment-detail .links-wrapper {
 | 
					        .attachment-detail .links-wrapper {
 | 
				
			||||||
            padding: 16px;
 | 
					 | 
				
			||||||
            font-size: larger;
 | 
					            font-size: larger;
 | 
				
			||||||
 | 
					            padding: 16px 0 16px 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        .attachment-detail .attachment-wrapper {
 | 
					        .attachment-detail .attachment-wrapper {
 | 
				
			||||||
 | 
				
			|||||||
@ -109,8 +109,8 @@ export default class EtapiOptions extends OptionsWidget {
 | 
				
			|||||||
            message: "Please enter new token's name",
 | 
					            message: "Please enter new token's name",
 | 
				
			||||||
            defaultValue: oldName
 | 
					            defaultValue: oldName
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if(tokenName === null) {
 | 
					        if (!tokenName?.trim()) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -110,7 +110,7 @@ button.close:hover {
 | 
				
			|||||||
.icon-action {
 | 
					.icon-action {
 | 
				
			||||||
    border: 1px solid transparent;
 | 
					    border: 1px solid transparent;
 | 
				
			||||||
    padding: 5px;
 | 
					    padding: 5px;
 | 
				
			||||||
    width: 35px;
 | 
					    width: 37px;
 | 
				
			||||||
    height: 35px;
 | 
					    height: 35px;
 | 
				
			||||||
    cursor: pointer;
 | 
					    cursor: pointer;
 | 
				
			||||||
    font-size: 1.5em;
 | 
					    font-size: 1.5em;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
const becca = require("../../becca/becca");
 | 
					const becca = require("../../becca/becca");
 | 
				
			||||||
const blobService = require("../../services/blob.js");
 | 
					const blobService = require("../../services/blob.js");
 | 
				
			||||||
 | 
					const ValidationError = require("../../errors/validation_error");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getAttachmentBlob(req) {
 | 
					function getAttachmentBlob(req) {
 | 
				
			||||||
    const preview = req.query.preview === 'true';
 | 
					    const preview = req.query.preview === 'true';
 | 
				
			||||||
@ -41,7 +42,7 @@ function uploadAttachment(req) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const note = becca.getNoteOrThrow(noteId);
 | 
					    const note = becca.getNoteOrThrow(noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const attachment = note.saveAttachment({
 | 
					    note.saveAttachment({
 | 
				
			||||||
        role: 'file',
 | 
					        role: 'file',
 | 
				
			||||||
        mime: file.mimetype,
 | 
					        mime: file.mimetype,
 | 
				
			||||||
        title: file.originalname,
 | 
					        title: file.originalname,
 | 
				
			||||||
@ -53,6 +54,20 @@ function uploadAttachment(req) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function renameAttachment(req) {
 | 
				
			||||||
 | 
					    const {title} = req.body;
 | 
				
			||||||
 | 
					    const {attachmentId} = req.params;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const attachment = becca.getAttachmentOrThrow(attachmentId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!title?.trim()) {
 | 
				
			||||||
 | 
					        throw new ValidationError("Title must not be empty");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    attachment.title = title;
 | 
				
			||||||
 | 
					    attachment.save();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function deleteAttachment(req) {
 | 
					function deleteAttachment(req) {
 | 
				
			||||||
    const {attachmentId} = req.params;
 | 
					    const {attachmentId} = req.params;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -77,6 +92,7 @@ module.exports = {
 | 
				
			|||||||
    getAllAttachments,
 | 
					    getAllAttachments,
 | 
				
			||||||
    saveAttachment,
 | 
					    saveAttachment,
 | 
				
			||||||
    uploadAttachment,
 | 
					    uploadAttachment,
 | 
				
			||||||
 | 
					    renameAttachment,
 | 
				
			||||||
    deleteAttachment,
 | 
					    deleteAttachment,
 | 
				
			||||||
    convertAttachmentToNote
 | 
					    convertAttachmentToNote
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -35,6 +35,7 @@ function updateFile(req) {
 | 
				
			|||||||
function updateAttachment(req) {
 | 
					function updateAttachment(req) {
 | 
				
			||||||
    const attachment = becca.getAttachmentOrThrow(req.params.attachmentId);
 | 
					    const attachment = becca.getAttachmentOrThrow(req.params.attachmentId);
 | 
				
			||||||
    const file = req.file;
 | 
					    const file = req.file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    attachment.getNote().saveRevision();
 | 
					    attachment.getNote().saveRevision();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    attachment.mime = file.mimetype.toLowerCase();
 | 
					    attachment.mime = file.mimetype.toLowerCase();
 | 
				
			||||||
 | 
				
			|||||||
@ -159,6 +159,7 @@ function register(app) {
 | 
				
			|||||||
    apiRoute(GET, '/api/attachments/:attachmentId/all', attachmentsApiRoute.getAllAttachments);
 | 
					    apiRoute(GET, '/api/attachments/:attachmentId/all', attachmentsApiRoute.getAllAttachments);
 | 
				
			||||||
    apiRoute(PST, '/api/attachments/:attachmentId/convert-to-note', attachmentsApiRoute.convertAttachmentToNote);
 | 
					    apiRoute(PST, '/api/attachments/:attachmentId/convert-to-note', attachmentsApiRoute.convertAttachmentToNote);
 | 
				
			||||||
    apiRoute(DEL, '/api/attachments/:attachmentId', attachmentsApiRoute.deleteAttachment);
 | 
					    apiRoute(DEL, '/api/attachments/:attachmentId', attachmentsApiRoute.deleteAttachment);
 | 
				
			||||||
 | 
					    apiRoute(PUT, '/api/attachments/:attachmentId/rename', attachmentsApiRoute.renameAttachment);
 | 
				
			||||||
    apiRoute(GET, '/api/attachments/:attachmentId/blob', attachmentsApiRoute.getAttachmentBlob);
 | 
					    apiRoute(GET, '/api/attachments/:attachmentId/blob', attachmentsApiRoute.getAttachmentBlob);
 | 
				
			||||||
    route(GET, '/api/attachments/:attachmentId/image/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnAttachedImage);
 | 
					    route(GET, '/api/attachments/:attachmentId/image/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnAttachedImage);
 | 
				
			||||||
    route(GET, '/api/attachments/:attachmentId/open', [auth.checkApiAuthOrElectron], filesRoute.openAttachment);
 | 
					    route(GET, '/api/attachments/:attachmentId/open', [auth.checkApiAuthOrElectron], filesRoute.openAttachment);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user