mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-12-25 09:15:56 +08:00
Remove useless page
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"path"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
type Channel struct {
|
||||
Id int `json:"id"`
|
||||
Filename string `json:"filename" gorm:"index"`
|
||||
Description string `json:"description"`
|
||||
@@ -19,27 +19,27 @@ type File struct {
|
||||
DownloadCounter int `json:"download_counter"`
|
||||
}
|
||||
|
||||
func GetAllFiles(startIdx int, num int) ([]*File, error) {
|
||||
var files []*File
|
||||
func GetAllChannels(startIdx int, num int) ([]*Channel, error) {
|
||||
var files []*Channel
|
||||
var err error
|
||||
err = DB.Order("id desc").Limit(num).Offset(startIdx).Find(&files).Error
|
||||
return files, err
|
||||
}
|
||||
|
||||
func SearchFiles(keyword string) (files []*File, err error) {
|
||||
func SearchChannels(keyword string) (files []*Channel, err error) {
|
||||
err = DB.Select([]string{"id", "filename", "description", "uploader", "uploader_id", "link", "upload_time", "download_counter"}).Where(
|
||||
"filename LIKE ? or uploader LIKE ? or uploader_id = ?", keyword+"%", keyword+"%", keyword).Find(&files).Error
|
||||
return files, err
|
||||
}
|
||||
|
||||
func (file *File) Insert() error {
|
||||
func (file *Channel) Insert() error {
|
||||
var err error
|
||||
err = DB.Create(file).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete Make sure link is valid! Because we will use os.Remove to delete it!
|
||||
func (file *File) Delete() error {
|
||||
func (file *Channel) Delete() error {
|
||||
var err error
|
||||
err = DB.Delete(file).Error
|
||||
err = os.Remove(path.Join(common.UploadPath, file.Link))
|
||||
@@ -47,5 +47,5 @@ func (file *File) Delete() error {
|
||||
}
|
||||
|
||||
func UpdateDownloadCounter(link string) {
|
||||
DB.Model(&File{}).Where("link = ?", link).UpdateColumn("download_counter", gorm.Expr("download_counter + 1"))
|
||||
DB.Model(&Channel{}).Where("link = ?", link).UpdateColumn("download_counter", gorm.Expr("download_counter + 1"))
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func InitDB() (err error) {
|
||||
}
|
||||
if err == nil {
|
||||
DB = db
|
||||
err := db.AutoMigrate(&File{})
|
||||
err := db.AutoMigrate(&Channel{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user