bfg-common 1.4.306 → 1.4.308

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.
@@ -101,6 +101,7 @@ import type { UI_I_SelectInputItem } from '~/components/common/select/input/lib/
101
101
  import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
102
102
  import type { UI_I_InitialValidationFields } from '~/components/common/pages/scheduledTasks/modals/common/newTaskForm/lib/models/interfaces'
103
103
  import type { UI_T_FrequencyType } from '~/components/common/pages/scheduledTasks/modals/common/frequency/lib/models/types'
104
+ import * as cron from '~/components/common/pages/scheduledTasks/modals/common/newTaskForm/lib/utils'
104
105
  import { frequencyMethodFunc } from '~/components/common/pages/scheduledTasks/modals/common/frequency/lib/config/frequencyOptions'
105
106
 
106
107
  const props = defineProps<{
@@ -134,72 +135,6 @@ watch(
134
135
  { deep: true }
135
136
  )
136
137
 
137
- /* TODO рефакторинг все методы надо рефакторить */
138
- const generateHourlyCronExpression = (
139
- data: UI_I_ScheduleNewTasksForm
140
- ): string => {
141
- const startTimestamp = Math.floor(
142
- new Date(data.frg_start_on_time).getTime() / 1000
143
- )
144
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
145
-
146
- // Генерируем cron-выражение
147
- return endTimestamp
148
- ? `* * * * * ${startTimestamp}-${endTimestamp}:${data.frg_interval}-0-0-0`
149
- : `* * * * * ${startTimestamp}:${data.frg_interval}-0-0-0`
150
- }
151
- const generateDailyCronExpression = (
152
- data: UI_I_ScheduleNewTasksForm
153
- ): string => {
154
- const startTimestamp = Math.floor(
155
- new Date(data.frg_start_on_time).getTime() / 1000
156
- )
157
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
158
-
159
- // Генерируем cron-выражение
160
- return endTimestamp
161
- ? `* * * * * ${startTimestamp}-${endTimestamp}:0-${data.frg_interval}-0-0`
162
- : `* * * * * ${startTimestamp}:0-${data.frg_interval}-0-0`
163
- }
164
- const generateWeeklyCronExpression = (
165
- data: UI_I_ScheduleNewTasksForm
166
- ): string => {
167
- const { frg_on_week_days } = data
168
-
169
- const startTimestamp = Math.floor(
170
- new Date(data.frg_start_on_time).getTime() / 1000
171
- )
172
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
173
- const daysOfWeek = frg_on_week_days.join(',')
174
-
175
- return endTimestamp
176
- ? `* * * * ${daysOfWeek} ${startTimestamp}-${endTimestamp}:0-0-0-${data.frg_interval}`
177
- : `* * * * ${daysOfWeek} ${startTimestamp}:0-0-0-${data.frg_interval}`
178
- }
179
-
180
- const generateMonthlyCronExpression = (
181
- data: UI_I_ScheduleNewTasksForm
182
- ): string => {
183
- const { frg_interval, frg_monthly_day, frq_week_day, frq_ordinal_number } =
184
- data
185
-
186
- const startTimestamp = Math.floor(
187
- new Date(data.frg_start_on_time).getTime() / 1000
188
- )
189
- const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
190
-
191
- const daysOfWeek = `${frq_week_day}#${frq_ordinal_number}`
192
-
193
- const timestamp = endTimestamp
194
- ? `${startTimestamp}-${endTimestamp}`
195
- : startTimestamp
196
-
197
- // Генерируем cron-выражение
198
- return data.frg_monthly_mode === 'week'
199
- ? `* * * * * ${timestamp}:0-0-${frg_interval}-${daysOfWeek}`
200
- : `* * ${frg_monthly_day} */${frg_interval} * ${timestamp}:0-0-0-0`
201
- }
202
-
203
138
  const generateCronExpression = (
204
139
  runType: UI_T_FrequencyType,
205
140
  interval: UI_I_ScheduleNewTasksForm
@@ -220,16 +155,16 @@ const generateCronExpression = (
220
155
  cronExpression = `* * * * * after_procurator_startup${suffixDelay}` // Выполняется после запуска procurator_startup с задержой N минут
221
156
  break
222
157
  case 'hour':
223
- cronExpression = generateHourlyCronExpression(interval)
158
+ cronExpression = cron.generateHourlyCronExpression(interval)
224
159
  break
225
160
  case 'day':
226
- cronExpression = generateDailyCronExpression(interval)
161
+ cronExpression = cron.generateDailyCronExpression(interval)
227
162
  break
228
163
  case 'week':
229
- cronExpression = generateWeeklyCronExpression(interval)
164
+ cronExpression = cron.generateWeeklyCronExpression(interval)
230
165
  break
231
166
  case 'month':
232
- cronExpression = generateMonthlyCronExpression(interval)
167
+ cronExpression = cron.generateMonthlyCronExpression(interval)
233
168
  break
234
169
  default:
235
170
  cronExpression = '* * * * *'
@@ -0,0 +1,67 @@
1
+ import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
2
+
3
+ export const generateHourlyCronExpression = (
4
+ data: UI_I_ScheduleNewTasksForm
5
+ ): string => {
6
+ const startTimestamp = Math.floor(
7
+ new Date(data.frg_start_on_time).getTime() / 1000
8
+ )
9
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
10
+
11
+ // Генерируем cron-выражение
12
+ return endTimestamp
13
+ ? `* * * * * ${startTimestamp}-${endTimestamp}:${data.frg_interval}-0-0-0`
14
+ : `* * * * * ${startTimestamp}:${data.frg_interval}-0-0-0`
15
+ }
16
+ export const generateWeeklyCronExpression = (
17
+ data: UI_I_ScheduleNewTasksForm
18
+ ): string => {
19
+ const { frg_on_week_days } = data
20
+
21
+ const startTimestamp = Math.floor(
22
+ new Date(data.frg_start_on_time).getTime() / 1000
23
+ )
24
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
25
+ const daysOfWeek = frg_on_week_days.join(',')
26
+
27
+ return endTimestamp
28
+ ? `* * * * ${daysOfWeek} ${startTimestamp}-${endTimestamp}:0-0-0-${data.frg_interval}`
29
+ : `* * * * ${daysOfWeek} ${startTimestamp}:0-0-0-${data.frg_interval}`
30
+ }
31
+
32
+ export const generateDailyCronExpression = (
33
+ data: UI_I_ScheduleNewTasksForm
34
+ ): string => {
35
+ const startTimestamp = Math.floor(
36
+ new Date(data.frg_start_on_time).getTime() / 1000
37
+ )
38
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
39
+
40
+ // Генерируем cron-выражение
41
+ return endTimestamp
42
+ ? `* * * * * ${startTimestamp}-${endTimestamp}:0-${data.frg_interval}-0-0`
43
+ : `* * * * * ${startTimestamp}:0-${data.frg_interval}-0-0`
44
+ }
45
+
46
+ export const generateMonthlyCronExpression = (
47
+ data: UI_I_ScheduleNewTasksForm
48
+ ): string => {
49
+ const { frg_interval, frg_monthly_day, frq_week_day, frq_ordinal_number } =
50
+ data
51
+
52
+ const startTimestamp = Math.floor(
53
+ new Date(data.frg_start_on_time).getTime() / 1000
54
+ )
55
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
56
+
57
+ const daysOfWeek = `${frq_week_day}#${frq_ordinal_number}`
58
+
59
+ const timestamp = endTimestamp
60
+ ? `${startTimestamp}-${endTimestamp}`
61
+ : startTimestamp
62
+
63
+ // Генерируем cron-выражение
64
+ return data.frg_monthly_mode === 'week'
65
+ ? `* * * * * ${timestamp}:0-0-${frg_interval}-${daysOfWeek}`
66
+ : `* * ${frg_monthly_day} */${frg_interval} * ${timestamp}:0-0-0-0`
67
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.4.306",
4
+ "version": "1.4.308",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
@@ -16,8 +16,14 @@
16
16
  You should have received a copy of the GNU Affero General Public License
17
17
  along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
+ const _SOI = new Uint8Array([0xff, 0xd8]);
20
+ const _EOI = new Uint8Array([0xff, 0xd9]);
19
21
 
20
22
  wdi.RasterEngine = $.spcExtend(wdi.EventObject.prototype, {
23
+ chunks: [],
24
+ size: 0,
25
+ jpegInst: null,
26
+
21
27
  init: function (c) {
22
28
  this.time = Date.now()
23
29
  this.clientGui = c.clientGui
@@ -101,6 +107,9 @@ wdi.RasterEngine = $.spcExtend(wdi.EventObject.prototype, {
101
107
  handleStreamData: function (spiceMessage) {
102
108
  var stream = wdi.Stream.getStream(spiceMessage.args.id)
103
109
  switch (stream.codec) {
110
+ case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_MJPEG:
111
+ this.handleMjpegStream(spiceMessage)
112
+ break
104
113
  case wdi.SpiceVideoCodecType.SPICE_VIDEO_CODEC_TYPE_H264:
105
114
  this.handleH264Stream(spiceMessage)
106
115
  break
@@ -151,6 +160,76 @@ wdi.RasterEngine = $.spcExtend(wdi.EventObject.prototype, {
151
160
  console.log('%chandleStreamDestroy', 'color:rgb(255,100,100)')
152
161
  },
153
162
 
163
+ indexOfBytes: function(haystack, needle, start = 0) {
164
+ for (let i = start; i <= haystack.length - needle.length; i++) {
165
+ let found = true;
166
+ for (let j = 0; j < needle.length; j++) {
167
+ if (haystack[i + j] !== needle[j]) {
168
+ found = false;
169
+ break;
170
+ }
171
+ }
172
+ if (found) return i;
173
+ }
174
+ return -1;
175
+ },
176
+
177
+ concatenateChunks: function(chunks, totalLength) {
178
+ const result = new Uint8Array(totalLength);
179
+ let offset = 0;
180
+ for (const chunk of chunks) {
181
+ result.set(chunk, offset);
182
+ offset += chunk.length;
183
+ }
184
+ return result;
185
+ },
186
+
187
+ pushWholeMjpegFrame: function(chunk) {
188
+ const chunkLength = chunk.length;
189
+ let pos = 0;
190
+ while (true) {
191
+ if (this.size) {
192
+ const eoi = this.indexOfBytes(chunk, _EOI);
193
+ if (eoi === -1) {
194
+ this.chunks.push(chunk);
195
+ size += chunkLength;
196
+ break;
197
+ } else {
198
+ pos = eoi + _EOI.length;
199
+ const sliced = chunk.slice(0, pos);
200
+ this.chunks.push(sliced);
201
+ this.size += sliced.length;
202
+ this.jpegInst = this.concatenateChunks(chunks, size);
203
+ this.chunks = [];
204
+ size = 0;
205
+ if (pos === chunkLength) {
206
+ break;
207
+ }
208
+ }
209
+ } else {
210
+ const soi = this.indexOfBytes(chunk, _SOI, pos);
211
+ if (soi === -1) {
212
+ break;
213
+ } else {
214
+ pos = soi + 500; // можно уменьшить значение для улучшения производительности
215
+ }
216
+ const eoi = this.indexOfBytes(chunk, _EOI, pos);
217
+ if (eoi === -1) {
218
+ const sliced = chunk.slice(soi);
219
+ this.chunks = [sliced];
220
+ this.size = sliced.length;
221
+ break;
222
+ } else {
223
+ pos = eoi + _EOI.length;
224
+ this.jpegInst = chunk.slice(soi, pos);
225
+ if (pos === chunkLength) {
226
+ break;
227
+ }
228
+ }
229
+ }
230
+ }
231
+ },
232
+
154
233
  handleMjpegStream: function (spiceMessage) {
155
234
  var imageData = spiceMessage.args.data //jpeg string encoded
156
235
  var stream = wdi.Stream.getStream(spiceMessage.args.id) //recover the stream
@@ -186,8 +265,17 @@ wdi.RasterEngine = $.spcExtend(wdi.EventObject.prototype, {
186
265
  URL.revokeObjectURL(url)
187
266
  }
188
267
 
189
- url = wdi.SpiceObject.bytesToURI(imageData)
190
- img.src = url
268
+
269
+ // Здесь предполагается, что imageData – это двоичные данные в виде Uint8Array
270
+ const byteData = new Uint8Array(imageData); // Преобразование в Uint8Array
271
+ this.pushWholeMjpegFrame(byteData);
272
+
273
+ // Проверяем, был ли сформирован полный JPEG-кадр
274
+ if (this.jpegInst) {
275
+ url = wdi.SpiceObject.bytesToURI(this.jpegInst);
276
+ img.src = url;
277
+ }
278
+
191
279
  },
192
280
 
193
281
  handleH264Stream: function (spiceMessage) {