@mulingai-npm/redis 2.0.3 → 2.0.4
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.
|
@@ -2,6 +2,7 @@ import { RedisClient } from '../redis-client';
|
|
|
2
2
|
export type StepStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
|
|
3
3
|
export type SttProvider = 'azure' | 'whisper' | 'google' | 'aws';
|
|
4
4
|
export type MulingstreamChunkData = {
|
|
5
|
+
roomId: string;
|
|
5
6
|
chunkNumber: number;
|
|
6
7
|
language: string;
|
|
7
8
|
sttProviders: SttProvider[];
|
|
@@ -42,8 +42,9 @@ class MulingstreamChunkManager {
|
|
|
42
42
|
async getMulingstreamChunksByRoom(roomId) {
|
|
43
43
|
// JSON.GET [roomId] .
|
|
44
44
|
const chunks = await this.redisClient.jsonGet(`[${roomId}]`, '.');
|
|
45
|
-
if (chunks === null)
|
|
46
|
-
return null;
|
|
45
|
+
if (chunks === null) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
47
48
|
return chunks;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
@@ -59,8 +60,8 @@ class MulingstreamChunkManager {
|
|
|
59
60
|
async addMulingstreamChunk(params) {
|
|
60
61
|
const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, sttProviders, targetLanguages } = params;
|
|
61
62
|
// ensure we only keep the last 5 elements
|
|
62
|
-
const currentLength = await this.redisClient.
|
|
63
|
-
if (
|
|
63
|
+
const currentLength = await this.redisClient.jsonArrLen(`[${roomId}]`, '.');
|
|
64
|
+
if ((currentLength !== null && currentLength !== void 0 ? currentLength : 0) >= ROOM_ARRAY_LENGTH) {
|
|
64
65
|
// remove the oldest (front of the array)
|
|
65
66
|
await this.redisClient.jsonArrPop(`[${roomId}]`, '.', 0);
|
|
66
67
|
}
|
|
@@ -97,6 +98,7 @@ class MulingstreamChunkManager {
|
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
const newChunk = {
|
|
101
|
+
roomId,
|
|
100
102
|
chunkNumber,
|
|
101
103
|
language,
|
|
102
104
|
sttProviders,
|
package/dist/redis-client.d.ts
CHANGED
|
@@ -23,5 +23,6 @@ export declare class RedisClient {
|
|
|
23
23
|
jsonGet<T>(key: string, path: string): Promise<T | null>;
|
|
24
24
|
jsonDel(key: string, path: string): Promise<number>;
|
|
25
25
|
jsonArrAppend<T>(key: string, path: string, ...values: T[]): Promise<number>;
|
|
26
|
+
jsonArrLen(key: string, path: string): Promise<number | null>;
|
|
26
27
|
jsonArrPop(key: string, path: string, index?: number): Promise<any>;
|
|
27
28
|
}
|
package/dist/redis-client.js
CHANGED
|
@@ -81,6 +81,10 @@ class RedisClient {
|
|
|
81
81
|
const result = await this.client.call('JSON.ARRAPPEND', key, path, ...stringifiedValues);
|
|
82
82
|
return Number(result);
|
|
83
83
|
}
|
|
84
|
+
async jsonArrLen(key, path) {
|
|
85
|
+
const result = await this.client.call('JSON.ARRLEN', key, path);
|
|
86
|
+
return result === null ? null : Number(result);
|
|
87
|
+
}
|
|
84
88
|
async jsonArrPop(key, path, index) {
|
|
85
89
|
if (index !== undefined) {
|
|
86
90
|
return this.client.call('JSON.ARRPOP', key, path, index);
|