Skip to content

Commit

Permalink
Merge pull request #543 from xxxxibo/main
Browse files Browse the repository at this point in the history
Add api support to return to the download link
  • Loading branch information
nkwangleiGIT authored Jan 11, 2024
2 parents d828a3d + 181b3df commit 4737e37
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 0 deletions.
67 changes: 67 additions & 0 deletions apiserver/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,73 @@ const docTemplate = `{
}
}
},
"/model/files/downloadlink": {
"get": {
"description": "Get a download link",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"MinioAPI"
],
"summary": "Get a download link",
"parameters": [
{
"type": "string",
"description": "Name of the bucket",
"name": "namespace",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Path of the bucket",
"name": "bucketPath",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Name of the file",
"name": "fileName",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/model/files/stat": {
"get": {
"description": "Statistics file information",
Expand Down
67 changes: 67 additions & 0 deletions apiserver/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,73 @@
}
}
},
"/model/files/downloadlink": {
"get": {
"description": "Get a download link",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"MinioAPI"
],
"summary": "Get a download link",
"parameters": [
{
"type": "string",
"description": "Name of the bucket",
"name": "namespace",
"in": "header",
"required": true
},
{
"type": "string",
"description": "Path of the bucket",
"name": "bucketPath",
"in": "query",
"required": true
},
{
"type": "string",
"description": "Name of the file",
"name": "fileName",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/model/files/stat": {
"get": {
"description": "Statistics file information",
Expand Down
45 changes: 45 additions & 0 deletions apiserver/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,51 @@ paths:
summary: Download files in chunks
tags:
- MinioAPI
/model/files/downloadlink:
get:
consumes:
- application/json
description: Get a download link
parameters:
- description: Name of the bucket
in: header
name: namespace
required: true
type: string
- description: Path of the bucket
in: query
name: bucketPath
required: true
type: string
- description: Name of the file
in: query
name: fileName
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
additionalProperties:
type: string
type: object
"400":
description: Bad Request
schema:
additionalProperties:
type: string
type: object
"500":
description: Internal Server Error
schema:
additionalProperties:
type: string
type: object
summary: Get a download link
tags:
- MinioAPI
/model/files/stat:
get:
consumes:
Expand Down
43 changes: 43 additions & 0 deletions apiserver/service/minio_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -730,6 +731,46 @@ func (m *minioAPI) ReadCSVLines(ctx *gin.Context) {
ctx.JSON(http.StatusOK, result)
}

// @Summary Get a download link
// @Schemes
// @Description Get a download link
// @Tags MinioAPI
// @Accept json
// @Produce json
// @Param namespace header string true "Name of the bucket"
// @Param bucketPath query string true "Path of the bucket"
// @Param fileName query string true "Name of the file"
// @Success 200 {object} map[string]string
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /model/files/downloadlink [get]
func (m *minioAPI) GetDownloadLink(ctx *gin.Context) {
source, err := common.SystemDatasourceOSS(ctx.Request.Context(), nil, m.client)
if err != nil {
klog.Errorf("failed to get datasource %s", err)
ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
return
}

bucket := ctx.GetHeader(namespaceHeader)
bucketPath := ctx.Query(bucketPathQuery)
fileName := ctx.Query("fileName")
objectName := fmt.Sprintf("%s/%s", bucketPath, fileName)

u, err := source.Core.PresignedGetObject(ctx.Request.Context(), bucket, objectName, time.Hour*12, url.Values{})
if err != nil {
klog.Errorf("failed to generate download link %s", err)
ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
return
}

ctx.JSON(http.StatusOK, gin.H{"url": u.String()})
}

func RegisterMinIOAPI(group *gin.RouterGroup, conf gqlconfig.ServerConfig) {
c, err := client.GetClient(nil)
if err != nil {
Expand All @@ -749,6 +790,7 @@ func RegisterMinIOAPI(group *gin.RouterGroup, conf gqlconfig.ServerConfig) {
group.DELETE("/model/files", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "delete", "models"), api.DeleteFiles)
group.GET("/model/files/stat", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "models"), api.StatFile)
group.GET("/model/files/download", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "models"), api.Download)
group.GET("/model/files/downloadlink", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "models"), api.GetDownloadLink)
}

{
Expand All @@ -762,5 +804,6 @@ func RegisterMinIOAPI(group *gin.RouterGroup, conf gqlconfig.ServerConfig) {
group.GET("/versioneddataset/files/stat", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "versioneddatasets"), api.StatFile)
group.GET("/versioneddataset/files/download", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "versioneddatasets"), api.Download)
group.GET("/versioneddataset/files/csv", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "versioneddatasets"), api.ReadCSVLines)
group.GET("/versioneddataset/files/downloadlink", auth.AuthInterceptor(conf.EnableOIDC, oidc.Verifier, "get", "versioneddatasets"), api.GetDownloadLink)
}
}

0 comments on commit 4737e37

Please sign in to comment.