Compare commits

..
Author SHA1 Message Date
whoswhip 336990f5b8 style: separate comments from the paste container 2026-10-18 11:55:39 -04:00
whoswhip 45878d5af1 omfg, actually fix #lib imports 2026-10-18 11:47:06 -04:00
whoswhip 2c43c0b29c chore(deps): update nuget packages for security 2026-10-18 11:24:29 -04:00
whoswhip 0e3a6d97e3 fix: use node env instead of sveltekit env 2026-10-11 22:15:13 -04:00
whoswhip 878457f49d fix #lib 2026-10-10 21:32:51 -04:00
whoswhip 8d060204c8 fix: use #lib instead of $lib 2026-10-10 21:29:02 -04:00
whoswhip f2559eaad0 fix: update TypeScript configuration to extend from $app/tsconfig and adjust include/exclude paths 2026-10-10 21:04:04 -04:00
whoswhip e485b9782b fix node adapter 2026-10-10 20:33:08 -04:00
whoswhip ed7e82adc2 Merge branch 'SharpbinV3' of github.com:whoswhip/Sharpbin into SharpbinV3 2026-10-10 13:34:52 -04:00
whoswhip f8a74d415d Merge pull request #27 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-b9088de85f
chore(deps): bump the npm_and_yarn group across 1 directory with 6 updates
2026-10-10 13:33:41 -04:00
dependabot[bot] 41342efbed chore(deps): bump the npm_and_yarn group across 1 directory with 6 updates
Bumps the npm_and_yarn group with 6 updates in the /SharpbinV3.Client directory:

| Package | From | To |
| --- | --- | --- |
| [dompurify](https://github.com/cure53/DOMPurify) | `3.4.14` | `3.4.16` |
| [sharp](https://github.com/lovell/sharp) | `0.35.4` | `0.35.5` |
| [brace-expansion](https://github.com/juliangruber/brace-expansion) | `1.1.18` | `1.1.21` |
| [cookie](https://github.com/jshttp/cookie) | `0.6.0` | `2.0.1` |
| [handlebars](https://github.com/handlebars-lang/handlebars.js) | `4.7.9` | `4.7.10` |
| [source-map-js](https://github.com/7rulnik/source-map-js) | `1.2.1` | `1.2.2` |



Updates `dompurify` from 3.4.14 to 3.4.16
- [Release notes](https://github.com/cure53/DOMPurify/releases)
- [Commits](https://github.com/cure53/DOMPurify/compare/3.4.14...3.4.16)

Updates `sharp` from 0.35.4 to 0.35.5
- [Release notes](https://github.com/lovell/sharp/releases)
- [Commits](https://github.com/lovell/sharp/compare/v0.35.4...v0.35.5)

Updates `brace-expansion` from 1.1.18 to 1.1.21
- [Release notes](https://github.com/juliangruber/brace-expansion/releases)
- [Commits](https://github.com/juliangruber/brace-expansion/compare/v1.1.18...v1.1.21)

Updates `cookie` from 0.6.0 to 2.0.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v2.0.1)

Updates `handlebars` from 4.7.9 to 4.7.10
- [Release notes](https://github.com/handlebars-lang/handlebars.js/releases)
- [Changelog](https://github.com/handlebars-lang/handlebars.js/blob/v4.7.10/release-notes.md)
- [Commits](https://github.com/handlebars-lang/handlebars.js/compare/v4.7.9...v4.7.10)

Updates `source-map-js` from 1.2.1 to 1.2.2
- [Release notes](https://github.com/7rulnik/source-map-js/releases)
- [Changelog](https://github.com/7rulnik/source-map-js/blob/main/CHANGELOG.md)
- [Commits](https://github.com/7rulnik/source-map-js/compare/v1.2.1...v1.2.2)

---
updated-dependencies:
- dependency-name: dompurify
  dependency-version: 3.4.16
  dependency-type: direct:production
  dependency-group: npm_and_yarn
- dependency-name: sharp
  dependency-version: 0.35.5
  dependency-type: direct:production
  dependency-group: npm_and_yarn
- dependency-name: brace-expansion
  dependency-version: 1.1.21
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: cookie
  dependency-version: 2.0.1
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: handlebars
  dependency-version: 4.7.10
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: source-map-js
  dependency-version: 1.2.2
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-10 03:19:03 +00:00
whoswhip e7a28ea8c0 Merge pull request #26 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-e422db4233
chore(deps): bump devalue from 5.8.1 to 5.9.4 in /SharpbinV3.Client in the npm_and_yarn group across 1 directory
2026-10-09 23:17:00 -04:00
whoswhip e375b0a020 refactor: simplify configuration to a single env file 2026-09-26 19:40:36 -04:00
whoswhip ee8b8f239d docs: fix example secrets 2026-09-26 15:26:00 -04:00
dependabot[bot] eb331f7339 chore(deps): bump devalue
Bumps the npm_and_yarn group with 1 update in the /SharpbinV3.Client directory: [devalue](https://github.com/sveltejs/devalue).


Updates `devalue` from 5.8.1 to 5.9.4
- [Release notes](https://github.com/sveltejs/devalue/releases)
- [Changelog](https://github.com/sveltejs/devalue/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sveltejs/devalue/compare/v5.8.1...v5.9.4)

---
updated-dependencies:
- dependency-name: devalue
  dependency-version: 5.9.4
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-26 19:20:42 +00:00
whoswhip b304d8ac9f chore: update node to 24 in ci and docker 2026-09-26 15:19:29 -04:00
whoswhip d45f253c00 fix: normalize cononical 2026-09-14 18:58:28 -04:00
whoswhip b0e9f5104c fix: remove trailing '.' in filename
firefox removes it but chrome sanitizes it to '_'
2026-09-13 18:35:24 -04:00
whoswhip da79f3713a Merge pull request #25 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-c2134247b9
chore(deps): bump the npm_and_yarn group across 1 directory with 2 updates
2026-09-13 18:31:28 -04:00
dependabot[bot] 18e8154248 chore(deps): bump the npm_and_yarn group across 1 directory with 2 updates
Bumps the npm_and_yarn group with 2 updates in the /SharpbinV3.Client directory: [@humanfs/node](https://github.com/humanwhocodes/humanfs/tree/HEAD/packages/node) and [fflate](https://github.com/101arrowz/fflate).


Updates `@humanfs/node` from 0.16.7 to 0.16.8
- [Release notes](https://github.com/humanwhocodes/humanfs/releases)
- [Changelog](https://github.com/humanwhocodes/humanfs/blob/main/packages/node/CHANGELOG.md)
- [Commits](https://github.com/humanwhocodes/humanfs/commits/node-v0.16.8/packages/node)

Updates `fflate` from 0.7.4 to 0.7.5
- [Release notes](https://github.com/101arrowz/fflate/releases)
- [Changelog](https://github.com/101arrowz/fflate/blob/master/CHANGELOG.md)
- [Commits](https://github.com/101arrowz/fflate/commits)

---
updated-dependencies:
- dependency-name: "@humanfs/node"
  dependency-version: 0.16.8
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: fflate
  dependency-version: 0.7.5
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-04 22:23:22 +00:00
whoswhip 4e8187c186 Merge pull request #24 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-275026e82a
chore(deps-dev): bump the npm_and_yarn group across 1 directory with 3 updates
2026-09-04 18:21:27 -04:00
60 changed files with 646 additions and 1138 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
**/.classpath
**/.dockerignore
**/.env
**/backend.env
**/frontend.env
**/.git
**/.gitignore
**/.project
@@ -27,4 +29,4 @@ README.md
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
!.git/refs/heads/**
+26
View File
@@ -0,0 +1,26 @@
# Copy to .env in the repository root. Replace every replace_with_ value before running.
# Generate a different random value for each secret. See README.md for instructions.
# Site
Domain=example.com
Https=true
AllowedCorsOrigins__0=https://example.com
ORIGIN=https://example.com
# Authentication
JwtSettings__Secret=replace_with_a_unique_random_jwt_secret_before_running
# These Turnstile keys are for testing. Use your own site and secret keys in production.
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
AuthSettings__Registration_Enabled=true
AuthSettings__Admins_Require_2FA=true
AuthSettings__API_Key_HMAC_Secret=replace_with_a_unique_random_api_key_hmac_secret_before_running
# Pastes
PasteSettings__MaxTitleLength=500
PasteSettings__MaxPasteSizeInBytes=1048576
PasteSettings__EnablePasteCompression=true
PasteSettings__RequiresVerification=true
PasteSettings__View_HMAC_Secret=replace_with_a_unique_random_view_hmac_secret_before_running
# Compose passes this value to both services. No separate frontend key is needed.
PasteSettings__View_Internal_API_Key=replace_with_a_unique_random_internal_api_key_before_running
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 24
cache: npm
cache-dependency-path: SharpbinV3.Client/package-lock.json
- run: npm ci
+3 -1
View File
@@ -325,4 +325,6 @@ Data
!SharpbinV3.Server/Data
.idea
**/.env
**/.env
backend.env
frontend.env
+44 -10
View File
@@ -26,15 +26,45 @@ The easiest way to run SharpbinV3 is using Docker Compose.
git clone https://github.com/whoswhip/Sharpbin.git
```
3. Run the following command in the root directory:
3. In the repository root, copy `.env.example` to `.env`.
4. Replace the secret placeholders and configure your domain and Turnstile keys. Set `ORIGIN` to the public frontend URL, including the scheme. For local Docker testing, use `ORIGIN=http://localhost:5173`, `Domain=localhost:5173`, `Https=false`, and `AllowedCorsOrigins__0=http://localhost:5173`.
5. Run the following command in the root directory:
```bash
docker-compose up -d
docker compose up -d --build
```
### Configuration
You can configure Sharpbin using environment variables or `appsettings.json`. When using Docker Compose, these can be set in the `docker-compose.yml` file.
Configure Sharpbin in the root `.env` file when using Docker Compose. The backend loads this file as environment variables. Compose passes only the backend URL, public origin, and shared view-recording key to the frontend.
The backend image includes `appsettings.json` with application defaults. Environment variables have priority, so you do not need to edit or mount that file for normal setup. Additional backend settings, including `EmailSettings__Host` and other SMTP settings, can be added to `.env` using their existing names.
Compose defaults the database to `/app/data/sharpbin.db`, Data Protection keys to `/app/data/keys`, and `VITE_API_URL` to `http://backend:8080`. To override them, add `ConnectionStrings__DefaultConnection`, `DATA_PROTECTION_KEY_PATH`, or `VITE_API_URL` to `.env`. Keep database and key paths under `/app/data` to use the existing persistent volume.
The example secrets are placeholders, not secure defaults. Generate a separate secret for JWT signing, API-key hashing, and view hashing, plus one shared internal API key. This command generates a 64-character random hex value; run it once for each secret:
```bash
docker run --rm node:24-alpine node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
```
or use openSSL:
```bash
openssl rand -hex 32
```
Set the shared key once as `PasteSettings__View_Internal_API_Key`. Compose supplies it to the frontend as `VIEW_INTERNAL_API_KEY`. Keep generated secrets across restarts and updates. Changing the API-key HMAC secret invalidates existing API keys.
#### Migrating an Existing Installation
1. Copy the values from `backend.env` into the root `.env` file. If `.env` already exists, merge the settings without replacing existing values blindly.
2. Copy `ORIGIN` from `frontend.env`. If it was unset, use your public frontend URL, including the scheme.
3. Keep `PasteSettings__View_Internal_API_Key` set to the existing shared key. The separate `VIEW_INTERNAL_API_KEY` entry is no longer needed for Compose.
4. Move any custom `appsettings.json` values into `.env` using `__` for nested settings. For array settings, use numbered entries such as `AllowedCorsOrigins__0`. If you need to retain a custom JSON file, add a read-only mount for it in `compose.override.yaml`.
5. Run `docker compose up -d --build`. The old `backend.env` and `frontend.env` files are no longer read by Compose.
Keep the existing database volume, Data Protection keys, and secret values. Do not regenerate secrets during this migration.
> When configuring via `appsettings.json` instead of for example `ConnectionStrings__DefaultConnection` it would be:
@@ -47,9 +77,10 @@ You can configure Sharpbin using environment variables or `appsettings.json`. Wh
#### Backend (SharpbinV3.Server)
- `Domain`: The domain your instance of Sharpbin will be hosted at (e.g., example.com)
- `Https`: Whether or not your instance is behind https. Used when sendings emails.
- `Https`: Whether the public instance uses HTTPS. Used when generating email links; this does not enable TLS on the server.
- `AllowedCorsOrigins__0`: An allowed browser origin for the backend API (e.g., `https://example.com`). Use numbered entries for additional origins.
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
- `JwtSettings__Secret`: A random secret of 32-128 characters used for signing JWT tokens.
- `AuthSettings__CF_Turnstile_SecretKey`: Your Cloudflare Turnstile secret key.
- `AuthSettings__CF_Turnstile_SiteKey`: Your Cloudflare Turnstile site key.
- `AuthSettings__Registration_Enabled`:**true**: Enables/disables registration.
@@ -60,14 +91,17 @@ You can configure Sharpbin using environment variables or `appsettings.json`. Wh
- `PasteSettings__MaxPasteSizeInBytes`:**1_048_576** (1MB): Max Paste Size set in bytes.
- `PasteSettings__EnablePasteCompression`:**true**: Enables/Disables server-side paste compression.
- `PasteSettings__RequiresVerification`:**true**: Enables/Disables CAPTCHA verification when creating pastes.
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Compose passes it to both services.
#### Frontend (SharpbinV3.Client)
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.cc`)
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `VITE_API_URL`: The backend URL reachable from the frontend server. Defaults to `http://localhost:5050` when running directly and `http://backend:8080` in Compose. Browser requests use the frontend's `/api` proxy.
- `ORIGIN`: The public frontend URL, including its scheme (e.g., `https://example.com`). Used by the production Node server; see [SvelteKit's Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#ORIGIN-PROTOCOL_HEADER-HOST_HEADER-and-PORT_HEADER).
- `VITE_ALLOWED_HOSTS`: A comma-separated list used only by Vite dev/preview (e.g., `localhost,sharpbin.cc`). Export it in the shell before starting Vite; the config reads `process.env` directly. It does not configure production host restrictions.
- `VIEW_INTERNAL_API_KEY`: The production frontend's shared view-recording key. Compose sets it from `PasteSettings__View_Internal_API_Key`; do not duplicate it in the root `.env`. When running the frontend directly, set it yourself or use the existing `View_HMAC_Internal_API_Key` fallback.
When `NODE_ENV=development`, the frontend uses a fixed development-only internal key matching the backend's checked-in development configuration and ignores both environment key names. See the [client README](SharpbinV3.Client/README.md) for development and standalone production setup.
The frontend will be accessible at http://localhost:5173.
+2 -2
View File
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM node:20-alpine as build
FROM node:24-alpine as build
ARG GIT_COMMIT_HASH
ENV GIT_COMMIT_HASH=${GIT_COMMIT_HASH}
WORKDIR /app
@@ -8,7 +8,7 @@ RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine as runner
FROM node:24-alpine as runner
WORKDIR /app
ENV NODE_ENV=production
ENV HOST=0.0.0.0
+25 -5
View File
@@ -6,7 +6,7 @@ This is the SvelteKit frontend for SharpbinV3.
### Prerequisites
- Node.js (v20 or newer recommended)
- Node.js 24
- npm
### Installation
@@ -19,11 +19,12 @@ npm install
### Environment Configuration
The frontend requires an environment variable to point to the backend API. Create a `.env` file in this directory or set the variable in your environment:
The frontend defaults to the backend at `http://localhost:5050`. SvelteKit loads `.env` files during development, but `vite.config.ts` reads shell environment variables directly for its proxy and allowed hosts:
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.whoswhip.dev`)
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `VITE_API_URL`: The backend URL reachable from the frontend server. Export this in the shell when changing the development backend URL so the Vite proxy and server-side requests use the same value.
- `VITE_ALLOWED_HOSTS`: A comma-separated list of hosts for Vite dev/preview. Export this in the shell before starting Vite. It does not configure the production Node server.
In development, the frontend uses a fixed internal view-recording key matching `appsettings.Development.json`. It ignores `VIEW_INTERNAL_API_KEY` and `View_HMAC_Internal_API_Key` while `NODE_ENV=development`.
### Running in Development
@@ -35,6 +36,25 @@ npm run dev
The frontend will be available at http://localhost:5173.
### Running in Production
Docker Compose reads the root `.env` file and runs the built Node server on port 5173. Configure these values there:
- `VITE_API_URL`: Backend URL. Defaults to `http://backend:8080` in Compose.
- `ORIGIN`: Public frontend URL, such as `https://example.com` or `http://localhost:5173` for local Docker testing.
- `PasteSettings__View_Internal_API_Key`: Shared view-recording key. Compose passes it to the frontend as `VIEW_INTERNAL_API_KEY`, so you only set it once.
For a standalone Node deployment, set `VITE_API_URL`, `ORIGIN`, and `VIEW_INTERNAL_API_KEY` in the client's own `.env` file. The key must match the backend's `PasteSettings__View_Internal_API_Key`. The frontend still supports `View_HMAC_Internal_API_Key` as a fallback; it does not read the backend setting name directly.
The standalone server does not load `.env` automatically. Build the frontend, then load your environment file explicitly:
```bash
npm run build
node --env-file=.env build
```
Set `PORT=5173` in that file to use the same port as Docker; the Node adapter otherwise defaults to port 3000. See the [Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#Environment-variables) for runtime configuration.
## Script Reference
- `npm run dev`: Start the Vite development server.
+1 -3
View File
@@ -6,7 +6,6 @@ import svelte from 'eslint-plugin-svelte';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import ts from 'typescript-eslint';
import svelteConfig from './svelte.config.js';
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
@@ -33,8 +32,7 @@ export default defineConfig(
parserOptions: {
projectService: true,
extraFileExtensions: ['.svelte'],
parser: ts.parser,
svelteConfig
parser: ts.parser
}
}
}
+364 -910
View File
File diff suppressed because it is too large Load Diff
+11 -7
View File
@@ -17,8 +17,8 @@
"devDependencies": {
"@eslint/compat": "^1.4.0",
"@eslint/js": "^9.39.1",
"@sveltejs/adapter-auto": "^7.0.0",
"@sveltejs/kit": "^2.60.1",
"@sveltejs/adapter-auto": "^8.0.0",
"@sveltejs/kit": "^3.0.1",
"@sveltejs/vite-plugin-svelte": "^7.1.2",
"@tailwindcss/vite": "^4.3.1",
"@types/better-sqlite3": "^7.6.13",
@@ -40,18 +40,22 @@
"svelte-check": "^4.3.4",
"tailwind-scrollbar": "^4.0.2",
"tailwindcss": "^4.1.17",
"typescript": "^5.9.3",
"typescript-eslint": "^8.48.1",
"typescript": "^6.0.3",
"typescript-eslint": "^8.71.2",
"vite": "^8.0.16"
},
"imports": {
"#lib": "./src/lib/index.ts",
"#lib/*": "./src/lib/*"
},
"dependencies": {
"@fontsource/inter": "^5.2.8",
"@fontsource/jetbrains-mono": "^5.2.8",
"@lucide/svelte": "^0.562.0",
"@resvg/resvg-js": "^2.6.2",
"@sveltejs/adapter-node": "^5.4.0",
"@sveltejs/adapter-node": "^6.0.0",
"better-sqlite3": "^12.8.0",
"dompurify": "^3.4.12",
"dompurify": "^3.4.16",
"hash-wasm": "^4.12.0",
"highlight.js": "^11.8.0",
"jsdom": "^27.4.0",
@@ -60,6 +64,6 @@
"qrcode": "^1.5.4",
"satori": "^0.26.0",
"satori-html": "^0.3.2",
"sharp": "^0.35.0"
"sharp": "^0.35.5"
}
}
@@ -1,10 +1,10 @@
<script lang="ts">
import QRCode from 'qrcode';
import { getRefreshToken, getToken, setTokens } from '$lib/utils/auth';
import { parseTotpEnabled } from '$lib/utils/totp';
import { getRefreshToken, getToken, setTokens } from '#lib/utils/auth';
import { parseTotpEnabled } from '#lib/utils/totp';
import { tick } from 'svelte';
import { extractError } from '$lib/utils/misc';
import type { ModalItem, ModalMode } from '$lib/types/modal';
import { extractError } from '#lib/utils/misc';
import type { ModalItem, ModalMode } from '#lib/types/modal';
interface Props {
show?: boolean;
@@ -1,6 +1,6 @@
<script lang="ts">
import Modal from '$lib/components/Modal.svelte';
import { cancelModal, confirmModal, modal } from '$lib/stores/modal';
import Modal from '#lib/components/Modal.svelte';
import { cancelModal, confirmModal, modal } from '#lib/stores/modal';
let state = $derived($modal);
</script>
@@ -1,9 +1,9 @@
<script lang="ts">
import { user } from '$lib/stores/user';
import { user } from '#lib/stores/user';
import { resolve } from '$app/paths';
import { page } from '$app/state';
import { clearTokens, hasRole } from '$lib/utils/auth';
import logo from '$lib/assets/favicon.svg';
import { clearTokens, hasRole } from '#lib/utils/auth';
import logo from '#lib/assets/favicon.svg';
import type { PageData } from '../../routes/$types';
import { slide } from 'svelte/transition';
import { Menu, X } from '@lucide/svelte';
@@ -1,5 +1,5 @@
<script lang="ts">
import { tooltip, dateToRelativeString, formatNumber, formatBytes } from '$lib/utils/misc';
import { tooltip, dateToRelativeString, formatNumber, formatBytes } from '#lib/utils/misc';
import { resolve } from '$app/paths';
import {
Eye,
@@ -15,8 +15,8 @@
HatGlasses,
ThumbsUp
} from '@lucide/svelte';
import { syntaxes } from '$lib/consts';
import type { Paste } from '$lib/types/paste';
import { syntaxes } from '#lib/consts';
import type { Paste } from '#lib/types/paste';
interface Props {
paste: Paste;
@@ -1,14 +1,14 @@
<script lang="ts">
import type { CommentReaction, CommentTreeNode } from '$lib/types/comment';
import { dateToRelativeString, tooltip } from '$lib/utils/misc';
import { parseCommentMarkdown } from '$lib/utils/markdown';
import { escapeHtml } from '$lib/utils/html';
import { user } from '$lib/stores/user';
import PasteCommentItem from '$lib/components/PasteCommentItem.svelte';
import type { CommentReaction, CommentTreeNode } from '#lib/types/comment';
import { dateToRelativeString, tooltip } from '#lib/utils/misc';
import { parseCommentMarkdown } from '#lib/utils/markdown';
import { escapeHtml } from '#lib/utils/html';
import { user } from '#lib/stores/user';
import PasteCommentItem from '#lib/components/PasteCommentItem.svelte';
import { ThumbsUp, ThumbsDown, Trash2, Shredder, Reply, Quote } from '@lucide/svelte';
import { resolve } from '$app/paths';
import RichTextEditor from './RichTextEditor.svelte';
import { hasRole, roles } from '$lib/utils/auth';
import { hasRole, roles } from '#lib/utils/auth';
interface Props {
node: CommentTreeNode;
@@ -1,17 +1,17 @@
<script lang="ts">
import { onMount } from 'svelte';
import { getToken } from '$lib/utils/auth';
import { user } from '$lib/stores/user';
import { getToken } from '#lib/utils/auth';
import { user } from '#lib/stores/user';
import type {
CommentReaction,
CommentReactionResult,
PasteComment,
CommentTreeNode
} from '$lib/types/comment';
import PasteCommentItem from '$lib/components/PasteCommentItem.svelte';
} from '#lib/types/comment';
import PasteCommentItem from '#lib/components/PasteCommentItem.svelte';
import { SvelteMap } from 'svelte/reactivity';
import RichTextEditor from './RichTextEditor.svelte';
import { openModal } from '$lib/stores/modal';
import { openModal } from '#lib/stores/modal';
import { RefreshCw } from '@lucide/svelte';
interface Props {
@@ -237,15 +237,10 @@
}
</script>
<section id="comments-section" class="mt-6 rounded border border-neutral-700 bg-neutral-900 p-4">
<section id="comments-section" class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-4 mt-4">
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
<div class="flex items-center gap-2">
<h2 class="text-lg font-semibold text-neutral-100">Comments</h2>
<span
class="rounded border border-neutral-700 bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
>
{comments.length}
</span>
<h2 class="text-lg font-semibold text-neutral-100">{comments.length} Comments</h2>
</div>
<button
type="button"
@@ -1,6 +1,6 @@
<script lang="ts">
import { Bold, Italic, CodeXml, Quote, Send, Eye, Pencil } from '@lucide/svelte';
import { parseCommentMarkdown } from '$lib/utils/markdown';
import { parseCommentMarkdown } from '#lib/utils/markdown';
interface Props {
class?: string;
+1 -1
View File
@@ -1 +1 @@
// place files you want to import through the `$lib` alias in this folder.
// place files you want to import through the `#lib` alias in this folder.
+1 -1
View File
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/private';
import { env } from 'node:process';
export const apiUrl = env.VITE_API_URL ?? 'http://localhost:5050';
export const viewInternalApiKey =
+1 -1
View File
@@ -1,4 +1,4 @@
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
const methodsWithoutBody = new Set(['GET', 'HEAD']);
+1 -1
View File
@@ -1,5 +1,5 @@
import { writable } from 'svelte/store';
import type { ModalOpenOptions, ModalState } from '$lib/types/modal';
import type { ModalOpenOptions, ModalState } from '#lib/types/modal';
const initialState: ModalState = {
show: false,
+1 -1
View File
@@ -1,6 +1,6 @@
import { writable } from 'svelte/store';
import { browser } from '$app/environment';
import type { AuthUser } from '$lib/types/user';
import type { AuthUser } from '#lib/types/user';
let initial: AuthUser | null = null;
+2 -2
View File
@@ -1,7 +1,7 @@
import { browser } from '$app/environment';
import type { Cookies } from '@sveltejs/kit';
import { user } from '$lib/stores/user';
import type { JWTUser } from '$lib/types/user';
import { user } from '#lib/stores/user';
import type { JWTUser } from '#lib/types/user';
export const roles = {
User: 1,
+1 -1
View File
@@ -1,7 +1,7 @@
import { marked } from 'marked';
import createDOMPurify from 'dompurify';
import type { WindowLike } from 'dompurify';
import { trustedDomains } from '$lib/consts';
import { trustedDomains } from '#lib/consts';
import { escapeHtml } from './html';
export const externalMediaWarningStorageKey = 'sharpbin:ignore-external-media-warning';
+1 -1
View File
@@ -1,4 +1,4 @@
import { syntaxes } from '$lib/consts';
import { syntaxes } from '#lib/consts';
/**
* @param bytes Bytes to format.
+7 -7
View File
@@ -1,13 +1,13 @@
<script lang="ts">
import { onMount } from 'svelte';
import './layout.css';
import favicon from '$lib/assets/favicon.svg';
import Navbar from '$lib/components/Navbar.svelte';
import Footer from '$lib/components/Footer.svelte';
import ModalHost from '$lib/components/ModalHost.svelte';
import { user } from '$lib/stores/user';
import { startTokenRefreshInterval, getToken, refreshTokenIfNeeded } from '$lib/utils/auth';
import { parseTotpEnabled } from '$lib/utils/totp';
import favicon from '#lib/assets/favicon.svg';
import Navbar from '#lib/components/Navbar.svelte';
import Footer from '#lib/components/Footer.svelte';
import ModalHost from '#lib/components/ModalHost.svelte';
import { user } from '#lib/stores/user';
import { startTokenRefreshInterval, getToken, refreshTokenIfNeeded } from '#lib/utils/auth';
import { parseTotpEnabled } from '#lib/utils/totp';
import { page } from '$app/state';
import type { LayoutData } from './$types';
+7 -7
View File
@@ -1,20 +1,20 @@
<script lang="ts">
import type { PageData } from './$types';
import { syntaxes, expiresOptions } from '$lib/consts';
import { user } from '$lib/stores/user';
import { getToken } from '$lib/utils/auth';
import { syntaxes, expiresOptions } from '#lib/consts';
import { user } from '#lib/stores/user';
import { getToken } from '#lib/utils/auth';
import { onMount } from 'svelte';
import { fly, fade } from 'svelte/transition';
import { encryptAES, estimateEncryptedSize } from '$lib/utils/encryption';
import { encryptAES, estimateEncryptedSize } from '#lib/utils/encryption';
import {
formatBytes,
formatNumber,
isBinaryData,
tooltip,
syntaxFromExtension
} from '$lib/utils/misc';
import { parseMarkdown } from '$lib/utils/markdown';
import Dropdown from '$lib/components/Dropdown.svelte';
} from '#lib/utils/misc';
import { parseMarkdown } from '#lib/utils/markdown';
import Dropdown from '#lib/components/Dropdown.svelte';
import { SvelteURLSearchParams } from 'svelte/reactivity';
import { FileUp, X, Eye, EyeClosed, Dices } from '@lucide/svelte';
@@ -1,21 +1,21 @@
import { syntaxes } from '$lib/consts';
import { apiUrl } from '$lib/server/api';
import { syntaxes } from '#lib/consts';
import { apiUrl } from '#lib/server/api';
import {
getCachedOgImage,
getCacheControlHeader,
getCacheTtlSeconds,
scheduleOgImageCachePurge,
storeCachedOgImage
} from '$lib/server/og/cache';
import OgPasteEmbed from '$lib/server/og/PasteEmbed.svelte';
import type { PasteEmbedProps } from '$lib/server/og/pasteEmbed';
import type { Paste } from '$lib/types/paste';
} from '#lib/server/og/cache';
import OgPasteEmbed from '#lib/server/og/PasteEmbed.svelte';
import type { PasteEmbedProps } from '#lib/server/og/pasteEmbed';
import type { Paste } from '#lib/types/paste';
import {
dateToRelativeString,
extractDateFromUUIDv7,
formatBytes,
formatNumber
} from '$lib/utils/misc';
} from '#lib/utils/misc';
import { Resvg } from '@resvg/resvg-js';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
@@ -1,8 +1,8 @@
import type { PageServerLoad } from './$types';
import type { Paste } from '$lib/types/paste';
import type { PasteComment } from '$lib/types/comment';
import { getServerToken } from '$lib/utils/auth';
import { apiUrl, viewInternalApiKey } from '$lib/server/api';
import type { Paste } from '#lib/types/paste';
import type { PasteComment } from '#lib/types/comment';
import { getServerToken } from '#lib/utils/auth';
import { apiUrl, viewInternalApiKey } from '#lib/server/api';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ params, fetch, url, cookies, parent, request }) => {
+25 -19
View File
@@ -36,24 +36,24 @@
dateToRelativeString,
tooltip,
isBinaryData
} from '$lib/utils/misc';
} from '#lib/utils/misc';
import {
getIgnoreExternalMediaWarning,
parseMarkdown,
setIgnoreExternalMediaWarning
} from '$lib/utils/markdown';
import { syntaxes, expiresOptions } from '$lib/consts';
} from '#lib/utils/markdown';
import { syntaxes, expiresOptions } from '#lib/consts';
import { resolve } from '$app/paths';
import { decryptAES, encryptAES } from '$lib/utils/encryption';
import { escapeHtml } from '$lib/utils/html';
import { decryptAES, encryptAES } from '#lib/utils/encryption';
import { escapeHtml } from '#lib/utils/html';
import { fade } from 'svelte/transition';
import { getToken, hasRole } from '$lib/utils/auth';
import { user } from '$lib/stores/user';
import Dropdown from '$lib/components/Dropdown.svelte';
import PasteComments from '$lib/components/PasteComments.svelte';
import { openModal } from '$lib/stores/modal';
import type { Paste, PasteReaction } from '$lib/types/paste';
import HighlightWorker from '$lib/workers/highlight.worker?worker';
import { getToken, hasRole } from '#lib/utils/auth';
import { user } from '#lib/stores/user';
import Dropdown from '#lib/components/Dropdown.svelte';
import PasteComments from '#lib/components/PasteComments.svelte';
import { openModal } from '#lib/stores/modal';
import type { Paste, PasteReaction } from '#lib/types/paste';
import HighlightWorker from '#lib/workers/highlight.worker?worker';
interface Props {
data: PageData;
}
@@ -100,6 +100,9 @@
let highlightRequestId = 0;
let ignoreExternalMediaWarning = false;
let iconsOnly = $state(false);
const canonicalUrl = $derived(
data.paste ? new URL(`/${data.paste.id}`, data.url).href : undefined
);
let scrollY = $state(0);
@@ -590,14 +593,14 @@
name="robots"
content={data.paste.visibility === 0 ? 'index, follow' : 'noindex, nofollow'}
/>
<link rel="canonical" href={data.url} />
<link rel="canonical" href={canonicalUrl} />
{#if data.paste.author}
<meta name="author" content={data.paste.author.username} />
{/if}
<meta property="og:title" content={data.paste.title || 'Untitled Paste'} />
<meta property="og:description" content={pasteDescription} />
<meta property="og:type" content="article" />
<meta property="og:url" content={data.url} />
<meta property="og:url" content={canonicalUrl} />
<meta property="og:site_name" content="Sharpbin" />
{#if pasteImageUrl}
<meta property="og:image" content={pasteImageUrl} />
@@ -899,10 +902,13 @@
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const filename = data.paste?.title
? `${data.paste.title.slice(0, 100)}${extension ? `.${extension}` : ''}`
: `paste_${data.paste?.id}${extension ? `.${extension}` : ''}`;
a.href = url;
a.download = data.paste?.title
? `${data.paste.title.slice(0, 100)}.${extension}`
: `paste_${data.paste?.id}.${extension}`;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
@@ -1104,14 +1110,14 @@
{@html pasteContent}
</div>
{/if}
<PasteComments pasteId={data.paste.id} initialComments={data.comments ?? []} />
{:else}
<h1 class="mb-4 text-center text-4xl font-bold">Paste not found</h1>
<h2 class="mt-2 text-center text-xl">The paste you are looking for does not exist.</h2>
{/if}
</div>
<PasteComments pasteId={data.paste.id} initialComments={data.comments ?? []} />
<style>
.hljs {
background-color: var(--color-neutral-800) !important;
@@ -1,4 +1,4 @@
import { proxyBackendRequest } from '$lib/server/proxy';
import { proxyBackendRequest } from '#lib/server/proxy';
import type { RequestHandler } from './$types';
const handle: RequestHandler = ({ params, request, url }) => {
@@ -1,6 +1,6 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { extractError } from '$lib/utils/misc';
import { extractError } from '#lib/utils/misc';
import { onMount } from 'svelte';
import type { PageData } from './$types';
@@ -1,4 +1,4 @@
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
import { json } from '@sveltejs/kit';
export const GET = async () => {
@@ -1,7 +1,7 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { setTokens, startTokenRefreshInterval } from '$lib/utils/auth';
import { extractError } from '$lib/utils/misc';
import { setTokens, startTokenRefreshInterval } from '#lib/utils/auth';
import { extractError } from '#lib/utils/misc';
import { onMount } from 'svelte';
import type { PageData } from './$types';
@@ -1,4 +1,4 @@
import { proxyBackendRequest } from '$lib/server/proxy';
import { proxyBackendRequest } from '#lib/server/proxy';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = ({ request, url }) => {
@@ -1,4 +1,4 @@
import { proxyBackendRequest } from '$lib/server/proxy';
import { proxyBackendRequest } from '#lib/server/proxy';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = ({ params, request, url }) => {
@@ -1,5 +1,5 @@
import type { RequestHandler } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
export const GET: RequestHandler = async ({ params, request }) => {
const { id } = params;
@@ -1,6 +1,6 @@
import type { PageServerLoad } from './$types';
import type { Paste } from '$lib/types/paste';
import { extractError } from '$lib/utils/misc';
import type { Paste } from '#lib/types/paste';
import { extractError } from '#lib/utils/misc';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ fetch, request }) => {
@@ -1,7 +1,7 @@
<script lang="ts">
import type { PageData } from './$types';
import { onMount } from 'svelte';
import Paste from '$lib/components/Paste.svelte';
import Paste from '#lib/components/Paste.svelte';
interface Props {
data: PageData;
@@ -1,7 +1,7 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { setTokens, startTokenRefreshInterval } from '$lib/utils/auth';
import { extractError } from '$lib/utils/misc';
import { setTokens, startTokenRefreshInterval } from '#lib/utils/auth';
import { extractError } from '#lib/utils/misc';
import { Check, X, Eye, EyeClosed } from '@lucide/svelte';
import { slide, fade } from 'svelte/transition';
import { resolve } from '$app/paths';
@@ -1,8 +1,8 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { getServerToken, clearServerTokens, roles, getUserFromToken } from '$lib/utils/auth';
import type { Report } from '$lib/types/report';
import { apiUrl } from '#lib/server/api';
import { getServerToken, clearServerTokens, roles, getUserFromToken } from '#lib/utils/auth';
import type { Report } from '#lib/types/report';
export const load: PageServerLoad = async ({ fetch, cookies, params, url, request }) => {
const token = getServerToken(cookies);
@@ -1,9 +1,9 @@
<script lang="ts">
import type { PageData } from './$types';
import { resolve } from '$app/paths';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
import { tooltip } from '$lib/utils/misc';
import { getToken } from '$lib/utils/auth';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '#lib/types/report';
import { tooltip } from '#lib/utils/misc';
import { getToken } from '#lib/utils/auth';
interface Props {
data: PageData;
@@ -1,15 +1,15 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
import {
getServerToken,
getUserFromToken,
clearServerTokens,
hasRole,
roles
} from '$lib/utils/auth';
import type { ReportListResponse } from '$lib/types/report';
import { extractError } from '$lib/utils/misc';
} from '#lib/utils/auth';
import type { ReportListResponse } from '#lib/types/report';
import { extractError } from '#lib/utils/misc';
function normalizeTarget(value: string | null): 'all' | 'pastes' | 'users' {
if (value === 'pastes' || value === 'users') return value;
@@ -5,8 +5,8 @@
import type { PageData } from './$types';
import { resolve } from '$app/paths';
import { goto } from '$app/navigation';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
import { tooltip } from '$lib/utils/misc';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '#lib/types/report';
import { tooltip } from '#lib/utils/misc';
import { SvelteURLSearchParams } from 'svelte/reactivity';
interface Props {
@@ -1,5 +1,5 @@
import { apiUrl } from '$lib/server/api';
import { extractError } from '$lib/utils/misc';
import { apiUrl } from '#lib/server/api';
import { extractError } from '#lib/utils/misc';
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
@@ -1,6 +1,6 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { extractError } from '$lib/utils/misc';
import { extractError } from '#lib/utils/misc';
import { Check, X } from '@lucide/svelte';
import { slide, fade } from 'svelte/transition';
import type { PageData } from './$types';
@@ -1,7 +1,7 @@
import type { PageServerLoad } from './$types';
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
import { error, isHttpError } from '@sveltejs/kit';
import { extractError } from '$lib/utils/misc';
import { extractError } from '#lib/utils/misc';
export const load: PageServerLoad = async ({ fetch }) => {
try {
@@ -1,6 +1,6 @@
<script lang="ts">
import type { PageData } from './$types';
import { formatBytes, formatNumber, tooltip } from '$lib/utils/misc';
import { formatBytes, formatNumber, tooltip } from '#lib/utils/misc';
import { FileText, Users, Database, TrendingUp } from '@lucide/svelte';
interface Props {
@@ -1,11 +1,11 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { getServerToken } from '$lib/utils/auth';
import type { User } from '$lib/types/user';
import type { Paste } from '$lib/types/paste';
import type { Pagination } from '$lib/types/pagination';
import type { Report, ReportListResponse } from '$lib/types/report';
import { apiUrl } from '#lib/server/api';
import { getServerToken } from '#lib/utils/auth';
import type { User } from '#lib/types/user';
import type { Paste } from '#lib/types/paste';
import type { Pagination } from '#lib/types/pagination';
import type { Report, ReportListResponse } from '#lib/types/report';
function decodeJwtRoles(token?: string | null): number {
try {
@@ -6,7 +6,7 @@
import { goto, afterNavigate } from '$app/navigation';
import { page } from '$app/state';
import type { PageData } from './$types';
import type { Pagination } from '$lib/types/pagination';
import type { Pagination } from '#lib/types/pagination';
import {
User,
CalendarDays,
@@ -30,13 +30,13 @@
tooltip,
dateToRelativeString,
extractError
} from '$lib/utils/misc';
import { clearTokens, getToken, hasRole, roles } from '$lib/utils/auth';
import { openModal } from '$lib/stores/modal';
import { user } from '$lib/stores/user';
} from '#lib/utils/misc';
import { clearTokens, getToken, hasRole, roles } from '#lib/utils/auth';
import { openModal } from '#lib/stores/modal';
import { user } from '#lib/stores/user';
import { onMount } from 'svelte';
import Paste from '$lib/components/Paste.svelte';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
import Paste from '#lib/components/Paste.svelte';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '#lib/types/report';
import { fade } from 'svelte/transition';
interface Props {
@@ -1,7 +1,7 @@
import type { RequestEvent } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { getServerToken } from '$lib/utils/auth';
import { apiUrl } from '#lib/server/api';
import { getServerToken } from '#lib/utils/auth';
export const load = async ({ params, fetch, cookies }: RequestEvent) => {
const token = getServerToken(cookies);
@@ -1,5 +1,5 @@
import { apiUrl } from '$lib/server/api';
import { extractError } from '$lib/utils/misc';
import { apiUrl } from '#lib/server/api';
import { extractError } from '#lib/utils/misc';
import { error } from '@sveltejs/kit';
export const load = async ({ url, request }) => {
-18
View File
@@ -1,18 +0,0 @@
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;
+8 -3
View File
@@ -1,5 +1,7 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"extends": "$app/tsconfig",
"include": ["src", "test", "*"],
"exclude": ["src/service-worker"],
"compilerOptions": {
"rewriteRelativeImportExtensions": true,
"allowJs": true,
@@ -10,10 +12,13 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
"moduleResolution": "bundler",
"paths": {
"#lib/*": ["./src/lib/*"]
}
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
// except #lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// To make changes to top-level options such as include and exclude, we recommend extending
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
+3 -1
View File
@@ -1,5 +1,7 @@
import tailwindcss from '@tailwindcss/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { defineConfig } from 'vite';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
@@ -14,7 +16,7 @@ const allowedHosts = process.env.VITE_ALLOWED_HOSTS
: ['localhost'];
export default defineConfig({
plugins: [tailwindcss(), sveltekit()],
plugins: [tailwindcss(), sveltekit({ adapter: adapter(), preprocess: vitePreprocess() })],
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
COMMIT_HASH: JSON.stringify(process.env.GIT_COMMIT_HASH || 'unknown')
+10 -6
View File
@@ -13,14 +13,18 @@ This is the backend API for SharpbinV3, built with ASP.NET Core and Entity Frame
The server configuration is managed in `appsettings.json`. For development, ensure you have set the following in `appsettings.Development.json` or as environment variables:
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=sharpbin.db` locally). Compose defaults to `Data Source=/app/data/sharpbin.db`.
- `JwtSettings__Secret`: A random secret of 32–128 characters used for signing JWT tokens.
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Compose passes it to both services. For standalone deployments, match the frontend's `VIEW_INTERNAL_API_KEY`.
For Docker Compose, configure the backend in the root `.env` file. The image includes `appsettings.json` defaults, and environment variables override them. No host configuration mount is required.
The development frontend uses a fixed internal key matching the checked-in `appsettings.Development.json`. Changing only the backend key will break development view recording. Use generated secrets for deployment; see the [root configuration guide](../README.md#configuration).
### Database Migrations
Apply the database migrations to initialize the SQLite database:
The backend applies database migrations automatically on startup. To apply them manually before starting it:
```bash
dotnet ef database update
@@ -34,4 +38,4 @@ Use the following command to run the server with hot reload:
dotnet watch run
```
The API will be accessible at http://localhost:5050 by default (check `Properties/launchSettings.json` or your specific configuration).
The API will be accessible at http://localhost:5050 by default (check `Properties/launchSettings.json` or your specific configuration).
@@ -34,10 +34,13 @@
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="Otp.NET" Version="1.4.1" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.53.4.1-pre1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="11.0.0-rc.2.26504.105" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<EmbeddedResource Include="EmailTemplates\*.html" />
</ItemGroup>
</Project>
-23
View File
@@ -1,23 +0,0 @@
# Required Misc. Variables
Domain=example.com
Https=true
AllowedCorsOrigins__0=https://example.com
JwtSettings__Secret=totally_random_and_secure_string
ConnectionStrings__DefaultConnection=Data Source=/app/data/sharpbin.db
# Auth Settings
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
AuthSettings__Registration_Enabled=true
AuthSettings__Admins_Require_2FA=true
AuthSettings__API_Key_HMAC_Secret=another_random_and_secure_string
# Paste Settings
PasteSettings__MaxTitleLength=500
PasteSettings__MaxPasteSizeInBytes=1048576
PasteSettings__EnablePasteCompression=true
PasteSettings__RequiresVerification=true
PasteSettings__View_HMAC_Secret=random_minimum_32_char_string
# Used so that views are only counted from the frontend
# Must be the same on both the frontend and backend environment
PasteSettings__View_Internal_API_Key=another_random_minimum_32_char_string
+8 -8
View File
@@ -6,13 +6,13 @@ services:
image: sharpbin-backend
container_name: sharpbin-backend
env_file:
- "backend.env"
- ".env"
environment:
DATA_PROTECTION_KEY_PATH: /app/data/keys
ConnectionStrings__DefaultConnection: "Data Source=/app/data/sharpbin.db"
DATA_PROTECTION_KEY_PATH: ${DATA_PROTECTION_KEY_PATH:-/app/data/keys}
ConnectionStrings__DefaultConnection: ${ConnectionStrings__DefaultConnection:-Data Source=/app/data/sharpbin.db}
PasteSettings__View_Internal_API_Key: ${PasteSettings__View_Internal_API_Key:?Set PasteSettings__View_Internal_API_Key in .env}
volumes:
- sharpbin-data:/app/data
- ./SharpbinV3.Server/appsettings.json:/app/appsettings.json
networks:
- sharpbin-net
healthcheck:
@@ -28,13 +28,13 @@ services:
context: ./SharpbinV3.Client
dockerfile: Dockerfile
args:
GIT_COMMIT_HASH: ${GIT_COMMIT_HASH}
GIT_COMMIT_HASH: ${GIT_COMMIT_HASH:-unknown}
image: sharpbin-frontend
container_name: sharpbin-frontend
env_file:
- "frontend.env"
environment:
VITE_API_URL: http://backend:8080
VITE_API_URL: ${VITE_API_URL:-http://backend:8080}
ORIGIN: ${ORIGIN:?Set ORIGIN in .env}
VIEW_INTERNAL_API_KEY: ${PasteSettings__View_Internal_API_Key:?Set PasteSettings__View_Internal_API_Key in .env}
ports:
- "5173:5173"
-6
View File
@@ -1,6 +0,0 @@
VITE_API_URL=http://backend:8080
VITE_ALLOWED_HOSTS=localhost,example.com
# Used so that views are only counted from the frontend
# Must be the same on both the frontend and backend environment
# The frontend will also try to parse 'PasteSettings__View_Internal_API_Key'
VIEW_INTERNAL_API_KEY=another_random_minimum_32_char_string