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
*.swp

View File

@ -1,5 +1,5 @@
/** @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 { useState } from "react";
import { Box, Flex, jsx } from "theme-ui";
@ -28,7 +28,11 @@ const Index = () => {
<Container>
<Flex sx={{ alignItems: "center", height: 120 }}>
<Box>
<Typography sx={{ fontWeight: 700 }}>Sia Skynet</Typography>
<Typography sx={{ fontWeight: 700 }}>
<Link href="/">
Sia Skynet
</Link>
</Typography>
</Box>
<Box sx={{ ml: "auto" }}>
<Button href="/stats">

View File

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

View File

@ -22,8 +22,14 @@ function MyDropzone() {
const onDrop = useCallback(
acceptedFiles => {
setLoading(true)
const file = R.head(acceptedFiles)
const url = API_ENDPOINT + "/skyfile"
const file = acceptedFiles[0]
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()
fd.append("file", file)

View File

@ -1,17 +1,18 @@
import axios from "axios"
import cors from "cors"
import express, { Request, Response } from "express"
import fs from "fs";
import fileUpload, { UploadedFile } from "express-fileupload"
import { homedir } from "os"
import proxy from "express-http-proxy"
import requestId from "express-request-id"
import fs from "fs"
import morgan from 'morgan'
import { homedir } from "os"
import R from "ramda"
import shortid from "shortid"
import { Logger } from "winston"
import logger from "./logger"
// import * as AxiosLogger from 'axios-logger'
// AxiosLogger.setGlobalConfig({
// prefixText: 'your prefix',
@ -113,7 +114,9 @@ export class Server {
},
proxyReqPathResolver: req => {
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> {
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}`)
try {
@ -194,7 +200,7 @@ export class Server {
file.data,
{
maxContentLength: MAX_UPLOAD_FILESIZE,
params: { name: file.name }
params: { filename: file.name }
}
)
return res.send(data)