Skip to content

Commit a3e39b4

Browse files
authored
Merge pull request #148 from SeleiXi/main
refactor: Change the api route in order to be compatible with the previous api ; Update README.md
2 parents e442d1b + 0888f71 commit a3e39b4

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

image_hosting/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ To retrieve an image, use the `GET` method with the following endpoint: `{hostna
1717

1818
## System Environment Variables
1919
- DB_URL
20-
- HOST_NAME (optional)
21-
---
20+
- root:`PASSWORD`@tcp(localhost:`PORT`)/`YOUR_DATABASE_NAME`?parseTime=true&loc=Asia%2fShanghai
21+
- HOST_NAME (change it to your own host, which directly exports to users)
22+
- http://localhost:8000
23+
- https://image.fduhole.com
24+
---

image_hosting/api/upload_image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func UploadImage(c *fiber.Ctx) error {
6868
if bytes.Equal(image.ImageFileData, imageData) && strings.EqualFold(image.ImageType, fileExtension) {
6969
slog.LogAttrs(context.Background(), slog.LevelInfo, "The file has been uploaded before")
7070
imageIdentifier = image.ImageIdentifier
71-
imageUrl := viper.GetString(EnvHostName) + "/api/i/" + image.CreatedAt.Format("2006/01/02/") + imageIdentifier + "." + fileExtension
71+
imageUrl := viper.GetString(EnvHostName) + "/i/" + image.CreatedAt.Format("2006/01/02/") + imageIdentifier + "." + fileExtension
7272
response.StatusCode = 200
7373
response.StatusTxt = "The image has been uploaded before"
7474
response.Image = CheveretoImageInfo{
@@ -83,7 +83,7 @@ func UploadImage(c *fiber.Ctx) error {
8383
}
8484
}
8585

86-
imageUrl := viper.GetString(EnvHostName) + "/api/i/" + time.Now().Format("2006/01/02/") + imageIdentifier + "." + fileExtension
86+
imageUrl := viper.GetString(EnvHostName) + "/i/" + time.Now().Format("2006/01/02/") + imageIdentifier + "." + fileExtension
8787
uploadedImage := &ImageTable{
8888
ImageIdentifier: imageIdentifier,
8989
OriginalFileName: originalFileName,

image_hosting/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ func main() {
3232
// will catch every HTTP request
3333
// app.Use(MiddlewareCustomLogger)
3434
Init()
35-
router := app.Group("/api")
36-
router.Post("/uploadImage", UploadImage)
37-
router.Get("/i/:year/:month/:day/:identifier", GetImage) // get images based on the identifier(excluding the extension)
35+
// router := app.Group("/") // Compatible with the previous API.
36+
app.Post("/api/uploadImage", UploadImage)
37+
app.Post("/api/json", UploadImage) // Compatible with the previous API.
38+
app.Get("/i/:year/:month/:day/:identifier", GetImage) // get images based on the identifier(excluding the extension)
3839

3940
go func() {
4041
slog.LogAttrs(context.Background(), slog.LevelInfo, "Service started.")

0 commit comments

Comments
 (0)