Commit Graph

85 Commits

Author SHA1 Message Date
CaIon 209645e26b feat(topup-log): add NODE_NAME env var for audit logs
Introduce NODE_NAME environment variable to identify node identity in top-up
audit logs, improving readability over auto-detected container internal IPs
in Docker/K8s deployments. Surface node_name in admin expanded log rows and
add it as a commented example to docker-compose.yml.
2026-04-18 00:51:04 +08:00
CaIon c31343ac76 fix(log): hide admin identity in user-visible management logs
Admin username/ID was embedded directly into the log Content for
quota changes and forced 2FA disable, leaking the operator's
identity to the target user via their own usage log page.

Move operator info into Other.admin_info so formatUserLogs strips
it for non-admin viewers, and render it in the expand panel only
for admins as "操作管理员".

Closes #4301
2026-04-18 00:16:52 +08:00
CaIon 209d90e861 feat(topup): add admin-only audit info to top-up logs
Thread caller IP from webhook/admin controllers through model recharge
functions and record a new RecordTopupLog entry with admin_info (server
IP, caller IP, order payment method, callback payment method, system
version). Frontend shows these fields in the expanded log row and the
IP column for admins on top-up logs, while non-admins continue to see
admin_info stripped by formatUserLogs.
2026-04-17 23:51:30 +08:00
CaIon 5238f279db feat: record stream interruption reasons via StreamStatus
- Add StreamStatus type (relay/common) to track stream end reason
  (done/timeout/client_gone/scanner_error/eof/panic/ping_fail) and
  accumulate soft errors during streaming via sync.Once + sync.Mutex.
- Add StreamResult (relay/helper) as the callback interface: adapters
  call sr.Error() for soft errors, sr.Stop() for fatal, sr.Done() for
  normal completion. No early-return problem — multiple errors per chunk
  are naturally supported.
- Refactor StreamScannerHandler callback from func(string) bool to
  func(string, *StreamResult). All 9 channel adapters updated.
- Write stream_status into log other JSON field (admin-only) with
  status ok/error, end_reason, error_count, and error messages.
- Frontend: display stream status in log detail expansion for admins.
2026-03-31 16:54:39 +08:00
CaIon 2b3bfd4e1e feat: implement caching for channel retrieval 2026-02-23 14:11:11 +08:00
CaIon 64d18a5fdf refactor(logs): add refund logging for asynchronous tasks and update translations 2026-02-22 16:01:19 +08:00
CaIon bdacc5af3f 🔧 refactor: Enhance Log struct indexing for improved query performance 2026-02-07 23:20:43 +08:00
CaIon 8580d76d58 🔧 refactor: Update formatUserLogs function to accept start index
Modified the formatUserLogs function to include a startIdx parameter, allowing for more flexible log ID assignment. Updated calls to this function in GetLogByTokenId and GetUserLogs to pass the appropriate starting index.
2026-02-07 22:51:26 +08:00
CaIon 5cf788f1bf refactor: enhance API security with read-only token authentication and improved rate limiting 2026-02-06 21:26:26 +08:00
Seefs 3d529b4eea feat: capture request_id, filter by request_id, show request_conversion 2026-02-04 14:47:42 +08:00
Seefs a6a0e694b2 The conversion path is displayed to users by default. 2026-02-04 02:17:30 +08:00
Seefs 3570bc2d83 feat: log search field request_id 2026-02-04 02:12:18 +08:00
Seefs 68e1e635e9 feat: logs show reject reason 2026-01-25 14:52:18 +08:00
Seefs 38791fa46d feat: log shows request conversion 2026-01-20 23:43:29 +08:00
CaIon 812ab67780 refactor: replace iota with explicit values for log type constants 2025-10-15 19:54:13 +08:00
CaIon b9c2089d37 fix 2025-10-15 19:46:06 +08:00
CaIon 31e09b960f refactor: aws 2025-10-15 16:44:33 +08:00
Seefs 5010f2d004 format: package name -> github.com/QuantumNous/new-api (#2017) 2025-10-11 15:30:09 +08:00
CaIon 4e3f008ae9 fix: update token usage calculation 2025-08-16 19:11:15 +08:00
CaIon c9e9a24e99 refactor: centralize logging and update resource initialization
This commit refactors the logging mechanism across the application by replacing direct logger calls with a centralized logging approach using the `common` package. Key changes include:

- Replaced instances of `logger.SysLog` and `logger.FatalLog` with `common.SysLog` and `common.FatalLog` for consistent logging practices.
- Updated resource initialization error handling to utilize the new logging structure, enhancing maintainability and readability.
- Minor adjustments to improve code clarity and organization throughout various modules.

This change aims to streamline logging and improve the overall architecture of the codebase.
2025-08-14 21:10:04 +08:00
CaIon 97ea8b6560 refactor: Introduce pre-consume quota and unify relay handlers
This commit introduces a major architectural refactoring to improve quota management, centralize logging, and streamline the relay handling logic.

Key changes:
- **Pre-consume Quota:** Implements a new mechanism to check and reserve user quota *before* making the request to the upstream provider. This ensures more accurate quota deduction and prevents users from exceeding their limits due to concurrent requests.

- **Unified Relay Handlers:** Refactors the relay logic to use generic handlers (e.g., `ChatHandler`, `ImageHandler`) instead of provider-specific implementations. This significantly reduces code duplication and simplifies adding new channels.

- **Centralized Logger:** A new dedicated `logger` package is introduced, and all system logging calls are migrated to use it, moving this responsibility out of the `common` package.

- **Code Reorganization:** DTOs are generalized (e.g., `dalle.go` -> `openai_image.go`) and utility code is moved to more appropriate packages (e.g., `common/http.go` -> `service/http.go`) for better code structure.
2025-08-14 20:05:06 +08:00
feitianbubu b3beb412bb fix: mySQL does not support default false 2025-07-18 13:52:16 +08:00
CaIon 1437ceaa56 Merge branch 'alpha' into refactor_error
# Conflicts:
#	controller/channel.go
#	middleware/distributor.go
#	model/channel.go
#	model/user.go
#	model/user_cache.go
#	relay/common/relay_info.go
2025-07-10 15:11:55 +08:00
Xiangyuan-liu db98c0f4b1 refactor: log params and channel params
refactor: log params and channel params
2025-07-07 14:26:37 +08:00
CaIon cf11a22c3a 🔧 refactor(auth, channel, context): improve context setup and validation for multi-key channels 2025-07-06 12:37:56 +08:00
CaIon 49cb5f3fa3 🐛 fix(log): optimize channel ID collection by using a map to prevent duplicates 2025-06-14 18:23:25 +08:00
CaIon 4371717c78 fix: Resolving conflicts caused by mixing multiple databases 2025-06-14 17:51:05 +08:00
Apple\Apple 28c3aef76f 🔒 feat: Add user-configurable IP logging for consume and error logs
- Add IP field to Log model with database index and default empty value
- Implement conditional IP recording based on user setting in RecordConsumeLog and RecordErrorLog
- Add UserSettingRecordIpLog constant and update user settings API to handle record_ip_log field
- Create dedicated "IP记录" tab in personal settings under "其他设置" section
- Add IP column to logs table with help tooltip explaining recording conditions
- Make IP column visible to all users (not admin-only) with proper filtering for consume/error log types
- Restrict display of use_time and retry columns to consume and error log types only
- Update personal settings UI structure: rename "通知设置" to "其他设置" to accommodate new functionality
- Add proper translation support and maintain consistent styling across components

The IP logging feature is disabled by default and only records client IP addresses
for consume (type 2) and error (type 5) logs when explicitly enabled by users
in their personal settings.
2025-06-13 01:34:01 +08:00
wzxjohn 45073b3b2b feat: improve log delete api 2025-04-28 11:25:04 +08:00
jasonzeng 75f0cb8eb0 feat: add error logging functionality to relay and update logs table for error type display 2025-04-12 00:43:34 +08:00
1808837298@qq.com 35cd4fde3a refactor: Add index to Username column in Log model 2025-03-02 17:57:52 +08:00
1808837298@qq.com d04d78a116 refactor: Enhance user context and quota management
- Add new context keys for user-related information
- Modify user cache and authentication middleware to populate context
- Refactor quota and notification services to use context-based user data
- Remove redundant database queries by leveraging context information
- Update various components to use new context-based user retrieval methods
2025-02-25 20:56:16 +08:00
1808837298@qq.com 5665b1a58b refactor: Optimize log retrieval with separate channel name fetching (fix #751)
- Remove inline channel join in log queries
- Implement separate channel name lookup for logs
- Improve performance by fetching channel names in a single query
- Ensure channel names are correctly associated with logs
2025-02-12 19:19:13 +08:00
1808837298@qq.com 4470ef97f2 fix: clear channel name in user logs 2025-01-27 13:31:24 +08:00
1808837298@qq.com 1ae20bdd89 refactor: update log queries to explicitly reference 'logs' table for clarity and consistency 2025-01-22 13:37:32 +08:00
Lilo a335d9e1f4 Add channel name (tooltip / detail) to logs 2025-01-09 17:07:28 +08:00
CalciumIon 0a845ae69f fix: try to fix pgsql #682 2024-12-31 02:10:19 +08:00
CalciumIon aefd53b683 refactor: token cache logic 2024-12-30 17:10:48 +08:00
CalciumIon 966cdc1f7f refactor: user cache logic 2024-12-29 16:50:26 +08:00
CalciumIon c917ce64db refactor: streamline log processing by introducing formatUserLogs function 2024-12-28 16:40:29 +08:00
CalciumIon 9e25f05930 refactor: enhance log retrieval and user interaction in LogsTable component 2024-12-28 15:34:28 +08:00
CalciumIon 7e8adb5b34 feat: Enhance logging functionality with group support
- Added a new 'group' parameter to various logging functions, including RecordConsumeLog, GetAllLogs, and GetUserLogs, to allow for more granular log tracking.
- Updated the logs table component to display group information, improving the visibility of log data.
- Refactored related functions to accommodate the new group parameter, ensuring consistent handling across the application.
- Improved the initialization of the group column for PostgreSQL compatibility.
2024-12-24 14:48:11 +08:00
licoy 80e1dafa28 修复独立日志数据库查询令牌日志时错误问题 2024-11-12 16:22:13 +08:00
CalciumIon e77d94ca8d fix: log page 'Cannot read properties of undefined (reading 'length')' 2024-08-14 22:43:57 +08:00
Calcium-Ion a019acf9c2 Merge pull request #426 from OswinWu/fix-log-page
Fix log page
2024-08-13 17:50:03 +08:00
liuzhifei 3a6a30a811 support log db 2024-08-13 10:29:55 +08:00
Nothing. d3e6151747 Merge branch 'Calcium-Ion:main' into fix-log-page 2024-08-11 11:22:34 +08:00
OswinWu 8a51ae300e fix: log分页问题 2024-08-11 11:21:34 +08:00
CalciumIon 356e8a50df fix: close #422 2024-08-09 16:14:05 +08:00
CalciumIon d59bf0b0be feat: 优化日志查询条件 2024-08-01 16:33:59 +08:00