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 // Use a ref instead of computed for stable reactivity
const data = ref<TcStateResponse | null>(null); 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 // Initialize from fetch data
watch(fetchData, (val) => { watch(fetchData, (val) => {
if (val) { if (val) {
@ -251,9 +254,6 @@ function getClientsForClass(cls: TcClass): TcClient[] {
return data.value.clients.filter((c) => c.ipv4Address && ipSet.has(c.ipv4Address)); 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 // Prevent empty string / NaN from resetting the field to 0
function onDefaultClassKeydown(e: KeyboardEvent) { function onDefaultClassKeydown(e: KeyboardEvent) {
const input = e.target as HTMLInputElement; 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` ( CREATE TABLE `tc_state_table` (
`id` integer PRIMARY KEY DEFAULT 1 NOT NULL, `id` integer PRIMARY KEY DEFAULT 1 NOT NULL,
`total_ul_rate` integer NOT NULL DEFAULT 100, `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 '[]', `classes` text NOT NULL DEFAULT '[]',
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL, `created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_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), id: int().primaryKey({ autoIncrement: false }).default(1),
totalUlRate: int('total_ul_rate').notNull().default(100), 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[] } */ /** JSON array of { id: number, ulRate: number, clientIps: string[] } */
classes: text({ mode: 'json' }).$type<TcClass[]>().notNull().default([]), 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(); let state = await this.#statements.get.execute();
if (!state) { 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({ await this.#db.insert(tcState).values({
id: 1, id: 1,
totalUlRate: 100, totalUlRate: 100,
defaultClassId: 11, defaultClassId: 21, // 2{ulRate} convention: 21 means ulRate=1
classes: [], classes: [],
}).execute(); }).execute();
state = await this.#statements.get.execute(); state = await this.#statements.get.execute();

Loading…
Cancel
Save