(option FileOption)
| 288 | } |
| 289 | |
| 290 | func (f *FileInfo) listChildren(option FileOption) error { |
| 291 | var ( |
| 292 | files []FileSearchInfo |
| 293 | err error |
| 294 | total int |
| 295 | ) |
| 296 | |
| 297 | if option.Search != "" && option.ContainSub { |
| 298 | files, total, err = f.search(option.Search, option.Page*option.PageSize) |
| 299 | if err != nil { |
| 300 | return err |
| 301 | } |
| 302 | } else { |
| 303 | files, err = f.getFiles(option) |
| 304 | if err != nil { |
| 305 | return err |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | items, err := f.processFiles(files, option) |
| 310 | if err != nil { |
| 311 | return err |
| 312 | } |
| 313 | |
| 314 | if option.ContainSub { |
| 315 | f.ItemTotal = total |
| 316 | } |
| 317 | start := (option.Page - 1) * option.PageSize |
| 318 | end := option.PageSize + start |
| 319 | var result []*FileInfo |
| 320 | if start < 0 || start > f.ItemTotal || end < 0 || start > end { |
| 321 | result = items |
| 322 | } else { |
| 323 | if end > f.ItemTotal { |
| 324 | result = items[start:] |
| 325 | } else { |
| 326 | result = items[start:end] |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | f.Items = result |
| 331 | return nil |
| 332 | } |
| 333 | |
| 334 | func (f *FileInfo) getFiles(option FileOption) ([]FileSearchInfo, error) { |
| 335 | infos, err := os.ReadDir(f.Path) |
no test coverage detected