Refactor Oribi Sync settings: remove pages folder option and enhance case-insensitive directory handling
This commit is contained in:
@@ -30,15 +30,6 @@ add_action( 'rest_api_init', function () {
|
||||
},
|
||||
] );
|
||||
|
||||
// ── List Pages sub-folders from the repo ───────────────────────────
|
||||
register_rest_route( 'oribi-sync/v1', '/repo-folders', [
|
||||
'methods' => 'GET',
|
||||
'callback' => 'oribi_sync_rest_repo_folders',
|
||||
'permission_callback' => function () {
|
||||
return current_user_can( 'manage_options' );
|
||||
},
|
||||
] );
|
||||
|
||||
// ── Push page to repo ──────────────────────────────────────────────────
|
||||
register_rest_route( 'oribi-sync/v1', '/push', [
|
||||
'methods' => 'POST',
|
||||
@@ -160,53 +151,3 @@ function oribi_sync_rest_push( WP_REST_Request $request ): WP_REST_Response {
|
||||
/**
|
||||
* REST: Push all synced pages to the repo.
|
||||
*/
|
||||
function oribi_sync_rest_push_all( WP_REST_Request $request ): WP_REST_Response {
|
||||
$result = oribi_sync_push_all();
|
||||
|
||||
return new WP_REST_Response( $result, $result['ok'] ? 200 : 500 );
|
||||
}
|
||||
|
||||
/**
|
||||
* REST: List available sub-folders under Pages/ in the configured repository.
|
||||
*
|
||||
* Returns a JSON object: { folders: ["folder-a", "folder-b", …] }
|
||||
*/
|
||||
function oribi_sync_rest_repo_folders(): WP_REST_Response {
|
||||
$repo_url = get_option( 'oribi_sync_repo', '' );
|
||||
$branch = get_option( 'oribi_sync_branch', 'main' ) ?: 'main';
|
||||
$pat = oribi_sync_get_pat();
|
||||
|
||||
if ( empty( $repo_url ) || empty( $pat ) ) {
|
||||
return new WP_REST_Response( [ 'error' => 'Repository URL or PAT is not configured.' ], 400 );
|
||||
}
|
||||
|
||||
$parsed = oribi_sync_parse_repo_url( $repo_url );
|
||||
if ( is_wp_error( $parsed ) ) {
|
||||
return new WP_REST_Response( [ 'error' => $parsed->get_error_message() ], 400 );
|
||||
}
|
||||
|
||||
$provider = oribi_sync_get_provider();
|
||||
$api_base = oribi_sync_api_base( $provider, $parsed );
|
||||
|
||||
$tree = oribi_sync_fetch_tree( $api_base, $branch, $provider, $pat );
|
||||
if ( is_wp_error( $tree ) ) {
|
||||
return new WP_REST_Response( [ 'error' => 'Tree fetch failed: ' . $tree->get_error_message() ], 500 );
|
||||
}
|
||||
|
||||
// Find direct sub-directories of Pages/
|
||||
$folders = [];
|
||||
$prefix = 'Pages/';
|
||||
foreach ( $tree as $entry ) {
|
||||
if ( $entry['type'] !== 'tree' ) continue;
|
||||
if ( strpos( $entry['path'], $prefix ) !== 0 ) continue;
|
||||
$relative = substr( $entry['path'], strlen( $prefix ) );
|
||||
// Only direct children (no nested slash)
|
||||
if ( strpos( $relative, '/' ) !== false ) continue;
|
||||
if ( $relative === '' ) continue;
|
||||
$folders[] = $relative;
|
||||
}
|
||||
|
||||
sort( $folders );
|
||||
|
||||
return new WP_REST_Response( [ 'folders' => $folders ], 200 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user