initial linkfile impl
This commit is contained in:
parent
bdbd5b81c9
commit
cae5d7b09c
|
@ -10,43 +10,37 @@ import {
|
||||||
makeStyles,
|
makeStyles,
|
||||||
AppBar,
|
AppBar,
|
||||||
Tabs,
|
Tabs,
|
||||||
Tab
|
Tab,
|
||||||
|
Input
|
||||||
} from "@material-ui/core"
|
} from "@material-ui/core"
|
||||||
import Dropzone from "../src/components/Dropzone"
|
import Dropzone from "../src/components/Dropzone"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { TabPanel } from "../src/components/TabPanel"
|
import { TabPanel } from "../src/components/TabPanel"
|
||||||
|
import * as R from "ramda"
|
||||||
const useStyles = makeStyles({
|
|
||||||
card: {
|
|
||||||
minWidth: 275
|
|
||||||
},
|
|
||||||
bullet: {
|
|
||||||
display: "inline-block",
|
|
||||||
margin: "0 2px",
|
|
||||||
transform: "scale(0.8)"
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
fontSize: 14
|
|
||||||
},
|
|
||||||
pos: {
|
|
||||||
marginBottom: 12
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
const classes = useStyles({})
|
const [value, setValue] = useState(1)
|
||||||
const [value, setValue] = useState(0)
|
const [linkfileUrl, setInput] = useState("")
|
||||||
|
|
||||||
const handleChange = (event, newValue) => {
|
const handleChange = (event, newValue) => {
|
||||||
setValue(newValue)
|
setValue(newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const directView = () => {
|
||||||
|
const removeHead = R.compose(R.tail, R.split("sia://"))
|
||||||
|
const hash = removeHead(linkfileUrl)[0]
|
||||||
|
if (window) {
|
||||||
|
var win = window.open(`/direct/${hash}`, "_blank")
|
||||||
|
win.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box color="white">
|
<Box color="white">
|
||||||
<Container>
|
<Container>
|
||||||
<Flex sx={{ alignItems: "center", height: 120 }}>
|
<Flex sx={{ alignItems: "center", height: 120 }}>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography sx={{ fontWeight: 500 }}>Sia View Node</Typography>
|
<Typography sx={{ fontWeight: 700 }}>Sia Skynet</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{ ml: "auto" }}>
|
<Box sx={{ ml: "auto" }}>
|
||||||
<Button href="https://sia.tech/" target="_blank">
|
<Button href="https://sia.tech/" target="_blank">
|
||||||
|
@ -82,7 +76,35 @@ const Index = () => {
|
||||||
<Container>
|
<Container>
|
||||||
<TabPanel value={value} index={1}>
|
<TabPanel value={value} index={1}>
|
||||||
<Card sx={{ width: "100%" }}>
|
<Card sx={{ width: "100%" }}>
|
||||||
<CardContent></CardContent>
|
<CardContent>
|
||||||
|
<Flex
|
||||||
|
sx={{
|
||||||
|
height: 400,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
flexDirection: "column"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<p>Download a file by pasting in a Sia linkfile below:</p>
|
||||||
|
<Box sx={{ width: "60%" }}>
|
||||||
|
<Input
|
||||||
|
placeholder="sia://"
|
||||||
|
value={linkfileUrl}
|
||||||
|
onChange={e => setInput(e.target.value)}
|
||||||
|
sx={{ width: "100%" }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ mt: 3 }}>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={directView}
|
||||||
|
>
|
||||||
|
Download
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
|
@ -18,49 +18,64 @@ const splitFilename = R.compose(R.head, R.split(".sia"))
|
||||||
function MyDropzone() {
|
function MyDropzone() {
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState(null)
|
const [error, setError] = useState(null)
|
||||||
const formRef = useRef(null)
|
const [link, setLink] = useState("")
|
||||||
const inputRef = useRef(null)
|
|
||||||
|
|
||||||
const onDrop = useCallback(
|
const onDrop = useCallback(
|
||||||
acceptedFiles => {
|
acceptedFiles => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const file = R.head(acceptedFiles)
|
const file = R.head(acceptedFiles)
|
||||||
const url = API_ENDPOINT + "/linkfile/upload"
|
const url = API_ENDPOINT + "/linkfile/upload"
|
||||||
console.log("file is", file)
|
const fd = new FormData()
|
||||||
|
fd.append("file", file)
|
||||||
|
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: file
|
body: fd,
|
||||||
|
mode: "cors"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
return res.json()
|
return res.json()
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(({ sialink }) => {
|
||||||
console.log("WE OUT HERE BOYS", data)
|
console.log("WE OUT HERE BOYS", sialink)
|
||||||
|
setLink(sialink)
|
||||||
|
setLoading(false)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log("error is", e)
|
console.log("Upload error:", e)
|
||||||
|
setError("An unexpected error occured. Check console for details.")
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[loading, setLoading, error, setError, formRef]
|
[loading, setLoading, error, setError]
|
||||||
)
|
)
|
||||||
|
|
||||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop })
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Flex
|
{link ? (
|
||||||
{...getRootProps()}
|
<Flex
|
||||||
sx={{ height: 400, justifyContent: "center", alignItems: "center" }}
|
sx={{ height: 400, justifyContent: "center", alignItems: "center" }}
|
||||||
>
|
>
|
||||||
<input {...getInputProps()} />
|
<h5>{link}</h5>
|
||||||
{isDragActive ? (
|
</Flex>
|
||||||
<p>Drop file here ...</p>
|
) : (
|
||||||
) : (
|
<Flex
|
||||||
<p>Drag 'n' drop a file here, or click to select a file</p>
|
{...getRootProps()}
|
||||||
)}
|
sx={{ height: 400, justifyContent: "center", alignItems: "center" }}
|
||||||
</Flex>
|
>
|
||||||
|
<input {...getInputProps()} />
|
||||||
|
{isDragActive && !loading && !error && !link && (
|
||||||
|
<p>Drop file here ...</p>
|
||||||
|
)}
|
||||||
|
{!isDragActive && !loading && !error && !link && (
|
||||||
|
<p>Drag 'n' drop a file here, or click to select a file</p>
|
||||||
|
)}
|
||||||
|
{loading && <CircularProgress />}
|
||||||
|
{error && !loading && <h5>{error}</h5>}
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ export class Server {
|
||||||
private setRoutes = (): void => {
|
private setRoutes = (): void => {
|
||||||
this.app.use(
|
this.app.use(
|
||||||
cors({
|
cors({
|
||||||
origin: "http://localhost:*",
|
origin: "*",
|
||||||
credentials: true
|
credentials: true
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -71,7 +71,7 @@ export class Server {
|
||||||
// siafile
|
// siafile
|
||||||
this.app.post("/siafile", this.postSiaFile)
|
this.app.post("/siafile", this.postSiaFile)
|
||||||
// linkfile
|
// linkfile
|
||||||
this.app.post("/linkfile", this.handleLinkUpload)
|
this.app.post("/linkfile/upload", this.handleLinkUpload)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleLinkUpload(
|
private async handleLinkUpload(
|
||||||
|
@ -98,7 +98,7 @@ export class Server {
|
||||||
console.log("data is ", data)
|
console.log("data is ", data)
|
||||||
return res.send(data)
|
return res.send(data)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("err", err)
|
console.log("err", err.message)
|
||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue