update file metadata request

This commit is contained in:
Pavel 2024-09-04 17:35:34 +03:00 committed by GitHub
commit 8eb473d7d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 7 deletions

View File

@ -912,6 +912,43 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe
return resp, status, err return resp, status, err
} }
// UpdateFileMetadata update file metadata
//
// Example:
//
// response, status, err := c.UpdateFileMetadata(UploadFileByUrlRequest{
// ID: "e038aa39-2338-4285-be86-e2a0bb424daa"
// Transcription: "demo transcription",
// })
//
// if err != nil {
// fmt.Printf("%v", err)
// }
//
// fmt.Printf("%s\n%s", response.ID, status)
func (c *MgClient) UpdateFileMetadata(request UpdateFileMetadataRequest) (UploadFileResponse, int, error) {
var resp UploadFileResponse
outgoing, err := json.Marshal(&request)
if err != nil {
return resp, 0, err
}
data, status, err := c.PutRequest(fmt.Sprintf("/files/%s/meta", request.ID), outgoing)
if err != nil {
return resp, status, err
}
if status != http.StatusOK {
return resp, status, c.Error(data)
}
if e := json.Unmarshal(data, &resp); e != nil {
return resp, status, e
}
return resp, status, err
}
type wsParams struct { type wsParams struct {
options []string options []string
} }

View File

@ -273,6 +273,11 @@ type (
UploadFileByUrlRequest struct { UploadFileByUrlRequest struct {
Url string `json:"url"` Url string `json:"url"`
} }
UpdateFileMetadataRequest struct {
ID string `json:"-"`
Transcription string `json:"transcription,omitempty"`
}
) )
// Response types // Response types
@ -495,13 +500,21 @@ type (
} }
Attachment struct { Attachment struct {
ID string `json:"id"` File
Mime string `json:"type"`
Caption string `json:"caption"` Caption string `json:"caption"`
Size uint64 `json:"size"` }
File struct {
PreviewURL *string `json:"preview_url,omitempty"` PreviewURL *string `json:"preview_url,omitempty"`
Height *uint64 `json:"height,omitempty"` Height *uint64 `json:"height,omitempty"`
Width *uint64 `json:"width,omitempty"` Width *uint64 `json:"width,omitempty"`
Transcription string `json:"transcription,omitempty"`
ID string `json:"id"`
Mime string `json:"type"`
Type string `json:"kind"`
Duration int `json:"duration,omitempty"`
Size uint64 `json:"size"`
} }
MessageProduct struct { MessageProduct struct {