Merge branch 'logging'

This commit is contained in:
PJ 2020-02-04 19:27:10 +01:00
commit d8a743b02f
5 changed files with 34 additions and 11 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
node_modules
**/*/.next
*.swo *.swo
*.swp *.swp

View File

@ -1,5 +1,5 @@
/** @jsx jsx */ /** @jsx jsx */
import { AppBar, Button, Card, CardContent, Container, Input, Tab, Tabs, Typography } from "@material-ui/core"; import { AppBar, Button, Card, CardContent, Container, Input, Link, Tab, Tabs, Typography } from "@material-ui/core";
import * as R from "ramda"; import * as R from "ramda";
import { useState } from "react"; import { useState } from "react";
import { Box, Flex, jsx } from "theme-ui"; import { Box, Flex, jsx } from "theme-ui";
@ -28,7 +28,11 @@ const Index = () => {
<Container> <Container>
<Flex sx={{ alignItems: "center", height: 120 }}> <Flex sx={{ alignItems: "center", height: 120 }}>
<Box> <Box>
<Typography sx={{ fontWeight: 700 }}>Sia Skynet</Typography> <Typography sx={{ fontWeight: 700 }}>
<Link href="/">
Sia Skynet
</Link>
</Typography>
</Box> </Box>
<Box sx={{ ml: "auto" }}> <Box sx={{ ml: "auto" }}>
<Button href="/stats"> <Button href="/stats">

View File

@ -1,5 +1,5 @@
/** @jsx jsx */ /** @jsx jsx */
import { Button, CircularProgress, Container, Typography } from "@material-ui/core"; import { Button, CircularProgress, Container, Link, Typography } from "@material-ui/core";
import axios from "axios"; import axios from "axios";
import { useState } from "react"; import { useState } from "react";
import { Box, Flex, jsx } from "theme-ui"; import { Box, Flex, jsx } from "theme-ui";
@ -60,7 +60,11 @@ const Stats = () => {
<Container> <Container>
<Flex sx={{ alignItems: "center", height: 120 }}> <Flex sx={{ alignItems: "center", height: 120 }}>
<Box> <Box>
<Typography sx={{ fontWeight: 700 }}>Sia Skynet</Typography> <Typography sx={{ fontWeight: 700 }}>
<Link href="/">
Sia Skynet
</Link>
</Typography>
</Box> </Box>
<Box sx={{ ml: "auto" }}> <Box sx={{ ml: "auto" }}>
<Button href="/stats"> <Button href="/stats">

View File

@ -22,8 +22,14 @@ function MyDropzone() {
const onDrop = useCallback( const onDrop = useCallback(
acceptedFiles => { acceptedFiles => {
setLoading(true) setLoading(true)
const file = R.head(acceptedFiles) const file = acceptedFiles[0]
const url = API_ENDPOINT + "/skyfile" if (!file) {
setError("An unexpected error occured. Check console for details.")
setLoading(false)
return
}
const url = `${API_ENDPOINT}/skyfile?filename=${file.name}`
const fd = new FormData() const fd = new FormData()
fd.append("file", file) fd.append("file", file)

View File

@ -1,17 +1,18 @@
import axios from "axios" import axios from "axios"
import cors from "cors" import cors from "cors"
import express, { Request, Response } from "express" import express, { Request, Response } from "express"
import fs from "fs";
import fileUpload, { UploadedFile } from "express-fileupload" import fileUpload, { UploadedFile } from "express-fileupload"
import { homedir } from "os"
import proxy from "express-http-proxy" import proxy from "express-http-proxy"
import requestId from "express-request-id" import requestId from "express-request-id"
import fs from "fs"
import morgan from 'morgan' import morgan from 'morgan'
import { homedir } from "os"
import R from "ramda" import R from "ramda"
import shortid from "shortid" import shortid from "shortid"
import { Logger } from "winston" import { Logger } from "winston"
import logger from "./logger" import logger from "./logger"
// import * as AxiosLogger from 'axios-logger' // import * as AxiosLogger from 'axios-logger'
// AxiosLogger.setGlobalConfig({ // AxiosLogger.setGlobalConfig({
// prefixText: 'your prefix', // prefixText: 'your prefix',
@ -113,7 +114,9 @@ export class Server {
}, },
proxyReqPathResolver: req => { proxyReqPathResolver: req => {
const { hash } = req.params const { hash } = req.params
return `/skynet/skylink/${hash}` return req.query && req.query.attachment
? `/skynet/skylink/${hash}?attachment=true`
: `/skynet/skylink/${hash}`
} }
}) })
) )
@ -184,8 +187,11 @@ export class Server {
private async handleSkyfilePOST(req: Request, res: Response): Promise<Response> { private async handleSkyfilePOST(req: Request, res: Response): Promise<Response> {
const file = selectFile(req) as UploadedFile const file = selectFile(req) as UploadedFile
const uid = shortid.generate() if (!file) {
res.status(400).send({ error: "Missing file" })
}
const uid = shortid.generate()
this.logger.info(`POST skyfile w/name ${file.name} and uid ${uid}`) this.logger.info(`POST skyfile w/name ${file.name} and uid ${uid}`)
try { try {
@ -194,7 +200,7 @@ export class Server {
file.data, file.data,
{ {
maxContentLength: MAX_UPLOAD_FILESIZE, maxContentLength: MAX_UPLOAD_FILESIZE,
params: { name: file.name } params: { filename: file.name }
} }
) )
return res.send(data) return res.send(data)