Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added update file metadata request #77

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,43 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe
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 {
options []string
}
Expand Down
27 changes: 20 additions & 7 deletions v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ type (
UploadFileByUrlRequest struct {
Url string `json:"url"`
}

UpdateFileMetadataRequest struct {
ID string `json:"-"`
Transcription string `json:"transcription,omitempty"`
}
)

// Response types
Expand Down Expand Up @@ -495,13 +500,21 @@ type (
}

Attachment struct {
ID string `json:"id"`
Mime string `json:"type"`
Caption string `json:"caption"`
Size uint64 `json:"size"`
PreviewURL *string `json:"preview_url,omitempty"`
Height *uint64 `json:"height,omitempty"`
Width *uint64 `json:"width,omitempty"`
File

Caption string `json:"caption"`
}

File struct {
PreviewURL *string `json:"preview_url,omitempty"`
Height *uint64 `json:"height,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 {
Expand Down
Loading