Refactor API integration to use config module#2067
Conversation
deadlyjack
commented
Apr 28, 2026
- Replaced instances of constants with config module for API_BASE and related URLs in sponsor, sponsors, themeSetting, welcome, and various settings files.
- Updated logic to check for premium features based on config settings.
- Enhanced Authenticator plugin to intercept requests and manage authentication tokens more effectively.
- Fixed minor typos and improved code readability in sidebarApp and helpers.
- Replaced instances of constants with config module for API_BASE and related URLs in sponsor, sponsors, themeSetting, welcome, and various settings files. - Updated logic to check for premium features based on config settings. - Enhanced Authenticator plugin to intercept requests and manage authentication tokens more effectively. - Fixed minor typos and improved code readability in sidebarApp and helpers.
Greptile SummaryThis PR refactors the codebase to use a new
Confidence Score: 2/5Not safe to merge — the auth interceptor silently fails on any non-2xx response and the ad-reward identity function is entirely broken. Three P1 issues on core auth and monetization paths: broken getRewardIdentity (undeclared variable + missing return), HttpURLConnection.getInputStream() crash on error responses, and missing request-body forwarding in the interceptor. src/plugins/auth/src/android/Authenticator.java and src/lib/adRewards.js require fixes before merging. Important Files Changed
|
| return new WebResourceResponse( | ||
| conn.getContentType(), | ||
| conn.getContentEncoding(), | ||
| conn.getResponseCode(), | ||
| conn.getResponseMessage(), | ||
| responseHeaders, | ||
| conn.getInputStream() | ||
| ); |
There was a problem hiding this comment.
getInputStream() throws for non-2xx responses
HttpURLConnection.getInputStream() throws IOException for 4xx/5xx status codes. A 401 Unauthorized response causes the catch to fire and fall back to super.shouldInterceptRequest(), retrying without the auth token. JavaScript's fetch receives an unauthenticated response, breaking the res.status === 401 check in auth.getLoggedInUser() and preventing proper session invalidation. Use conn.getErrorStream() for non-2xx codes.
| if (url.startsWith("https://acode.app/api") || url.startsWith("https://dev.acode.app/api")) { | ||
| try { | ||
| HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); | ||
| conn.setRequestMethod(request.getMethod()); | ||
|
|
||
| for (Map.Entry<String, String> header : request.getRequestHeaders().entrySet()) { | ||
| conn.setRequestProperty(header.getKey(), header.getValue()); | ||
| } | ||
|
|
||
| String token = prefManager.getString(KEY_TOKEN, ""); | ||
| if (!token.isEmpty()) { | ||
| conn.setRequestProperty("x-auth-token", token); | ||
| } |
| try { | ||
| HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); | ||
| conn.setRequestMethod(request.getMethod()); |
| ) { | ||
| // Use fsOperation for Acode registry URL |
There was a problem hiding this comment.