mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
file upload WIP
This commit is contained in:
parent
0234ff5fca
commit
38839532d5
2
libraries/ckeditor/ckeditor.js
vendored
2
libraries/ckeditor/ckeditor.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -15,7 +15,7 @@ function setupGlobs() {
|
|||||||
window.glob.getHeaders = server.getHeaders;
|
window.glob.getHeaders = server.getHeaders;
|
||||||
|
|
||||||
// required for ESLint plugin and CKEditor
|
// required for ESLint plugin and CKEditor
|
||||||
window.glob.getActiveTabNote = () => appContext.tabManager.getActiveContextNote();
|
window.glob.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
|
||||||
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
||||||
window.glob.ESLINT = libraryLoader.ESLINT;
|
window.glob.ESLINT = libraryLoader.ESLINT;
|
||||||
window.glob.appContext = appContext; // for debugging
|
window.glob.appContext = appContext; // for debugging
|
||||||
|
@ -98,31 +98,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
this.contentSized();
|
this.contentSized();
|
||||||
|
|
||||||
this.$widget.on("dragover", e => e.preventDefault());
|
|
||||||
|
|
||||||
this.$widget.on("dragleave", e => e.preventDefault());
|
|
||||||
|
|
||||||
this.$widget.on("drop", async e => {
|
|
||||||
const activeNote = appContext.tabManager.getActiveContextNote();
|
|
||||||
|
|
||||||
if (!activeNote) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const files = [...e.originalEvent.dataTransfer.files]; // chrome has issue that dataTransfer.files empties after async operation
|
|
||||||
|
|
||||||
const importService = await import('../services/import.js');
|
|
||||||
|
|
||||||
importService.uploadFiles('notes', activeNote.noteId, files, {
|
|
||||||
safeImport: true,
|
|
||||||
shrinkImages: true,
|
|
||||||
textImportedAsText: true,
|
|
||||||
codeImportedAsCode: true,
|
|
||||||
explodeArchives: true,
|
|
||||||
replaceUnderscoresWithSpaces: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async refresh() {
|
async refresh() {
|
||||||
|
@ -35,6 +35,24 @@ function saveAttachment(req) {
|
|||||||
note.saveAttachment({attachmentId, role, mime, title, content});
|
note.saveAttachment({attachmentId, role, mime, title, content});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function uploadAttachment(req) {
|
||||||
|
const {noteId} = req.params;
|
||||||
|
const {file} = req;
|
||||||
|
|
||||||
|
const note = becca.getNoteOrThrow(noteId);
|
||||||
|
|
||||||
|
const attachment = note.saveAttachment({
|
||||||
|
role: 'file',
|
||||||
|
mime: file.mimetype,
|
||||||
|
title: file.originalname,
|
||||||
|
content: file.buffer
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
uploaded: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function deleteAttachment(req) {
|
function deleteAttachment(req) {
|
||||||
const {attachmentId} = req.params;
|
const {attachmentId} = req.params;
|
||||||
|
|
||||||
@ -58,6 +76,7 @@ module.exports = {
|
|||||||
getAttachment,
|
getAttachment,
|
||||||
getAllAttachments,
|
getAllAttachments,
|
||||||
saveAttachment,
|
saveAttachment,
|
||||||
|
uploadAttachment,
|
||||||
deleteAttachment,
|
deleteAttachment,
|
||||||
convertAttachmentToNote
|
convertAttachmentToNote
|
||||||
};
|
};
|
||||||
|
@ -63,7 +63,7 @@ function uploadImage(req) {
|
|||||||
const {noteId} = req.query;
|
const {noteId} = req.query;
|
||||||
const {file} = req;
|
const {file} = req;
|
||||||
|
|
||||||
const note = becca.getNoteOrThrow(noteId);
|
becca.getNoteOrThrow(noteId);
|
||||||
|
|
||||||
if (!["image/png", "image/jpg", "image/jpeg", "image/gif", "image/webp", "image/svg+xml"].includes(file.mimetype)) {
|
if (!["image/png", "image/jpg", "image/jpeg", "image/gif", "image/webp", "image/svg+xml"].includes(file.mimetype)) {
|
||||||
throw new ValidationError(`Unknown image type '${file.mimetype}'`);
|
throw new ValidationError(`Unknown image type '${file.mimetype}'`);
|
||||||
|
@ -153,6 +153,7 @@ function register(app) {
|
|||||||
|
|
||||||
apiRoute(GET, '/api/notes/:noteId/attachments', attachmentsApiRoute.getAttachments);
|
apiRoute(GET, '/api/notes/:noteId/attachments', attachmentsApiRoute.getAttachments);
|
||||||
apiRoute(PST, '/api/notes/:noteId/attachments', attachmentsApiRoute.saveAttachment);
|
apiRoute(PST, '/api/notes/:noteId/attachments', attachmentsApiRoute.saveAttachment);
|
||||||
|
route(PST, '/api/notes/:noteId/attachments/upload', [auth.checkApiAuthOrElectron, uploadMiddlewareWithErrorHandling, csrfMiddleware], attachmentsApiRoute.uploadAttachment, apiResultHandler);
|
||||||
apiRoute(GET, '/api/attachments/:attachmentId', attachmentsApiRoute.getAttachment);
|
apiRoute(GET, '/api/attachments/:attachmentId', attachmentsApiRoute.getAttachment);
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user