mirror of
				https://github.com/linux-do/new-api.git
				synced 2025-11-04 21:33:41 +08:00 
			
		
		
		
	feat: 区分额度不足和预扣费失败提示
This commit is contained in:
		@@ -75,7 +75,7 @@ func AudioHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
 | 
			
		||||
		return service.OpenAIErrorWrapperLocal(err, "get_user_quota_failed", http.StatusInternalServerError)
 | 
			
		||||
	}
 | 
			
		||||
	if userQuota-preConsumedQuota < 0 {
 | 
			
		||||
		return service.OpenAIErrorWrapperLocal(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
 | 
			
		||||
		return service.OpenAIErrorWrapperLocal(errors.New("pre-consumed quota is more than user quota"), "insufficient_user_quota", http.StatusForbidden)
 | 
			
		||||
	}
 | 
			
		||||
	err = model.CacheDecreaseUserQuota(relayInfo.UserId, preConsumedQuota)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -125,7 +125,7 @@ func ImageHelper(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode {
 | 
			
		||||
	quota := int(imageRatio * groupRatio * common.QuotaPerUnit)
 | 
			
		||||
 | 
			
		||||
	if userQuota-quota < 0 {
 | 
			
		||||
		return service.OpenAIErrorWrapperLocal(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
 | 
			
		||||
		return service.OpenAIErrorWrapperLocal(errors.New("pre-consumed quota is more than user quota"), "insufficient_user_quota", http.StatusForbidden)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	adaptor := GetAdaptor(relayInfo.ApiType)
 | 
			
		||||
 
 | 
			
		||||
@@ -238,9 +238,12 @@ func preConsumeQuota(c *gin.Context, preConsumedQuota int, relayInfo *relaycommo
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, 0, service.OpenAIErrorWrapperLocal(err, "get_user_quota_failed", http.StatusInternalServerError)
 | 
			
		||||
	}
 | 
			
		||||
	if userQuota <= 0 || userQuota-preConsumedQuota < 0 {
 | 
			
		||||
	if userQuota <= 0 {
 | 
			
		||||
		return 0, 0, service.OpenAIErrorWrapperLocal(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
 | 
			
		||||
	}
 | 
			
		||||
	if userQuota-preConsumedQuota < 0 {
 | 
			
		||||
		return 0, 0, service.OpenAIErrorWrapperLocal(errors.New("pre-consumed quota is more than user quota"), "insufficient_user_quota", http.StatusForbidden)
 | 
			
		||||
	}
 | 
			
		||||
	err = model.CacheDecreaseUserQuota(relayInfo.UserId, preConsumedQuota)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, 0, service.OpenAIErrorWrapperLocal(err, "decrease_user_quota_failed", http.StatusInternalServerError)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user