require drive id
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
export const OWN_OAUTH_TYPES = ['drive', 'google photos']
|
||||
|
||||
export const OVERRIDES = {
|
||||
alias: {
|
||||
Description: 'ALIAS',
|
||||
|
||||
@@ -6,7 +6,7 @@ import { platform } from '@tauri-apps/plugin-os'
|
||||
import { ChevronDown, ChevronUp, RefreshCcwIcon } from 'lucide-react'
|
||||
import { type Key, startTransition, useCallback, useMemo, useState } from 'react'
|
||||
import rclone from '../../lib/rclone/client'
|
||||
import { OVERRIDES } from '../../lib/rclone/overrides'
|
||||
import { OVERRIDES, OWN_OAUTH_TYPES } from '../../lib/rclone/overrides'
|
||||
import type { BackendOption } from '../../types/rclone'
|
||||
import RemoteField from './RemoteField'
|
||||
|
||||
@@ -67,6 +67,16 @@ export default function RemoteCreateDrawer({
|
||||
[currentBackend, config.provider, config.type]
|
||||
)
|
||||
|
||||
// Google Drive / Google Photos require the user's own OAuth credentials (rclone is retiring its
|
||||
// shared client-id). Block creation until they're supplied.
|
||||
const missingCredentials = useMemo(
|
||||
() =>
|
||||
OWN_OAUTH_TYPES.includes(config.type)
|
||||
? ['client_id', 'client_secret'].filter((f) => !(config[f] || '').trim())
|
||||
: [],
|
||||
[config]
|
||||
)
|
||||
|
||||
const createRemoteMutation = useMutation({
|
||||
mutationFn: async ({
|
||||
name,
|
||||
@@ -269,6 +279,7 @@ export default function RemoteCreateDrawer({
|
||||
<Button
|
||||
color="primary"
|
||||
isLoading={createRemoteMutation.isPending}
|
||||
isDisabled={missingCredentials.length > 0}
|
||||
data-focus-visible="false"
|
||||
onPress={() => {
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { onErrorDialog } from '../../lib/errors'
|
||||
import { useRemoteConfig } from '../../lib/hooks'
|
||||
import queryClient from '../../lib/query'
|
||||
import rclone from '../../lib/rclone/client'
|
||||
import { OVERRIDES } from '../../lib/rclone/overrides'
|
||||
import { OVERRIDES, OWN_OAUTH_TYPES } from '../../lib/rclone/overrides'
|
||||
import RemoteField from './RemoteField'
|
||||
|
||||
export default function RemoteEditDrawer({
|
||||
@@ -83,6 +83,17 @@ export default function RemoteEditDrawer({
|
||||
[currentBackend, remoteConfig]
|
||||
)
|
||||
|
||||
// Google Drive / Google Photos require the user's own OAuth credentials (rclone is retiring its
|
||||
// shared client-id). Check the effective config (saved values + pending edits) so a legacy
|
||||
// remote missing credentials can't be saved until they're added, while a remote that already
|
||||
// has them stays editable.
|
||||
const missingCredentials = useMemo(() => {
|
||||
const effective = { ...remoteConfig, ...config }
|
||||
return OWN_OAUTH_TYPES.includes(effective.type ?? '')
|
||||
? ['client_id', 'client_secret'].filter((f) => !(effective[f] || '').trim())
|
||||
: []
|
||||
}, [remoteConfig, config])
|
||||
|
||||
const updateRemoteMutation = useMutation({
|
||||
mutationFn: async (updatedRemoteConfig: Record<string, any>) => {
|
||||
console.log('[RemoteEditDrawer] updatedRemoteConfig', updatedRemoteConfig)
|
||||
@@ -230,7 +241,9 @@ export default function RemoteEditDrawer({
|
||||
</Button>
|
||||
<Button
|
||||
color="primary"
|
||||
isDisabled={updateRemoteMutation.isPending}
|
||||
isDisabled={
|
||||
updateRemoteMutation.isPending || missingCredentials.length > 0
|
||||
}
|
||||
data-focus-visible="false"
|
||||
onPress={() => {
|
||||
updateRemoteMutation.mutate(config)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Autocomplete, AutocompleteItem, Button, Checkbox, Input } from '@heroui
|
||||
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||
import { ExternalLinkIcon } from 'lucide-react'
|
||||
import { useMemo } from 'react'
|
||||
import { OWN_OAUTH_TYPES } from '../../lib/rclone/overrides'
|
||||
import type { BackendOption } from '../../types/rclone'
|
||||
|
||||
export default function RemoteField({
|
||||
@@ -127,6 +128,10 @@ export default function RemoteField({
|
||||
)
|
||||
}
|
||||
|
||||
const requiresOwnCredentials =
|
||||
OWN_OAUTH_TYPES.includes(config?.type) &&
|
||||
(option.Name === 'client_id' || option.Name === 'client_secret')
|
||||
|
||||
return (
|
||||
<Input
|
||||
key={option.Name}
|
||||
@@ -137,7 +142,7 @@ export default function RemoteField({
|
||||
placeholder={helpTitle}
|
||||
type={option.IsPassword ? 'password' : 'text'}
|
||||
classNames={
|
||||
config?.type && config.type === 'drive' && option.Name === 'client_id'
|
||||
requiresOwnCredentials
|
||||
? {
|
||||
description: 'text-warning',
|
||||
'inputWrapper': 'pr-0',
|
||||
@@ -151,29 +156,29 @@ export default function RemoteField({
|
||||
}))
|
||||
}}
|
||||
endContent={
|
||||
config?.type &&
|
||||
config.type === 'drive' &&
|
||||
option.Name === 'client_id' && (
|
||||
requiresOwnCredentials && (
|
||||
<Button
|
||||
size="sm"
|
||||
className="h-full gap-1 rounded-l-none"
|
||||
color="warning"
|
||||
endContent={<ExternalLinkIcon className="mb-0.5 size-4 shrink-0" />}
|
||||
onPress={() => {
|
||||
openUrl('https://rclone.org/drive/#making-your-own-client-id')
|
||||
openUrl(
|
||||
`https://rclone.org/${config?.type === 'google photos' ? 'googlephotos' : 'drive'}/#making-your-own-client-id`
|
||||
)
|
||||
}}
|
||||
>
|
||||
GUIDE
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
isRequired={option.Required}
|
||||
isRequired={option.Required || requiresOwnCredentials}
|
||||
defaultValue={initialFieldValue}
|
||||
autoComplete="off"
|
||||
autoCapitalize="off"
|
||||
autoCorrect="off"
|
||||
spellCheck="false"
|
||||
description={helpDescription}
|
||||
description={requiresOwnCredentials ? undefined : helpDescription}
|
||||
isDisabled={isDisabled}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user