Stefan Huber

new release

...@@ -16,14 +16,6 @@ export declare class Repository { ...@@ -16,14 +16,6 @@ export declare class Repository {
16 tryLocalEnvironment(response: any): Promise<void>; 16 tryLocalEnvironment(response: any): Promise<void>;
17 prepare(url: string): Promise<any>; 17 prepare(url: string): Promise<any>;
18 init(db_name: string): Promise<any>; 18 init(db_name: string): Promise<any>;
19 - parseUrl(url: string): { 19 + parseUrl(url: string): any;
20 - url: string;
21 - protocol: string;
22 - user: string;
23 - pass: string;
24 - domain: string;
25 - db_name: string;
26 - orig_db_name: string;
27 - };
28 prepareDocs(res: any): Array<any>; 20 prepareDocs(res: any): Array<any>;
29 } 21 }
......
...@@ -104,7 +104,9 @@ var Repository = (function () { ...@@ -104,7 +104,9 @@ var Repository = (function () {
104 _this.rest.scanEnvironment(response.local_ips) 104 _this.rest.scanEnvironment(response.local_ips)
105 .then(function (node) { 105 .then(function (node) {
106 var res = _this.parseUrl(response.db_url); 106 var res = _this.parseUrl(response.db_url);
107 - resolve(_this.prepare('http://' + node.ip + ':' + node.couchPort + '/' + res.orig_db_name)); 107 + var localCouchUrl = 'http://' + node.ip + ':' + node.couchPort + '/' + res.orig_db_name;
108 + console.log("prepare local couch url: ", localCouchUrl);
109 + resolve(_this.prepare(localCouchUrl));
108 }).catch(function () { 110 }).catch(function () {
109 resolve(_this.prepare(response.db_url)); 111 resolve(_this.prepare(response.db_url));
110 }); 112 });
...@@ -115,7 +117,7 @@ var Repository = (function () { ...@@ -115,7 +117,7 @@ var Repository = (function () {
115 return new Promise(function (resolve, reject) { 117 return new Promise(function (resolve, reject) {
116 _this.params = _this.parseUrl(url); 118 _this.params = _this.parseUrl(url);
117 if (!_this.params) { 119 if (!_this.params) {
118 - reject(); 120 + reject('params are incorrect');
119 } 121 }
120 if (_this.db && _this.db.name == _this.params.db_name) { 122 if (_this.db && _this.db.name == _this.params.db_name) {
121 resolve(); 123 resolve();
...@@ -152,9 +154,10 @@ var Repository = (function () { ...@@ -152,9 +154,10 @@ var Repository = (function () {
152 }); 154 });
153 }; 155 };
154 Repository.prototype.parseUrl = function (url) { 156 Repository.prototype.parseUrl = function (url) {
155 - // matches: 0:user,1:password,2:domain,3:db_name 157 + // matches: protocol, user, password, domain, db_name
156 - var exp = /^(https?):\/\/(\w+?):(\w+?)@([a-zA-Z0-9.\-_:]+?)\/([a-zA-Z0-9\-_]+?)$/; 158 + var expWithUsers = /^(https?):\/\/(\w+?):(\w+?)@([a-zA-Z0-9.\-_:]+?)\/([a-zA-Z0-9\-_]+?)$/;
157 - var match = url.match(exp); 159 + var expWithoutUsers = /^(https?):\/\/([a-zA-Z0-9.\-_:]+?)\/([a-zA-Z0-9\-_]+?)$/;
160 + var match = url.match(expWithUsers);
158 if (match) { 161 if (match) {
159 return { 162 return {
160 url: match[0], 163 url: match[0],
...@@ -166,6 +169,16 @@ var Repository = (function () { ...@@ -166,6 +169,16 @@ var Repository = (function () {
166 orig_db_name: match[5] 169 orig_db_name: match[5]
167 }; 170 };
168 } 171 }
172 + match = url.match(expWithoutUsers);
173 + if (match) {
174 + return {
175 + url: match[0],
176 + protocol: match[1],
177 + domain: match[2],
178 + db_name: 'local_' + match[3],
179 + orig_db_name: match[3]
180 + };
181 + }
169 return null; 182 return null;
170 }; 183 };
171 Repository.prototype.prepareDocs = function (res) { 184 Repository.prototype.prepareDocs = function (res) {
......