@internetarchive/ia-book-actions 0.0.29-alpha4 → 0.0.29-alpha5
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.
package/demo/index.html
CHANGED
|
@@ -128,8 +128,8 @@
|
|
|
128
128
|
iaBookActions.returnUrl = 'https://openlibrary.org';
|
|
129
129
|
iaBookActions.localCache = localCache;
|
|
130
130
|
iaBookActions.autoRenewConfig = {
|
|
131
|
-
totalTime:
|
|
132
|
-
autoCheckAt:
|
|
131
|
+
totalTime: 20, // 60 second = 1 min
|
|
132
|
+
autoCheckAt: 15, // totalTime - 10th minute
|
|
133
133
|
FlippedInLast: 15, // within last 15 second/minute
|
|
134
134
|
};
|
|
135
135
|
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
await localCache.set({
|
|
227
227
|
key: `${identifier}-loanTime`,
|
|
228
228
|
value: new Date(), // current time
|
|
229
|
-
ttl:
|
|
229
|
+
ttl: Number(iaBookActions.autoRenewConfig.totalTime),
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
await localCache.delete(`${identifier}-pageFlipTime`);
|
package/package.json
CHANGED
|
@@ -100,7 +100,7 @@ export const canBrowseAndBorrow = {
|
|
|
100
100
|
// userid: "",
|
|
101
101
|
bookUrl: '/details/practicalorganic00plim',
|
|
102
102
|
daysLeftOnLoan: 0,
|
|
103
|
-
isAdmin:
|
|
103
|
+
isAdmin: false,
|
|
104
104
|
isArchiveOrgLending: true,
|
|
105
105
|
isAvailable: false,
|
|
106
106
|
isAvailableForBrowsing: false,
|
|
@@ -128,7 +128,6 @@ export default class ActionsHandler extends LitElement {
|
|
|
128
128
|
|
|
129
129
|
handleAutoBrowseIt() {
|
|
130
130
|
const action = 'renew_loan';
|
|
131
|
-
this.setBrowseTimeSession()
|
|
132
131
|
|
|
133
132
|
ActionsHandlerService({
|
|
134
133
|
action,
|
|
@@ -295,6 +294,19 @@ export default class ActionsHandler extends LitElement {
|
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
296
|
|
|
297
|
+
async setBrowseTimeSession(_date = '') {
|
|
298
|
+
try {
|
|
299
|
+
// set a value
|
|
300
|
+
await this.localCache.set({
|
|
301
|
+
key: `${this.identifier}-loanTime`,
|
|
302
|
+
value: new Date(), // current time
|
|
303
|
+
ttl: Number(this.autoRenewConfig.totalTime),
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
307
|
+
} catch (error) {}
|
|
308
|
+
}
|
|
309
|
+
|
|
298
310
|
deleteLoanCookies() {
|
|
299
311
|
const date = new Date();
|
|
300
312
|
date.setTime(date.getTime() - 24 * 60 * 60 * 1000); // one day ago
|
|
@@ -314,17 +326,4 @@ export default class ActionsHandler extends LitElement {
|
|
|
314
326
|
'.archive.org'
|
|
315
327
|
);
|
|
316
328
|
}
|
|
317
|
-
|
|
318
|
-
async setBrowseTimeSession() {
|
|
319
|
-
try {
|
|
320
|
-
// set a value
|
|
321
|
-
await this.localCache.set({
|
|
322
|
-
key: `${this.identifier}-loanTime`,
|
|
323
|
-
value: new Date(), // current time
|
|
324
|
-
ttl: parseInt(this.autoRenewConfig.totalTime),
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
328
|
-
} catch (error) {}
|
|
329
|
-
}
|
|
330
329
|
}
|
|
@@ -51,7 +51,7 @@ export class OneHourAutoRenew {
|
|
|
51
51
|
await this.localCache.set({
|
|
52
52
|
key: `${this.identifier}-pageFlipTime`,
|
|
53
53
|
value: new Date(), // current time
|
|
54
|
-
ttl:
|
|
54
|
+
ttl: Number(this.autoRenewConfig.totalTime),
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -75,6 +75,8 @@ export class OneHourAutoRenew {
|
|
|
75
75
|
this.resultRes.browseAgainNow = true;
|
|
76
76
|
this.resultRes.hideToast = false;
|
|
77
77
|
this.resultRes.renewNow = true;
|
|
78
|
+
|
|
79
|
+
this.setNewBrowseTime();
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
return this.resultRes;
|
|
@@ -105,11 +107,32 @@ export class OneHourAutoRenew {
|
|
|
105
107
|
|
|
106
108
|
// delete pageFlipTime when book is auto renew at nth minute
|
|
107
109
|
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
110
|
+
this.setNewBrowseTime();
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
return this.resultRes;
|
|
111
114
|
}
|
|
112
115
|
|
|
116
|
+
async setNewBrowseTime() {
|
|
117
|
+
try {
|
|
118
|
+
// last 15 min if used flipped a page.
|
|
119
|
+
const expireDate = await this.changeTime(
|
|
120
|
+
new Date(),
|
|
121
|
+
this.autoRenewConfig.totalTime,
|
|
122
|
+
'add'
|
|
123
|
+
); // 15 seconds
|
|
124
|
+
|
|
125
|
+
// set a value
|
|
126
|
+
await this.localCache.set({
|
|
127
|
+
key: `${this.identifier}-loanTime`,
|
|
128
|
+
value: expireDate, // expireDate time
|
|
129
|
+
ttl: Number(this.autoRenewConfig.totalTime),
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
await this.localCache.delete(`${this.identifier}-pageFlipTime`);
|
|
133
|
+
} catch (error) {}
|
|
134
|
+
}
|
|
135
|
+
|
|
113
136
|
async changeTime(date, minutes, op) {
|
|
114
137
|
if (date === undefined) return undefined;
|
|
115
138
|
|
|
@@ -128,25 +151,4 @@ export class OneHourAutoRenew {
|
|
|
128
151
|
`identifier=${this.identifier}`
|
|
129
152
|
);
|
|
130
153
|
}
|
|
131
|
-
|
|
132
|
-
async handleAutoRenew() {
|
|
133
|
-
const action = 'renew_loan';
|
|
134
|
-
ActionsHandlerService({
|
|
135
|
-
identifier: this.identifier,
|
|
136
|
-
action,
|
|
137
|
-
error: data => {
|
|
138
|
-
window?.Sentry?.captureMessage(
|
|
139
|
-
'handleAutoRenew error',
|
|
140
|
-
JSON.stringify(data)
|
|
141
|
-
);
|
|
142
|
-
// this.errorCallback({ detail: { action, data } });
|
|
143
|
-
// send LendingServiceError to GA
|
|
144
|
-
this.sendEvent('handleAutoRenew', action);
|
|
145
|
-
},
|
|
146
|
-
success: () => {
|
|
147
|
-
console.log('success!');
|
|
148
|
-
return 'success';
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
154
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -102,7 +102,7 @@ export default class IABookActions extends LitElement {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
updated(changed) {
|
|
105
|
-
console.log(changed)
|
|
105
|
+
// console.log(changed)
|
|
106
106
|
if (changed.has('lendingStatus') || changed.has('bwbPurchaseUrl')) {
|
|
107
107
|
this.setupLendingToolbarActions();
|
|
108
108
|
this.update();
|
|
@@ -142,6 +142,7 @@ export default class IABookActions extends LitElement {
|
|
|
142
142
|
async browseHasExpired() {
|
|
143
143
|
const currStatus = { ...this.lendingStatus, browsingExpired: true };
|
|
144
144
|
this.lendingStatus = currStatus;
|
|
145
|
+
this.browseAgainNow = false;
|
|
145
146
|
|
|
146
147
|
// remove respected key:value
|
|
147
148
|
await this.localCache.delete(`${this.identifier}-loanTime`);
|
|
@@ -152,11 +153,14 @@ export default class IABookActions extends LitElement {
|
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
async browseHasRenew() {
|
|
155
|
-
const
|
|
156
|
+
const loanTime = await this.localCache.get(`${this.identifier}-loanTime`);
|
|
157
|
+
const secondsLeft =(loanTime - new Date()) / 1000; // different in seconds
|
|
158
|
+
|
|
159
|
+
const currStatus = {
|
|
156
160
|
...this.lendingStatus,
|
|
157
161
|
user_has_browsed: true,
|
|
158
162
|
browsingExpired: false,
|
|
159
|
-
secondsLeftOnLoan:
|
|
163
|
+
secondsLeftOnLoan: Math.abs(Math.round(secondsLeft)),
|
|
160
164
|
};
|
|
161
165
|
this.lendingStatus = currStatus;
|
|
162
166
|
|