-
-
Notifications
You must be signed in to change notification settings - Fork 137
add support for javalin v7 #1556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
概述将 Javalin 框架从 6.7.0 升级至 7.0.0-alpha.4,并将所有模块路由注册方式从标准 API 改为不安全路由 API,同时重构 JavalinWebContainer 以支持虚拟线程、更新配置策略和异常处理机制。 变更内容
估算代码审查工作量🎯 3 (中等复杂度) | ⏱️ ~40 分钟 可能相关的 PR
建议的标签
建议的审查者
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @Gaojianli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a major upgrade of the underlying web framework, Javalin, to its version 7. The primary goal is to ensure compatibility and leverage the latest features of the framework. This involved updating the dependency, refactoring how routes are registered, and adjusting various server configurations to match the new API, ensuring the application remains robust and performant with the updated web server. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request upgrades Javalin from v6 to v7, which is a major update with significant API changes. The changes across the codebase reflect the necessary adaptations to the new version. My review focuses on the potential risks introduced by this upgrade, such as the use of an alpha version of the library and reliance on internal or unsafe APIs for the migration. I've provided suggestions for more robust and maintainable alternatives that align with Javalin 7's intended usage.
| // Core dependencies | ||
| implementation("com.vdurmont:semver4j:3.1.0") | ||
| implementation("io.javalin:javalin:6.7.0") | ||
| implementation("io.javalin:javalin:7.0.0-alpha.4") |
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.
Using an alpha version of a dependency (7.0.0-alpha.4) in a project can be risky. Alpha versions are not feature-complete, may contain bugs, and their APIs can change without notice. It's generally recommended to use stable releases for production code. If this is for testing the upcoming Javalin v7, it's acceptable, but it should be updated to a stable release as soon as one becomes available.
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.
Actionable comments posted: 9
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/MultiDialingBlocker.java (1)
89-89: 存在键名拼写错误。
tolerateNumV5应该是tolerateNumV6,这会导致 API 响应中的配置信息键名与实际配置项不一致。🐛 修复建议
- config.put("tolerateNumV5", tolerateNumV6); + config.put("tolerateNumV6", tolerateNumV6);src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPlusController.java (1)
152-168: 空指针检查错误:应检查mappedLicense而非licenseManager。第 155 行检查了
licenseManager == null,但licenseManager是@Autowired注入的,初始化后永远不会为 null。实际应该检查的是第 154 行获取的mappedLicense。当
mappedLicense为 null 时,第 160 行调用mappedLicense.getKeyText()会抛出NullPointerException。🐛 修复空指针检查
private void handleLicenseDelete(@NotNull Context context) throws Exception { String key = context.bodyAsClass(LicenseDeleteBody.class).getLicenseId(); var mappedLicense = licenseManager.getLicenseBackend().getLicensesMap().get(key); - if (licenseManager == null) { + if (mappedLicense == null) { context.json(new StdResp(false, tlUI(Lang.PBH_LICENSE_KEY_DELETE_FAILED_NOT_EXISTS), "Not found mappedLicense")); return; }src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAlertController.java (1)
91-98:handleRead方法存在潜在的空指针异常风险。当
id对应的实体不存在时,queryForId可能返回null,直接调用entity.setReadAt()会导致 NPE。🐛 建议修复
private void handleRead(Context ctx) throws SQLException { var id = Long.parseLong(ctx.pathParam("id")); var entity = alertDao.queryForId(id); + if (entity == null) { + ctx.status(404); + ctx.json(new StdResp(false, "Alert not found", null)); + return; + } entity.setReadAt(new Timestamp(System.currentTimeMillis())); alertDao.update(entity); ctx.status(200); ctx.json(new StdResp(true, "OK", null)); }src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPushController.java (1)
50-57: 重构路由注册以使用官方 Javalin v7 API。
javalin().unsafe.routes使用了 Javalin 内部未文档化的 API(由unsafe前缀标示)。虽然该模式在整个项目中一致使用,但不是官方推荐的 Javalin v7 路由注册方式。应改为使用官方支持的 API,例如 fluent 风格的app.get()、app.post()等,或使用router.apiBuilder()模式分组路由。
🤖 Fix all issues with AI agents
In @build.gradle.kts:
- Line 78: Update the Javalin dependency from 7.0.0-alpha.4 to 7.0.0-beta.1 by
changing the implementation coordinate to io.javalin:javalin:7.0.0-beta.1, then
rebuild and run the full test suite; specifically search the codebase for usages
of unsafe.routes (used across 30+ controllers/modules) and run integration/smoke
tests for every endpoint to catch API regressions, fix any compile errors or
behavioral changes caused by v7 API changes in the referenced
controllers/modules, and re-run tests before merging.
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/BtnNetworkOnline.java:
- Around line 89-95: Update the Javalin dependency from the old alpha to a newer
beta (at least 7.0.0-beta.1) in your build configuration (e.g., pom.xml or
build.gradle) so the code using javalin().unsafe.routes.get(...) remains aligned
with the v7 migration; after bumping the dependency, run a full build and tests
and verify that BtnNetworkOnline.onEnable() (and other modules using
javalin().unsafe.routes) still compile and behave correctly under the new
Javalin version, adjusting imports or route API usage only if compilation errors
reveal any breaking changes.
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/MultiDialingBlocker.java:
- Around line 57-59: The config map is using the wrong key for the V6 tolerance
value: replace the incorrect key used in the config.put call so the key matches
the value (use "tolerateNumV6" when putting the tolerateNumV6 variable), i.e.
find the config.put("tolerateNumV5", tolerateNumV6) invocation and change the
first argument to "tolerateNumV6" to match the pattern used for other entries
like tolerateNumV4.
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlacklist.java:
- Around line 57-58: The code uses the removed Javalin v7 internal API
unsafe.routes; replace the registration in PeerIdBlacklist that currently calls
webContainer.javalin().unsafe.routes.get(...) with the official Javalin 7 router
API (e.g., webContainer.javalin().config().router().get(...) or
webContainer.javalin().router().get(...)) and pass the same endpoint path
("/api/modules/" + getConfigName()), the same handler (this::handleWebAPI) and
the same role (Role.USER_READ) so routing is registered via the public API
instead of unsafe.routes.
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java:
- Around line 97-98: The code uses the unsafe runtime API
(webContainer.javalin().unsafe.routes) to register routes; replace this with the
Javalin v7 config-time router registration by moving the GET registration into
the router.apiBuilder during Javalin configuration so the route for
"/api/modules/" + getConfigName() that calls this::handleConfig with
Role.USER_READ is registered via config.router.apiBuilder(...) instead of
webContainer.javalin().unsafe.routes; apply the same change for other files
using .unsafe.routes to centralize route setup in the configuration phase.
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/BlockListController.java:
- Around line 34-37: The GET route registration for "/blocklist/ip" on
webContainer.javalin().unsafe.routes is missing a role parameter; update the
.get call that currently reads .get("/blocklist/ip", this::blocklistIp) to
include the appropriate Role (e.g., Role.ANYONE for public access or
Role.USER_READ for authenticated reads) to match the other endpoints
(.get("/blocklist/p2p-plain-format", this::blocklistP2pPlain, Role.ANYONE) and
.get("/blocklist/dat-emule", this::blocklistDatEmule, Role.ANYONE)).
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLogsController.java:
- Around line 44-46: The code uses the internal unsafe.routes API on
webContainer.javalin(), which must be replaced with Javalin 7's public router
API; update the registration of the HTTP and WebSocket routes for handleLogs and
handleLogsStream (and preserve Role.USER_WRITE) to use the supported router
methods (e.g. app/router.get(...) and the published ws registration) instead of
unsafe.routes so the routes are registered via the public API rather than
webContainer.javalin().unsafe.routes; ensure you call the public router off the
Javalin instance returned by webContainer.javalin() and keep the same handlers
(handleLogs, handleLogsStream) and permission Role.USER_WRITE.
In @src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java:
- Around line 76-78: The code uses the internal method getState$javalin() to
toggle virtual threads and startup watcher; replace this with the public Javalin
configuration API by creating or updating the Javalin configuration to call
cfg.useVirtualThreads(true) (or equivalent on the Config object) instead of
accessing c.getState$javalin(), and set the startup watcher flag via the public
config (e.g., config.startup().startupWatcherEnabled = false) so that
getState$javalin() is removed and configuration is done through the official
Javalin.create(cfg -> ...) / Config APIs.
- Line 89: The config uses an invalid Javalin v7 option
staticFiles.precompressMaxSize; in JavalinWebContainer replace that setting with
the supported option staticFiles.precompress = false to disable precompression
(update the staticFiles configuration block where staticFiles.precompressMaxSize
is set). Ensure you remove the precompressMaxSize assignment and set
staticFiles.precompress to false so Javalin honors the disabled precompress
behavior.
🧹 Nitpick comments (6)
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHBanController.java (1)
94-102: 可简化计数逻辑。
size变量的递增是多余的,可以直接使用request.length。♻️ 建议的简化
private void handleBanAdd(@NotNull Context context) { String[] request = context.bodyAsClass(String[].class); - int size = 0; for (String s : request) { downloaderServer.scheduleBanPeerNoAssign(new PeerAddress(s, 0, s)); - size++; } - context.json(new StdResp(true, null, Map.of("count", size))); + context.json(new StdResp(true, null, Map.of("count", request.length))); }src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLabController.java (1)
72-83: 布尔值解析逻辑可简化。当前的
if-else链可以使用更简洁的方式处理三态布尔值(true/false/null)。♻️ 建议的简化
private void handleExperimentSet(@NotNull Context context) { var id = context.pathParam("id"); var activated = context.bodyAsClass(ExperimentPutBody.class); - Boolean bool = null; - if(activated.getStatus().equalsIgnoreCase("true")){ - bool = true; - } else if(activated.getStatus().equalsIgnoreCase("false")){ - bool = false; - } + Boolean bool = switch (activated.getStatus().toLowerCase()) { + case "true" -> true; + case "false" -> false; + default -> null; + }; laboratory.setExperimentActivated(id, bool); context.json(new StdResp(true, null, activated.getStatus())); }src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPeerController.java (1)
114-116: 移除空注释。第 115 行的
/**/看起来是调试遗留的空注释,建议清理。♻️ 建议的修改
if (btnNetwork == null) { ctx.json(new StdResp(false, tl(locale(ctx), Lang.BTN_NETWORK_NOT_ENABLED), null)); return; - /**/ }src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAlertController.java (1)
100-104:handleDelete方法缺少实体存在性检查。建议在删除前检查实体是否存在,以便向客户端返回更准确的响应状态码。
♻️ 建议改进
private void handleDelete(Context ctx) throws SQLException { - alertDao.deleteById(Long.parseLong(ctx.pathParam("id"))); - ctx.status(200); - ctx.json(new StdResp(true, "OK", null)); + var id = Long.parseLong(ctx.pathParam("id")); + var entity = alertDao.queryForId(id); + if (entity == null) { + ctx.status(404); + ctx.json(new StdResp(false, "Alert not found", null)); + return; + } + alertDao.deleteById(id); + ctx.status(200); + ctx.json(new StdResp(true, "OK", null)); }src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPushController.java (2)
73-86: (已有问题)缺少return语句可能导致状态不一致。当
addPushProvider返回false时(第 76-78 行),代码会返回BAD_REQUEST响应,但随后仍会执行savePushProviders()。建议在第 78 行后添加return;。这是已有代码的问题,不是本 PR 引入的,可以在后续修复。
♻️ 建议的修复
if (pushManager.addPushProvider(pushProvider)) { ctx.status(HttpStatus.CREATED); ctx.json(new StdResp(true, tl(locale(ctx), Lang.PUSH_PROVIDER_API_CREATED), null)); } else { ctx.status(HttpStatus.BAD_REQUEST); ctx.json(new StdResp(false, tl(locale(ctx), Lang.PUSH_PROVIDER_API_CREATION_FAILED_ALREADY_EXISTS), null)); + return; } try { pushManager.savePushProviders();
106-118: (已有问题)同样缺少return语句。与
handlePushProviderPut相同的问题:当更新失败时(第 109-110 行),代码仍会继续执行savePushProviders()。♻️ 建议的修复
if (pushManager.addPushProvider(pushProvider)) { ctx.json(new StdResp(true, tl(locale(ctx), Lang.PUSH_PROVIDER_API_UPDATED), null)); } else { ctx.status(HttpStatus.BAD_REQUEST); ctx.json(new StdResp(false, tl(locale(ctx), Lang.PUSH_PROVIDER_API_UPDATE_FAILURE_ALREADY_EXISTS), null)); + return; } try { pushManager.savePushProviders();
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (34)
build.gradle.ktssrc/main/java/com/ghostchu/peerbanhelper/module/AbstractWebSocketFeatureModule.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/monitor/SwarmTrackingModule.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/AutoRangeBan.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/BtnNetworkOnline.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ClientNameBlacklist.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ExpressionRule.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/IPBlackList.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/MultiDialingBlocker.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PTRBlacklist.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlacklist.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/BlockListController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAlertController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAsyncTaskController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAuthenticateController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAutoStunController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHBanController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHChartController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHEasterEggController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHGeneralController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLabController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLogsController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetadataController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetricsController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHOOBEController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPeerController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPlusController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPushController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHTorrentController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHUtilitiesController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/RuleSubController.javasrc/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/**/*.java
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Backend must be written in Java with main class at
com.ghostchu.peerbanhelper.MainJumpLoader. All Java source files go insrc/main/java/. Resources go insrc/main/resources/.
Files:
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHChartController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAlertController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHOOBEController.javasrc/main/java/com/ghostchu/peerbanhelper/module/AbstractWebSocketFeatureModule.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PTRBlacklist.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAsyncTaskController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetricsController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/IPBlackList.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlacklist.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/monitor/SwarmTrackingModule.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPushController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAuthenticateController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/BlockListController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.javasrc/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetadataController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/MultiDialingBlocker.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLabController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAutoStunController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ExpressionRule.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPlusController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHUtilitiesController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLogsController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/BtnNetworkOnline.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHBanController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHGeneralController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/RuleSubController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPeerController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHTorrentController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHEasterEggController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ClientNameBlacklist.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/rule/AutoRangeBan.java
🧠 Learnings (3)
📚 Learning: 2025-11-25T15:22:48.987Z
Learnt from: CR
Repo: PBH-BTN/PeerBanHelper PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-25T15:22:48.987Z
Learning: Always manually validate application functionality after making changes. Validate by: (1) Starting the application with `java -Dpbh.nogui=true -jar target/PeerBanHelper.jar`, (2) Testing web interface with `curl -I http://localhost:9898/`, (3) Testing API endpoint with `curl -s http://localhost:9898/api/general/status`, (4) Verifying dashboard loads and shows statistics.
Applied to files:
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHChartController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPushController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHUtilitiesController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHBanController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHGeneralController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPeerController.java
📚 Learning: 2025-01-08T12:53:19.783Z
Learnt from: Ghost-chu
Repo: PBH-BTN/PeerBanHelper PR: 875
File: src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java:199-205
Timestamp: 2025-01-08T12:53:19.783Z
Learning: The `runTestCode()` method in PeerBanHelperServer is an intentional design feature guarded by the `pbh.release=LiveDebug` system property, used for debug purposes in production code.
Applied to files:
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetricsController.javasrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHGeneralController.java
📚 Learning: 2025-01-08T17:57:58.596Z
Learnt from: Ghost-chu
Repo: PBH-BTN/PeerBanHelper PR: 880
File: src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHEasterEggController.java:75-86
Timestamp: 2025-01-08T17:57:58.596Z
Learning: The playful implementation in PBHEasterEggController, including casual error messages and non-standard HTTP status codes, is intentionally designed as part of the easter egg functionality and should not be "professionalized".
Applied to files:
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHEasterEggController.java
🧬 Code graph analysis (1)
src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java (3)
src/main/java/com/ghostchu/peerbanhelper/ExternalSwitch.java (1)
ExternalSwitch(7-116)src/main/java/com/ghostchu/peerbanhelper/util/WebUtil.java (1)
WebUtil(9-63)src/main/java/com/ghostchu/peerbanhelper/util/SharedObject.java (1)
SharedObject(7-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: CI
- GitHub Check: Build JAR Files / Gradle
- GitHub Check: Build Standalone Docker Images
🔇 Additional comments (28)
src/main/java/com/ghostchu/peerbanhelper/module/AbstractWebSocketFeatureModule.java (1)
23-28: Javalin v7 API 迁移正确,代码无问题。
ctx.session.getRemoteSocketAddress()是 Javalin v7 中正确的 API,该方法源自底层 Jetty WebSocket Session。使用instanceof模式匹配安全地处理了InetSocketAddress类型检查,getHostString()方法也正确地提取主机名,避免触发反向 DNS 查询。如果远程地址为 null 或非InetSocketAddress类型,登录检查会被跳过,这与之前的行为一致。src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ClientNameBlacklist.java (1)
56-61: 该代码模式与项目约定一致,但需要说明实际 API 来源。
webContainer.javalin().unsafe.routes.get(...)的使用在整个代码库中保持一致,遍及 16+ 个 Java 文件。但需要注意:Javalin v7 尚未正式发布(最新稳定版本为 v6.7.0),且官方 Javalin 文档中未记录unsafe.routesAPI。该 API 似乎是项目级别的自定义实现或内部 API,而非来自 Javalin 官方。Likely an incorrect or invalid review comment.
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAsyncTaskController.java (1)
51-57: 路由注册方式已正确更新为 Javalin v7 的unsafe.routesAPI。代码变更符合 Javalin v7 的官方迁移模式,整个项目有 30+ 个模块使用相同的
unsafe.routes注册方式。虽然unsafe前缀表示这是一个内部 API(类似 Java 的sun.misc.Unsafe),但这是 Javalin v7 的标准路由注册方式。建议:项目使用 alpha 版本
7.0.0-alpha.4,在正式发布前关注版本更新和稳定性改进。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPlusController.java (3)
82-87: LGTM!PoW 验证码生成逻辑实现正确,缓存配置合理(1小时过期)。
126-150: LGTM!许可证续期逻辑实现正确:验证码校验、重复许可证检查、配置持久化均已妥善处理。
73-80:unsafe.routes是已弃用的 API,应迁移到官方推荐的config.router.apiBuilder()模式。虽然代码实现本身在语法和逻辑上是正确的,但
unsafe.routes是 Javalin 内部/低级 API,已被标记为弃用。官方推荐的 Javalin 7 路由注册方式是使用config.router.apiBuilder()和 ApiBuilder 风格的路由分组。建议后续重构时将此处及整个代码库中的unsafe.routes调用迁移至官方 API。Likely an incorrect or invalid review comment.
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAuthenticateController.java (1)
45-47: 认证路由迁移正确。登录和登出端点的路由注册已正确迁移至
unsafe.routesAPI,与项目范围内的 Javalin v7 迁移模式保持一致。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHDownloaderController.java (1)
77-86: 下载器 API 路由迁移正确。所有下载器相关端点(列表、扫描、添加、更新、测试、删除、状态、种子、Peer 等)已正确迁移至
unsafe.routesAPI。路由路径、HTTP 方法和角色权限均保持不变。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHOOBEController.java (1)
56-59: OOBE 路由迁移正确。初始化向导(OOBE)相关端点已正确迁移至
unsafe.routesAPI。使用Role.ANYONE是合理的,因为这些端点在用户首次配置认证之前就需要访问。src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PTRBlacklist.java (1)
65-66: PTR 黑名单模块路由迁移正确。模块 API 端点已正确迁移至
unsafe.routesAPI。src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/AutoRangeBan.java (1)
66-67: LGTM!路由注册已正确迁移到 Javalin v7 的
unsafe.routesAPI。端点路径和角色保持不变,处理逻辑未受影响。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHBanController.java (1)
86-91: LGTM!路由注册已正确迁移到 Javalin v7 的
unsafe.routesAPI,方法链式调用清晰。新增的 DELETE 和 PUT 端点使用了适当的USER_WRITE角色。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLabController.java (1)
54-59: LGTM!路由注册已正确迁移,新增的实验功能端点遵循 RESTful 设计规范。
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHPeerController.java (1)
99-105: LGTM!路由注册已正确迁移到
unsafe.routesAPI,新增的 BTN 查询端点与现有端点保持一致的设计风格。src/main/java/com/ghostchu/peerbanhelper/module/impl/monitor/SwarmTrackingModule.java (1)
76-79: LGTM!路由注册已正确迁移到 Javalin v7 的
unsafe.routesAPI。两个 GET 端点的注册链式调用清晰且符合新 API 的使用模式。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetricsController.java (1)
55-59: LGTM!路由注册已正确迁移到 Javalin v7 的
unsafe.routesAPI,并新增了/api/statistic/analysis/date端点。链式调用结构清晰。src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java (1)
105-192: LGTM!异常处理器和
beforeMatched路由逻辑已正确迁移到 Javalin v7 的state.routes链式 API。认证流程逻辑完整:安全检查 → 角色验证 → Token 验证 → 登录尝试处理。各异常类型的响应状态码和消息设置合理。src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ExpressionRule.java (1)
81-86: LGTM!路由注册已正确迁移到 Javalin v7 的
unsafe.routesAPI。脚本管理的 CRUD 端点设置合理,权限控制正确(读操作使用USER_READ,写/删操作使用USER_WRITE)。src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/IPBlackList.java (1)
72-86: LGTM!路由注册已正确迁移到 Javalin v7 的
unsafe.routesAPI。IP 黑名单管理的各类端点(IP、端口、ASN、区域、城市、网络类型)的 CRUD 操作链式注册清晰完整。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHUtilitiesController.java (1)
57-59: 路由迁移变更符合 PR 整体模式。
unsafe.routes路由注册方式与其他控制器保持一致。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/RuleSubController.java (1)
83-107: 路由迁移变更符合 PR 整体模式。所有端点路径、处理程序和角色定义保持不变,仅切换到
unsafe.routesAPI。路由定义结构清晰,注释完善。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHGeneralController.java (1)
96-106: 路由迁移变更符合 PR 整体模式。所有
/api/general/*端点保持原有路径和处理程序不变。Based on learnings,建议在合并后手动验证功能:
- 启动应用:
java -Dpbh.nogui=true -jar target/PeerBanHelper.jar- 测试 API 端点:
curl -s http://localhost:9898/api/general/statussrc/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHEasterEggController.java (1)
63-64: 缺少必需的Role参数路由注册缺少
Role参数,与项目中所有其他unsafe.routes注册不一致。根据代码库中的模式,每个路由都需要指定角色权限(如Role.ANYONE、Role.USER_READ等)。彩蛋端点作为公开访问的功能,应该使用Role.ANYONE,与其他公开端点(如登录、OOBE 初始化等)的设置一致。请修改为:
javalinWebContainer.javalin().unsafe.routes .get("/api/egg", this::handleEgg, Role.ANYONE);⛔ Skipped due to learnings
Learnt from: Ghost-chu Repo: PBH-BTN/PeerBanHelper PR: 880 File: src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHEasterEggController.java:75-86 Timestamp: 2025-01-08T17:57:58.596Z Learning: The playful implementation in PBHEasterEggController, including casual error messages and non-standard HTTP status codes, is intentionally designed as part of the easter egg functionality and should not be "professionalized".src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAutoStunController.java (1)
67-74: 使用 Javalin 7.0.0-alpha.4 版本存在稳定性风险。项目依赖的 Javalin 7.0.0-alpha.4 仍处于 Alpha 阶段,意味着 API 和行为可能在后续版本中发生变更。虽然
unsafe.routes模式在该 Alpha 版本中是实际可用的 API,但其在官方文档中缺乏明确说明,不属于稳定的公开 API。建议:
- 跟踪 Javalin 官方稳定版本(目前为 6.7.0),待版本升级至正式发布后评估迁移成本
- 在代码中添加注释说明对 Alpha 版本的依赖,便于后续维护
- 监控 Javalin 7 正式发布时的 API 变更,确保
unsafe.routes仍为支持的路由注册方式src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHAlertController.java (1)
46-50: 路由迁移到unsafe.routes看起来正确。新增的 DELETE 路由
/api/alert/{id}使用Role.USER_WRITE权限,与其他写操作保持一致。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHTorrentController.java (1)
71-79: 路由迁移看起来正确。仅更改了路由注册方式,所有端点路径和处理器保持不变。
src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHChartController.java (1)
83-93: 路由迁移看起来正确。图表相关的端点都正确迁移到
unsafe.routes,权限设置保持不变。src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHMetadataController.java (1)
45-47: 路由迁移正确。元数据端点的迁移与其他控制器保持一致。
| // Core dependencies | ||
| implementation("com.vdurmont:semver4j:3.1.0") | ||
| implementation("io.javalin:javalin:6.7.0") | ||
| implementation("io.javalin:javalin:7.0.0-alpha.4") |
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.
🧩 Analysis chain
🌐 Web query:
Javalin 7.0.0 stable release January 2026 latest version
💡 Result:
No — as of January 13, 2026 the latest stable Javalin release is 6.7.0. Javalin 7.0.0 has pre-releases (alphas in late 2025 and a 7.0.0-beta.1 uploaded on Jan 2, 2026), but no 7.0.0 stable release yet. [1][2]
Sources:
- Javalin documentation (latest stable: 6.7.0). [1]
- Maven Central listing for io.javalin/javalin (shows 7.0.0-alpha.* and 7.0.0-beta.1 dated 2026-01-02). [2]
🌐 Web query:
Javalin unsafe.routes API v7 migration guide
💡 Result:
I couldn't find any official docs or references for an API named "unsafe.routes" in Javalin v7. The Javalin v7 redesign discussion exists, but it doesn't mention an unsafe.routes API. Would you like me to (a) search the Javalin repo for occurrences of "unsafe.routes" and related symbols, or (b) produce a migration plan for routing changes from v6→v7 based on the v7 redesign issue and existing migration guides? (github.com)
Citations:
🏁 Script executed:
rg "unsafe\.routes" --type kotlin --type javaRepository: PBH-BTN/PeerBanHelper
Length of output: 4306
🏁 Script executed:
rg "unsafe" --type kotlin --type java -i | head -30Repository: PBH-BTN/PeerBanHelper
Length of output: 4277
🏁 Script executed:
git ls-files | grep -E "\.(kt|kts|java)$" | head -20Repository: PBH-BTN/PeerBanHelper
Length of output: 1094
升级到 7.0.0-beta.1 并确保充分测试。
7.0.0-alpha.4 是预发布版本。截至 2026 年 1 月 13 日,Javalin v7 仍未发布稳定版本,但 7.0.0-beta.1(2026 年 1 月 2 日发布)已可用。建议将依赖升级至 beta.1 以获得更高的稳定性。
该项目已广泛使用 unsafe.routes API(在 30+ 个控制器和模块中使用),这表明这是迁移到 v7 的必要做法。在发布到生产环境前,需要充分测试所有 API 端点和路由处理。
🤖 Prompt for AI Agents
In @build.gradle.kts at line 78, Update the Javalin dependency from
7.0.0-alpha.4 to 7.0.0-beta.1 by changing the implementation coordinate to
io.javalin:javalin:7.0.0-beta.1, then rebuild and run the full test suite;
specifically search the codebase for usages of unsafe.routes (used across 30+
controllers/modules) and run integration/smoke tests for every endpoint to catch
API regressions, fix any compile errors or behavioral changes caused by v7 API
changes in the referenced controllers/modules, and re-run tests before merging.
| public void onEnable() { | ||
| reloadConfig(); | ||
| Main.getReloadManager().register(this); | ||
| javalinWebContainer.javalin() | ||
| javalinWebContainer.javalin().unsafe.routes | ||
| .get("/api/modules/btn", this::status, Role.USER_READ); | ||
| Main.getEventBus().register(this); | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
# First, find and check the build file to confirm the Javalin version
fd -e "pom.xml" -e "build.gradle" -e "build.gradle.kts" | head -5Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🌐 Web query:
Javalin 7.0 stable release date and unsafe.routes API
💡 Result:
Short answer:
- Javalin 7.0 has no stable release as of Jan 13, 2026 — only 7.0.x alphas and a 7.0.0-beta.1 (published Jan 2, 2026). [1][2]
- The documented public docs still show 6.7.0 as the latest stable; the "unsafe" / API redesign work for v7 is tracked in the Javalin 7 API redesign issue (discussion/changes), but there is no stable, finalized unsafe.routes API documented yet. [3][2]
Sources:
- Maven Central listing for io.javalin:javalin (shows 7.0.0-alpha.* and 7.0.0-beta.1). [turn0search1].
- javalin/javalin GitHub — 7 API redesign discussion (tracking API changes). [turn1search0].
- Official Javalin docs (currently for 6.7.0). [turn1search1].
Would you like me to watch the repo and notify you when 7.0.0 stable is published or look up the exact beta/alpha API (source code) for unsafe.* methods?
🌐 Web query:
Javalin 7.0 API documentation route registration
💡 Result:
Short answer — in Javalin 7 you register routes using the same routes/apiBuilder/path/get/post (ApiBuilder) style: call app.routes(...) (or config.router.apiBuilder(...) inside Javalin.create) and use path(...) with get/post/put/delete/ws/etc. Example (Java):
Javalin app = Javalin.create(config -> {
config.router.apiBuilder(() -> { // optional: use inside create
path("/users", () -> {
get(UserController::getAll);
post(UserController::create);
path("/{id}", () -> {
get(UserController::getOne);
patch(UserController::update);
delete(UserController::delete);
});
});
});
}).routes(() -> { // or register on the app instance
path("/health", () -> get(ctx -> ctx.result("OK")));
}).start(7000);
See the Javalin documentation on handler groups / apiBuilder and route registration. [1][2]
Also see the RouteOverview / plugin info for listing registered routes. [3]
Sources:
[1] Javalin Documentation — Handler groups / apiBuilder & routes.
[2] Javalin Documentation — general docs / routing (Javalin v6 docs page referenced for API style).
[3] RouteOverview plugin (showing registered routes).
🏁 Script executed:
# Find the BtnNetworkOnline.java file
find . -name "BtnNetworkOnline.java" -type fRepository: PBH-BTN/PeerBanHelper
Length of output: 146
🏁 Script executed:
# Search for route registration patterns in the codebase to understand the pattern
rg "javalin\(\)\..*\.get\(" --type java -A 2 -B 2 | head -50Repository: PBH-BTN/PeerBanHelper
Length of output: 660
🏁 Script executed:
# Search for "unsafe.routes" pattern in the codebase
rg "unsafe\.routes" --type javaRepository: PBH-BTN/PeerBanHelper
Length of output: 4306
🏁 Script executed:
# Look for other route registrations using the documented Javalin v7 pattern
rg "\.routes\(" --type java -A 3 | head -40Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
# Search for webContainer or javalinWebContainer definition
rg "class.*WebContainer|interface.*WebContainer" --type java -A 5Repository: PBH-BTN/PeerBanHelper
Length of output: 657
🏁 Script executed:
# Find build files and check Javalin version
find . -name "pom.xml" -o -name "build.gradle" -o -name "build.gradle.kts" | xargs catRepository: PBH-BTN/PeerBanHelper
Length of output: 10410
🏁 Script executed:
# Search for Javalin bean/configuration
rg "@Bean.*javalin|javalin.*config|JavalinConfig" --type java -B 2 -A 5 | head -60Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
# Read the JavalinWebContainer class to understand how Javalin is configured
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | head -100Repository: PBH-BTN/PeerBanHelper
Length of output: 5686
🏁 Script executed:
# Also check for any Javalin configuration/setup
rg "Javalin\.create|new Javalin|unsafe" --type java -B 3 -A 3 | head -80Repository: PBH-BTN/PeerBanHelper
Length of output: 8995
升级到 Javalin 7.0.0-beta.1 或更新版本。
路由迁移模式 javalin().unsafe.routes.get(...) 在整个项目中保持一致,符合现有的 v7 迁移模式。但构建文件当前依赖 io.javalin:javalin:7.0.0-alpha.4(发布于数月前),而 Javalin 7.0.0-beta.1 已在 2026 年 1 月 2 日发布。建议升级到更新的测试版或等待 7.0.0 稳定版本发布,以获得更好的稳定性和文档支持。
🤖 Prompt for AI Agents
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/BtnNetworkOnline.java
around lines 89 - 95, Update the Javalin dependency from the old alpha to a
newer beta (at least 7.0.0-beta.1) in your build configuration (e.g., pom.xml or
build.gradle) so the code using javalin().unsafe.routes.get(...) remains aligned
with the v7 migration; after bumping the dependency, run a full build and tests
and verify that BtnNetworkOnline.onEnable() (and other modules using
javalin().unsafe.routes) still compile and behave correctly under the new
Javalin version, adjusting imports or route API usage only if compilation errors
reveal any breaking changes.
| webContainer.javalin().unsafe.routes | ||
| .get("/api/modules/" + getConfigName(), this::handleConfig, Role.USER_READ) | ||
| .get("/api/modules/" + getConfigName() + "/status", this::handleStatus, Role.USER_READ); |
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.
🧩 Analysis chain
🏁 Script executed:
cat -n src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/MultiDialingBlocker.java | head -100Repository: PBH-BTN/PeerBanHelper
Length of output: 4496
🏁 Script executed:
rg "\.unsafe\.routes\b" src/main/java/ -A 2 -B 1Repository: PBH-BTN/PeerBanHelper
Length of output: 18007
Javalin v7 路由迁移正确,但第 89 行存在拼写错误。
第 57-59 行使用 unsafe.routes 进行路由注册符合 Javalin v7 迁移模式,与整个项目的其他模块保持一致。
但第 89 行存在 bug:
config.put("tolerateNumV5", tolerateNumV6);应改为:
config.put("tolerateNumV6", tolerateNumV6);配置键名应与值对应(参考第 88 行的 tolerateNumV4 模式)。
🤖 Prompt for AI Agents
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/MultiDialingBlocker.java
around lines 57 - 59, The config map is using the wrong key for the V6 tolerance
value: replace the incorrect key used in the config.put call so the key matches
the value (use "tolerateNumV6" when putting the tolerateNumV6 variable), i.e.
find the config.put("tolerateNumV5", tolerateNumV6) invocation and change the
first argument to "tolerateNumV6" to match the pattern used for other entries
like tolerateNumV4.
| webContainer.javalin().unsafe.routes | ||
| .get("/api/modules/" + getConfigName(), this::handleWebAPI, Role.USER_READ); |
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.
🧩 Analysis chain
🏁 Script executed:
fd -type f -name "JavalinWebContainer.java" | head -5Repository: PBH-BTN/PeerBanHelper
Length of output: 235
🏁 Script executed:
rg -n "unsafe\.routes" --type java -A 2 -B 2Repository: PBH-BTN/PeerBanHelper
Length of output: 21675
🏁 Script executed:
fd -type f -name "*.java" | xargs rg -l "class JavalinWebContainer"Repository: PBH-BTN/PeerBanHelper
Length of output: 322
🏁 Script executed:
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | head -100Repository: PBH-BTN/PeerBanHelper
Length of output: 5686
🏁 Script executed:
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | grep -A 5 "public.*javalin()"Repository: PBH-BTN/PeerBanHelper
Length of output: 287
🏁 Script executed:
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | tail -150Repository: PBH-BTN/PeerBanHelper
Length of output: 6517
🏁 Script executed:
rg -n "unsafe" --type java src/main/java/com/ghostchu/peerbanhelper/web/ -B 2 -A 2Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
fd -name "pom.xml" -o -name "build.gradle" | head -5 | xargs cat | rg -i "javalin|version" -A 1 -B 1Repository: PBH-BTN/PeerBanHelper
Length of output: 295
🏁 Script executed:
rg "unsafe" --type java src/main/java/com/ghostchu/peerbanhelper/web/ -B 2 -A 2Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
find . -name "pom.xml" -o -name "build.gradle.kts" -o -name "build.gradle" | head -1 | xargs cat 2>/dev/null | head -200Repository: PBH-BTN/PeerBanHelper
Length of output: 6468
🏁 Script executed:
web_search
"Javalin 7.0.0 unsafe routes API documentation"Repository: PBH-BTN/PeerBanHelper
Length of output: 199
🏁 Script executed:
web_search
"Javalin 7 alpha 4 router.get() route registration"Repository: PBH-BTN/PeerBanHelper
Length of output: 203
🌐 Web query:
Javalin 7.0.0 alpha 4 unsafe.routes API documentation
💡 Result:
I can't find any unsafe.routes API in Javalin 7.0.0-alpha4. The official Javalin docs and repository (current docs + Javalin 7 redesign discussion) don't show an unsafe.routes API or symbol. [1][2]
- Javalin documentation (main site). [1]
- Javalin 7 API redesign discussion on GitHub (no
unsafe.routessymbol shown). [2]
If you meant something else (e.g., a different library, a Javalin plugin, or a similarly named feature in another project like Nebula's unsafe_routes), tell me which project/version and I'll look it up.
Sources:
[1] javalin.io/documentation.
[2] github.com/javalin/javalin/issues/2091.
🌐 Web query:
Javalin 7 router.get() route registration API
💡 Result:
Summary — Javalin 7 route registration (router.get):
-
In Javalin 7 routing is done via the router on the Javalin config (or directly on the Javalin instance). Use config.router.get(path, handler) (or app.router.get(...) when you have the router available) to register GET routes. Example (Java):
var app = Javalin.create(config -> {
config.router.get("/hello", ctx -> ctx.result("Hello, World!"));
}).start(7070);
[1] (javalin.io) -
You can also group routes with apiBuilder/path-style DSL (ApiBuilder.get(...) or inside config.router.apiBuilder / path blocks) for nested routing and cleaner organization. Example (Kotlin):
config.router.apiBuilder {
path("/users") {
get(UserController::getAllUsers)
path("/{id}") { get(UserController::getUser) }
}
}
[1] (javalin.io) -
The Javalin 7 API was intentionally redesigned so routing methods live on the router (config.router / app.router) instead of being direct top-level Javalin methods; see the API redesign discussion for rationale and examples. [2] (github.com)
If you want, I can paste full Java/Kotlin snippets for mounting, middleware (before/after), error/exception handlers, and router options (contextPath, caseInsensitiveRoutes, ignoreTrailingSlashes). [1][2] (javalin.io)
Citations:
- 1: https://javalin.io/documentation?utm_source=openai
- 2: https://javalin.io/documentation?utm_source=openai
- 3: Javalin 7 API redesign javalin/javalin#2091
- 4: https://javalin.io/documentation?utm_source=openai
🏁 Script executed:
rg "\.unsafe" --type java -l | head -10Repository: PBH-BTN/PeerBanHelper
Length of output: 864
🏁 Script executed:
rg "class.*unsafe|interface.*unsafe" --type java -iRepository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
rg "unsafe\s*=" --type java -B 3 -A 3Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
rg "public.*unsafe|private.*unsafe" --type javaRepository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
rg "\.routes\s*\." --type java -B 2 | head -40Repository: PBH-BTN/PeerBanHelper
Length of output: 885
🏁 Script executed:
python3 << 'EOF'
# Check if unsafe.routes is a standard Javalin 7 API by examining the pattern
import subprocess
import re
# Search for all unsafe.routes usage
result = subprocess.run(['rg', 'unsafe\\.routes', '--type', 'java'],
capture_output=True, text=True)
lines = result.stdout.strip().split('\n')
# Count unique patterns
patterns = {}
for line in lines:
if '-' in line:
continue # Skip context lines
# Extract the pattern after unsafe.routes
match = re.search(r'unsafe\.routes\.(\w+)', line)
if match:
method = match.group(1)
patterns[method] = patterns.get(method, 0) + 1
print("Methods called on unsafe.routes:")
for method, count in sorted(patterns.items(), key=lambda x: -x[1]):
print(f" .{method}() - {count} times")
print(f"\nTotal usage: {len([l for l in lines if '-' not in l])}")
EOFRepository: PBH-BTN/PeerBanHelper
Length of output: 151
🏁 Script executed:
rg "state\." --type java src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java -B 2 -A 2Repository: PBH-BTN/PeerBanHelper
Length of output: 718
🏁 Script executed:
web_search
"Javalin 7 alpha Unsafe API state.routes"Repository: PBH-BTN/PeerBanHelper
Length of output: 193
🌐 Web query:
Javalin 7 alpha unsafe routes API JavalinState
💡 Result:
Short answer: in Javalin 7 the old "unsafe routes" / JavalinState APIs were removed as part of the API redesign — routing is exposed through the new routing API on Javalin (the redesigned routing/Javalin instance APIs) instead. See the Javalin 7 API redesign discussion and the 7.x javadoc for the new routing API. [1][2]
Links:
- Javalin 7 API redesign issue (explains the breaking changes / redesign). [1]
- javadoc for Javalin 7 (shows the new Javalin/routing API and current classes). [2]
If you want, tell me which specific unsafeRoutes/JavalinState call you used and I’ll show the exact 7.x replacement.
🏁 Script executed:
grep -r "unsafe" src/main/java --include="*.java" | head -20Repository: PBH-BTN/PeerBanHelper
Length of output: 2677
🏁 Script executed:
rg "Javalin\|javalin()" src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlacklist.java -B 5 -A 5Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
cat -n src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlacklist.java | sed -n '50,70p'Repository: PBH-BTN/PeerBanHelper
Length of output: 794
使用了已在 Javalin v7 中移除的内部 API unsafe.routes
unsafe.routes 是已在 Javalin 7 API 重新设计中被明确移除的内部 API。官方 Javalin 7 的路由注册应使用 config.router.get() 或 app.router.get() 方式。此模式在项目中被广泛使用(40+ 处),需要统一迁移至官方 Javalin 7 路由 API 以确保与稳定版本的兼容性。
🤖 Prompt for AI Agents
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlacklist.java
around lines 57 - 58, The code uses the removed Javalin v7 internal API
unsafe.routes; replace the registration in PeerIdBlacklist that currently calls
webContainer.javalin().unsafe.routes.get(...) with the official Javalin 7 router
API (e.g., webContainer.javalin().config().router().get(...) or
webContainer.javalin().router().get(...)) and pass the same endpoint path
("/api/modules/" + getConfigName()), the same handler (this::handleWebAPI) and
the same role (Role.USER_READ) so routing is registered via the public API
instead of unsafe.routes.
| webContainer.javalin().unsafe.routes | ||
| .get("/api/modules/" + getConfigName(), this::handleConfig, Role.USER_READ); |
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.
🧩 Analysis chain
🏁 Script executed:
# First, let's check the file content around lines 97-98
cd /tmp/repo 2>/dev/null || cd ~ && find . -name "ProgressCheatBlocker.java" -type f 2>/dev/null | head -1Repository: PBH-BTN/PeerBanHelper
Length of output: 154
🏁 Script executed:
# If found, read the file
if [ -f "src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java" ]; then
cat -n "src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java" | sed -n '85,110p'
fiRepository: PBH-BTN/PeerBanHelper
Length of output: 1004
🏁 Script executed:
# Search for other route registrations in the codebase to understand the pattern
rg "\.routes\.get\(" --type java -n | head -20Repository: PBH-BTN/PeerBanHelper
Length of output: 265
🏁 Script executed:
# Also search for unsafe.routes usage
rg "\.unsafe\.routes" --type java -n | head -20Repository: PBH-BTN/PeerBanHelper
Length of output: 2826
🌐 Web query:
Javalin v7 unsafe routes API migration recommended pattern
💡 Result:
Short answer — stop using the old "unsafe" direct-route API and register routes via Javalin's router or plugins. Recommended patterns for v7:
- Add routes in the create/config phase via the router apiBuilder (instead of calling unsafe route mutators after start):
- Kotlin: config.router.apiBuilder { get("/x") { ctx -> ... } }.
- Java: config.router.apiBuilder(() -> { get("/x", ctx -> ...); }).
- Alternatively encapsulate and register route sets as plugins (implement/register a plugin or use generated route adapters and call config.registerPlugin(...) / config.plugins.register(...)).
- For cross-cutting concerns (auth, before/after), use beforeMatched / access checks in config rather than global unsafe handlers.
References:
- Javalin migration guide (v5→v6) showing router.apiBuilder and moving routes into config. [1]
- Javalin v7 API redesign discussion (design/intent to move/centralize route registration, plugins). [2]
If you want, tell me whether you need a concrete Kotlin or Java code example for migrating your current unsafe-route usage and I’ll produce it.
🌐 Web query:
Javalin v7 route registration API changes from v6
💡 Result:
Quick summary of the route-registration / routing-related API changes from Javalin 6 → 7 (most important breaking/behavioral changes):
- Routing moved further into the config/router layer — you should register routes via the config’s router (apiBuilder / router) rather than calling many route-related methods directly on the Javalin instance. This continues the pattern introduced in v6. [1][2]
- “Routes” lifecycle and context stages tightened: before/endpoint/after have clearer distinct context types (BeforeContext / EndpointContext / AfterContext) and an endpoints-stack was added so Context no longer “lies” about available features at different stages. Adjust handlers that relied on previously shared Context behavior. [1]
- matchedPath / matched-route naming changed: matchedPath behavior was clarified/renamed (ctx.endpoint()?.path) — code that used matchedPath/matchedRoute should switch to the new endpoint API. [1]
- Javalin vs StartedJavalin split and API relocation: creation/start semantics and some formerly instance-level methods were moved to JavalinConfig (so calls you previously did on the Javalin instance may now live on config or router). Update call-sites accordingly. [1][3]
- Jetty & artifact/package upgrades (Jetty 12 in v7) caused package/artifact renames that can affect imports in examples demonstrating route registration; expect to update imports/dependencies when migrating. [3]
References / reading:
- Javalin 7 API redesign (GitHub issue describing API moves, endpoints-stack, context changes). [1]
- Javalin migration docs demonstrating the pattern of moving routes into config.router (example of apiBuilder moved in v5→v6 — same pattern continued). [2]
- Javalin blog post covering the Javalin 7 release work (Jetty 12 migration, migration tasks and examples). [3]
If you want, I can:
- produce a concrete before/after code diff for your v6 route setup to v7, or
- scan your code and show exact changes to make. Which would you prefer?
Javalin v7 路由注册 API 应使用 router.apiBuilder 而非 unsafe.routes。
代码当前使用 webContainer.javalin().unsafe.routes 模式,但根据 Javalin v7 官方文档,.unsafe API 明确不是推荐方式。Javalin v7 的正确做法是在配置阶段通过 config.router.apiBuilder() 注册路由,或采用插件模式注册路由集。
建议重构为:
// 在 Javalin 配置阶段
config.router.apiBuilder(() -> {
get("/api/modules/" + getConfigName(), this::handleConfig, Role.USER_READ);
});这个模式变更从 v6→v7 延续,目的是将路由注册集中到配置层而非使用不安全的运行时 API 调用。此外,这个问题影响项目中的所有路由注册文件(20+ 个文件均使用 .unsafe.routes),建议项目范围内统一迁移。
🤖 Prompt for AI Agents
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java
around lines 97 - 98, The code uses the unsafe runtime API
(webContainer.javalin().unsafe.routes) to register routes; replace this with the
Javalin v7 config-time router registration by moving the GET registration into
the router.apiBuilder during Javalin configuration so the route for
"/api/modules/" + getConfigName() that calls this::handleConfig with
Role.USER_READ is registered via config.router.apiBuilder(...) instead of
webContainer.javalin().unsafe.routes; apply the same change for other files
using .unsafe.routes to centralize route setup in the configuration phase.
| webContainer.javalin().unsafe.routes | ||
| .get("/blocklist/ip", this::blocklistIp) | ||
| .get("/blocklist/p2p-plain-format", this::blocklistP2pPlain, Role.ANYONE) | ||
| .get("/blocklist/dat-emule", this::blocklistDatEmule, Role.ANYONE); |
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.
🧩 Analysis chain
🏁 Script executed:
# First, locate and examine the BlockListController file
find . -name "BlockListController.java" -type fRepository: PBH-BTN/PeerBanHelper
Length of output: 151
🏁 Script executed:
# Check the context around lines 34-37 in the file
sed -n '1,50p' src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/BlockListController.javaRepository: PBH-BTN/PeerBanHelper
Length of output: 1854
🏁 Script executed:
# Search for other route registrations to understand the pattern
rg -n "\.get\(" src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/ -A 2 --type=java | head -100Repository: PBH-BTN/PeerBanHelper
Length of output: 11847
🏁 Script executed:
# Look for default role or role handling patterns
rg -n "Role\." src/main/java/com/ghostchu/peerbanhelper/ --type=java -B 2 -A 2 | head -150Repository: PBH-BTN/PeerBanHelper
Length of output: 19553
/blocklist/ip 端点缺少角色权限指定。
相比之下,其他两个端点(/blocklist/p2p-plain-format 和 /blocklist/dat-emule)均明确指定了 Role.ANYONE。请为 /blocklist/ip 添加相应的角色权限参数,以保持一致性。建议指定为 Role.ANYONE(如果应公开访问)或 Role.USER_READ(如果需要认证)。
🤖 Prompt for AI Agents
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/BlockListController.java
around lines 34 - 37, The GET route registration for "/blocklist/ip" on
webContainer.javalin().unsafe.routes is missing a role parameter; update the
.get call that currently reads .get("/blocklist/ip", this::blocklistIp) to
include the appropriate Role (e.g., Role.ANYONE for public access or
Role.USER_READ for authenticated reads) to match the other endpoints
(.get("/blocklist/p2p-plain-format", this::blocklistP2pPlain, Role.ANYONE) and
.get("/blocklist/dat-emule", this::blocklistDatEmule, Role.ANYONE)).
| webContainer.javalin().unsafe.routes | ||
| .get("/api/logs/history", this::handleLogs, Role.USER_WRITE) | ||
| .ws("/api/logs/stream", this::handleLogsStream, Role.USER_WRITE); |
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.
🧩 Analysis chain
🌐 Web query:
Javalin 7 route registration API unsafe.routes
💡 Result:
Do you mean Javalin 7's route-registration API (how to register routes in Javalin 7), or a specific property/method named "unsafe.routes"? I can look up Javalin 7 docs and show the exact API and examples—which would you like?
🌐 Web query:
Javalin 7.0.0-alpha.4 release status
💡 Result:
Javalin 7.0.0-alpha.4 was published to Maven Central on December 15, 2025 (artifacts present for core and modules). Note: a 7.0.0-beta.1 artifact was later published on January 2, 2026. [1][2]
Sources:
- Maven Central (io.javalin:javalin) listing. [1]
- Maven Central (io.javalin:javalin-rendering / javalin-testtools) listings showing alpha.4 and beta.1. [2]
🏁 Script executed:
# Check the actual Javalin version used in the project
find . -name "pom.xml" -o -name "build.gradle" | head -5 | xargs grep -l "javalin" 2>/dev/null | head -1 | xargs cat | grep -A 5 -B 5 "javalin"Repository: PBH-BTN/PeerBanHelper
Length of output: 47
🏁 Script executed:
# Look for other route registration patterns in the codebase to verify consistency
rg "unsafe\.routes\.(get|post|ws|put|delete)" --type javaRepository: PBH-BTN/PeerBanHelper
Length of output: 262
🌐 Web query:
Javalin 7 route registration migration guide from v6
💡 Result:
I can help — do you want a concise checklist of the breaking changes for route registration (examples + before/after code) or a full migration guide with links to the official Javalin 7 docs and release notes? If full, I’ll fetch the official migration docs and examples now.
🌐 Web query:
Javalin 7 unsafe.routes API documentation
💡 Result:
I couldn't find any documented API called unsafe.routes in Javalin 7. For Javalin 7 reference material see the official docs and the Javadoc (7 beta) — and the Javalin 7 API redesign discussion on GitHub if you’re tracking API changes. [1][2][3]
Sources:
- Javalin documentation (latest). [1]
- Javadoc for io.javalin (7.0.0-beta.1). [2]
- Javalin 7 API redesign (GitHub issue). [3]
🏁 Script executed:
# Find and read the pom.xml or build file
find . -type f \( -name "pom.xml" -o -name "build.gradle.kts" -o -name "build.gradle" \) | head -1 | xargs cat | grep -A 10 javalinRepository: PBH-BTN/PeerBanHelper
Length of output: 430
🏁 Script executed:
# Search for more route registration patterns to understand the full scope
rg "webContainer\.javalin\(\)" --type java -A 2 | head -50Repository: PBH-BTN/PeerBanHelper
Length of output: 5726
🌐 Web query:
Javalin 7 GitHub issue API redesign route registration
💡 Result:
There's an open GitHub issue describing the Javalin 7 API redesign that proposes moving route-registration methods (get/post/before/after/etc.) from Javalin instance into the config's router (e.g., config.router.get(...) and app.router.get(...)), with example code and discussion. See the issue for full details and examples. [1]
Links:
- Javalin 7 API redesign (GitHub issue #2091). [1]
- Javalin repository. [2]
Sources:
[1] javalin/javalin#2091
[2] https://github.com/javalin/javalin
🌐 Web query:
Javalin "unsafe.routes" internal API
💡 Result:
Short answer: "unsafe.routes" is not a supported public API in Javalin — it's an internal/unsafe surface that may change or be removed. Use the public routing APIs (Javalin/JavalinDefaultRoutingApi, ApiBuilder, app.routes(), RouteOverviewPlugin, etc.) or the RouteOverview plugin to inspect routes instead. [1][2][3]
Sources:
- Javalin documentation (config/Router and note about private/pvt options). [1]
- RouteOverview / RouteOverviewPlugin docs (inspect routes via supported plugin). [2]
- Javalin GitHub repository (project source; internal APIs can change between releases). [3]
If you want, tell me which Javalin version you’re on and I’ll look for any specific internal members named "unsafe.routes" in that release.
🏁 Script executed:
# Check if there are any comments or documentation in the code about the unsafe API
rg "unsafe" --type java -B 2 -A 2 | head -60Repository: PBH-BTN/PeerBanHelper
Length of output: 6672
🏁 Script executed:
# Look at the git history or any comments around the first usage of unsafe.routes
find . -type f -name "*.java" -path "*/webapi/*" -o -path "*/rule/*" | xargs grep -l "unsafe.routes" | head -1 | xargs cat | head -100Repository: PBH-BTN/PeerBanHelper
Length of output: 3544
unsafe.routes 是 Javalin 7 的内部/非公开 API,不应使用。
根据官方 Javalin 7 文档和 GitHub API 重设计讨论(issue #2091),unsafe.routes 是一个内部且非受支持的 API,官方明确声明该 API 可能在任何版本中被修改或移除。Javalin 7 推荐的路由注册方式是使用 app.router.get(...) 或 config.router.get(...) 等公开 API。
代码在 15+ 个模块和控制器中使用了 unsafe.routes 进行路由注册,这在使用 alpha 版本时会带来严重的稳定性风险。该内部 API 的任何变更都将导致应用崩溃。
建议迁移至官方推荐的公开路由 API,而非依赖不稳定的内部接口。
🤖 Prompt for AI Agents
In
@src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/PBHLogsController.java
around lines 44 - 46, The code uses the internal unsafe.routes API on
webContainer.javalin(), which must be replaced with Javalin 7's public router
API; update the registration of the HTTP and WebSocket routes for handleLogs and
handleLogsStream (and preserve Role.USER_WRITE) to use the supported router
methods (e.g. app/router.get(...) and the published ws registration) instead of
unsafe.routes so the routes are registered via the public API rather than
webContainer.javalin().unsafe.routes; ensure you call the public router off the
Javalin instance returned by webContainer.javalin() and keep the same handlers
(handleLogs, handleLogsStream) and permission Role.USER_WRITE.
| var state = c.getState$javalin(); | ||
| state.concurrency.useVirtualThreads = true; | ||
| c.startup.startupWatcherEnabled = false; |
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.
🧩 Analysis chain
🏁 Script executed:
# Read the JavalinWebContainer.java file to understand the context
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | head -100Repository: PBH-BTN/PeerBanHelper
Length of output: 5686
🌐 Web query:
Javalin 7 virtual threads configuration official API
💡 Result:
Short answer — enable Javalin’s built‑in virtual‑thread support in the config:
-
Kotlin:
val app = Javalin.create { cfg -> cfg.useVirtualThreads = true }.start(7000) [1][2] -
Java (equivalent):
Javalin app = Javalin.create(cfg -> cfg.setUseVirtualThreads(true)).start(7000); [1][2]
Notes:
- That makes Javalin use a virtual‑thread-per‑task executor for request handling; you can still customize Jetty’s thread setup (e.g., supply a QueuedThreadPool with a virtual‑threads executor) if you need bounded control. [3][4]
Sources:
- Javalin docs — Configuration / useVirtualThreads. [1]
- Javalin migration guide (virtual threads are opt‑in; use config.useVirtualThreads = true). [2]
- Javalin examples / GitHub showing config.useVirtualThreads usage. [4]
- Jetty docs — configuring QueuedThreadPool with virtual‑threads executors. [3]
🌐 Web query:
Javalin 7.0 release configuration concurrency virtual threads
💡 Result:
Short answer
- As of Jan 13, 2026 there is no stable Javalin 7.0 release; 7.0 has pre-releases on Maven (alpha/beta artifacts up to 7.0.0-beta.1). [1][2]
- Concurrency/virtual-thread handling in Javalin remains configurable: Javalin will use virtual threads when you enable them in the config (and run on a JDK that supports Loom); otherwise it falls back to a Jetty QueuedThreadPool. Enable with config.useVirtualThreads = true (Java/Kotlin config object). [3][4]
What to do (example)
-
Enable virtual threads:
- Java: Javalin.create(cfg -> cfg.useVirtualThreads = true) ...
- Kotlin: Javalin.create { it.useVirtualThreads = true } ...
This makes Javalin use a newVirtualThreadPerTaskExecutor (when the JDK supports it). [3][4]
-
If you want to control Jetty thread pool instead of virtual threads, supply your own server (QueuedThreadPool or custom Server) via the config.server / config.jetty options. Example pattern: config.server(() -> new Server(new QueuedThreadPool(maxThreads, minThreads))). [3][5]
Caveats
- Virtual threads must be supported/available in your JDK and can change semantics for blocking code. If you hit thread-exhaustion/unresponsiveness with Loom enabled, you can disable it (config.useVirtualThreads = false) or provide a custom executor/server. [4][5]
Sources
- Maven central listing for io.javalin showing 7.0 pre-releases (alpha/beta). [repo listing]. [2]
- Javalin docs (current site) — configuration and concurrency / useVirtualThreads option. [3]
- Javalin migration docs and archived docs discussing virtual threads, default fallback to QueuedThreadPool and how to disable or override. [4][5]
Would you like a concrete code snippet for your project (Java or Kotlin) using virtual threads or a custom Jetty thread pool?
使用 Javalin 官方 API 配置虚拟线程,避免内部 API。
getState$javalin() 是 Javalin 内部 API(Kotlin 编译器生成的内部方法,$ 符号表明这一点)。根据官方文档,配置虚拟线程的推荐方式是直接在配置对象上使用公开 API:
Javalin app = Javalin.create(cfg -> cfg.useVirtualThreads(true))请将 getState$javalin() 调用替换为官方公开 API,以确保代码的稳定性和可维护性。
🤖 Prompt for AI Agents
In @src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java around
lines 76 - 78, The code uses the internal method getState$javalin() to toggle
virtual threads and startup watcher; replace this with the public Javalin
configuration API by creating or updating the Javalin configuration to call
cfg.useVirtualThreads(true) (or equivalent on the Config object) instead of
accessing c.getState$javalin(), and set the startup watcher flag via the public
config (e.g., config.startup().startupWatcherEnabled = false) so that
getState$javalin() is removed and configuration is done through the official
Javalin.create(cfg -> ...) / Config APIs.
| staticFiles.directory = new File(Main.getDataDirectory(), "static").getPath(); | ||
| staticFiles.location = Location.EXTERNAL; | ||
| staticFiles.precompress = false; | ||
| staticFiles.precompressMaxSize = -1; |
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.
🧩 Analysis chain
🌐 Web query:
Javalin 7 staticFiles precompressMaxSize documentation
💡 Result:
I couldn't find any Javalin documentation or source mentioning a staticFiles.precompressMaxSize setting. The official staticFiles options documented are e.g. precompress (boolean), directory, hostedPath, headers, skipFileFunction, etc. [1] (javalin.io)
There is an open Javalin 7 API redesign discussion but it doesn't document a precompressMaxSize option. If you saw that name elsewhere, please share the link and I can check it. [2] (github.com)
Sources:
- Javalin documentation (StaticFileConfig / staticFiles). [1] (javalin.io)
- Javalin 7 API redesign issue on GitHub. [2] (github.com)
Citations:
- 1: https://javalin.io/documentation?utm_source=openai
- 2: Javalin 7 API redesign javalin/javalin#2091
- 3: https://javalin.io/documentation?utm_source=openai
- 4: Javalin 7 API redesign javalin/javalin#2091
🏁 Script executed:
# First, let's examine the file to understand the context
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | sed -n '80,100p'Repository: PBH-BTN/PeerBanHelper
Length of output: 186
🏁 Script executed:
# Search for related precompress references in the codebase
rg "precompress|precompressMaxSize" --type javaRepository: PBH-BTN/PeerBanHelper
Length of output: 334
🏁 Script executed:
# Get broader context around line 89
cat -n src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | sed -n '75,110p'Repository: PBH-BTN/PeerBanHelper
Length of output: 2740
🏁 Script executed:
# Check imports and class definition to understand custom configuration
head -n 80 src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java | cat -nRepository: PBH-BTN/PeerBanHelper
Length of output: 4116
precompressMaxSize = -1 不是 Javalin v7 的有效配置选项。
根据 Javalin v7 官方文档,staticFiles 的有效配置选项是 precompress(布尔值)、directory、hostedPath、headers 和 skipFileFunction 等,不包含 precompressMaxSize。设置 precompressMaxSize = -1 将被 Javalin 忽略,无法实现禁用预压缩的预期效果。
建议改用文档中的官方选项:staticFiles.precompress = false;
🤖 Prompt for AI Agents
In @src/main/java/com/ghostchu/peerbanhelper/web/JavalinWebContainer.java at
line 89, The config uses an invalid Javalin v7 option
staticFiles.precompressMaxSize; in JavalinWebContainer replace that setting with
the supported option staticFiles.precompress = false to disable precompression
(update the staticFiles configuration block where staticFiles.precompressMaxSize
is set). Ensure you remove the precompressMaxSize assignment and set
staticFiles.precompress to false so Javalin honors the disabled precompress
behavior.
Summary by CodeRabbit
发布说明
新功能
错误修复
重构
✏️ Tip: You can customize this high-level summary in your review settings.