mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	in web version use local client time instead of server time for recording dateModified etc.
This commit is contained in:
		
							parent
							
								
									8f68ff1932
								
							
						
					
					
						commit
						586d6b4557
					
				| @ -8,6 +8,7 @@ function getHeaders(headers) { | ||||
|     // also avoiding using underscores instead of dashes since nginx filters them out by default
 | ||||
|     const allHeaders = { | ||||
|         'trilium-source-id': glob.sourceId, | ||||
|         'trilium-local-now-datetime': utils.localNowDateTime(), | ||||
|         'x-csrf-token': glob.csrfToken | ||||
|     }; | ||||
| 
 | ||||
|  | ||||
| @ -58,6 +58,7 @@ class TabContext extends Component { | ||||
| 
 | ||||
|         this.autoBookDisabled = false; | ||||
|         this.textPreviewDisabled = false; | ||||
|         this.codePreviewDisabled = false; | ||||
| 
 | ||||
|         setTimeout(async () => { | ||||
|             // we include the note into recent list only if the user stayed on the note at least 5 seconds
 | ||||
|  | ||||
| @ -40,6 +40,10 @@ function formatDateTime(date) { | ||||
|     return formatDate(date) + " " + formatTime(date); | ||||
| } | ||||
| 
 | ||||
| function localNowDateTime() { | ||||
|     return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ') | ||||
| } | ||||
| 
 | ||||
| function now() { | ||||
|     return formatTimeWithSeconds(new Date()); | ||||
| } | ||||
| @ -321,6 +325,7 @@ export default { | ||||
|     formatDate, | ||||
|     formatDateISO, | ||||
|     formatDateTime, | ||||
|     localNowDateTime, | ||||
|     now, | ||||
|     isElectron, | ||||
|     isMac, | ||||
|  | ||||
| @ -1,3 +1,5 @@ | ||||
| "use strict"; | ||||
| 
 | ||||
| const setupRoute = require('./setup'); | ||||
| const loginRoute = require('./login'); | ||||
| const indexRoute = require('./index'); | ||||
| @ -82,6 +84,7 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio | ||||
|         try { | ||||
|             const result = await cls.init(async () => { | ||||
|                 cls.namespace.set('sourceId', req.headers['trilium-source-id']); | ||||
|                 cls.namespace.set('localNowDateTime', req.headers['`trilium-local-now-datetime`']); | ||||
|                 protectedSessionService.setProtectedSessionId(req); | ||||
| 
 | ||||
|                 if (transactional) { | ||||
|  | ||||
| @ -3,10 +3,11 @@ | ||||
| const sqlInit = require('../services/sql_init'); | ||||
| const setupService = require('../services/setup'); | ||||
| const utils = require('../services/utils'); | ||||
| const windowService = require('../services/window'); | ||||
| 
 | ||||
| async function setupPage(req, res) { | ||||
|     if (await sqlInit.isDbInitialized()) { | ||||
|         const windowService = require('../services/window'); | ||||
| 
 | ||||
|         if (utils.isElectron()) { | ||||
|             await windowService.createMainWindow(); | ||||
|             windowService.closeSetupWindow(); | ||||
|  | ||||
| @ -13,6 +13,10 @@ function getSourceId() { | ||||
|     return namespace.get('sourceId'); | ||||
| } | ||||
| 
 | ||||
| function getLocalNowDateTime() { | ||||
|     return namespace.get('localNowDateTime'); | ||||
| } | ||||
| 
 | ||||
| function disableEntityEvents() { | ||||
|     namespace.set('disableEntityEvents', true); | ||||
| } | ||||
| @ -50,6 +54,7 @@ module.exports = { | ||||
|     wrap, | ||||
|     namespace, | ||||
|     getSourceId, | ||||
|     getLocalNowDateTime, | ||||
|     disableEntityEvents, | ||||
|     isEntityEventsDisabled, | ||||
|     reset, | ||||
|  | ||||
| @ -1,17 +1,29 @@ | ||||
| const dayjs = require('dayjs'); | ||||
| const cls = require('./cls'); | ||||
| 
 | ||||
| function utcNowDateTime() { | ||||
|     return utcDateStr(new Date()); | ||||
| } | ||||
| 
 | ||||
| // CLS date time is important in web deployments - server often runs in different time zone than user is located in
 | ||||
| // so we'd prefer client timezone to be used to record local dates. For this reason requests from client contain
 | ||||
| // "trilium-local-now-datetime" header which is then stored in CLS
 | ||||
| function localNowDateTime() { | ||||
|     return dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ') | ||||
|     return cls.getLocalNowDateTime() | ||||
|         || dayjs().format('YYYY-MM-DD HH:mm:ss.SSSZZ') | ||||
| } | ||||
| 
 | ||||
| function localNowDate() { | ||||
|     const clsDateTime = cls.getLocalNowDateTime(); | ||||
| 
 | ||||
|     if (clsDateTime) { | ||||
|         return clsDateTime.substr(0, 10); | ||||
|     } | ||||
|     else { | ||||
|         const date = new Date(); | ||||
| 
 | ||||
|         return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function pad(num) { | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| module.exports = { | ||||
|     isDev: function () { | ||||
|         return process.env.TRILIUM_ENV && process.env.TRILIUM_ENV === 'dev'; | ||||
|         return !!(process.env.TRILIUM_ENV && process.env.TRILIUM_ENV === 'dev'); | ||||
|     } | ||||
| }; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam