-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
feat: Refactor routes and handlers This commit introduces a refactoring of the application's route handling and logic by moving route definitions into dedicated handler files. The commit includes the following changes: - Removed the route files - Created handler files - Fixed all the imports/exports This change improves the overall organization and maintainability of the codebase. ```
This commit improves code readability and consistency across handler files by: - Standardizing import statements to be grouped and ordered. - Ensuring consistent spacing and formatting within the code.
Reviewer's GuideThis PR refactors the API by extracting routing and logic into dedicated handler classes, replacing the previous Elysia server setup with a unified handlers export; implements a generic WebSocket broadcasting layer for logs, stack events, and Docker stats; refactors the core scheduler to use a reusable job loop; enhances plugin management with asynchronous startup and consolidated reporting; expands the database schema to include store repositories and themes (while removing API key storage); cleans up dependencies and configuration; and strengthens error handling and data validation throughout backup, restore, and stats operations. Sequence diagram for WebSocket broadcast of stack eventssequenceDiagram
participant StackHandler
participant Controller as StackController
participant Broadcast as broadcast (WebSocket)
participant Client
StackHandler->>Controller: deployStack(config)
Controller->>Broadcast: broadcast({topic: "stack", data: {...}})
Broadcast-->>Client: WebSocket message (stack event)
Note over Client: Client receives stack status/progress/error
Sequence diagram for unified handler invocationsequenceDiagram
actor User
participant App as Application
participant Handlers as handlers/index.ts
participant ApiHandler
User->>App: API request (e.g. updateConfig)
App->>Handlers: handlers.ApiHandler.updateConfig(...)
Handlers->>ApiHandler: updateConfig(...)
ApiHandler-->>Handlers: result
Handlers-->>App: result
App-->>User: response
ER diagram for updated database schema (config, store_repos, themes)erDiagram
CONFIG {
NUMBER keep_data_for
NUMBER fetching_interval
}
STORE_REPOS {
TEXT slug
TEXT base
}
THEMES {
TEXT name PK
TEXT creator
TEXT vars
TEXT tags
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This commit removes the API key functionality from the DockStatAPI. The API key column is removed from the config table in the database, and the updateConfig function no longer accepts or updates the API key. This change simplifies the configuration and security of the application. The Docker websocket route and auth middleware was removed, since it is not used anymore. BREAKING CHANGE: The API key functionality has been removed. Users will no longer be able to set or validate an API key. The config endpoint takes only keep_data_for and fetching_interval now.
6c1269e to
d3601a5
Compare
This commit moves the `typings` directory to the root of the project. This change affects the import paths in `runStackCommand.ts` and `logger.ts`, which have been updated accordingly. The diff includes: - Update import path for `postToClient` in `runStackCommand.ts` to `~/handlers/modules/live-stacks`. - Update import path for `Stack` in `runStackCommand.ts` to `~/../typings/docker-compose`. - Update import path for `log_message` in `logger.ts` to `../../../typings/database`. - Moves the typings dir to the root of the project The reason for this change is to simplify the project structure and make the typings more accessible to other parts of the application.
b547fae to
fd4e219
Compare
85ab23e to
6ef8769
Compare
5f47dbf to
082bfa8
Compare
This commit introduces the ability to manage store repositories within the application. It includes: - Creation of a table in the database to store repository information (slug and base URL). - Implementation of functions to add, retrieve, and delete store repositories from the database. - Creation of a new handler to expose store repository management functionalities via API.
…4Nik/DockStatAPI into remove-elysia-for-direct-integration
|
@sourcery-ai review |
This commit introduces a new table to the database, allowing users to store and manage custom themes for the application. It also provides the ability to save a default theme on first start. The following changes were made: - Added a table to the database schema. - Added functions to interact with the table. - Add a Theme handler to expose theme actions
Updates the theme colors to a dark mode palette. This includes changes to accent colors, border colors, background colors, and gradient colors.
4017eb6 to
4ac7e14
Compare
This commit introduces a transformation of the `vars` field in the `addTheme` function. It converts a JSON object of CSS variables into a string of CSS rules that target the root element. Additionally, it updates the themes table to set the name field as the primary key. This change is crucial for ensuring data integrity and efficient theme management.
3502579 to
503db97
Compare
This commit introduces new CSS variables for text colors: `--text-primary`, `--text-secondary`, and `--text-muted`. These variables are defined within the `:root, #root, #docs-root` CSS selector and provide a centralized way to manage text colors across the application. This will improve consistency and make it easier to adjust the color scheme in the future.
This commit introduces several enhancements to the configuration handling and adds functionality to retrieve the package.json data. The changes include: - Update config to use package.json - Enhanced config handling in `src/handlers/config.ts`: - Updated the getConfig, updateConfig, getPlugins, createbackup, listBackups, downloadbackup, restoreBackup, addHost, updateHost, and removeHost functions to improve error handling and logging. - Added a new getPackage function to retrieve package.json data. - Updated the index file to export new handlers
The `PackageJson` type from `knip` was imported but not used in the `config.ts` file. This commit removes the unused import to improve code clarity and reduce unnecessary dependencies.
- Updated the default theme variables in the database initialization to improve the initial user experience. - Minor formatting and consistency improvements in database initialization logic.
|
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Its4Nik - I've reviewed your changes - here's some feedback:
- Avoid performing heavy startup tasks (like scheduling jobs and launching the WebSocket server) as side-effects during module imports in handlers/index.ts; decouple initialization into an explicit start function so the entry point controls when and how the system comes up.
- Standardize error handling by preserving original Error instances instead of wrapping everything in
new Error(error as string), which strips stack traces and context—consider rethrowing or usingcauseto retain full error information. - Remove hard-coded plugin paths in PluginManager.start (e.g. './server/src/plugins') and make the plugin directory configurable or aligned with the actual project layout to prevent path mismatches during startup.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Avoid performing heavy startup tasks (like scheduling jobs and launching the WebSocket server) as side-effects during module imports in handlers/index.ts; decouple initialization into an explicit start function so the entry point controls when and how the system comes up.
- Standardize error handling by preserving original Error instances instead of wrapping everything in `new Error(error as string)`, which strips stack traces and context—consider rethrowing or using `cause` to retain full error information.
- Remove hard-coded plugin paths in PluginManager.start (e.g. './server/src/plugins') and make the plugin directory configurable or aligned with the actual project layout to prevent path mismatches during startup.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/core/docker/scheduler.ts
Outdated
| while (true) { | ||
| const start = Date.now(); | ||
| logger.info(`Task Start: ${name}`); | ||
| try { | ||
| await jobFn(); | ||
| logger.info(`Task End: ${name} succeeded.`); | ||
| } catch (e) { | ||
| logger.error(`Task End: ${name} failed:`, e); | ||
| } | ||
| const elapsed = Date.now() - start; | ||
| const delay = Math.max(0, intervalMs - elapsed); | ||
| await new Promise((r) => setTimeout(r, delay)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (code-quality): Avoid loops with missing or constant end conditions. (avoid-infinite-loops)
Explanation
Loops with a constant condition, or no terminator, can be useful in certain contexts, but it's easy to forget to break out of them. This rule highlights loops which may never end.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sourcery-ai issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created an issue for your comment: #52
This commit introduces a mechanism to reload the schedules when the configuration is updated. This ensures that the scheduler is always running with the latest configuration settings. It also adds logging to the deletion of Themes The changes include: - Added a function to the file. This function clears all existing schedules and restarts them. - Modified the function in to call the function after updating the configuration in the database. - Added logging to theme deletion
b51e708 to
253b084
Compare
@sourcery-ai
Summary by Sourcery
Move API logic into a dedicated handlers layer, centralize WebSocket broadcasting, reorganize project structure for better modularity, and enhance scheduler, plugin loading, and database initialization.
New Features:
Enhancements: