diff --git a/.prettierrc.json b/.prettierrc.json index b4ef012..b8de456 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,4 @@ { "proseWrap": "never", - "singleQuote": true, - "semi": false + "singleQuote": true } diff --git a/api/.prettierrc.json b/api/.prettierrc.json index b4ef012..b8de456 100644 --- a/api/.prettierrc.json +++ b/api/.prettierrc.json @@ -1,5 +1,4 @@ { "proseWrap": "never", - "singleQuote": true, - "semi": false + "singleQuote": true } diff --git a/api/schema.js b/api/schema.js index 42a2685..a3d6340 100644 --- a/api/schema.js +++ b/api/schema.js @@ -1,10 +1,10 @@ -'use strict' +'use strict'; -const { GraphQLSchema } = require('graphql') -const { MutationType } = require('./types/Mutation') -const { QueryType } = require('./types/Query') +const { GraphQLSchema } = require('graphql'); +const { MutationType } = require('./types/Mutation'); +const { QueryType } = require('./types/Query'); exports.schema = new GraphQLSchema({ query: QueryType, mutation: MutationType, -}) +}); diff --git a/api/server.js b/api/server.js index 913629f..69abc45 100644 --- a/api/server.js +++ b/api/server.js @@ -1,22 +1,22 @@ -'use strict' +'use strict'; -const { createWriteStream, unlink } = require('fs') -const { ApolloServer } = require('apollo-server-koa') -const Koa = require('koa') -const lowdb = require('lowdb') -const FileSync = require('lowdb/adapters/FileSync') -const mkdirp = require('mkdirp') -const shortid = require('shortid') -const { schema } = require('./schema') +const { createWriteStream, unlink } = require('fs'); +const { ApolloServer } = require('apollo-server-koa'); +const Koa = require('koa'); +const lowdb = require('lowdb'); +const FileSync = require('lowdb/adapters/FileSync'); +const mkdirp = require('mkdirp'); +const shortid = require('shortid'); +const { schema } = require('./schema'); -const UPLOAD_DIR = './uploads' -const db = lowdb(new FileSync('db.json')) +const UPLOAD_DIR = './uploads'; +const db = lowdb(new FileSync('db.json')); // Seed an empty DB. -db.defaults({ uploads: [] }).write() +db.defaults({ uploads: [] }).write(); // Ensure upload directory exists. -mkdirp.sync(UPLOAD_DIR) +mkdirp.sync(UPLOAD_DIR); /** * Stores a GraphQL file upload. The file is stored in the filesystem and its @@ -25,44 +25,44 @@ mkdirp.sync(UPLOAD_DIR) * @returns {object} File metadata. */ const storeUpload = async (upload) => { - const { createReadStream, filename, mimetype } = await upload - const stream = createReadStream() - const id = shortid.generate() - const path = `${UPLOAD_DIR}/${id}-${filename}` - const file = { id, filename, mimetype, path } + const { createReadStream, filename, mimetype } = await upload; + const stream = createReadStream(); + const id = shortid.generate(); + const path = `${UPLOAD_DIR}/${id}-${filename}`; + const file = { id, filename, mimetype, path }; // Store the file in the filesystem. await new Promise((resolve, reject) => { // Create a stream to which the upload will be written. - const writeStream = createWriteStream(path) + const writeStream = createWriteStream(path); // When the upload is fully written, resolve the promise. - writeStream.on('finish', resolve) + writeStream.on('finish', resolve); // If there's an error writing the file, remove the partially written file // and reject the promise. writeStream.on('error', (error) => { unlink(path, () => { - reject(error) - }) - }) + reject(error); + }); + }); // In node <= 13, errors are not automatically propagated between piped // streams. If there is an error receiving the upload, destroy the write // stream with the corresponding error. - stream.on('error', (error) => writeStream.destroy(error)) + stream.on('error', (error) => writeStream.destroy(error)); // Pipe the upload into the write stream. - stream.pipe(writeStream) - }) + stream.pipe(writeStream); + }); // Record the file metadata in the DB. - db.get('uploads').push(file).write() + db.get('uploads').push(file).write(); - return file -} + return file; +}; -const app = new Koa() +const app = new Koa(); const server = new ApolloServer({ uploads: { // Limits here should be stricter than config for surrounding @@ -74,14 +74,14 @@ const server = new ApolloServer({ }, schema, context: { db, storeUpload }, -}) +}); -server.applyMiddleware({ app }) +server.applyMiddleware({ app }); app.listen(process.env.PORT, (error) => { - if (error) throw error + if (error) throw error; console.info( `Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.` - ) -}) + ); +}); diff --git a/api/types/File.js b/api/types/File.js index f05940d..20db518 100644 --- a/api/types/File.js +++ b/api/types/File.js @@ -1,11 +1,11 @@ -'use strict' +'use strict'; const { GraphQLNonNull, GraphQLObjectType, GraphQLString, GraphQLID, -} = require('graphql') +} = require('graphql'); exports.FileType = new GraphQLObjectType({ name: 'File', @@ -28,4 +28,4 @@ exports.FileType = new GraphQLObjectType({ type: GraphQLNonNull(GraphQLString), }, }), -}) +}); diff --git a/api/types/Mutation.js b/api/types/Mutation.js index e8db0ce..41dda54 100644 --- a/api/types/Mutation.js +++ b/api/types/Mutation.js @@ -1,9 +1,9 @@ -'use strict' +'use strict'; -const { GraphQLUpload } = require('apollo-server-koa') -const { GraphQLList, GraphQLObjectType, GraphQLNonNull } = require('graphql') -const promisesAll = require('promises-all') -const { FileType } = require('./File') +const { GraphQLUpload } = require('apollo-server-koa'); +const { GraphQLList, GraphQLObjectType, GraphQLNonNull } = require('graphql'); +const promisesAll = require('promises-all'); +const { FileType } = require('./File'); exports.MutationType = new GraphQLObjectType({ name: 'Mutation', @@ -31,15 +31,15 @@ exports.MutationType = new GraphQLObjectType({ async resolve(parent, { files }, { storeUpload }) { const { resolve, reject } = await promisesAll.all( files.map(storeUpload) - ) + ); if (reject.length) reject.forEach(({ name, message }) => console.error(`${name}: ${message}`) - ) + ); - return resolve + return resolve; }, }, }), -}) +}); diff --git a/api/types/Query.js b/api/types/Query.js index 8728bb8..90c9455 100644 --- a/api/types/Query.js +++ b/api/types/Query.js @@ -1,7 +1,7 @@ -'use strict' +'use strict'; -const { GraphQLList, GraphQLObjectType, GraphQLNonNull } = require('graphql') -const { FileType } = require('./File') +const { GraphQLList, GraphQLObjectType, GraphQLNonNull } = require('graphql'); +const { FileType } = require('./File'); exports.QueryType = new GraphQLObjectType({ name: 'Query', @@ -12,4 +12,4 @@ exports.QueryType = new GraphQLObjectType({ resolve: (source, args, { db }) => db.get('uploads').value(), }, }), -}) +}); diff --git a/app/.prettierrc.json b/app/.prettierrc.json index b4ef012..b8de456 100644 --- a/app/.prettierrc.json +++ b/app/.prettierrc.json @@ -1,5 +1,4 @@ { "proseWrap": "never", - "singleQuote": true, - "semi": false + "singleQuote": true } diff --git a/app/components/Header.js b/app/components/Header.js index 027e731..9be856e 100644 --- a/app/components/Header.js +++ b/app/components/Header.js @@ -7,4 +7,4 @@ export const Header = (props) => ( } `} > -) +); diff --git a/app/components/Page.js b/app/components/Page.js index e432c06..58ed106 100644 --- a/app/components/Page.js +++ b/app/components/Page.js @@ -1,4 +1,4 @@ -import Head from 'next/head' +import Head from 'next/head'; export const Page = ({ title, children }) => ( <> @@ -7,4 +7,4 @@ export const Page = ({ title, children }) => ( {children} > -) +); diff --git a/app/components/Section.js b/app/components/Section.js index 89e9061..1fc5600 100644 --- a/app/components/Section.js +++ b/app/components/Section.js @@ -7,4 +7,4 @@ export const Section = (props) => ( } `} > -) +); diff --git a/app/components/UploadBlob.js b/app/components/UploadBlob.js index a9dfaa3..6db5b3a 100644 --- a/app/components/UploadBlob.js +++ b/app/components/UploadBlob.js @@ -1,7 +1,7 @@ -import { useApolloClient, useMutation } from '@apollo/react-hooks' -import { ButtonSubmit, Code, Fieldset, Textbox } from 'device-agnostic-ui' -import gql from 'graphql-tag' -import React from 'react' +import { useApolloClient, useMutation } from '@apollo/react-hooks'; +import { ButtonSubmit, Code, Fieldset, Textbox } from 'device-agnostic-ui'; +import gql from 'graphql-tag'; +import React from 'react'; const SINGLE_UPLOAD_MUTATION = gql` mutation singleUpload($file: Upload!) { @@ -9,28 +9,28 @@ const SINGLE_UPLOAD_MUTATION = gql` id } } -` +`; export const UploadBlob = () => { - const [name, setName] = React.useState('') - const [content, setContent] = React.useState('') + const [name, setName] = React.useState(''); + const [content, setContent] = React.useState(''); const [singleUploadMutation, { loading }] = useMutation( SINGLE_UPLOAD_MUTATION - ) - const apolloClient = useApolloClient() + ); + const apolloClient = useApolloClient(); - const onNameChange = ({ target: { value } }) => setName(value) - const onContentChange = ({ target: { value } }) => setContent(value) + const onNameChange = ({ target: { value } }) => setName(value); + const onContentChange = ({ target: { value } }) => setContent(value); const onSubmit = (event) => { - event.preventDefault() + event.preventDefault(); - const file = new Blob([content], { type: 'text/plain' }) - file.name = `${name}.txt` + const file = new Blob([content], { type: 'text/plain' }); + file.name = `${name}.txt`; singleUploadMutation({ variables: { file } }).then(() => { - apolloClient.resetStore() - }) - } + apolloClient.resetStore(); + }); + }; return (
- ) -} + ); +}; diff --git a/app/components/UploadFile.js b/app/components/UploadFile.js index 2b4b552..58cc221 100644 --- a/app/components/UploadFile.js +++ b/app/components/UploadFile.js @@ -1,5 +1,5 @@ -import { useApolloClient, useMutation } from '@apollo/react-hooks' -import gql from 'graphql-tag' +import { useApolloClient, useMutation } from '@apollo/react-hooks'; +import gql from 'graphql-tag'; const SINGLE_UPLOAD_MUTATION = gql` mutation singleUpload($file: Upload!) { @@ -7,11 +7,11 @@ const SINGLE_UPLOAD_MUTATION = gql` id } } -` +`; export const UploadFile = () => { - const [uploadFileMutation] = useMutation(SINGLE_UPLOAD_MUTATION) - const apolloClient = useApolloClient() + const [uploadFileMutation] = useMutation(SINGLE_UPLOAD_MUTATION); + const apolloClient = useApolloClient(); const onChange = ({ target: { @@ -21,8 +21,8 @@ export const UploadFile = () => { }) => validity.valid && uploadFileMutation({ variables: { file } }).then(() => { - apolloClient.resetStore() - }) + apolloClient.resetStore(); + }); - return -} + return ; +}; diff --git a/app/components/UploadFileList.js b/app/components/UploadFileList.js index e98c420..19dd7bf 100644 --- a/app/components/UploadFileList.js +++ b/app/components/UploadFileList.js @@ -1,5 +1,5 @@ -import { useApolloClient, useMutation } from '@apollo/react-hooks' -import gql from 'graphql-tag' +import { useApolloClient, useMutation } from '@apollo/react-hooks'; +import gql from 'graphql-tag'; const MULTIPLE_UPLOAD_MUTATION = gql` mutation multipleUpload($files: [Upload!]!) { @@ -7,17 +7,17 @@ const MULTIPLE_UPLOAD_MUTATION = gql` id } } -` +`; export const UploadFileList = () => { - const [multipleUploadMutation] = useMutation(MULTIPLE_UPLOAD_MUTATION) - const apolloClient = useApolloClient() + const [multipleUploadMutation] = useMutation(MULTIPLE_UPLOAD_MUTATION); + const apolloClient = useApolloClient(); const onChange = ({ target: { validity, files } }) => validity.valid && multipleUploadMutation({ variables: { files } }).then(() => { - apolloClient.resetStore() - }) + apolloClient.resetStore(); + }); - return -} + return ; +}; diff --git a/app/components/Uploads.js b/app/components/Uploads.js index f61ac1f..bfe724c 100644 --- a/app/components/Uploads.js +++ b/app/components/Uploads.js @@ -1,6 +1,6 @@ -import { useQuery } from '@apollo/react-hooks' -import { Scroll, Table } from 'device-agnostic-ui' -import gql from 'graphql-tag' +import { useQuery } from '@apollo/react-hooks'; +import { Scroll, Table } from 'device-agnostic-ui'; +import gql from 'graphql-tag'; const UPLOADS_QUERY = gql` query uploads { @@ -11,10 +11,10 @@ const UPLOADS_QUERY = gql` path } } -` +`; export const Uploads = () => { - const { data: { uploads = [] } = {} } = useQuery(UPLOADS_QUERY) + const { data: { uploads = [] } = {} } = useQuery(UPLOADS_QUERY); return (