mirror of
https://github.com/kopia/kopia.git
synced 2026-04-30 19:03:38 -04:00
* cli: simplified mount command See https://youtu.be/1Nt_HIl-NWQ It will always use WebDAV on Windows and FUSE on Unix. Removed confusing options. New usage: $ kopia mount [--browse] Mounts all snapshots in a temporary filesystem directory (both Unix and Windows). $ kopia mount <object> [--browse] Mounts given object in a temporary filesystem directory (both Unix and Windows). $ kopia mount <object> z: [--browse] Mounts given object as a given drive letter in Windows (using temporary WebDAV mount). $ kopia mount <object> * [--browse] Mounts given object as a random drive letter in Windows. $ kopia mount <object> /mount/path [--browse] Mounts given object in given path in Unix. <object> can be the ID of a directory 'k<hash>' or 'all' Optional --browse automatically opens OS-native file browser. * htmlui: added UI for mounting directories See https://youtu.be/T-9SshVa1d8 for a quick demo. Also replaced some UI text with icons. * lint: windows-specific fix
141 lines
3.9 KiB
JavaScript
141 lines
3.9 KiB
JavaScript
import { faArrowLeft, faCopy } from '@fortawesome/free-solid-svg-icons';
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
import axios from 'axios';
|
|
import React, { Component } from 'react';
|
|
import Button from 'react-bootstrap/Button';
|
|
import Row from 'react-bootstrap/Row';
|
|
import Spinner from 'react-bootstrap/Spinner';
|
|
import { DirectoryItems } from "./DirectoryItems";
|
|
|
|
|
|
export class DirectoryObject extends Component {
|
|
constructor() {
|
|
super();
|
|
|
|
this.state = {
|
|
items: [],
|
|
isLoading: false,
|
|
error: null,
|
|
mountInfo: {},
|
|
oid: "",
|
|
};
|
|
|
|
this.mount = this.mount.bind(this);
|
|
this.unmount = this.unmount.bind(this);
|
|
this.browseMounted = this.browseMounted.bind(this);
|
|
this.copyPath = this.copyPath.bind(this);
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.fetchDirectory(this.props);
|
|
}
|
|
|
|
fetchDirectory(props) {
|
|
let oid = props.match.params.oid;
|
|
|
|
this.setState({
|
|
isLoading: true,
|
|
oid: oid,
|
|
});
|
|
|
|
axios.get('/api/v1/objects/' + oid).then(result => {
|
|
this.setState({
|
|
items: result.data.entries || [],
|
|
isLoading: false,
|
|
});
|
|
}).catch(error => this.setState({
|
|
error,
|
|
isLoading: false
|
|
}));
|
|
|
|
axios.get('/api/v1/mounts/' + oid).then(result => {
|
|
this.setState({
|
|
mountInfo: result.data,
|
|
});
|
|
}).catch(error => this.setState({
|
|
mountInfo: {},
|
|
}));
|
|
}
|
|
|
|
componentWillReceiveProps(props) {
|
|
this.fetchDirectory(props);
|
|
}
|
|
|
|
mount() {
|
|
axios.post('/api/v1/mounts', { "root": this.state.oid }).then(result => {
|
|
this.setState({
|
|
mountInfo: result.data,
|
|
});
|
|
}).catch(error => this.setState({
|
|
mountInfo: {},
|
|
}));
|
|
}
|
|
|
|
unmount() {
|
|
axios.delete('/api/v1/mounts/' + this.state.oid).then(result => {
|
|
this.setState({
|
|
mountInfo: {},
|
|
});
|
|
}).catch(error => this.setState({
|
|
error: error,
|
|
mountInfo: {},
|
|
}));
|
|
}
|
|
|
|
browseMounted() {
|
|
if (!window.require) {
|
|
alert('Directory browsing is not supported in a web browser. Use Kopia UI.');
|
|
return;
|
|
}
|
|
|
|
const { shell } = window.require('electron').remote;
|
|
shell.openItem(this.state.mountInfo.path)
|
|
}
|
|
|
|
copyPath() {
|
|
const el = document.querySelector("#mountedPath");
|
|
if (!el) {
|
|
return
|
|
}
|
|
|
|
el.select();
|
|
el.setSelectionRange(0, 99999);
|
|
|
|
document.execCommand("copy");
|
|
}
|
|
|
|
render() {
|
|
let { items, isLoading, error } = this.state;
|
|
if (error) {
|
|
return <p>ERROR: {error.message}</p>;
|
|
}
|
|
if (isLoading) {
|
|
return <Spinner animation="border" variant="primary" />;
|
|
}
|
|
|
|
const browsingSupported = !!window.require;
|
|
|
|
return <div class="padded">
|
|
<Row>
|
|
<Button size="xxl" variant="secondary" onClick={this.props.history.goBack} ><FontAwesomeIcon icon={faArrowLeft} /></Button>
|
|
|
|
{ this.state.mountInfo.path ? <>
|
|
<Button size="xxl" variant="info" onClick={this.unmount} >Unmount</Button>
|
|
{browsingSupported && <>
|
|
|
|
<Button size="xxl" variant="info" onClick={this.browseMounted} >Browse</Button>
|
|
</>}
|
|
<input id="mountedPath" value={this.state.mountInfo.path } />
|
|
<Button size="xxl" variant="primary" onClick={this.copyPath} ><FontAwesomeIcon icon={faCopy} /></Button>
|
|
</> : <>
|
|
<Button size="xxl" variant="primary" onClick={this.mount} >Mount</Button>
|
|
</>}
|
|
</Row>
|
|
<hr/>
|
|
<Row>
|
|
<DirectoryItems items={items} />
|
|
</Row>
|
|
</div>
|
|
}
|
|
}
|