@@ -11,6 +11,7 @@ import (
1111 "github.com/memodb-io/Acontext/internal/modules/model"
1212 "github.com/memodb-io/Acontext/internal/modules/serializer"
1313 "github.com/memodb-io/Acontext/internal/modules/service"
14+ "github.com/memodb-io/Acontext/internal/pkg/utils/fileparser"
1415 "github.com/memodb-io/Acontext/internal/pkg/utils/path"
1516)
1617
@@ -148,24 +149,27 @@ func (h *ArtifactHandler) DeleteArtifact(c *gin.Context) {
148149type GetArtifactReq struct {
149150 FilePath string `form:"file_path" json:"file_path" binding:"required"` // File path including filename
150151 WithPublicURL bool `form:"with_public_url,default=true" json:"with_public_url" example:"true"`
152+ WithContent bool `form:"with_content,default=true" json:"with_content" example:"true"`
151153 Expire int `form:"expire,default=3600" json:"expire" example:"3600"` // Expire time in seconds for presigned URL
152154}
153155
154156type GetArtifactResp struct {
155- Artifact * model.Artifact `json:"artifact"`
156- PublicURL * string `json:"public_url,omitempty"`
157+ Artifact * model.Artifact `json:"artifact"`
158+ PublicURL * string `json:"public_url,omitempty"`
159+ Content * fileparser.FileContent `json:"content,omitempty"`
157160}
158161
159162// GetArtifact godoc
160163//
161164// @Summary Get artifact
162- // @Description Get artifact information by path and filename. Optionally include a presigned URL for downloading.
165+ // @Description Get artifact information by path and filename. Optionally include a presigned URL for downloading and parsed file content .
163166// @Tags artifact
164167// @Accept json
165168// @Produce json
166169// @Param disk_id path string true "Disk ID" Format(uuid) Example(123e4567-e89b-12d3-a456-426614174000)
167170// @Param file_path query string true "File path including filename" example:"/documents/report.pdf"
168171// @Param with_public_url query boolean false "Whether to return public URL, default is true" example:"true"
172+ // @Param with_content query boolean false "Whether to return parsed file content, default is true" example:"true"
169173// @Param expire query int false "Expire time in seconds for presigned URL (default: 3600)" example:"3600"
170174// @Security BearerAuth
171175// @Success 200 {object} serializer.Response{data=handler.GetArtifactResp}
@@ -210,6 +214,17 @@ func (h *ArtifactHandler) GetArtifact(c *gin.Context) {
210214 resp .PublicURL = & url
211215 }
212216
217+ // Parse file content if requested
218+ if req .WithContent {
219+ content , err := h .svc .GetFileContent (c .Request .Context (), diskID , filePath , filename )
220+ // Only set content if parsing succeeded
221+ // Unsupported file types (images, binaries, etc.) will not have content
222+ if err == nil && content != nil {
223+ resp .Content = content
224+ }
225+ // Don't return error for unsupported file types - just don't include content
226+ }
227+
213228 c .JSON (http .StatusOK , serializer.Response {Data : resp })
214229}
215230
0 commit comments