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