mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-22 22:25:21 +01:00
feat: get and verify backup
This commit is contained in:
parent
cef7a65ea5
commit
123dd904bc
5 changed files with 81 additions and 0 deletions
25
src/schemas/query/backup/getBackups.ts
Normal file
25
src/schemas/query/backup/getBackups.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { getBackups as getLnBackups } from 'ln-service';
|
||||
import { logger } from '../../../helpers/logger';
|
||||
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||
|
||||
export const getBackups = {
|
||||
type: GraphQLString,
|
||||
args: { auth: { type: new GraphQLNonNull(GraphQLString) } },
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, 'getBackups');
|
||||
|
||||
const lnd = getAuthLnd(params.auth);
|
||||
|
||||
try {
|
||||
const backups = await getLnBackups({
|
||||
lnd: lnd,
|
||||
});
|
||||
return JSON.stringify(backups);
|
||||
} catch (error) {
|
||||
logger.error('Error getting backups: %o', error);
|
||||
throw new Error(getErrorMsg(error));
|
||||
}
|
||||
},
|
||||
};
|
7
src/schemas/query/backup/index.ts
Normal file
7
src/schemas/query/backup/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { getBackups } from './getBackups';
|
||||
import { verifyBackups } from './verifyBackups';
|
||||
|
||||
export const backupQueries = {
|
||||
getBackups,
|
||||
verifyBackups,
|
||||
};
|
45
src/schemas/query/backup/verifyBackups.ts
Normal file
45
src/schemas/query/backup/verifyBackups.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import { verifyBackups as verifyLnBackups } from 'ln-service';
|
||||
import { logger } from '../../../helpers/logger';
|
||||
import { requestLimiter } from '../../../helpers/rateLimiter';
|
||||
import { GraphQLNonNull, GraphQLString, GraphQLBoolean } from 'graphql';
|
||||
import { getAuthLnd, getErrorMsg } from '../../../helpers/helpers';
|
||||
|
||||
interface BackupProps {
|
||||
backup: string;
|
||||
channels: {}[];
|
||||
}
|
||||
|
||||
export const verifyBackups = {
|
||||
type: GraphQLBoolean,
|
||||
args: {
|
||||
auth: { type: new GraphQLNonNull(GraphQLString) },
|
||||
backup: { type: new GraphQLNonNull(GraphQLString) },
|
||||
},
|
||||
resolve: async (root: any, params: any, context: any) => {
|
||||
await requestLimiter(context.ip, 'verifyBackups');
|
||||
|
||||
const lnd = getAuthLnd(params.auth);
|
||||
|
||||
let backupObj: BackupProps = { backup: '', channels: [] };
|
||||
try {
|
||||
backupObj = JSON.parse(params.backup);
|
||||
} catch (error) {
|
||||
logger.error('Corrupt backup file: %o', error);
|
||||
throw new Error('Corrupt backup file');
|
||||
}
|
||||
|
||||
const { backup, channels } = backupObj;
|
||||
|
||||
try {
|
||||
const { is_valid } = await verifyLnBackups({
|
||||
lnd: lnd,
|
||||
backup,
|
||||
channels,
|
||||
});
|
||||
return is_valid;
|
||||
} catch (error) {
|
||||
logger.error('Error verifying backups: %o', error);
|
||||
throw new Error(getErrorMsg(error));
|
||||
}
|
||||
},
|
||||
};
|
|
@ -4,6 +4,7 @@ import { invoiceQueries } from './invoices';
|
|||
import { dataQueries } from './data';
|
||||
import { reportQueries } from './report';
|
||||
import { flowQueries } from './flow';
|
||||
import { backupQueries } from './backup';
|
||||
|
||||
export const query = {
|
||||
...channelQueries,
|
||||
|
@ -12,4 +13,5 @@ export const query = {
|
|||
...dataQueries,
|
||||
...reportQueries,
|
||||
...flowQueries,
|
||||
...backupQueries,
|
||||
};
|
||||
|
|
|
@ -33,4 +33,6 @@ export const RateConfig: RateConfigProps = {
|
|||
pay: { max: 3, window: '1s' },
|
||||
getAddress: { max: 3, window: '1s' },
|
||||
sendToAddress: { max: 3, window: '1s' },
|
||||
getBackups: { max: 3, window: '1s' },
|
||||
verifyBackups: { max: 3, window: '1s' },
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue