initial commit
This commit is contained in:
34
backend/internal/storage/storage.go
Normal file
34
backend/internal/storage/storage.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"reichard.io/aethera/internal/api"
|
||||
)
|
||||
|
||||
func ListImages(dataDir string) ([]api.ImageRecord, error) {
|
||||
files, err := os.ReadDir(path.Join(dataDir, "generated/images"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var imageList []api.ImageRecord
|
||||
for _, file := range files {
|
||||
if !file.IsDir() && strings.HasSuffix(strings.ToLower(file.Name()), ".png") {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
imageList = append(imageList, api.ImageRecord{
|
||||
Name: file.Name(),
|
||||
Path: "/generated/images" + file.Name(),
|
||||
Size: info.Size(),
|
||||
Date: info.ModTime().Format("2006-01-02T15:04:05Z07:00"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return imageList, nil
|
||||
}
|
||||
Reference in New Issue
Block a user