Merge branch 'dev' of gitlab.com:NebulousLabs/siawebviewer into dev

This commit is contained in:
Eddie Wang 2019-12-20 09:02:02 -08:00
commit bdbd5b81c9
No known key found for this signature in database
GPG Key ID: 595553ADC5949F24
4 changed files with 56 additions and 2 deletions

View File

@ -0,0 +1,6 @@
/** @jsx jsx */
import { Box, jsx } from "theme-ui"
export const TabPanel = ({ children, value, index, ...props }) => {
return <Box>{value === index && <Box sx={{ p: 3 }}>{children}</Box>}</Box>
}

View File

@ -17,6 +17,7 @@
"express-fileupload": "1.1.6", "express-fileupload": "1.1.6",
"express-session": "1.17.0", "express-session": "1.17.0",
"ramda": "0.26.1", "ramda": "0.26.1",
"shortid": "2.2.15",
"typescript": "^3.5.2" "typescript": "^3.5.2"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,4 +1,5 @@
import * as express from "express" import * as express from "express"
import * as shortid from "shortid"
import * as fileUpload from "express-fileupload" import * as fileUpload from "express-fileupload"
import * as R from "ramda" import * as R from "ramda"
import * as cors from "cors" import * as cors from "cors"
@ -19,6 +20,10 @@ const siad = axios.create({
} }
}) })
// Ramda shared utility functions
const selectFile = R.path(["files", "file"])
const pName = R.prop("name")
declare var __DEV__: boolean declare var __DEV__: boolean
export class Server { export class Server {
@ -63,14 +68,45 @@ export class Server {
limits: { fileSize: 10 * 1024 * 1024 } limits: { fileSize: 10 * 1024 * 1024 }
}) })
) )
// siafile
this.app.post("/siafile", this.postSiaFile) this.app.post("/siafile", this.postSiaFile)
// linkfile
this.app.post("/linkfile", this.handleLinkUpload)
}
private async handleLinkUpload(
req: express.Request,
res: express.Response
): Promise<express.Response> {
const fileToUpload: any = selectFile(req)
console.log("file:", fileToUpload)
const filename = pName(fileToUpload)
console.log("filename:", filename)
const uid = shortid.generate()
console.log("uid:", uid)
try {
// TODO: add uuid so we don't collide
const { data } = await siad.post(
`/renter/linkfile/linkfiles/${uid}`,
fileToUpload.data,
{
params: {
name: filename
}
}
)
console.log("data is ", data)
return res.send(data)
} catch (err) {
console.log("err", err)
return res.sendStatus(500)
}
} }
private async postSiaFile( private async postSiaFile(
req: express.Request & any, req: express.Request & any,
res: express.Response res: express.Response
): Promise<express.Response> { ): Promise<express.Response> {
const selectFile = R.path(["files", "file"])
try { try {
const file: any = selectFile(req) const file: any = selectFile(req)
@ -89,7 +125,6 @@ export class Server {
) )
const contentLength = headers["Content-Length"] const contentLength = headers["Content-Length"]
const pName = R.prop("name")
const splitFilename = R.compose(R.head, R.split(".sia")) const splitFilename = R.compose(R.head, R.split(".sia"))
const fileName = R.compose(splitFilename, pName)(file) const fileName = R.compose(splitFilename, pName)(file)

View File

@ -6451,6 +6451,11 @@ nan@^2.12.1:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
nanoid@^2.1.0:
version "2.1.8"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.8.tgz#2dbb0224231b246e3b4c819de7bfea6384dabf08"
integrity sha512-g1z+n5s26w0TGKh7gjn7HCqurNKMZWzH08elXzh/gM/csQHd/UqDV6uxMghQYg9IvqRPm1QpeMk50YMofHvEjQ==
nanomatch@^1.2.9: nanomatch@^1.2.9:
version "1.2.13" version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@ -8543,6 +8548,13 @@ shell-quote@^1.6.1:
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2" resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg== integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
shortid@2.2.15:
version "2.2.15"
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.15.tgz#2b902eaa93a69b11120373cd42a1f1fe4437c122"
integrity sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==
dependencies:
nanoid "^2.1.0"
signal-exit@^3.0.0, signal-exit@^3.0.2: signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2" version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"