Browse Source

fixes for default class

pull/2685/head
pavelrzn 1 week ago
parent
commit
e94f13d708
  1. 6
      src/app/pages/admin/speed.vue
  2. 2
      src/server/database/migrations/0007_add_tc_state.sql
  3. 2
      src/server/database/repositories/tcState/schema.ts
  4. 4
      src/server/database/repositories/tcState/service.ts

6
src/app/pages/admin/speed.vue

@ -198,6 +198,9 @@ const { data: fetchData, refresh: _refresh } = await useFetch<TcStateResponse>('
// Use a ref instead of computed for stable reactivity
const data = ref<TcStateResponse | null>(null);
// Default class speed must be declared BEFORE the watch that uses it (avoid TDZ)
const defaultClassSpeed = ref(0);
// Initialize from fetch data
watch(fetchData, (val) => {
if (val) {
@ -251,9 +254,6 @@ function getClientsForClass(cls: TcClass): TcClient[] {
return data.value.clients.filter((c) => c.ipv4Address && ipSet.has(c.ipv4Address));
}
// Default class speed plain ref, not computed (avoid '2' prefix stripping bugs)
const defaultClassSpeed = ref(0);
// Prevent empty string / NaN from resetting the field to 0
function onDefaultClassKeydown(e: KeyboardEvent) {
const input = e.target as HTMLInputElement;

2
src/server/database/migrations/0007_add_tc_state.sql

@ -1,7 +1,7 @@
CREATE TABLE `tc_state_table` (
`id` integer PRIMARY KEY DEFAULT 1 NOT NULL,
`total_ul_rate` integer NOT NULL DEFAULT 100,
`default_class_id` integer NOT NULL DEFAULT 11,
`default_class_id` integer NOT NULL DEFAULT 21,
`classes` text NOT NULL DEFAULT '[]',
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL

2
src/server/database/repositories/tcState/schema.ts

@ -5,7 +5,7 @@ export const tcState = sqliteTable('tc_state_table', {
id: int().primaryKey({ autoIncrement: false }).default(1),
totalUlRate: int('total_ul_rate').notNull().default(100),
defaultClassId: int('default_class_id').notNull().default(11),
defaultClassId: int('default_class_id').notNull().default(21), // 2{ulRate} convention: 21 means ulRate=1
/** JSON array of { id: number, ulRate: number, clientIps: string[] } */
classes: text({ mode: 'json' }).$type<TcClass[]>().notNull().default([]),

4
src/server/database/repositories/tcState/service.ts

@ -28,11 +28,11 @@ export class TcStateService {
}> {
let state = await this.#statements.get.execute();
if (!state) {
// First run: create default state with empty classes and default class 1:11
// First run: create default state with empty classes and default class 1:21 (2{ulRate} convention: ulRate=1)
await this.#db.insert(tcState).values({
id: 1,
totalUlRate: 100,
defaultClassId: 11,
defaultClassId: 21, // 2{ulRate} convention: 21 means ulRate=1
classes: [],
}).execute();
state = await this.#statements.get.execute();

Loading…
Cancel
Save