mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix attachment sync
This commit is contained in:
parent
aa2bbc6575
commit
131af9ab12
@ -32,8 +32,8 @@ router.post('/upload/:parentNoteId', auth.checkApiAuthOrElectron, multer.single(
|
|||||||
mime: file.mimetype
|
mime: file.mimetype
|
||||||
}, req, sourceId)).noteId;
|
}, req, sourceId)).noteId;
|
||||||
|
|
||||||
await attributes.createAttribute(noteId, "original_file_name", originalName);
|
await attributes.createAttribute(noteId, "original_file_name", originalName, sourceId);
|
||||||
await attributes.createAttribute(noteId, "file_size", size);
|
await attributes.createAttribute(noteId, "file_size", size, sourceId);
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
noteId: noteId
|
noteId: noteId
|
||||||
|
@ -79,9 +79,12 @@ router.get('/changed', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|||||||
|
|
||||||
router.get('/notes/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.get('/notes/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
const noteId = req.params.noteId;
|
const noteId = req.params.noteId;
|
||||||
|
const entity = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId]);
|
||||||
|
|
||||||
|
sync.serializeNoteContentBuffer(entity);
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
entity: await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [noteId])
|
entity: entity
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -204,6 +204,8 @@ async function pushEntity(sync, syncContext) {
|
|||||||
|
|
||||||
if (sync.entityName === 'notes') {
|
if (sync.entityName === 'notes') {
|
||||||
entity = await sql.getRow('SELECT * FROM notes WHERE noteId = ?', [sync.entityId]);
|
entity = await sql.getRow('SELECT * FROM notes WHERE noteId = ?', [sync.entityId]);
|
||||||
|
|
||||||
|
serializeNoteContentBuffer(entity);
|
||||||
}
|
}
|
||||||
else if (sync.entityName === 'note_tree') {
|
else if (sync.entityName === 'note_tree') {
|
||||||
entity = await sql.getRow('SELECT * FROM note_tree WHERE noteTreeId = ?', [sync.entityId]);
|
entity = await sql.getRow('SELECT * FROM note_tree WHERE noteTreeId = ?', [sync.entityId]);
|
||||||
@ -258,6 +260,12 @@ async function pushEntity(sync, syncContext) {
|
|||||||
await syncRequest(syncContext, 'PUT', '/api/sync/' + sync.entityName, payload);
|
await syncRequest(syncContext, 'PUT', '/api/sync/' + sync.entityName, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function serializeNoteContentBuffer(note) {
|
||||||
|
if (note.type === 'file') {
|
||||||
|
note.content = note.content.toString("binary");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function checkContentHash(syncContext) {
|
async function checkContentHash(syncContext) {
|
||||||
const resp = await syncRequest(syncContext, 'GET', '/api/sync/check');
|
const resp = await syncRequest(syncContext, 'GET', '/api/sync/check');
|
||||||
|
|
||||||
@ -350,5 +358,6 @@ sql.dbReady.then(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sync
|
sync,
|
||||||
|
serializeNoteContentBuffer
|
||||||
};
|
};
|
@ -1,10 +1,17 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const eventLog = require('./event_log');
|
const eventLog = require('./event_log');
|
||||||
const notes = require('./notes');
|
|
||||||
const sync_table = require('./sync_table');
|
const sync_table = require('./sync_table');
|
||||||
|
|
||||||
|
function deserializeNoteContentBuffer(note) {
|
||||||
|
if (note.type === 'file') {
|
||||||
|
note.content = new Buffer(note.content, 'binary');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function updateNote(entity, sourceId) {
|
async function updateNote(entity, sourceId) {
|
||||||
|
deserializeNoteContentBuffer(entity);
|
||||||
|
|
||||||
const origNote = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [entity.noteId]);
|
const origNote = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [entity.noteId]);
|
||||||
|
|
||||||
if (!origNote || origNote.dateModified <= entity.dateModified) {
|
if (!origNote || origNote.dateModified <= entity.dateModified) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user