mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 10:40:41 +01:00
renaming attributes to labels, fixes #79
This commit is contained in:
@@ -5,7 +5,7 @@ const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const auth = require('../../services/auth');
|
||||
const notes = require('../../services/notes');
|
||||
const attributes = require('../../services/attributes');
|
||||
const labels = require('../../services/labels');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
const multer = require('multer')();
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
@@ -33,8 +33,8 @@ router.post('/upload/:parentNoteId', auth.checkApiAuthOrElectron, multer.single(
|
||||
mime: file.mimetype
|
||||
}, req, sourceId)).noteId;
|
||||
|
||||
await attributes.createAttribute(noteId, "original_file_name", originalName, sourceId);
|
||||
await attributes.createAttribute(noteId, "file_size", size, sourceId);
|
||||
await labels.createLabel(noteId, "original_file_name", originalName, sourceId);
|
||||
await labels.createLabel(noteId, "file_size", size, sourceId);
|
||||
|
||||
res.send({
|
||||
noteId: noteId
|
||||
@@ -62,8 +62,8 @@ router.get('/download/:noteId', auth.checkApiAuthOrElectron, wrap(async (req, re
|
||||
protected_session.decryptNote(dataKey, note);
|
||||
}
|
||||
|
||||
const attributeMap = await attributes.getNoteAttributeMap(noteId);
|
||||
const fileName = attributeMap.original_file_name ? attributeMap.original_file_name : note.title;
|
||||
const labelMap = await labels.getNoteLabelMap(noteId);
|
||||
const fileName = labelMap.original_file_name ? labelMap.original_file_name : note.title;
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=' + fileName);
|
||||
res.setHeader('Content-Type', note.mime);
|
||||
|
||||
@@ -22,7 +22,7 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, wrap(async (req, r
|
||||
|
||||
await sql.execute(`DELETE FROM note_images WHERE noteId IN (${noteIdsSql})`);
|
||||
|
||||
await sql.execute(`DELETE FROM attributes WHERE noteId IN (${noteIdsSql})`);
|
||||
await sql.execute(`DELETE FROM labels WHERE noteId IN (${noteIdsSql})`);
|
||||
|
||||
await sql.execute("DELETE FROM branches WHERE isDeleted = 1");
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ async function exportNote(branchId, directory, pack, repo) {
|
||||
|
||||
const metadata = await getMetadata(note);
|
||||
|
||||
if (metadata.attributes.find(attr => attr.name === 'exclude_from_export')) {
|
||||
if (metadata.labels.find(attr => attr.name === 'exclude_from_export')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ async function getMetadata(note) {
|
||||
title: note.title,
|
||||
type: note.type,
|
||||
mime: note.mime,
|
||||
attributes: (await note.getAttributes()).map(attr => {
|
||||
labels: (await note.getLabels()).map(attr => {
|
||||
return {
|
||||
name: attr.name,
|
||||
value: attr.value
|
||||
|
||||
@@ -4,7 +4,7 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const auth = require('../../services/auth');
|
||||
const attributes = require('../../services/attributes');
|
||||
const labels = require('../../services/labels');
|
||||
const notes = require('../../services/notes');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const tar = require('tar-stream');
|
||||
@@ -126,8 +126,8 @@ async function importNotes(files, parentNoteId, sourceId) {
|
||||
sourceId: sourceId
|
||||
});
|
||||
|
||||
for (const attr of file.meta.attributes) {
|
||||
await attributes.createAttribute(noteId, attr.name, attr.value);
|
||||
for (const attr of file.meta.labels) {
|
||||
await labels.createLabel(noteId, attr.name, attr.value);
|
||||
}
|
||||
|
||||
if (file.children.length > 0) {
|
||||
|
||||
@@ -7,24 +7,24 @@ const auth = require('../../services/auth');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const utils = require('../../services/utils');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const attributes = require('../../services/attributes');
|
||||
const labels = require('../../services/labels');
|
||||
|
||||
router.get('/notes/:noteId/attributes', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
router.get('/notes/:noteId/labels', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
res.send(await sql.getRows("SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ? ORDER BY position, dateCreated", [noteId]));
|
||||
res.send(await sql.getRows("SELECT * FROM labels WHERE isDeleted = 0 AND noteId = ? ORDER BY position, dateCreated", [noteId]));
|
||||
}));
|
||||
|
||||
router.put('/notes/:noteId/attributes', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
router.put('/notes/:noteId/labels', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const noteId = req.params.noteId;
|
||||
const attributes = req.body;
|
||||
const labels = req.body;
|
||||
const now = utils.nowDate();
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
for (const attr of attributes) {
|
||||
if (attr.attributeId) {
|
||||
await sql.execute("UPDATE attributes SET name = ?, value = ?, dateModified = ?, isDeleted = ?, position = ? WHERE attributeId = ?",
|
||||
[attr.name, attr.value, now, attr.isDeleted, attr.position, attr.attributeId]);
|
||||
for (const attr of labels) {
|
||||
if (attr.labelId) {
|
||||
await sql.execute("UPDATE labels SET name = ?, value = ?, dateModified = ?, isDeleted = ?, position = ? WHERE labelId = ?",
|
||||
[attr.name, attr.value, now, attr.isDeleted, attr.position, attr.labelId]);
|
||||
}
|
||||
else {
|
||||
// if it was "created" and then immediatelly deleted, we just don't create it at all
|
||||
@@ -32,10 +32,10 @@ router.put('/notes/:noteId/attributes', auth.checkApiAuth, wrap(async (req, res,
|
||||
continue;
|
||||
}
|
||||
|
||||
attr.attributeId = utils.newAttributeId();
|
||||
attr.labelId = utils.newLabelId();
|
||||
|
||||
await sql.insert("attributes", {
|
||||
attributeId: attr.attributeId,
|
||||
await sql.insert("labels", {
|
||||
labelId: attr.labelId,
|
||||
noteId: noteId,
|
||||
name: attr.name,
|
||||
value: attr.value,
|
||||
@@ -46,17 +46,17 @@ router.put('/notes/:noteId/attributes', auth.checkApiAuth, wrap(async (req, res,
|
||||
});
|
||||
}
|
||||
|
||||
await sync_table.addAttributeSync(attr.attributeId);
|
||||
await sync_table.addLabelSync(attr.labelId);
|
||||
}
|
||||
});
|
||||
|
||||
res.send(await sql.getRows("SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ? ORDER BY position, dateCreated", [noteId]));
|
||||
res.send(await sql.getRows("SELECT * FROM labels WHERE isDeleted = 0 AND noteId = ? ORDER BY position, dateCreated", [noteId]));
|
||||
}));
|
||||
|
||||
router.get('/attributes/names', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const names = await sql.getColumn("SELECT DISTINCT name FROM attributes WHERE isDeleted = 0");
|
||||
router.get('/labels/names', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const names = await sql.getColumn("SELECT DISTINCT name FROM labels WHERE isDeleted = 0");
|
||||
|
||||
for (const attr of attributes.BUILTIN_ATTRIBUTES) {
|
||||
for (const attr of labels.BUILTIN_LABELS) {
|
||||
if (!names.includes(attr)) {
|
||||
names.push(attr);
|
||||
}
|
||||
@@ -67,10 +67,10 @@ router.get('/attributes/names', auth.checkApiAuth, wrap(async (req, res, next) =
|
||||
res.send(names);
|
||||
}));
|
||||
|
||||
router.get('/attributes/values/:attributeName', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const attributeName = req.params.attributeName;
|
||||
router.get('/labels/values/:labelName', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const labelName = req.params.labelName;
|
||||
|
||||
const values = await sql.getColumn("SELECT DISTINCT value FROM attributes WHERE isDeleted = 0 AND name = ? AND value != '' ORDER BY value", [attributeName]);
|
||||
const values = await sql.getColumn("SELECT DISTINCT value FROM labels WHERE isDeleted = 0 AND name = ? AND value != '' ORDER BY value", [labelName]);
|
||||
|
||||
res.send(values);
|
||||
}));
|
||||
@@ -5,7 +5,7 @@ const router = express.Router();
|
||||
const auth = require('../../services/auth');
|
||||
const sql = require('../../services/sql');
|
||||
const notes = require('../../services/notes');
|
||||
const attributes = require('../../services/attributes');
|
||||
const labels = require('../../services/labels');
|
||||
const log = require('../../services/log');
|
||||
const utils = require('../../services/utils');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
@@ -26,19 +26,19 @@ router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
|
||||
protected_session.decryptNote(req, detail);
|
||||
|
||||
let attributeMap = null;
|
||||
let labelMap = null;
|
||||
|
||||
if (detail.type === 'file') {
|
||||
// no need to transfer attachment payload for this request
|
||||
detail.content = null;
|
||||
|
||||
// attributes contain important attachment metadata - filename and size
|
||||
attributeMap = await attributes.getNoteAttributeMap(noteId);
|
||||
// labels contain important attachment metadata - filename and size
|
||||
labelMap = await labels.getNoteLabelMap(noteId);
|
||||
}
|
||||
|
||||
res.send({
|
||||
detail: detail,
|
||||
attributes: attributeMap
|
||||
labels: labelMap
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const attributes = require('../../services/attributes');
|
||||
const labels = require('../../services/labels');
|
||||
const script = require('../../services/script');
|
||||
const Repository = require('../../services/repository');
|
||||
|
||||
@@ -29,7 +29,7 @@ router.post('/run/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
|
||||
router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const repository = new Repository(req);
|
||||
const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");
|
||||
const notes = await labels.getNotesWithLabel(repository, "run", "frontend_startup");
|
||||
|
||||
const scripts = [];
|
||||
|
||||
|
||||
@@ -144,10 +144,10 @@ router.get('/note_images/:noteImageId', auth.checkApiAuth, wrap(async (req, res,
|
||||
res.send(await sql.getRow("SELECT * FROM note_images WHERE noteImageId = ?", [noteImageId]));
|
||||
}));
|
||||
|
||||
router.get('/attributes/:attributeId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const attributeId = req.params.attributeId;
|
||||
router.get('/labels/:labelId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const labelId = req.params.labelId;
|
||||
|
||||
res.send(await sql.getRow("SELECT * FROM attributes WHERE attributeId = ?", [attributeId]));
|
||||
res.send(await sql.getRow("SELECT * FROM labels WHERE labelId = ?", [labelId]));
|
||||
}));
|
||||
|
||||
router.get('/api_tokens/:apiTokenId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
@@ -204,8 +204,8 @@ router.put('/note_images', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
res.send({});
|
||||
}));
|
||||
|
||||
router.put('/attributes', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
await syncUpdate.updateAttribute(req.body.entity, req.body.sourceId);
|
||||
router.put('/labels', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
await syncUpdate.updateLabel(req.body.entity, req.body.sourceId);
|
||||
|
||||
res.send({});
|
||||
}));
|
||||
|
||||
@@ -42,10 +42,10 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
notes.isProtected,
|
||||
notes.type,
|
||||
notes.mime,
|
||||
hideInAutocomplete.attributeId AS 'hideInAutocomplete'
|
||||
hideInAutocomplete.labelId AS 'hideInAutocomplete'
|
||||
FROM
|
||||
notes
|
||||
LEFT JOIN attributes AS hideInAutocomplete ON hideInAutocomplete.noteId = notes.noteId
|
||||
LEFT JOIN labels AS hideInAutocomplete ON hideInAutocomplete.noteId = notes.noteId
|
||||
AND hideInAutocomplete.name = 'hide_in_autocomplete'
|
||||
AND hideInAutocomplete.isDeleted = 0
|
||||
WHERE
|
||||
|
||||
@@ -106,7 +106,7 @@ router.put('/:branchId/expanded/:expanded', auth.checkApiAuth, wrap(async (req,
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.execute("UPDATE branches SET isExpanded = ? WHERE branchId = ?", [expanded, branchId]);
|
||||
|
||||
// we don't sync expanded attribute
|
||||
// we don't sync expanded label
|
||||
});
|
||||
|
||||
res.send({});
|
||||
|
||||
Reference in New Issue
Block a user