mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-15 15:30:26 +00:00
Token API done without verification
This commit is contained in:
@@ -5,28 +5,32 @@ import (
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
Id int `json:"id"`
|
||||
Type int `json:"type" gorm:"default:0"`
|
||||
Key string `json:"key"`
|
||||
Status int `json:"status" gorm:"default:1"`
|
||||
Id int `json:"id"`
|
||||
Type int `json:"type" gorm:"default:0"`
|
||||
Key string `json:"key"`
|
||||
Status int `json:"status" gorm:"default:1"`
|
||||
Name string `json:"name" gorm:"unique;index"`
|
||||
Weight int `json:"weight"`
|
||||
CreatedTime int64 `json:"created_time" gorm:"bigint"`
|
||||
AccessedTime int64 `json:"accessed_time" gorm:"bigint"`
|
||||
}
|
||||
|
||||
func GetAllChannels(startIdx int, num int) ([]*Channel, error) {
|
||||
var channels []*Channel
|
||||
var err error
|
||||
err = DB.Order("id desc").Limit(num).Offset(startIdx).Find(&channels).Error
|
||||
err = DB.Order("id desc").Limit(num).Offset(startIdx).Omit("key").Find(&channels).Error
|
||||
return channels, err
|
||||
}
|
||||
|
||||
func SearchChannels(keyword string) (channels []*Channel, err error) {
|
||||
err = DB.Select([]string{"id", "key"}, keyword, keyword).Find(&channels).Error
|
||||
err = DB.Omit("key").Where("id = ? or name LIKE ?", keyword, keyword+"%").Find(&channels).Error
|
||||
return channels, err
|
||||
}
|
||||
|
||||
func GetChannelById(id int) (*Channel, error) {
|
||||
channel := Channel{Id: id}
|
||||
var err error = nil
|
||||
err = DB.Select([]string{"id", "type"}).First(&channel, "id = ?", id).Error
|
||||
err = DB.Omit("key").First(&channel, "id = ?", id).Error
|
||||
return &channel, err
|
||||
}
|
||||
|
||||
@@ -42,7 +46,6 @@ func (channel *Channel) Update() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete Make sure link is valid! Because we will use os.Remove to delete it!
|
||||
func (channel *Channel) Delete() error {
|
||||
var err error
|
||||
err = DB.Delete(channel).Error
|
||||
|
Reference in New Issue
Block a user