mirror of
				https://github.com/songquanpeng/one-api.git
				synced 2025-11-04 07:43:41 +08:00 
			
		
		
		
	feat: increase initial root user quota and support INITIAL_ROOT_TOKEN now (#1105)
This commit is contained in:
		@@ -23,7 +23,7 @@ func CreateRootAccountIfNeed() error {
 | 
			
		||||
	var user User
 | 
			
		||||
	//if user.Status != util.UserStatusEnabled {
 | 
			
		||||
	if err := DB.First(&user).Error; err != nil {
 | 
			
		||||
		logger.SysLog("no user exists, create a root user for you: username is root, password is 123456")
 | 
			
		||||
		logger.SysLog("no user exists, creating a root user for you: username is root, password is 123456")
 | 
			
		||||
		hashedPassword, err := common.Password2Hash("123456")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
@@ -35,9 +35,25 @@ func CreateRootAccountIfNeed() error {
 | 
			
		||||
			Status:      common.UserStatusEnabled,
 | 
			
		||||
			DisplayName: "Root User",
 | 
			
		||||
			AccessToken: helper.GetUUID(),
 | 
			
		||||
			Quota:       100000000,
 | 
			
		||||
			Quota:       500000000000000,
 | 
			
		||||
		}
 | 
			
		||||
		DB.Create(&rootUser)
 | 
			
		||||
		if config.InitialRootToken != "" {
 | 
			
		||||
			logger.SysLog("creating initial root token as requested")
 | 
			
		||||
			token := Token{
 | 
			
		||||
				Id:             1,
 | 
			
		||||
				UserId:         rootUser.Id,
 | 
			
		||||
				Key:            config.InitialRootToken,
 | 
			
		||||
				Status:         common.TokenStatusEnabled,
 | 
			
		||||
				Name:           "Initial Root Token",
 | 
			
		||||
				CreatedTime:    helper.GetTimestamp(),
 | 
			
		||||
				AccessedTime:   helper.GetTimestamp(),
 | 
			
		||||
				ExpiredTime:    -1,
 | 
			
		||||
				RemainQuota:    500000000000000,
 | 
			
		||||
				UnlimitedQuota: true,
 | 
			
		||||
			}
 | 
			
		||||
			DB.Create(&token)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ type Redemption struct {
 | 
			
		||||
	Key          string `json:"key" gorm:"type:char(32);uniqueIndex"`
 | 
			
		||||
	Status       int    `json:"status" gorm:"default:1"`
 | 
			
		||||
	Name         string `json:"name" gorm:"index"`
 | 
			
		||||
	Quota        int64  `json:"quota" gorm:"default:100"`
 | 
			
		||||
	Quota        int64  `json:"quota" gorm:"bigint;default:100"`
 | 
			
		||||
	CreatedTime  int64  `json:"created_time" gorm:"bigint"`
 | 
			
		||||
	RedeemedTime int64  `json:"redeemed_time" gorm:"bigint"`
 | 
			
		||||
	Count        int    `json:"count" gorm:"-:all"` // only for api request
 | 
			
		||||
 
 | 
			
		||||
@@ -20,9 +20,9 @@ type Token struct {
 | 
			
		||||
	CreatedTime    int64  `json:"created_time" gorm:"bigint"`
 | 
			
		||||
	AccessedTime   int64  `json:"accessed_time" gorm:"bigint"`
 | 
			
		||||
	ExpiredTime    int64  `json:"expired_time" gorm:"bigint;default:-1"` // -1 means never expired
 | 
			
		||||
	RemainQuota    int64  `json:"remain_quota" gorm:"default:0"`
 | 
			
		||||
	RemainQuota    int64  `json:"remain_quota" gorm:"bigint;default:0"`
 | 
			
		||||
	UnlimitedQuota bool   `json:"unlimited_quota" gorm:"default:false"`
 | 
			
		||||
	UsedQuota      int64  `json:"used_quota" gorm:"default:0"` // used quota
 | 
			
		||||
	UsedQuota      int64  `json:"used_quota" gorm:"bigint;default:0"` // used quota
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAllUserTokens(userId int, startIdx int, num int) ([]*Token, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -26,9 +26,9 @@ type User struct {
 | 
			
		||||
	WeChatId         string `json:"wechat_id" gorm:"column:wechat_id;index"`
 | 
			
		||||
	VerificationCode string `json:"verification_code" gorm:"-:all"`                                    // this field is only for Email verification, don't save it to database!
 | 
			
		||||
	AccessToken      string `json:"access_token" gorm:"type:char(32);column:access_token;uniqueIndex"` // this token is for system management
 | 
			
		||||
	Quota            int64  `json:"quota" gorm:"type:int;default:0"`
 | 
			
		||||
	UsedQuota        int64  `json:"used_quota" gorm:"type:int;default:0;column:used_quota"` // used quota
 | 
			
		||||
	RequestCount     int    `json:"request_count" gorm:"type:int;default:0;"`               // request number
 | 
			
		||||
	Quota            int64  `json:"quota" gorm:"bigint;default:0"`
 | 
			
		||||
	UsedQuota        int64  `json:"used_quota" gorm:"bigint;default:0;column:used_quota"` // used quota
 | 
			
		||||
	RequestCount     int    `json:"request_count" gorm:"type:int;default:0;"`             // request number
 | 
			
		||||
	Group            string `json:"group" gorm:"type:varchar(32);default:'default'"`
 | 
			
		||||
	AffCode          string `json:"aff_code" gorm:"type:varchar(32);column:aff_code;uniqueIndex"`
 | 
			
		||||
	InviterId        int    `json:"inviter_id" gorm:"type:int;column:inviter_id;index"`
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user