get images, and display images

This commit is contained in:
m
2026-07-11 22:59:25 +02:00
parent 1cc8b94b60
commit f7cf2a2bef
5 changed files with 164 additions and 4 deletions
+1
View File
@@ -19,6 +19,7 @@ func main() {
r.GET("/api/v1/health", handlers.Health)
r.GET("/api/v1/files", handlers.ListFiles)
r.GET("/api/v1/file/:id", handlers.ListFile)
r.POST("/api/v1/files/upload", handlers.UploadFile)
r.GET("/api/v1/files/:id", handlers.GetFile)
r.DELETE("/api/v1/files/:id", handlers.DeleteFile)
+66 -1
View File
@@ -70,6 +70,71 @@ func ListFiles(c *gin.Context) {
})
}
func ListFile(c *gin.Context) {
id := c.Query("id")
dirs, err := os.ReadDir("./uploads/")
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"data": []interface{}{},
"meta": gin.H{
"page": 1,
"total": 0,
},
})
return
}
type Finfo struct {
Url string `json:"url"`
Name string `json:"name"`
Size int64 `json:"size"`
Tags []string `json:"tags"`
}
file := Finfo{}
for _, dir := range dirs {
if dir.IsDir() {
continue
}
i, e := dir.Info()
if e != nil {
continue
}
if id != i.Name() {
continue
}
ps := Finfo{
Url: service.GenerateFileDownloadUrl(i.Name()),
Name: i.Name(),
Size: i.Size(),
Tags: []string{},
}
file = ps
break
}
c.JSON(http.StatusOK, gin.H{
"data": file,
"meta": gin.H{
"total": 1,
},
})
}
func GetFile(c *gin.Context) {
exp, _ := strconv.ParseInt(c.Query("expires"), 10, 64)
@@ -78,7 +143,7 @@ func GetFile(c *gin.Context) {
if r != true {
c.JSON(http.StatusNotFound, gin.H{
c.JSON(http.StatusForbidden, gin.H{
"error": gin.H{
"code": "FILE_NOT_FOUND",
"message": "File not found",