add proto backup support
This commit is contained in:
@@ -6,12 +6,11 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import React, { useContext, useEffect } from 'react';
|
import React, { useContext, useEffect } from 'react';
|
||||||
import { ListItemIcon } from '@material-ui/core';
|
|
||||||
import List from '@material-ui/core/List';
|
import List from '@material-ui/core/List';
|
||||||
import InboxIcon from '@material-ui/icons/Inbox';
|
|
||||||
import ListItem from '@material-ui/core/ListItem';
|
import ListItem from '@material-ui/core/ListItem';
|
||||||
import ListItemText from '@material-ui/core/ListItemText';
|
import ListItemText from '@material-ui/core/ListItemText';
|
||||||
import { fromEvent } from 'file-selector';
|
import { fromEvent } from 'file-selector';
|
||||||
|
import makeToast from 'components/Toast';
|
||||||
import ListItemLink from '../../util/ListItemLink';
|
import ListItemLink from '../../util/ListItemLink';
|
||||||
import NavbarContext from '../../context/NavbarContext';
|
import NavbarContext from '../../context/NavbarContext';
|
||||||
import client from '../../util/client';
|
import client from '../../util/client';
|
||||||
@@ -23,13 +22,23 @@ export default function Backup() {
|
|||||||
const { baseURL } = client.defaults;
|
const { baseURL } = client.defaults;
|
||||||
|
|
||||||
const submitBackup = (file: File) => {
|
const submitBackup = (file: File) => {
|
||||||
file.text()
|
if (file.name.toLowerCase().endsWith('proto.gz')) {
|
||||||
.then(
|
const formData = new FormData();
|
||||||
(fileContent: string) => {
|
formData.append('backup.proto.gz', file);
|
||||||
client.post('/api/v1/backup/legacy/import',
|
|
||||||
fileContent, { headers: { 'Content-Type': 'application/json' } });
|
client.post('/api/v1/backup/import/file',
|
||||||
},
|
formData, { headers: { 'Content-Type': 'multipart/form-data' } });
|
||||||
);
|
} else if (file.name.toLowerCase().endsWith('json')) {
|
||||||
|
file.text()
|
||||||
|
.then(
|
||||||
|
(fileContent: string) => {
|
||||||
|
client.post('/api/v1/backup/legacy/import',
|
||||||
|
fileContent, { headers: { 'Content-Type': 'application/json' } });
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
makeToast('invalid file type!', 'error');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropHandler = async (e: Event) => {
|
const dropHandler = async (e: Event) => {
|
||||||
@@ -60,32 +69,39 @@ export default function Backup() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List style={{ padding: 0 }}>
|
<>
|
||||||
<ListItemLink href={`${baseURL}/api/v1/backup/legacy/export/file`}>
|
<List style={{ padding: 0 }}>
|
||||||
<ListItemIcon>
|
<ListItemLink href={`${baseURL}/api/v1/backup/export/file`}>
|
||||||
<InboxIcon />
|
<ListItemText
|
||||||
</ListItemIcon>
|
primary="Create Backup"
|
||||||
<ListItemText
|
secondary="Backup library as a Tachiyomi backup"
|
||||||
primary="Create Legacy Backup"
|
/>
|
||||||
secondary="Backup library as a Tachiyomi legacy backup"
|
</ListItemLink>
|
||||||
/>
|
<ListItem button onClick={() => document.getElementById('backup-file')?.click()}>
|
||||||
</ListItemLink>
|
<ListItemText
|
||||||
<ListItem button onClick={() => document.getElementById('backup-file')?.click()}>
|
primary="Restore Backup"
|
||||||
<ListItemIcon>
|
secondary="You can also drag and drop the backup file here to restore"
|
||||||
<InboxIcon />
|
/>
|
||||||
</ListItemIcon>
|
</ListItem>
|
||||||
<ListItemText
|
<ListItemLink href={`${baseURL}/api/v1/backup/legacy/export/file`}>
|
||||||
primary="Restore Legacy Backup"
|
<ListItemText
|
||||||
secondary="You can also drop the backup file anywhere to restore"
|
primary="Create Legacy Backup"
|
||||||
/>
|
secondary="Backup library as a Tachiyomi legacy backup"
|
||||||
<input
|
/>
|
||||||
type="file"
|
</ListItemLink>
|
||||||
name="backup.json"
|
<ListItem button onClick={() => document.getElementById('backup-file')?.click()}>
|
||||||
id="backup-file"
|
<ListItemText
|
||||||
style={{ display: 'none' }}
|
primary="Restore Legacy Backup"
|
||||||
/>
|
secondary="You can also drag and drop the backup file here to restore"
|
||||||
</ListItem>
|
/>
|
||||||
</List>
|
</ListItem>
|
||||||
|
</List>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
id="backup-file"
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user