chuvsu-js 2.8.1 → 2.8.2
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/dist/tt/client.d.ts +1 -0
- package/dist/tt/client.js +24 -15
- package/dist/tt/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/tt/client.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export declare class TtClient {
|
|
|
78
78
|
audienceId: number;
|
|
79
79
|
period: Period;
|
|
80
80
|
}): Promise<Schedule>;
|
|
81
|
+
private getCachedAudienceImage;
|
|
81
82
|
/** Get the audience photo (audimage). Returns null if missing. */
|
|
82
83
|
getAudienceImage(audienceId: number): Promise<Buffer | null>;
|
|
83
84
|
/** Get the building exterior image (blockimage). Returns null if missing. */
|
package/dist/tt/client.js
CHANGED
|
@@ -259,29 +259,38 @@ export class TtClient {
|
|
|
259
259
|
schedules.set(opts.period, days);
|
|
260
260
|
return new Schedule(opts.audienceId, schedules, opts.period, this.educationType);
|
|
261
261
|
}
|
|
262
|
+
async getCachedAudienceImage(cacheKey, fetchUrl) {
|
|
263
|
+
const cached = this.cache?.get("audienceImages", cacheKey);
|
|
264
|
+
if (cached !== null && cached !== undefined) {
|
|
265
|
+
const entry = cached;
|
|
266
|
+
return entry.data ? Buffer.from(entry.data, "base64") : null;
|
|
267
|
+
}
|
|
268
|
+
const url = await fetchUrl();
|
|
269
|
+
if (!url) {
|
|
270
|
+
this.cache?.set("audienceImages", cacheKey, { data: null });
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const buf = await this.authGetBuffer(`${BASE}${url}`);
|
|
274
|
+
if (buf.length === 0) {
|
|
275
|
+
this.cache?.set("audienceImages", cacheKey, { data: null });
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
this.cache?.set("audienceImages", cacheKey, {
|
|
279
|
+
data: buf.toString("base64"),
|
|
280
|
+
});
|
|
281
|
+
return buf;
|
|
282
|
+
}
|
|
262
283
|
/** Get the audience photo (audimage). Returns null if missing. */
|
|
263
284
|
async getAudienceImage(audienceId) {
|
|
264
|
-
|
|
265
|
-
if (!info?.audImageUrl)
|
|
266
|
-
return null;
|
|
267
|
-
const buf = await this.authGetBuffer(`${BASE}${info.audImageUrl}`);
|
|
268
|
-
return buf.length > 0 ? buf : null;
|
|
285
|
+
return this.getCachedAudienceImage(`aud:${audienceId}`, async () => (await this.getAudienceInfo(audienceId))?.audImageUrl);
|
|
269
286
|
}
|
|
270
287
|
/** Get the building exterior image (blockimage). Returns null if missing. */
|
|
271
288
|
async getAudienceBlockImage(audienceId) {
|
|
272
|
-
|
|
273
|
-
if (!info?.blockImageUrl)
|
|
274
|
-
return null;
|
|
275
|
-
const buf = await this.authGetBuffer(`${BASE}${info.blockImageUrl}`);
|
|
276
|
-
return buf.length > 0 ? buf : null;
|
|
289
|
+
return this.getCachedAudienceImage(`block:${audienceId}`, async () => (await this.getAudienceInfo(audienceId))?.blockImageUrl);
|
|
277
290
|
}
|
|
278
291
|
/** Get the floor plan image for the audience. Returns null if missing. */
|
|
279
292
|
async getAudienceFloorplan(audienceId) {
|
|
280
|
-
|
|
281
|
-
if (!info?.floorplanUrl)
|
|
282
|
-
return null;
|
|
283
|
-
const buf = await this.authGetBuffer(`${BASE}${info.floorplanUrl}`);
|
|
284
|
-
return buf.length > 0 ? buf : null;
|
|
293
|
+
return this.getCachedAudienceImage(`floor:${audienceId}`, async () => (await this.getAudienceInfo(audienceId))?.floorplanUrl);
|
|
285
294
|
}
|
|
286
295
|
async searchTeacher(opts) {
|
|
287
296
|
const { body } = await this.authPost(`${BASE}/`, {
|
package/dist/tt/types.d.ts
CHANGED