diff --git a/.gitignore b/.gitignore index 718ec3e..c22c0f3 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ # misc .DS_Store *.pem +.turbo # debug npm-debug.log* @@ -30,6 +31,11 @@ yarn-error.log* .env.test.local .env.production.local +# config files +micro.yaml +micro +!example/* + *.tsbuildinfo dist /.microrc @@ -42,4 +48,4 @@ dist packages/web/.next packages/api/data -packages/*/.turbo \ No newline at end of file +packages/*/.turbo diff --git a/README.md b/README.md index 72065ad..4b41d36 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,10 @@ A vanity file sharing service with support for ShareX. You can see a preview at ## development -You can pull the repo and then `pnpm install`, after that everything should be good to go. You can start the `packages/api`/`packages/web` with `pnpm watch`. +1. Pull the repo and then `pnpm install`. +2. Run `docker compose up -d` to start postgres and minio development instances. +3. Copy `micro.example.yaml` to `micro.yaml`, change any options relevant to your environment. +5. Then, you can start the `packages/api`/`packages/web` with `pnpm watch`. Keep a look out for a `InviteService` log entry, which will direct you to an invite to then create the initial account. ## todo diff --git a/compose.yml b/compose.yml index 91c7762..7f364c8 100644 --- a/compose.yml +++ b/compose.yml @@ -8,7 +8,7 @@ services: container_name: micro_postgres restart: unless-stopped ports: - - 127.0.0.1:5433:5432 + - 127.0.0.1:5432:5432 environment: - POSTGRES_USER=micro - POSTGRES_PASSWORD=youshallnotpass diff --git a/example/micro.yaml b/example/micro.yaml index 2059f48..b28d2a1 100644 --- a/example/micro.yaml +++ b/example/micro.yaml @@ -18,6 +18,9 @@ inquiries: admin@example.com # where to store files, can be relative to the cwd or absolute. storagePath: /data +# string formatted maximum file upload size. +uploadLimit: 10MB + # whether files uploaded to one domain should be available on other domains. # you should leave this enabled as it stops users uploading to {{username}} # domains as other users, for example user "one" could upload to one.example.com diff --git a/micro.example.yaml b/micro.example.yaml new file mode 100644 index 0000000..24dadfd --- /dev/null +++ b/micro.example.yaml @@ -0,0 +1,111 @@ +# you can pass in most config options through environment variables, +# for example `MICRO_DATABASE_URL` will override the databaseUrl in this config file. +# remove the .yaml extension or change it to .json to use JSON-with-comments +# ref: https://github.com/sylv/venera#sources + +databaseUrl: postgresql://micro:youshallnotpass@127.0.0.1/micro + +# EXTREMELY IMPORTANT +# this is the secret used to sign json web tokens. this *must* be a secure, random string that no one else has. +# if you dont change this, any user will be able to act as any other user by creating a token for someone else. +# 32+ characters is recommended. +secret: YOU_SHALL_NOT_PASS + +# the email that will show on the home page. in the future the home page will be customisable, +# until then change this to your own email. +inquiries: admin@example.com + +# where to store files, can be relative to the cwd or absolute. +storagePath: data + +# string formatted maximum file upload size. +uploadLimit: 10MB + +# whether files uploaded to one domain should be available on other domains. +# you should leave this enabled as it stops users uploading to {{username}} +# domains as other users, for example user "one" could upload to one.example.com +# then replace "one" with "two" and it would look like user "two" uploaded it. +restrictFilesToHost: true + +# # purging can be used to clean up old files, useful if you want to allow large files to be uploaded +# # but dont want to store them forever. this is commented by default to prevent accidental purging +# # uncomment the section below to enable it. +# purge: +# overLimit: 1MB # files over this size will be purged +# afterTime: 1d # after this many days +# underViews: 5 # only delete files with <5 views + +# # allowTypes is a list of file types that can be uploaded. +# # a prefix will be expanded into known types, so `video` becomes `video/mp4`, `video/webm`, etc. +# # omit entirely to allow all types to be uploaded. +# allowTypes: +# - video +# - image +# - image/png + +hosts: + # the first host in the list is the default host + - url: http://127.0.0.1 + + # {{username}} will become the users name when they use this host + # - url: https://{{username}}.example.com + + # - url: https://i.example.net + # redirect when users go to this hosts url without a file + # redirect: https://example.net + # only allow users with the "admin" tag to use this host + # tags: ["admin"] + + + + + +# # To allow and require users to sign up with an email, specify an SMTP server to send emails from. +# # If you do not specify an email, it will not be asked for during signup and users will sign in with their username. +# # Enabling this on an existing instance will prompt users without an email to add one (https://micro.sylo.digital/i/J1Ilba) +# email: +# from: 'noreply@example.net' +# smtp: +# host: smtp.example.net +# port: 465 +# secure: true +# auth: +# user: 'username' +# pass: 'password' + + + + + +# Conversions allow you to convert files to other formats on upload. +# This is intended for converting inefficient formats like gif to webm (40mb>4mb in testing). +# The original copy will be discarded. + +# Video conversions rely on ffmpeg which is a slow and flakey process. If possible, +# it's recommended to disable conversions and just don't upload gifs. + +# The recommended options are below, on low power devices like a raspberry pi you should disable conversions entirely. +# This is currently not retroactive, but in the future old files may also be converted. +conversions: + # You cannot convert video/* to image/* and vice versa. How would that even work? + # image/gif to video/webm is an exception. + - from: image/gif # This could also be a list of types, just a category like "image", or both. + to: video/webm + minSize: 1MB # Required size before conversion, files uploaded under this limit are ignored + +# # externalStorage lets you offload files to S3 to free up space locally. +# # you should prefer local storage over external storage, as external storage is usually very slow. +# # the benefit is that external storage is unlimited, local disk space is not. +# externalStorage: +# type: s3 +# bucket: my-bucket +# region: us-west-1 +# endpoint: s3.us-west-1.amazonaws.com # optional +# forcePathStyle: false # optional +# credentials: +# accessKeyId: my-access-key +# secretAccessKey: my-secret-key +# filter: +# decayDuration: 7d # how long before files are moved to external storage +# minSize: 1MB # files under this size will not be moved +# maxSize: 1GB # files over this size will be moved \ No newline at end of file diff --git a/packages/api/package.json b/packages/api/package.json index fdc3cd0..8b79636 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -13,7 +13,7 @@ "build": "tsc --noEmit && tsup", "start": "node dist/main.js", "test": "vitest run", - "watch": "tsup --watch --onSuccess \"node dist/main.js\"", + "watch": "NODE_ENV=development tsup --watch --onSuccess \"node dist/main.js\"", "mikro-orm": "tsup --no-dts --silent && MIKRO_ORM_MIGRATIONS_PATH=src/migrations mikro-orm" }, "dependencies": { diff --git a/packages/api/src/config.ts b/packages/api/src/config.ts index 07d63fd..d14bda9 100644 --- a/packages/api/src/config.ts +++ b/packages/api/src/config.ts @@ -106,7 +106,7 @@ if (rootHost.isWildcard) { } const disallowed = new Set(["youshallnotpass", "you_shall_not_pass", "secret", "test"]); -if (disallowed.has(config.secret.toLowerCase())) { +if (process.env.NODE_ENV !== "development" && disallowed.has(config.secret.toLowerCase())) { const token = randomBytes(24).toString("hex"); throw new Error( dedent` diff --git a/packages/web/src/pages/upload/+Page.tsx b/packages/web/src/pages/upload/+Page.tsx index 941d700..bc2c92b 100644 --- a/packages/web/src/pages/upload/+Page.tsx +++ b/packages/web/src/pages/upload/+Page.tsx @@ -133,7 +133,7 @@ export const Page: FC = () => {

{file.name}

-
+