From a999abfbf86a350145868716a754859cb63ba990 Mon Sep 17 00:00:00 2001 From: dicedtomato <35403473+diced@users.noreply.github.com> Date: Wed, 6 Jul 2022 16:57:39 +0000 Subject: [PATCH] feat: a bunch of changes --- .eslintrc.json | 2 +- README.md | 4 +- config.example.toml | 33 +- esbuild.config.js | 2 + next.config.js | 2 + package.json | 1 - scripts/migrate-v2-v3.js | 35 - src/components/Backdrop.tsx | 8 - src/components/Card.tsx | 11 +- src/components/{Image.tsx => File.tsx} | 10 +- src/components/ImagesTable.tsx | 33 +- src/components/Layout.tsx | 28 +- src/components/Link.tsx | 8 +- src/components/MutedText.tsx | 5 + src/components/SmallTable.tsx | 29 + src/components/StatText.tsx | 6 - src/components/Theming.tsx | 16 +- src/components/dropzone/Dropzone.tsx | 52 + src/components/dropzone/DropzoneFile.tsx | 60 + src/components/pages/Dashboard.tsx | 78 +- src/components/pages/Files.tsx | 89 +- src/components/pages/Manage.tsx | 71 +- src/components/pages/Stats.tsx | 68 +- src/components/pages/Upload.tsx | 115 +- src/components/pages/Urls.tsx | 23 +- src/components/pages/Users.tsx | 18 +- src/lib/clientUtils.ts | 16 +- src/lib/config/readConfig.ts | 2 +- src/lib/config/validateConfig.ts | 4 +- src/lib/datasource.ts | 6 +- scripts/exts.js => src/lib/exts.ts | 6 +- src/lib/middleware/withZipline.ts | 4 +- scripts/mimes.js => src/lib/mimes.ts | 6 +- src/lib/util.ts | 3 +- src/pages/404.tsx | 14 +- src/pages/500.tsx | 25 + src/pages/[...id].tsx | 2 +- src/pages/_app.tsx | 1 - src/pages/_error.tsx | 30 + src/pages/api/auth/image.ts | 2 +- src/pages/api/upload.ts | 4 +- src/pages/api/user/export.ts | 14 +- src/pages/auth/login.tsx | 25 +- src/pages/auth/logout.tsx | 10 +- src/pages/code/[id].tsx | 2 +- src/pages/dashboard/files.tsx | 5 +- src/pages/dashboard/index.tsx | 4 +- src/pages/dashboard/manage.tsx | 3 +- src/pages/dashboard/stats.tsx | 4 +- src/pages/dashboard/upload.tsx | 5 +- src/pages/dashboard/urls.tsx | 3 +- src/pages/dashboard/users.tsx | 3 +- src/server/index.ts | 20 +- yarn.lock | 1920 +++++++++------------- 54 files changed, 1312 insertions(+), 1638 deletions(-) delete mode 100644 scripts/migrate-v2-v3.js delete mode 100644 src/components/Backdrop.tsx rename src/components/{Image.tsx => File.tsx} (94%) create mode 100644 src/components/MutedText.tsx create mode 100644 src/components/SmallTable.tsx delete mode 100644 src/components/StatText.tsx create mode 100644 src/components/dropzone/Dropzone.tsx create mode 100644 src/components/dropzone/DropzoneFile.tsx rename scripts/exts.js => src/lib/exts.ts (94%) rename scripts/mimes.js => src/lib/mimes.ts (98%) create mode 100644 src/pages/500.tsx create mode 100644 src/pages/_error.tsx diff --git a/.eslintrc.json b/.eslintrc.json index 766d694..1e346ec 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -17,7 +17,7 @@ "react/no-direct-mutation-state": "warn", "react/no-is-mounted": "warn", "react/no-typos": "error", - "react/react-in-jsx-scope": "error", + "react/react-in-jsx-scope": "off", "react/require-render-return": "error", "react/style-prop-object": "warn", "@next/next/no-img-element": "off" diff --git a/README.md b/README.md index 7f830da..a0fbd75 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ yarn start ``` # NGINX Proxy -This section requires [nginx](https://nginx.org/). +This section requires [NGINX](https://nginx.org/). ```nginx server { @@ -97,7 +97,7 @@ curl -H "Content-Type: multipart/form-data" -H "authorization: $TOKEN" -F file=@ # Contributing ## Bug reports -Create an issue on GitHub, please include the following: +Create an issue on GitHub, please include the following (if one of them is not applicable to the issue then it's not needed): * The steps to reproduce the bug * Logs of Zipline * The version of Zipline diff --git a/config.example.toml b/config.example.toml index 9bb0299..7136a6d 100644 --- a/config.example.toml +++ b/config.example.toml @@ -1,10 +1,32 @@ [core] -secure = true -secret = 'changethis' +secure = true # whether to return https or http in links +secret = 'changethis' # change this or zipline will not work host = '0.0.0.0' port = 3000 database_url = 'postgres://postgres:postgres@postgres/postgres' +[datasource] +type = 'local' # s3, local, or swift + +[datasource.local] +directory = './uploads' # directory to store uploads in + +[datasource.s3] +access_key_id = 'AKIAEXAMPLEKEY' +secret_access_key = 'somethingsomethingsomething' +bucket = 'zipline-storage' +endpoint = 's3.amazonaws.com' +region = 'us-west-2' # not required, defaults to us-east-1 if not specified +force_s3_path = false + +[datasource.swift] +container = 'default' +auth_endpoint = 'http://127.0.0.1:49155/v3' # only supports v3 swift endpoints at the moment. +username = 'swift' +password = 'fingertips' +project_id = 'Default' +domain_id = 'Default' + [urls] route = '/go' length = 6 @@ -13,7 +35,10 @@ length = 6 route = '/u' embed_route = '/a' length = 6 -directory = './uploads' user_limit = 104900000 # 100mb admin_limit = 104900000 # 100mb -disabled_extensions = ['jpg'] \ No newline at end of file +disabled_extensions = ['jpg'] + +[ratelimit] +user = 5 # 5 seconds +admin = 0 # 0 seconds, disabled \ No newline at end of file diff --git a/esbuild.config.js b/esbuild.config.js index 3369b71..4d5c264 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -20,6 +20,8 @@ const { rm } = require('fs/promises'); 'src/server/util.ts', 'src/lib/logger.ts', 'src/lib/config.ts', + 'src/lib/mimes.ts', + 'src/lib/exts.ts', 'src/lib/config/Config.ts', 'src/lib/config/readConfig.ts', 'src/lib/config/validateConfig.ts', diff --git a/next.config.js b/next.config.js index bfede79..ddfc9de 100644 --- a/next.config.js +++ b/next.config.js @@ -11,4 +11,6 @@ module.exports = { api: { responseLimit: false, }, + poweredByHeader: false, + reactStrictMode: true, }; \ No newline at end of file diff --git a/package.json b/package.json index db49984..a9efd99 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "react-redux": "^8.0.2", "react-table": "^7.8.0", "redux": "^4.2.0", - "uuid": "^8.3.2", "yup": "^0.32.11" }, "devDependencies": { diff --git a/scripts/migrate-v2-v3.js b/scripts/migrate-v2-v3.js deleted file mode 100644 index 2b12e21..0000000 --- a/scripts/migrate-v2-v3.js +++ /dev/null @@ -1,35 +0,0 @@ -const { readdir } = require('fs/promises'); -const { extname } = require('path'); -const validateConfig = require('../server/validateConfig'); -const Logger = require('../src/lib/logger'); -const readConfig = require('../src/lib/readConfig'); -const mimes = require('./mimes'); -const { PrismaClient } = require('@prisma/client'); - -(async () => { - const config = readConfig(); - - await validateConfig(config); - - process.env.DATABASE_URL = config.core.database_url; - - const files = await readdir(process.argv[2]); - const data = files.map(x => { - const mime = mimes[extname(x)] ?? 'application/octet-stream'; - - return { - file: x, - mimetype: mime, - userId: 1, - }; - }); - - const prisma = new PrismaClient(); - - Logger.get('migrator').info('starting migrations...'); - await prisma.image.createMany({ - data, - }); - Logger.get('migrator').info('finished migrations! It is recomended to move your old uploads folder (' + process.argv[2] + ') to the current one which is ' + config.uploader.directory); - process.exit(); -})(); \ No newline at end of file diff --git a/src/components/Backdrop.tsx b/src/components/Backdrop.tsx deleted file mode 100644 index 05d886e..0000000 --- a/src/components/Backdrop.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import React from 'react'; -import { LoadingOverlay } from '@mantine/core'; - -export default function Backdrop({ open }) { - return ( - - ); -} \ No newline at end of file diff --git a/src/components/Card.tsx b/src/components/Card.tsx index 3c13897..c3f56d5 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -1,14 +1,9 @@ -import React from 'react'; -import { - Card as MCard, - Title, -} from '@mantine/core'; +import { Card as MCard, Title } from '@mantine/core'; -export default function Card(props) { - const { name, children, ...other } = props; +export default function Card({ name, children, ...other }) { return ( - + {name} {children} diff --git a/src/components/Image.tsx b/src/components/File.tsx similarity index 94% rename from src/components/Image.tsx rename to src/components/File.tsx index 0a75c0a..1e62b36 100644 --- a/src/components/Image.tsx +++ b/src/components/File.tsx @@ -1,11 +1,11 @@ -import React, { useState } from 'react'; -import useFetch from 'hooks/useFetch'; import { Button, Card, Group, Image as MImage, Modal, Title } from '@mantine/core'; +import { useClipboard } from '@mantine/hooks'; import { useNotifications } from '@mantine/notifications'; import { CopyIcon, Cross1Icon, StarIcon, TrashIcon } from '@modulz/radix-icons'; -import { useClipboard } from '@mantine/hooks'; +import useFetch from 'hooks/useFetch'; +import { useState } from 'react'; -export default function Image({ image, updateImages }) { +export default function File({ image, updateImages }) { const [open, setOpen] = useState(false); const [t] = useState(image.mimetype.split('/')[0]); const notif = useNotifications(); @@ -56,7 +56,7 @@ export default function Image({ image, updateImages }) { const Type = (props) => { return { 'video':