From b414d13e24c98bb5d4c39796fcdb1aeecbd0cfec Mon Sep 17 00:00:00 2001 From: QiuSW <105186638@qq.com> Date: Thu, 17 Sep 2026 17:57:58 +0800 Subject: [PATCH] feat: query uploaded Shopee image URL --- app/admin/apis/shopee_product_image.go | 40 +++++++++++++++++++ app/admin/router/shopee_product.go | 1 + .../shopee_product_image_query.http | 6 +++ ...CAL-020-query-uploaded-shopee-image-url.md | 21 ++++++++++ 4 files changed, 68 insertions(+) create mode 100644 http-client-cli_file/shopee_product_image_query.http create mode 100644 tickets/LOCAL-020-query-uploaded-shopee-image-url.md diff --git a/app/admin/apis/shopee_product_image.go b/app/admin/apis/shopee_product_image.go index 9d7f1bd..4a67c25 100644 --- a/app/admin/apis/shopee_product_image.go +++ b/app/admin/apis/shopee_product_image.go @@ -9,8 +9,11 @@ import ( "time" "github.com/gin-gonic/gin" + "go-admin/app/admin/models" "go-admin/app/admin/service" + "go-admin/config" "go-admin/internal/imagestore" + "gorm.io/gorm" ) var allowedImageContentTypes = map[string]bool{ @@ -31,6 +34,43 @@ func (e ShopeeProduct) UploadImage(c *gin.Context) { e.uploadImage(c, strings.TrimSpace(c.Param("shopeeId"))) } +// GetUploadedImage returns the URL generated by this project's image upload +// endpoint. It deliberately reads only erpgo's image record: querying a URL +// must not trigger a Huohanhan detail call or a Shopee synchronization. +func (e ShopeeProduct) GetUploadedImage(c *gin.Context) { + e.MakeContext(c) + if !ValidateAPIKey(c) { + e.Error(http.StatusUnauthorized, fmt.Errorf("invalid api key"), "未授权") + return + } + shopeeID := strings.TrimSpace(c.Param("shopeeId")) + if err := imagestore.ValidateShopeeID(shopeeID); err != nil { + e.Error(http.StatusBadRequest, err, "参数错误") + return + } + db, err := imageDB() + if err != nil { + e.Error(http.StatusInternalServerError, err, "数据库初始化失败") + return + } + var row models.ShopeeProductImage + if err := db.Where("shopee_id = ?", shopeeID).First(&row).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + e.Error(http.StatusNotFound, err, "未找到已上传图片") + return + } + e.Error(http.StatusInternalServerError, err, "读取图片记录失败") + return + } + base, _ := service.ResolveImageBaseURL(db, config.ExtConfig.Image.BaseURL) + e.OK(gin.H{ + "shopeeId": row.ShopeeID, + "url": service.ImageURL(base, row.ShopeeID, row.UpdatedAt), + "fileSize": row.FileSize, + "updatedAt": row.UpdatedAt, + }, "查询成功") +} + // UploadImageAdmin is the JWT-authenticated upload used by the Admin page. func (e ShopeeProduct) UploadImageAdmin(c *gin.Context) { e.MakeContext(c) diff --git a/app/admin/router/shopee_product.go b/app/admin/router/shopee_product.go index a92592a..561809f 100644 --- a/app/admin/router/shopee_product.go +++ b/app/admin/router/shopee_product.go @@ -17,6 +17,7 @@ func registerShopeeProductRouter(v1 *gin.RouterGroup) { v1.GET("/shopee/product/spec/:shopeeId", a.GetSpecByShopeeID) v1.PUT("/shopee/products/:shopeeId/title", a.UpdateTitle) v1.PUT("/shopee/products/:shopeeId/cover", a.UpdateCover) + v1.GET("/shopee/products/:shopeeId/image", a.GetUploadedImage) v1.POST("/shopee/products/:shopeeId/image", a.UploadImage) v1.POST("/shopee/products/:shopeeId/sync", a.SyncByShopeeID) v1.POST("/shopee/products/:shopeeId/sync-wait", a.SyncWaitByShopeeID) diff --git a/http-client-cli_file/shopee_product_image_query.http b/http-client-cli_file/shopee_product_image_query.http new file mode 100644 index 0000000..fdafc3e --- /dev/null +++ b/http-client-cli_file/shopee_product_image_query.http @@ -0,0 +1,6 @@ +@baseUrl = http://127.0.0.1:8020/api/v1 +@shopeeId = 24720421377 +@apiKey = replace-with-api-key + +### 查询由 POST /image 上传并保存的图片 URL +GET {{baseUrl}}/shopee/products/{{shopeeId}}/image?apikey={{apiKey}} diff --git a/tickets/LOCAL-020-query-uploaded-shopee-image-url.md b/tickets/LOCAL-020-query-uploaded-shopee-image-url.md new file mode 100644 index 0000000..f7cf83e --- /dev/null +++ b/tickets/LOCAL-020-query-uploaded-shopee-image-url.md @@ -0,0 +1,21 @@ +# LOCAL-020:查询已上传 Shopee 商品图片 URL + +## 目标 + +为 `POST /api/v1/shopee/products/{shopeeId}/image` 上传服务增加同路径的查询接口: + +`GET /api/v1/shopee/products/{shopeeId}/image` + +接口只查询 erpgo 保存的上传图片记录,不读取 Huohanhan,也不触发 Shopee 同步。 + +## 验收标准 + +- API Key 鉴权方式与上传接口一致。 +- 根据 Shopee ID 返回最近上传图片的可访问 URL、上传时间和文件大小。 +- 返回 URL 与上传接口一致,包含更新时间版本参数,避免浏览器/CDN 使用旧缓存。 +- Shopee ID 不合法返回 400;未上传图片返回 404。 +- 不发起 Huohanhan 或 Shopee 请求。 + +## 状态 + +已完成。