mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-12-24 10:40:55 +08:00
fix: ignore count query for gorm
This commit is contained in:
@@ -21,6 +21,7 @@ type listDirOptions struct {
|
||||
prefixPath string
|
||||
enableDownload bool // default: false
|
||||
enableFilter bool // default: true
|
||||
middlewares []gin.HandlerFunc
|
||||
}
|
||||
|
||||
func (o *listDirOptions) apply(opts ...ListDirOption) {
|
||||
@@ -70,6 +71,13 @@ func WithListDirDirsFilter(filters ...string) ListDirOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithListDirMiddlewares sets middlewares.
|
||||
func WithListDirMiddlewares(middlewares ...gin.HandlerFunc) ListDirOption {
|
||||
return func(o *listDirOptions) {
|
||||
o.middlewares = append(o.middlewares, middlewares...)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
|
||||
// FileInfo is a struct that represents a file or directory in the file system.
|
||||
@@ -317,11 +325,20 @@ func ListDir(r *gin.Engine, opts ...ListDirOption) {
|
||||
prefixPath = ""
|
||||
}
|
||||
|
||||
r.GET(prefixPath+"/dir/list", handleList(prefixPath, o))
|
||||
if o.enableDownload {
|
||||
r.GET(prefixPath+"/dir/file/download", handleDownload)
|
||||
if len(o.middlewares) > 0 {
|
||||
group := r.Group("", o.middlewares...)
|
||||
group.GET(prefixPath+"/dir/list", handleList(prefixPath, o))
|
||||
if o.enableDownload {
|
||||
group.GET(prefixPath+"/dir/file/download", handleDownload)
|
||||
}
|
||||
group.GET(prefixPath+"/dir/list/api", handleAPIList(o.enableFilter))
|
||||
} else {
|
||||
r.GET(prefixPath+"/dir/list", handleList(prefixPath, o))
|
||||
if o.enableDownload {
|
||||
r.GET(prefixPath+"/dir/file/download", handleDownload)
|
||||
}
|
||||
r.GET(prefixPath+"/dir/list/api", handleAPIList(o.enableFilter))
|
||||
}
|
||||
r.GET(prefixPath+"/dir/list/api", handleAPIList(o.enableFilter))
|
||||
}
|
||||
|
||||
// nolint
|
||||
|
||||
@@ -391,7 +391,13 @@ func TestListDirRouterSetup(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("WithDownloadEnabled", func(t *testing.T) {
|
||||
r, tmpDir := setupTestServer(t, WithListDirDownload())
|
||||
middleware := func(c *gin.Context) {
|
||||
c.Header("X-Test-Header", "test-value")
|
||||
c.Next()
|
||||
}
|
||||
r, tmpDir := setupTestServer(t,
|
||||
WithListDirDownload(),
|
||||
WithListDirMiddlewares(middleware))
|
||||
filePath := filepath.Join(tmpDir, "file1.txt")
|
||||
url := fmt.Sprintf("/dir/file/download?path=%s", filePath)
|
||||
w := newRequest(t, r, "GET", url)
|
||||
|
||||
@@ -84,7 +84,7 @@ func NewPage(page int, limit int, columnNames string) *Page {
|
||||
// columnNames="-name,-age" means sort by name descending before sorting by age descending.
|
||||
func getSort(columnNames string) string {
|
||||
columnNames = strings.Replace(columnNames, " ", "", -1)
|
||||
if columnNames == "" {
|
||||
if columnNames == "" || columnNames == "ignorecount" {
|
||||
return "id DESC"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user