Files
kite/frontend/src/api/cloud.js
T
curo1305andClaude Sonnet 4.6 b6911fb4ed fix(12): resolve critical code review findings (CR-01 through CR-04)
- CR-01: fix browse URL from /folders/{id} to /items?parent_ref= (broken feature)
- CR-02: remove raw provider exception text from _TerminalProviderError messages
- CR-03: add user_id predicate to get_or_create_folder_state query (ownership boundary)
- CR-04: add max_length=255 to ConnectionRenameRequest.display_name

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 02:00:05 +02:00

76 lines
2.5 KiB
JavaScript

/**
* Cloud Storage API — connections, OAuth initiation, folder browsing, config.
*
* Consumers: stores/cloudConnections.js, SettingsCloudTab.vue,
* CloudCredentialModal.vue, CloudProviderTreeItem.vue,
* CloudFolderTreeItem.vue
*/
import { request, jsonRequest } from './utils.js'
export function listCloudConnections() {
return request('/api/cloud/connections')
}
export function disconnectCloud(id) {
return request(`/api/cloud/connections/${id}`, { method: 'DELETE' })
}
export function connectWebDav(provider, serverUrl, username, password) {
return jsonRequest('/api/cloud/connections/webdav', 'POST', {
provider,
server_url: serverUrl,
username,
password,
})
}
export function updateDefaultStorage(backend) {
return jsonRequest('/api/users/me/default-storage', 'PATCH', { backend })
}
/**
* Browse a cloud folder by connection UUID and optional parent_ref.
* connectionId is always a UUID; parentRef is a provider path string (default '').
*/
export function getCloudFoldersByConnectionId(connectionId, parentRef = '') {
const qs = parentRef ? `?parent_ref=${encodeURIComponent(parentRef)}` : ''
return request(`/api/cloud/connections/${connectionId}/items${qs}`)
}
/** @deprecated Use getCloudFoldersByConnectionId instead. */
export function getCloudFolders(provider, folderId) {
return request(`/api/cloud/folders/${provider}/${folderId}`)
}
/**
* Rename a cloud connection's display name.
*/
export function renameCloudConnection(id, displayName) {
return jsonRequest(`/api/cloud/connections/${id}`, 'PATCH', { display_name: displayName })
}
/**
* Initiate OAuth flow for Google Drive or OneDrive.
*
* Returns a JSON object {url: "<authorization_url>"} from the backend.
* The caller is responsible for navigating: window.location.href = data.url
*
* Using request() (not bare window.location.href) ensures the Bearer header
* is injected and the 401→refresh retry path fires if the token has expired.
* See plan 05-10 trust boundary: frontend→/api/cloud/oauth/initiate/{provider}.
*/
export function initiateOAuth(provider) {
return request(`/api/cloud/oauth/initiate/${provider}`)
}
/**
* Fetch non-secret configuration for a WebDAV/Nextcloud connection (edit flow).
*
* Returns {id, provider, server_url, connection_username} — never the password.
* Used to pre-populate the Edit modal when re-editing an existing connection.
*/
export function getConnectionConfig(connectionId) {
return request(`/api/cloud/connections/${connectionId}/config`)
}