-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add media command (mediaStorage), deprecate upload #78
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ## runware media | ||
|
|
||
| Store and delete media in your Runware account | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for media | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --debug Show full debug output | ||
| -F, --format string CLI output format: table, json, yaml (default "table") | ||
| --transport string Transport protocol: ws (WebSocket) or http (REST) (default "ws") | ||
| -v, --verbose Show request/response details | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [runware](runware.md) - CLI tool for the Runware API | ||
| * [runware media delete](runware_media_delete.md) - Permanently delete stored media by its UUID | ||
| * [runware media upload](runware_media_upload.md) - Upload media and return its UUID | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| ## runware media delete | ||
|
|
||
| Permanently delete stored media by its UUID | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Permanently remove media previously uploaded to your Runware account, | ||
| identified by its mediaUUID. This cannot be undone. | ||
|
|
||
| ``` | ||
| runware media delete <mediaUUID> [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| # delete a stored asset by its UUID | ||
| runware media delete 5f1d2c3b-8a4e-4c2a-9f1a-2b3c4d5e6f70 | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help help for delete | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| --debug Show full debug output | ||
| -F, --format string CLI output format: table, json, yaml (default "table") | ||
| --transport string Transport protocol: ws (WebSocket) or http (REST) (default "ws") | ||
| -v, --verbose Show request/response details | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [runware media](runware_media.md) - Store and delete media in your Runware account | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "log/slog" | ||
| "testing" | ||
|
|
||
| "github.com/google/uuid" | ||
| ) | ||
|
|
||
| // TestMediaStorage_UploadSuccess: a valid upload response is parsed and the | ||
| // request carries the mediaStorage task type, the upload operation, and media. | ||
| func TestMediaStorage_UploadSuccess(t *testing.T) { | ||
| mediaUUID := uuid.New() | ||
| mediaURL := "https://im.runware.ai/asset.png" | ||
| mock := &mockTransport{ | ||
| responses: []mockResponse{ | ||
| {data: []json.RawMessage{rawJSON(t, map[string]any{ | ||
| fieldTaskType: "mediaStorage", | ||
| fieldTaskUUID: uuid.New().String(), | ||
| "operation": MediaOperationUpload, | ||
| "mediaUUID": mediaUUID.String(), | ||
| "mediaURL": mediaURL, | ||
| })}}, | ||
| }, | ||
| } | ||
|
|
||
| c := NewClient(mock, slog.Default()) | ||
| result, err := c.MediaStorage(context.Background(), MediaOperationUpload, "data:image/png;base64,AAAA") | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if result.MediaUUID != mediaUUID { | ||
| t.Errorf("MediaUUID = %v, want %v", result.MediaUUID, mediaUUID) | ||
| } | ||
| if result.MediaURL != mediaURL { | ||
| t.Errorf("MediaURL = %q, want %q", result.MediaURL, mediaURL) | ||
| } | ||
|
|
||
| if len(mock.captured) != 1 || len(mock.captured[0]) != 1 { | ||
| t.Fatalf("expected one submitted task, got %#v", mock.captured) | ||
| } | ||
| req, ok := mock.captured[0][0].(*MediaStorageRequest) | ||
| if !ok { | ||
| t.Fatalf("submitted task is not *MediaStorageRequest: %T", mock.captured[0][0]) | ||
| } | ||
| if req.TaskType != taskTypeMediaStorage { | ||
| t.Errorf("TaskType = %q, want %q", req.TaskType, taskTypeMediaStorage) | ||
| } | ||
| if req.Operation != MediaOperationUpload { | ||
| t.Errorf("Operation = %q, want %q", req.Operation, MediaOperationUpload) | ||
| } | ||
| if req.Media != "data:image/png;base64,AAAA" { | ||
| t.Errorf("Media = %q, want the supplied value", req.Media) | ||
| } | ||
| } | ||
|
|
||
| // TestMediaStorage_DeleteSuccess: a delete response (no mediaURL) is parsed and | ||
| // the request carries the delete operation with the target UUID as media. | ||
| func TestMediaStorage_DeleteSuccess(t *testing.T) { | ||
| mediaUUID := uuid.New() | ||
| mock := &mockTransport{ | ||
| responses: []mockResponse{ | ||
| {data: []json.RawMessage{rawJSON(t, map[string]any{ | ||
| fieldTaskType: "mediaStorage", | ||
| fieldTaskUUID: uuid.New().String(), | ||
| "operation": MediaOperationDelete, | ||
| "mediaUUID": mediaUUID.String(), | ||
| })}}, | ||
| }, | ||
| } | ||
|
|
||
| c := NewClient(mock, slog.Default()) | ||
| result, err := c.MediaStorage(context.Background(), MediaOperationDelete, mediaUUID.String()) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if result.MediaUUID != mediaUUID { | ||
| t.Errorf("MediaUUID = %v, want %v", result.MediaUUID, mediaUUID) | ||
| } | ||
| if result.MediaURL != "" { | ||
| t.Errorf("MediaURL = %q, want empty for delete", result.MediaURL) | ||
| } | ||
|
|
||
| req, ok := mock.captured[0][0].(*MediaStorageRequest) | ||
| if !ok { | ||
| t.Fatalf("submitted task is not *MediaStorageRequest: %T", mock.captured[0][0]) | ||
| } | ||
| if req.Operation != MediaOperationDelete { | ||
| t.Errorf("Operation = %q, want %q", req.Operation, MediaOperationDelete) | ||
| } | ||
| if req.Media != mediaUUID.String() { | ||
| t.Errorf("Media = %q, want the target UUID", req.Media) | ||
| } | ||
| } | ||
|
|
||
| // TestMediaStorage_EmptyOperation: an empty operation is rejected before any | ||
| // transport call. | ||
| func TestMediaStorage_EmptyOperation(t *testing.T) { | ||
| mock := &mockTransport{} | ||
| c := NewClient(mock, slog.Default()) | ||
| if _, err := c.MediaStorage(context.Background(), "", "data:image/png;base64,AAAA"); err == nil { | ||
| t.Fatal("expected error for empty operation, got nil") | ||
| } | ||
| if mock.callCount != 0 { | ||
| t.Errorf("expected no transport calls, got %d", mock.callCount) | ||
| } | ||
| } | ||
|
|
||
| // TestMediaStorage_EmptyMedia: an empty media value is rejected before any | ||
| // transport call. | ||
| func TestMediaStorage_EmptyMedia(t *testing.T) { | ||
| mock := &mockTransport{} | ||
| c := NewClient(mock, slog.Default()) | ||
| if _, err := c.MediaStorage(context.Background(), MediaOperationUpload, ""); err == nil { | ||
| t.Fatal("expected error for empty media, got nil") | ||
| } | ||
| if mock.callCount != 0 { | ||
| t.Errorf("expected no transport calls, got %d", mock.callCount) | ||
| } | ||
| } | ||
|
|
||
| // TestMediaStorage_EmptyResponse: an empty data slice returns an error. | ||
| func TestMediaStorage_EmptyResponse(t *testing.T) { | ||
| mock := &mockTransport{ | ||
| responses: []mockResponse{ | ||
| {data: []json.RawMessage{}}, | ||
| }, | ||
| } | ||
| c := NewClient(mock, slog.Default()) | ||
| if _, err := c.MediaStorage(context.Background(), MediaOperationDelete, uuid.New().String()); err == nil { | ||
| t.Fatal("expected error for empty response, got nil") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.