-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c79f20
commit 455a35f
Showing
8 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) Contributors to the Suwayomi project | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import React, { useContext, useEffect } from 'react'; | ||
import { ListItemIcon } from '@material-ui/core'; | ||
import List from '@material-ui/core/List'; | ||
import InboxIcon from '@material-ui/icons/Inbox'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import { fromEvent } from 'file-selector'; | ||
import ListItemLink from '../../util/ListItemLink'; | ||
import NavbarContext from '../../context/NavbarContext'; | ||
import client from '../../util/client'; | ||
|
||
export default function Backup() { | ||
const { setTitle, setAction } = useContext(NavbarContext); | ||
useEffect(() => { setTitle('Backup'); setAction(<></>); }, []); | ||
|
||
const { baseURL } = client.defaults; | ||
|
||
const submitBackup = (file: File) => { | ||
file.text() | ||
.then( | ||
(fileContent: string) => { | ||
client.post('/api/v1/backup/legacy/import', | ||
fileContent, { headers: { 'Content-Type': 'application/json' } }); | ||
}, | ||
); | ||
}; | ||
|
||
const dropHandler = async (e: Event) => { | ||
e.preventDefault(); | ||
const files = await fromEvent(e); | ||
|
||
submitBackup(files[0] as File); | ||
}; | ||
|
||
const dragOverHandler = (e: Event) => { | ||
e.preventDefault(); | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener('drop', dropHandler); | ||
document.addEventListener('dragover', dragOverHandler); | ||
|
||
const input = document.getElementById('backup-file'); | ||
input?.addEventListener('change', async (evt) => { | ||
const files = await fromEvent(evt); | ||
submitBackup(files[0] as File); | ||
}); | ||
|
||
return () => { | ||
document.removeEventListener('drop', dropHandler); | ||
document.removeEventListener('dragover', dragOverHandler); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<List style={{ padding: 0 }}> | ||
<ListItemLink href={`${baseURL}/api/v1/backup/legacy/export/file`}> | ||
<ListItemIcon> | ||
<InboxIcon /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary="Create Legacy Backup" | ||
secondary="Backup library as a Tachiyomi legacy backup" | ||
/> | ||
</ListItemLink> | ||
<ListItem button onClick={() => document.getElementById('backup-file')?.click()}> | ||
<ListItemIcon> | ||
<InboxIcon /> | ||
</ListItemIcon> | ||
<ListItemText | ||
primary="Restore Legacy Backup" | ||
secondary="You can also drop the backup file anywhere to restore" | ||
/> | ||
<input | ||
type="file" | ||
name="backup.json" | ||
id="backup-file" | ||
style={{ display: 'none' }} | ||
/> | ||
</ListItem> | ||
</List> | ||
|
||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (C) Contributors to the Suwayomi project | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import React from 'react'; | ||
import ListItem, { ListItemProps } from '@material-ui/core/ListItem'; | ||
|
||
export default function ListItemLink(props: ListItemProps<'a', { button?: true }>) { | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <ListItem button component="a" {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5136,6 +5136,13 @@ [email protected]: | |
loader-utils "^2.0.0" | ||
schema-utils "^3.0.0" | ||
|
||
file-selector@^0.2.4: | ||
version "0.2.4" | ||
resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.2.4.tgz#7b98286f9dbb9925f420130ea5ed0a69238d4d80" | ||
integrity sha512-ZDsQNbrv6qRi1YTDOEWzf5J2KjZ9KMI1Q2SGeTkCJmNNW25Jg4TW4UMcmoqcg4WrAyKRcpBXdbWRxkfrOzVRbA== | ||
dependencies: | ||
tslib "^2.0.3" | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" | ||
|