curtain-web-api 1.0.26 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -188,6 +188,7 @@ class CurtainWebAPI {
|
|
|
188
188
|
this.user.access_token = response.data.access;
|
|
189
189
|
this.user.refresh_token = response.data.refresh;
|
|
190
190
|
this.user.loginStatus = true;
|
|
191
|
+
console.log(this.user.loginStatus);
|
|
191
192
|
this.user.saveIntoDB().then();
|
|
192
193
|
return this.getUserInfo();
|
|
193
194
|
});
|
|
@@ -24,7 +24,7 @@ export declare class User {
|
|
|
24
24
|
init(): Promise<void | undefined>;
|
|
25
25
|
initiateDB(): Promise<void>;
|
|
26
26
|
updateDB(): Promise<void>;
|
|
27
|
-
saveIntoDB(): Promise<void>;
|
|
27
|
+
saveIntoDB(): Promise<void | undefined>;
|
|
28
28
|
loadFromDB(): Promise<void>;
|
|
29
29
|
clearDB(): Promise<void>;
|
|
30
30
|
reset(): void;
|
|
@@ -87,6 +87,47 @@ class User {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
saveIntoDB() {
|
|
90
|
+
this.db.get("user").catch((error) => {
|
|
91
|
+
if (error.name === "not_found") {
|
|
92
|
+
console.log(this.loginStatus);
|
|
93
|
+
return {
|
|
94
|
+
_id: "user",
|
|
95
|
+
access_token: this.access_token,
|
|
96
|
+
refresh_token: this.refresh_token,
|
|
97
|
+
username: this.username,
|
|
98
|
+
loginStatus: this.loginStatus,
|
|
99
|
+
isStaff: this.isStaff,
|
|
100
|
+
id: this.id,
|
|
101
|
+
totalCurtain: this.totalCurtain,
|
|
102
|
+
canDelete: this.canDelete,
|
|
103
|
+
curtainLinkLimit: this.curtainLinkLimit,
|
|
104
|
+
curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
|
|
105
|
+
lastAccessTokenUpdate: this.lastAccessTokenUpdate,
|
|
106
|
+
lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}).then((doc) => {
|
|
113
|
+
console.log(this.loginStatus);
|
|
114
|
+
return this.db.put({
|
|
115
|
+
_id: "user",
|
|
116
|
+
_rev: doc._rev,
|
|
117
|
+
access_token: this.access_token,
|
|
118
|
+
refresh_token: this.refresh_token,
|
|
119
|
+
username: this.username,
|
|
120
|
+
loginStatus: this.loginStatus,
|
|
121
|
+
isStaff: this.isStaff,
|
|
122
|
+
id: this.id,
|
|
123
|
+
totalCurtain: this.totalCurtain,
|
|
124
|
+
canDelete: this.canDelete,
|
|
125
|
+
curtainLinkLimit: this.curtainLinkLimit,
|
|
126
|
+
curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
|
|
127
|
+
lastAccessTokenUpdate: this.lastAccessTokenUpdate,
|
|
128
|
+
lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
|
|
129
|
+
});
|
|
130
|
+
});
|
|
90
131
|
return this.db.put({
|
|
91
132
|
_id: "user",
|
|
92
133
|
access_token: this.access_token,
|
|
@@ -105,6 +146,10 @@ class User {
|
|
|
105
146
|
console.log(response);
|
|
106
147
|
}).catch((error) => {
|
|
107
148
|
console.log(error);
|
|
149
|
+
console.log(this.loginStatus);
|
|
150
|
+
if (error.name === "conflict") {
|
|
151
|
+
return this.updateDB();
|
|
152
|
+
}
|
|
108
153
|
});
|
|
109
154
|
}
|
|
110
155
|
loadFromDB() {
|
package/package.json
CHANGED
|
@@ -172,6 +172,7 @@ export class CurtainWebAPI {
|
|
|
172
172
|
this.user.access_token = response.data.access;
|
|
173
173
|
this.user.refresh_token = response.data.refresh;
|
|
174
174
|
this.user.loginStatus = true;
|
|
175
|
+
console.log(this.user.loginStatus)
|
|
175
176
|
this.user.saveIntoDB().then();
|
|
176
177
|
return this.getUserInfo();
|
|
177
178
|
})
|
|
@@ -95,6 +95,46 @@ export class User {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
saveIntoDB() {
|
|
98
|
+
this.db.get("user").catch((error) => {
|
|
99
|
+
if (error.name === "not_found") {
|
|
100
|
+
console.log(this.loginStatus)
|
|
101
|
+
return {
|
|
102
|
+
_id: "user",
|
|
103
|
+
access_token: this.access_token,
|
|
104
|
+
refresh_token: this.refresh_token,
|
|
105
|
+
username: this.username,
|
|
106
|
+
loginStatus: this.loginStatus,
|
|
107
|
+
isStaff: this.isStaff,
|
|
108
|
+
id: this.id,
|
|
109
|
+
totalCurtain: this.totalCurtain,
|
|
110
|
+
canDelete: this.canDelete,
|
|
111
|
+
curtainLinkLimit: this.curtainLinkLimit,
|
|
112
|
+
curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
|
|
113
|
+
lastAccessTokenUpdate: this.lastAccessTokenUpdate,
|
|
114
|
+
lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
throw error
|
|
118
|
+
}
|
|
119
|
+
}).then((doc: any) => {
|
|
120
|
+
console.log(this.loginStatus)
|
|
121
|
+
return this.db.put({
|
|
122
|
+
_id: "user",
|
|
123
|
+
_rev: doc._rev,
|
|
124
|
+
access_token: this.access_token,
|
|
125
|
+
refresh_token: this.refresh_token,
|
|
126
|
+
username: this.username,
|
|
127
|
+
loginStatus: this.loginStatus,
|
|
128
|
+
isStaff: this.isStaff,
|
|
129
|
+
id: this.id,
|
|
130
|
+
totalCurtain: this.totalCurtain,
|
|
131
|
+
canDelete: this.canDelete,
|
|
132
|
+
curtainLinkLimit: this.curtainLinkLimit,
|
|
133
|
+
curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
|
|
134
|
+
lastAccessTokenUpdate: this.lastAccessTokenUpdate,
|
|
135
|
+
lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
|
|
136
|
+
})
|
|
137
|
+
})
|
|
98
138
|
return this.db.put({
|
|
99
139
|
_id: "user",
|
|
100
140
|
access_token: this.access_token,
|
|
@@ -113,6 +153,10 @@ export class User {
|
|
|
113
153
|
console.log(response);
|
|
114
154
|
}).catch((error) => {
|
|
115
155
|
console.log(error);
|
|
156
|
+
console.log(this.loginStatus);
|
|
157
|
+
if (error.name === "conflict") {
|
|
158
|
+
return this.updateDB();
|
|
159
|
+
}
|
|
116
160
|
});
|
|
117
161
|
}
|
|
118
162
|
|