Add parent
This commit is contained in:
parent
d8b9a83693
commit
8d937ca10e
1 changed files with 34 additions and 3 deletions
|
@ -9,12 +9,14 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
loaded: boolean;
|
||||||
folders: string[];
|
folders: string[];
|
||||||
files: string[];
|
files: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
class ObjectList extends React.Component<Props, State> {
|
class ObjectList extends React.Component<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
|
loaded: false,
|
||||||
folders: [],
|
folders: [],
|
||||||
files: [],
|
files: [],
|
||||||
};
|
};
|
||||||
|
@ -32,23 +34,52 @@ class ObjectList extends React.Component<Props, State> {
|
||||||
Delimiter: '/',
|
Delimiter: '/',
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
const pxlen = this.props.prefix.length;
|
||||||
|
|
||||||
const data = await this.props.client.send(command);
|
const data = await this.props.client.send(command);
|
||||||
console.log("ok", data);
|
console.log("ok", data);
|
||||||
this.setState({
|
this.setState({
|
||||||
folders: (data.CommonPrefixes || []).map((cp) => cp.Prefix!),
|
loaded: true,
|
||||||
files: (data.Contents || []).map((obj) => obj.Key!),
|
folders: (data.CommonPrefixes || []).map((cp) => cp.Prefix!.substring(pxlen)),
|
||||||
|
files: (data.Contents || []).map((obj) => obj.Key!.substring(pxlen)),
|
||||||
});
|
});
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.log("err", error);
|
console.log("err", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parentTag() {
|
||||||
|
let spl = this.props.prefix.split("/");
|
||||||
|
while (spl.pop() == "");
|
||||||
|
spl.push("");
|
||||||
|
let pp = spl.join("/");
|
||||||
|
return (
|
||||||
|
<li key="PARENT">
|
||||||
|
<Link to={ "/" + this.props.bucket + "/" + pp }>..</Link>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
let par = (this.props.prefix.length > 0 ?
|
||||||
|
this.parentTag()
|
||||||
|
: <></>);
|
||||||
|
|
||||||
|
if (!this.state.loaded) {
|
||||||
|
return (
|
||||||
|
<ul>
|
||||||
|
{ par }
|
||||||
|
<li>Loading...</li>
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul>
|
<ul>
|
||||||
|
{ par }
|
||||||
{ this.state.folders.map((f) =>
|
{ this.state.folders.map((f) =>
|
||||||
<li key={f + "/" }>
|
<li key={f + "/" }>
|
||||||
<Link to={ "/" + this.props.bucket + "/" + f }>{ f }</Link>
|
<Link to={ "/" + this.props.bucket + "/" + this.props.prefix + f }>{ f }</Link>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
{ this.state.files.map((f) =>
|
{ this.state.files.map((f) =>
|
||||||
|
|
Loading…
Reference in a new issue