mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	
						commit
						fbc79eae62
					
				| @ -2,7 +2,7 @@ const becca = require('./becca'); | |||||||
| const log = require('../services/log'); | const log = require('../services/log'); | ||||||
| const beccaService = require('./becca_service'); | const beccaService = require('./becca_service'); | ||||||
| const dateUtils = require('../services/date_utils'); | const dateUtils = require('../services/date_utils'); | ||||||
| const { JSDOM } = require("jsdom"); | const {JSDOM} = require("jsdom"); | ||||||
| 
 | 
 | ||||||
| const DEBUG = false; | const DEBUG = false; | ||||||
| 
 | 
 | ||||||
| @ -168,7 +168,6 @@ function trimMime(mime) { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         mimeCache[mime] = str; |         mimeCache[mime] = str; | ||||||
|         mimeCache[mime] = str; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return mimeCache[mime]; |     return mimeCache[mime]; | ||||||
| @ -224,8 +223,8 @@ function splitToWords(text) { | |||||||
|  */ |  */ | ||||||
| function hasConnectingRelation(sourceNote, targetNote) { | function hasConnectingRelation(sourceNote, targetNote) { | ||||||
|     return sourceNote.getAttributes().find(attr => attr.type === 'relation' |     return sourceNote.getAttributes().find(attr => attr.type === 'relation' | ||||||
|                                            && ['includenotelink', 'imagelink'].includes(attr.name) |         && ['includenotelink', 'imagelink'].includes(attr.name) | ||||||
|                                            && attr.value === targetNote.noteId); |         && attr.value === targetNote.noteId); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function findSimilarNotes(noteId) { | async function findSimilarNotes(noteId) { | ||||||
| @ -301,7 +300,7 @@ async function findSimilarNotes(noteId) { | |||||||
| 
 | 
 | ||||||
|                     for (const branch of parentNote.getParentBranches()) { |                     for (const branch of parentNote.getParentBranches()) { | ||||||
|                         score += gatherRewards(branch.prefix, 0.3) |                         score += gatherRewards(branch.prefix, 0.3) | ||||||
|                                + gatherAncestorRewards(branch.parentNote); |                             + gatherAncestorRewards(branch.parentNote); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @ -314,7 +313,7 @@ async function findSimilarNotes(noteId) { | |||||||
| 
 | 
 | ||||||
|     function computeScore(candidateNote) { |     function computeScore(candidateNote) { | ||||||
|         let score = gatherRewards(trimMime(candidateNote.mime)) |         let score = gatherRewards(trimMime(candidateNote.mime)) | ||||||
|                   + gatherAncestorRewards(candidateNote); |             + gatherAncestorRewards(candidateNote); | ||||||
| 
 | 
 | ||||||
|         if (candidateNote.isDecrypted) { |         if (candidateNote.isDecrypted) { | ||||||
|             score += gatherRewards(candidateNote.title); |             score += gatherRewards(candidateNote.title); | ||||||
| @ -382,7 +381,7 @@ async function findSimilarNotes(noteId) { | |||||||
|                 score += 1; |                 score += 1; | ||||||
|             } |             } | ||||||
|             else if (utcDateCreated.substr(0, 10) === dateLimits.minDate.substr(0, 10) |             else if (utcDateCreated.substr(0, 10) === dateLimits.minDate.substr(0, 10) | ||||||
|                    || utcDateCreated.substr(0, 10) === dateLimits.maxDate.substr(0, 10)) { |                 || utcDateCreated.substr(0, 10) === dateLimits.maxDate.substr(0, 10)) { | ||||||
|                 if (displayRewards) { |                 if (displayRewards) { | ||||||
|                     console.log("Adding reward for same day of creation"); |                     console.log("Adding reward for same day of creation"); | ||||||
|                 } |                 } | ||||||
|  | |||||||
| @ -20,7 +20,7 @@ function register(router) { | |||||||
|         const {date} = req.params; |         const {date} = req.params; | ||||||
| 
 | 
 | ||||||
|         if (!isValidDate(date)) { |         if (!isValidDate(date)) { | ||||||
|             throw getDateInvalidError(res, date); |             throw getDateInvalidError(date); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const note = specialNotesService.getInboxNote(date); |         const note = specialNotesService.getInboxNote(date); | ||||||
| @ -31,7 +31,7 @@ function register(router) { | |||||||
|         const {date} = req.params; |         const {date} = req.params; | ||||||
| 
 | 
 | ||||||
|         if (!isValidDate(date)) { |         if (!isValidDate(date)) { | ||||||
|             throw getDateInvalidError(res, date); |             throw getDateInvalidError(date); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const note = dateNotesService.getDayNote(date); |         const note = dateNotesService.getDayNote(date); | ||||||
| @ -42,7 +42,7 @@ function register(router) { | |||||||
|         const {date} = req.params; |         const {date} = req.params; | ||||||
| 
 | 
 | ||||||
|         if (!isValidDate(date)) { |         if (!isValidDate(date)) { | ||||||
|             throw getDateInvalidError(res, date); |             throw getDateInvalidError(date); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const note = dateNotesService.getWeekNote(date); |         const note = dateNotesService.getWeekNote(date); | ||||||
| @ -53,7 +53,7 @@ function register(router) { | |||||||
|         const {month} = req.params; |         const {month} = req.params; | ||||||
| 
 | 
 | ||||||
|         if (!/[0-9]{4}-[0-9]{2}/.test(month)) { |         if (!/[0-9]{4}-[0-9]{2}/.test(month)) { | ||||||
|             throw getMonthInvalidError(res, month); |             throw getMonthInvalidError(month); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const note = dateNotesService.getMonthNote(month); |         const note = dateNotesService.getMonthNote(month); | ||||||
| @ -64,7 +64,7 @@ function register(router) { | |||||||
|         const {year} = req.params; |         const {year} = req.params; | ||||||
| 
 | 
 | ||||||
|         if (!/[0-9]{4}/.test(year)) { |         if (!/[0-9]{4}/.test(year)) { | ||||||
|             throw getYearInvalidError(res, year); |             throw getYearInvalidError(year); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const note = dateNotesService.getYearNote(year); |         const note = dateNotesService.getYearNote(year); | ||||||
|  | |||||||
| @ -10,7 +10,7 @@ async function moveBeforeBranch(branchIdsToMove, beforeBranchId) { | |||||||
|     branchIdsToMove = filterRootNote(branchIdsToMove); |     branchIdsToMove = filterRootNote(branchIdsToMove); | ||||||
|     branchIdsToMove = filterSearchBranches(branchIdsToMove); |     branchIdsToMove = filterSearchBranches(branchIdsToMove); | ||||||
| 
 | 
 | ||||||
|     const beforeBranch = await froca.getBranch(beforeBranchId); |     const beforeBranch = froca.getBranch(beforeBranchId); | ||||||
| 
 | 
 | ||||||
|     if (['root', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(beforeBranch.noteId)) { |     if (['root', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(beforeBranch.noteId)) { | ||||||
|         toastService.showError('Cannot move notes here.'); |         toastService.showError('Cannot move notes here.'); | ||||||
| @ -31,7 +31,7 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) { | |||||||
|     branchIdsToMove = filterRootNote(branchIdsToMove); |     branchIdsToMove = filterRootNote(branchIdsToMove); | ||||||
|     branchIdsToMove = filterSearchBranches(branchIdsToMove); |     branchIdsToMove = filterSearchBranches(branchIdsToMove); | ||||||
| 
 | 
 | ||||||
|     const afterNote = await froca.getBranch(afterBranchId).getNote(); |     const afterNote = froca.getBranch(afterBranchId).getNote(); | ||||||
| 
 | 
 | ||||||
|     const forbiddenNoteIds = [ |     const forbiddenNoteIds = [ | ||||||
|         'root', |         'root', | ||||||
| @ -59,7 +59,7 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function moveToParentNote(branchIdsToMove, newParentBranchId) { | async function moveToParentNote(branchIdsToMove, newParentBranchId) { | ||||||
|     const newParentBranch = await froca.getBranch(newParentBranchId); |     const newParentBranch = froca.getBranch(newParentBranchId); | ||||||
| 
 | 
 | ||||||
|     if (newParentBranch.noteId === '_lbRoot') { |     if (newParentBranch.noteId === '_lbRoot') { | ||||||
|         toastService.showError('Cannot move notes here.'); |         toastService.showError('Cannot move notes here.'); | ||||||
| @ -165,7 +165,7 @@ function filterRootNote(branchIds) { | |||||||
|     const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); |     const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); | ||||||
| 
 | 
 | ||||||
|     return branchIds.filter(branchId => { |     return branchIds.filter(branchId => { | ||||||
|        const branch = froca.getBranch(branchId); |         const branch = froca.getBranch(branchId); | ||||||
| 
 | 
 | ||||||
|         return branch.noteId !== 'root' |         return branch.noteId !== 'root' | ||||||
|             && branch.noteId !== hoistedNoteId; |             && branch.noteId !== hoistedNoteId; | ||||||
|  | |||||||
| @ -10,7 +10,6 @@ export async function uploadFiles(parentNoteId, files, options) { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const taskId = utils.randomString(10); |     const taskId = utils.randomString(10); | ||||||
|     let noteId; |  | ||||||
|     let counter = 0; |     let counter = 0; | ||||||
| 
 | 
 | ||||||
|     for (const file of files) { |     for (const file of files) { | ||||||
| @ -25,19 +24,19 @@ export async function uploadFiles(parentNoteId, files, options) { | |||||||
|             formData.append(key, options[key]); |             formData.append(key, options[key]); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         ({noteId} = await $.ajax({ |         await $.ajax({ | ||||||
|             url: `${baseApiUrl}notes/${parentNoteId}/import`, |             url: `${baseApiUrl}notes/${parentNoteId}/import`, | ||||||
|             headers: await server.getHeaders(), |             headers: await server.getHeaders(), | ||||||
|             data: formData, |             data: formData, | ||||||
|             dataType: 'json', |             dataType: 'json', | ||||||
|             type: 'POST', |             type: 'POST', | ||||||
|             timeout: 60 * 60 * 1000, |             timeout: 60 * 60 * 1000, | ||||||
|             error: function(xhr) { |             error: function (xhr) { | ||||||
|                 toastService.showError(`Import failed: ${xhr.responseText}`); |                 toastService.showError(`Import failed: ${xhr.responseText}`); | ||||||
|             }, |             }, | ||||||
|             contentType: false, // NEEDED, DON'T REMOVE THIS
 |             contentType: false, // NEEDED, DON'T REMOVE THIS
 | ||||||
|             processData: false, // NEEDED, DON'T REMOVE THIS
 |             processData: false, // NEEDED, DON'T REMOVE THIS
 | ||||||
|         })); |         }); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -74,4 +73,4 @@ ws.subscribeToMessages(async message => { | |||||||
| 
 | 
 | ||||||
| export default { | export default { | ||||||
|     uploadFiles |     uploadFiles | ||||||
| } | }; | ||||||
|  | |||||||
| @ -29,7 +29,7 @@ function formatTimeWithSeconds(date) { | |||||||
| 
 | 
 | ||||||
| // this is producing local time!
 | // this is producing local time!
 | ||||||
| function formatDate(date) { | function formatDate(date) { | ||||||
| //    return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear();
 |     //    return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear();
 | ||||||
|     // instead of european format we'll just use ISO as that's pretty unambiguous
 |     // instead of european format we'll just use ISO as that's pretty unambiguous
 | ||||||
| 
 | 
 | ||||||
|     return formatDateISO(date); |     return formatDateISO(date); | ||||||
| @ -45,7 +45,7 @@ function formatDateTime(date) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function localNowDateTime() { | function localNowDateTime() { | ||||||
|     return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ') |     return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ'); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function now() { | function now() { | ||||||
| @ -101,7 +101,7 @@ async function stopWatch(what, func) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function formatValueWithWhitespace(val) { | function formatValueWithWhitespace(val) { | ||||||
|     return /[^\w_-]/.test(val) ? `"${val}"` : val; |     return /[^\w-]/.test(val) ? `"${val}"` : val; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function formatLabel(label) { | function formatLabel(label) { | ||||||
| @ -318,7 +318,7 @@ function initHelpDropdown($el) { | |||||||
|     initHelpButtons($dropdownMenu); |     initHelpButtons($dropdownMenu); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/" | const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/"; | ||||||
| 
 | 
 | ||||||
| function openHelp(e) { | function openHelp(e) { | ||||||
|     window.open(wikiBaseUrl + $(e.target).attr("data-help-page"), '_blank'); |     window.open(wikiBaseUrl + $(e.target).attr("data-help-page"), '_blank'); | ||||||
| @ -329,7 +329,7 @@ function initHelpButtons($el) { | |||||||
|     // so we do it manually
 |     // so we do it manually
 | ||||||
|     $el.on("click", e => { |     $el.on("click", e => { | ||||||
|         if ($(e.target).attr("data-help-page")) { |         if ($(e.target).attr("data-help-page")) { | ||||||
|             openHelp(e) |             openHelp(e); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| "use strict" | "use strict"; | ||||||
| 
 | 
 | ||||||
| function formatAttrForSearch(attr, searchWithValue) { | function formatAttrForSearch(attr, searchWithValue) { | ||||||
|     let searchStr = ''; |     let searchStr = ''; | ||||||
| @ -28,7 +28,7 @@ function formatAttrForSearch(attr, searchWithValue) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function formatValue(val) { | function formatValue(val) { | ||||||
|     if (!/[^\w_]/.test(val)) { |     if (!/[^\w]/.test(val)) { | ||||||
|         return val; |         return val; | ||||||
|     } |     } | ||||||
|     else if (!val.includes('"')) { |     else if (!val.includes('"')) { | ||||||
| @ -47,4 +47,4 @@ function formatValue(val) { | |||||||
| 
 | 
 | ||||||
| module.exports = { | module.exports = { | ||||||
|     formatAttrForSearch |     formatAttrForSearch | ||||||
| } | }; | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ const BAttribute = require('../becca/entities/battribute'); | |||||||
| const {formatAttrForSearch} = require("./attribute_formatter"); | const {formatAttrForSearch} = require("./attribute_formatter"); | ||||||
| const BUILTIN_ATTRIBUTES = require("./builtin_attributes"); | const BUILTIN_ATTRIBUTES = require("./builtin_attributes"); | ||||||
| 
 | 
 | ||||||
| const ATTRIBUTE_TYPES = [ 'label', 'relation' ]; | const ATTRIBUTE_TYPES = ['label', 'relation']; | ||||||
| 
 | 
 | ||||||
| /** @returns {BNote[]} */ | /** @returns {BNote[]} */ | ||||||
| function getNotesWithLabel(name, value = undefined) { | function getNotesWithLabel(name, value = undefined) { | ||||||
| @ -122,7 +122,7 @@ function isAttributeType(type) { | |||||||
| 
 | 
 | ||||||
| function isAttributeDangerous(type, name) { | function isAttributeDangerous(type, name) { | ||||||
|     return BUILTIN_ATTRIBUTES.some(attr => |     return BUILTIN_ATTRIBUTES.some(attr => | ||||||
|         attr.type === attr.type && |         attr.type === type && | ||||||
|         attr.name.toLowerCase() === name.trim().toLowerCase() && |         attr.name.toLowerCase() === name.trim().toLowerCase() && | ||||||
|         attr.isDangerous |         attr.isDangerous | ||||||
|     ); |     ); | ||||||
|  | |||||||
| @ -155,7 +155,7 @@ function getExpression(tokens, searchContext, level = 0) { | |||||||
| 
 | 
 | ||||||
|             i++; |             i++; | ||||||
| 
 | 
 | ||||||
|             return new NoteContentFulltextExp(operator.token, {tokens: [tokens[i].token], raw }); |             return new NoteContentFulltextExp(operator.token, {tokens: [tokens[i].token], raw}); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (tokens[i].token === 'parents') { |         if (tokens[i].token === 'parents') { | ||||||
| @ -389,7 +389,7 @@ function getExpression(tokens, searchContext, level = 0) { | |||||||
|         else if (token === 'note') { |         else if (token === 'note') { | ||||||
|             i++; |             i++; | ||||||
| 
 | 
 | ||||||
|             expressions.push(parseNoteProperty(tokens)); |             expressions.push(parseNoteProperty()); | ||||||
| 
 | 
 | ||||||
|             continue; |             continue; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -73,7 +73,7 @@ function searchFromRelation(note, relationName) { | |||||||
|         return []; |         return []; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const result = scriptService.executeNote(scriptNote, { originEntity: note }); |     const result = scriptService.executeNote(scriptNote, {originEntity: note}); | ||||||
| 
 | 
 | ||||||
|     if (!Array.isArray(result)) { |     if (!Array.isArray(result)) { | ||||||
|         log.info(`Result from ${scriptNote.noteId} is not an array.`); |         log.info(`Result from ${scriptNote.noteId} is not an array.`); | ||||||
| @ -288,7 +288,7 @@ function searchNotesForAutocomplete(query) { | |||||||
|             noteTitle: beccaService.getNoteTitle(result.noteId), |             noteTitle: beccaService.getNoteTitle(result.noteId), | ||||||
|             notePathTitle: result.notePathTitle, |             notePathTitle: result.notePathTitle, | ||||||
|             highlightedNotePathTitle: result.highlightedNotePathTitle |             highlightedNotePathTitle: result.highlightedNotePathTitle | ||||||
|         } |         }; | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -370,7 +370,7 @@ function formatAttribute(attr) { | |||||||
|         let label = `#${utils.escapeHtml(attr.name)}`; |         let label = `#${utils.escapeHtml(attr.name)}`; | ||||||
| 
 | 
 | ||||||
|         if (attr.value) { |         if (attr.value) { | ||||||
|             const val = /[^\w_-]/.test(attr.value) ? `"${attr.value}"` : attr.value; |             const val = /[^\w-]/.test(attr.value) ? `"${attr.value}"` : attr.value; | ||||||
| 
 | 
 | ||||||
|             label += `=${utils.escapeHtml(val)}`; |             label += `=${utils.escapeHtml(val)}`; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -217,7 +217,7 @@ function wrap(query, func) { | |||||||
|             // in these cases error should be simply ignored.
 |             // in these cases error should be simply ignored.
 | ||||||
|             console.log(e.message); |             console.log(e.message); | ||||||
| 
 | 
 | ||||||
|             return null |             return null; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         throw e; |         throw e; | ||||||
| @ -281,7 +281,7 @@ function fillParamList(paramIds, truncate = true) { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // doing it manually to avoid this showing up on the sloq query list
 |     // doing it manually to avoid this showing up on the sloq query list
 | ||||||
|     const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map(paramId => `(?)`).join(',')}`, paramIds); |     const s = stmt(`INSERT INTO param_list VALUES ${paramIds.map(paramId => `(?)`).join(',')}`); | ||||||
| 
 | 
 | ||||||
|     s.run(paramIds); |     s.run(paramIds); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam