mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
cleanup + context menu clip now works
This commit is contained in:
parent
989da8877b
commit
154a575701
@ -832,4 +832,8 @@ a.external:after, a[href^="http://"]:after, a[href^="https://"]:after {
|
|||||||
|
|
||||||
.note-detail-empty {
|
.note-detail-empty {
|
||||||
margin: 50px;
|
margin: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
padding: 0.7rem 1rem !important; /* make modal header padding slightly smaller */
|
||||||
}
|
}
|
59
src/routes/api/clipper.js
Normal file
59
src/routes/api/clipper.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const noteService = require('../../services/notes');
|
||||||
|
const dateNoteService = require('../../services/date_notes');
|
||||||
|
const dateUtils = require('../../services/date_utils');
|
||||||
|
const imageService = require('../../services/image');
|
||||||
|
|
||||||
|
async function createNote(req) {
|
||||||
|
console.log(req.body);
|
||||||
|
|
||||||
|
const {title, html, source_url} = req.body;
|
||||||
|
|
||||||
|
const todayNote = await dateNoteService.getDateNote(dateUtils.localNowDate());
|
||||||
|
|
||||||
|
await noteService.createNote(todayNote.noteId, title, html, {
|
||||||
|
attributes: [
|
||||||
|
{
|
||||||
|
type: 'label',
|
||||||
|
name: 'sourceUrl',
|
||||||
|
value: source_url
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createScreenshot(req) {
|
||||||
|
console.log(req.body);
|
||||||
|
|
||||||
|
const {imageDataUrl, title, url} = req.body;
|
||||||
|
|
||||||
|
const prefix = "data:image/png;base64,";
|
||||||
|
|
||||||
|
if (imageDataUrl.startsWith(prefix)) {
|
||||||
|
const buffer = Buffer.from(imageDataUrl.substr(prefix.length), 'base64');
|
||||||
|
|
||||||
|
const todayNote = await dateNoteService.getDateNote(dateUtils.localNowDate());
|
||||||
|
|
||||||
|
const {note} = await imageService.saveImage(buffer, title, todayNote.noteId, true);
|
||||||
|
|
||||||
|
await note.setLabel('sourceUrl', url);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Unrecognized prefix");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ping(req, res) {
|
||||||
|
console.log("PING!!!!");
|
||||||
|
|
||||||
|
res.status(200).send("TriliumClipperServer");
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createNote,
|
||||||
|
createScreenshot,
|
||||||
|
ping
|
||||||
|
};
|
@ -32,6 +32,7 @@ const filesRoute = require('./api/file_upload');
|
|||||||
const searchRoute = require('./api/search');
|
const searchRoute = require('./api/search');
|
||||||
const dateNotesRoute = require('./api/date_notes');
|
const dateNotesRoute = require('./api/date_notes');
|
||||||
const linkMapRoute = require('./api/link_map');
|
const linkMapRoute = require('./api/link_map');
|
||||||
|
const clipperRoute = require('./api/clipper');
|
||||||
|
|
||||||
const log = require('../services/log');
|
const log = require('../services/log');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@ -223,6 +224,10 @@ function register(app) {
|
|||||||
// this is for entering protected mode so user has to be already logged-in (that's the reason we don't require username)
|
// this is for entering protected mode so user has to be already logged-in (that's the reason we don't require username)
|
||||||
apiRoute(POST, '/api/login/protected', loginApiRoute.loginToProtectedSession);
|
apiRoute(POST, '/api/login/protected', loginApiRoute.loginToProtectedSession);
|
||||||
|
|
||||||
|
route(POST, '/api/clipper/notes', [], clipperRoute.createNote, apiResultHandler);
|
||||||
|
route(POST, '/api/clipper/screenshot', [], clipperRoute.createScreenshot, apiResultHandler);
|
||||||
|
route(GET, '/api/clipper/ping', [], clipperRoute.ping);
|
||||||
|
|
||||||
app.use('', router);
|
app.use('', router);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ async function shrinkImage(buffer, originalName) {
|
|||||||
try {
|
try {
|
||||||
finalImageBuffer = await optimize(resizedImage);
|
finalImageBuffer = await optimize(resizedImage);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("Failed to optimize image '" + originalName + "\nStack: " + e.stack);
|
log.error("Failed to optimize image '" + originalName + "'\nStack: " + e.stack);
|
||||||
finalImageBuffer = resizedImage;
|
finalImageBuffer = resizedImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ async function optimize(buffer) {
|
|||||||
quality: 50
|
quality: 50
|
||||||
}),
|
}),
|
||||||
imageminPngQuant({
|
imageminPngQuant({
|
||||||
quality: "0-70"
|
quality: [0, 0.7]
|
||||||
}),
|
}),
|
||||||
imageminGifLossy({
|
imageminGifLossy({
|
||||||
lossy: 80,
|
lossy: 80,
|
||||||
|
@ -3,7 +3,7 @@ const config = require('./config');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
module.exports = getPort();
|
module.exports = 53010;//getPort();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
module.exports = Promise.resolve(config['Network']['port'] || '3000');
|
module.exports = Promise.resolve(config['Network']['port'] || '3000');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user