From 30fd8b0fca65416db9ee4aa439a227d3d675bb16 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 29 Oct 2023 01:45:08 +0200 Subject: [PATCH] Feature/support new tachiyomi backup file extension (#430) * [Codegen] Fix restore backup mutation/query The server doesn't support nested objects for file uploads * Support new tachiyomi backup extension --- src/lib/graphql/generated/graphql.ts | 4 ++-- src/lib/graphql/mutations/BackupMutation.ts | 4 ++-- src/lib/graphql/queries/BackupQuery.ts | 4 ++-- src/lib/requests/RequestManager.ts | 6 +++--- src/screens/settings/Backup.tsx | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/graphql/generated/graphql.ts b/src/lib/graphql/generated/graphql.ts index c528500bad..c8f5cb480f 100644 --- a/src/lib/graphql/generated/graphql.ts +++ b/src/lib/graphql/generated/graphql.ts @@ -2094,7 +2094,7 @@ export type CreateBackupMutationVariables = Exact<{ export type CreateBackupMutation = { __typename?: 'Mutation', createBackup: { __typename?: 'CreateBackupPayload', clientMutationId?: string | null, url: string } }; export type RestoreBackupMutationVariables = Exact<{ - input: RestoreBackupInput; + backup: Scalars['Upload']['input']; }>; @@ -2409,7 +2409,7 @@ export type StopUpdaterMutationVariables = Exact<{ export type StopUpdaterMutation = { __typename?: 'Mutation', updateStop: { __typename?: 'UpdateStopPayload', clientMutationId?: string | null } }; export type ValidateBackupQueryVariables = Exact<{ - input: ValidateBackupInput; + backup: Scalars['Upload']['input']; }>; diff --git a/src/lib/graphql/mutations/BackupMutation.ts b/src/lib/graphql/mutations/BackupMutation.ts index dc4c1d5a32..da09b9b10d 100644 --- a/src/lib/graphql/mutations/BackupMutation.ts +++ b/src/lib/graphql/mutations/BackupMutation.ts @@ -18,8 +18,8 @@ export const CREATE_BACKUP = gql` `; export const RESTORE_BACKUP = gql` - mutation RESTORE_BACKUP($input: RestoreBackupInput!) { - restoreBackup(input: $input) { + mutation RESTORE_BACKUP($backup: Upload!) { + restoreBackup(input: { backup: $backup }) { clientMutationId status { mangaProgress diff --git a/src/lib/graphql/queries/BackupQuery.ts b/src/lib/graphql/queries/BackupQuery.ts index 8d09c94c9c..028f815b6c 100644 --- a/src/lib/graphql/queries/BackupQuery.ts +++ b/src/lib/graphql/queries/BackupQuery.ts @@ -9,8 +9,8 @@ import gql from 'graphql-tag'; export const VALIDATE_BACKUP = gql` - query VALIDATE_BACKUP($input: ValidateBackupInput!) { - validateBackup(input: $input) { + query VALIDATE_BACKUP($backup: Upload!) { + validateBackup(input: { backup: $backup }) { missingSources { id name diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index dd8a7f87ad..f9faa65702 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -1571,7 +1571,7 @@ export class RequestManager { const result = this.doRequest( GQLMethod.MUTATION, RESTORE_BACKUP, - { input: { backup: file } }, + { backup: file }, { ...options, }, @@ -1584,11 +1584,11 @@ export class RequestManager { return result; } - public useValidateBackupFile( + public validateBackupFile( file: File, options?: QueryOptions, ): AbortabaleApolloQueryResponse { - return this.doRequest(GQLMethod.QUERY, VALIDATE_BACKUP, { input: { backup: file } }, options); + return this.doRequest(GQLMethod.QUERY, VALIDATE_BACKUP, { backup: file }, options); } public getExportBackupUrl(): string { diff --git a/src/screens/settings/Backup.tsx b/src/screens/settings/Backup.tsx index 48e22117ff..ebb903c432 100644 --- a/src/screens/settings/Backup.tsx +++ b/src/screens/settings/Backup.tsx @@ -28,7 +28,7 @@ export function Backup() { useSetDefaultBackTo('settings'); const submitBackup = (file: File) => { - if (file.name.toLowerCase().endsWith('proto.gz')) { + if (file.name.toLowerCase().match(/proto\.gz$|tachibk$/g)) { makeToast(t('settings.backup.label.restoring_backup'), 'info'); requestManager .restoreBackupFile(file)