mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	using http service for sync setup as well, removed request(-promise) dependency
This commit is contained in:
		| @@ -14,6 +14,17 @@ function exec(opts) { | ||||
|  | ||||
|     return new Promise(async (resolve, reject) => { | ||||
|         try { | ||||
|             const headers = { | ||||
|                 Cookie: (opts.cookieJar && opts.cookieJar.header) || "", | ||||
|                 'Content-Type': 'application/json' | ||||
|             }; | ||||
|  | ||||
|             if (opts.auth) { | ||||
|                 const token = new Buffer(opts.auth.user + ":" + opts.auth.pass).toString('base64'); | ||||
|  | ||||
|                 headers['Authorization'] = `Basic ${token}`; | ||||
|             } | ||||
|  | ||||
|             const request = client.request({ | ||||
|                 method: opts.method, | ||||
|                 // url is used by electron net module | ||||
| @@ -24,10 +35,7 @@ function exec(opts) { | ||||
|                 port: parsedUrl.port, | ||||
|                 path: parsedUrl.path, | ||||
|                 timeout: opts.timeout, | ||||
|                 headers: { | ||||
|                     Cookie: (opts.cookieJar && opts.cookieJar.header) || "", | ||||
|                     'Content-Type': 'application/json' | ||||
|                 } | ||||
|                 headers | ||||
|             }); | ||||
|  | ||||
|             request.on('response', response => { | ||||
| @@ -48,7 +56,7 @@ function exec(opts) { | ||||
|                     catch (e) { | ||||
|                         log.error("Failed to deserialize sync response: " + responseStr); | ||||
|  | ||||
|                         reject(generateError(e)); | ||||
|                         reject(generateError(e, opts)); | ||||
|                     } | ||||
|                 }); | ||||
|             }); | ||||
| @@ -56,7 +64,7 @@ function exec(opts) { | ||||
|             request.end(opts.body ? JSON.stringify(opts.body) : undefined); | ||||
|         } | ||||
|         catch (e) { | ||||
|             reject(generateError(e)); | ||||
|             reject(generateError(e, opts)); | ||||
|         } | ||||
|     }) | ||||
| } | ||||
| @@ -77,8 +85,8 @@ function getClient(opts) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| function generateError(e) { | ||||
|     return new Error(`Request to ${method} ${syncServerHost}${requestPath} failed, error: ${e.message}`); | ||||
| function generateError(e, opts) { | ||||
|     return new Error(`Request to ${opts.method} ${opts.url} failed, error: ${e.message}`); | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user