assist-feedback.php
10 months ago
assistant.php
8 months ago
base.php
8 months ago
dropped-file.php
7 months ago
edit-image.php
8 months ago
embed.php
10 months ago
feedback.php
10 months ago
function.php
8 months ago
image.php
8 months ago
parameter.php
1 year ago
text.php
8 months ago
transcribe.php
8 months ago
edit-image.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_EditImage extends Meow_MWAI_Query_Image { |
| 4 | public ?Meow_MWAI_Query_DroppedFile $mask = null; |
| 5 | public ?int $mediaId = null; |
| 6 | |
| 7 | public function set_mask( Meow_MWAI_Query_DroppedFile $mask ): void { |
| 8 | $this->mask = $mask; |
| 9 | } |
| 10 | |
| 11 | public function set_media_id( int $mediaId ) { |
| 12 | $this->mediaId = $mediaId; |
| 13 | } |
| 14 | |
| 15 | #[\ReturnTypeWillChange] |
| 16 | public function jsonSerialize(): array { |
| 17 | $json = parent::jsonSerialize(); |
| 18 | if ( !empty( $this->mediaId ) ) { |
| 19 | $json['mediaId'] = $this->mediaId; |
| 20 | } |
| 21 | return $json; |
| 22 | } |
| 23 | |
| 24 | public function inject_params( array $params ): void { |
| 25 | parent::inject_params( $params ); |
| 26 | $params = $this->convert_keys( $params ); |
| 27 | // Check both camelCase and snake_case |
| 28 | $mediaId = $params['mediaId'] ?? $params['media_id'] ?? null; |
| 29 | if ( !empty( $mediaId ) ) { |
| 30 | $this->set_media_id( intval( $mediaId ) ); |
| 31 | $path = get_attached_file( $this->mediaId ); |
| 32 | if ( $path ) { |
| 33 | $this->add_file( Meow_MWAI_Query_DroppedFile::from_path( $path, 'vision' ) ); |
| 34 | } |
| 35 | else { |
| 36 | error_log( 'EditImage: Could not find file for mediaId: ' . $this->mediaId ); |
| 37 | } |
| 38 | } |
| 39 | else { |
| 40 | error_log( 'EditImage: No mediaId provided in params: ' . json_encode( $params ) ); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |