This commit modifies the ConsumeToken function in the token.go file to decrease the token quota by the specified amount. It replaces the previous code that directly updated the quota values with a call to the DecreaseTokenQuota function from the model package. This change improves code clarity and maintainability.
Closes#123
This commit adds a new endpoint `/token/consume` to the API router, allowing users to consume tokens from another source. It includes changes to the `token.go` file in the `controller` package.
- Refactor constant definitions and organization
- Clean up package level variables and functions
- Introduce new `relaymode` and `apitype` packages for constant definitions
- Refactor and simplify code in several packages including `openai`, `relay/channel/baidu`, `relay/util`, `relay/controller`, `relay/channeltype`
- Add helper functions in `relay/channeltype` package to convert channel type constants to corresponding API type constants
- Remove deprecated functions such as `ResponseText2Usage` from `relay/channel/openai/helper.go`
- Modify code in `relay/util/validation.go` and related files to use new `validator.ValidateTextRequest` function
- Rename `util` package to `relaymode` and update related imports in several packages
* feat: add user list sorting and pagination enhancements
* feat: add user list sorting for THEME=air
* feat: add token list sorting and pagination enhancements
* feat: add token list sorting for THEME=air
- Remove the unnecessary `AddRemainQuota` field from `updateTokenDto` struct
- Adjust `cleanToken.RemainQuota` by subtracting `tokenPatch.AddUsedQuota`
- Increase `cleanToken.UsedQuota` by adding `tokenPatch.AddUsedQuota`
- Update `model.RecordLog` call to include `tokenPatch.AddReason` and `tokenPatch.AddUsedQuota` values
- Add `gorm:"-"` tag to exclude certain fields from the database schema
- Add `AddReason` field to the `updateTokenDto` struct
- Record consumption log if `AddUsedQuota` is non-zero
- Record token quota modification log if `AddRemainQuota` is non-zero
- Update and save `cleanToken` with new values
- Updated base image in Dockerfile from `node:16` to `node:18`
- Added `tokenPatch` struct to handle updates to the `Token` model
- Updated `UpdateToken` function to use `tokenPatch` struct for binding JSON
- Improved error handling and validation for token updates
- Refined checks for token status, expiration, and quota
- Enhanced error handling and response for token updates
- Updated JSON response to include `data` field