mirror of
https://github.com/zadam/trilium.git
synced 2024-09-20 15:45:58 +08: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;
|
||||
|
||||
// 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.ESLINT = libraryLoader.ESLINT;
|
||||
window.glob.appContext = appContext; // for debugging
|
||||
|
|
|
@ -98,31 +98,6 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
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() {
|
||||
|
|
|
@ -35,6 +35,24 @@ function saveAttachment(req) {
|
|||
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) {
|
||||
const {attachmentId} = req.params;
|
||||
|
||||
|
@ -58,6 +76,7 @@ module.exports = {
|
|||
getAttachment,
|
||||
getAllAttachments,
|
||||
saveAttachment,
|
||||
uploadAttachment,
|
||||
deleteAttachment,
|
||||
convertAttachmentToNote
|
||||
};
|
||||
|
|
|
@ -63,7 +63,7 @@ function uploadImage(req) {
|
|||
const {noteId} = req.query;
|
||||
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)) {
|
||||
throw new ValidationError(`Unknown image type '${file.mimetype}'`);
|
||||
|
|
|
@ -153,6 +153,7 @@ function register(app) {
|
|||
|
||||
apiRoute(GET, '/api/notes/:noteId/attachments', attachmentsApiRoute.getAttachments);
|
||||
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/all', attachmentsApiRoute.getAllAttachments);
|
||||
apiRoute(PST, '/api/attachments/:attachmentId/convert-to-note', attachmentsApiRoute.convertAttachmentToNote);
|
||||
|
|
Loading…
Reference in a new issue