Enhance Gitea support by improving base64 decoding and UTF-8 encoding handling
This commit is contained in:
@@ -380,13 +380,15 @@ function oribi_sync_fetch_file( string $api_base, string $branch, string $file_p
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
|
||||
// For Gitea, the /contents/ endpoint returns base64-encoded content in JSON
|
||||
// For Gitea, the /contents/ endpoint returns base64-encoded content in JSON.
|
||||
// Gitea (like GitHub) inserts \n every 60 chars in the base64 — strip them before decoding.
|
||||
if ( $provider === 'gitea' ) {
|
||||
$decoded = json_decode( $body, true );
|
||||
if ( isset( $decoded['content'] ) && is_string( $decoded['content'] ) ) {
|
||||
$body = base64_decode( $decoded['content'], true );
|
||||
$clean = str_replace( [ "\r", "\n", " " ], '', $decoded['content'] );
|
||||
$body = base64_decode( $clean, true );
|
||||
if ( $body === false ) {
|
||||
return new WP_Error( 'oribi_sync_decode_error', 'Failed to decode base64 content from Gitea' );
|
||||
return new WP_Error( 'oribi_sync_decode_error', 'Failed to decode base64 content from Gitea.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user