Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a815cb764 | |||
| 84909ff4e0 | |||
| d750cd88f4 | |||
| 0d6f4a9df3 | |||
| a1ee84967d |
11
.dockerignore
Normal file
11
.dockerignore
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
.npmrc
|
||||||
|
.DS_Store
|
||||||
|
server/node_modules
|
||||||
|
server/.env
|
||||||
|
db_data
|
||||||
|
server/uploads
|
||||||
|
coverage
|
||||||
|
dist
|
||||||
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,2 +1,11 @@
|
|||||||
# macOS metadata
|
# macOS metadata
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# Dependencies and build artifacts
|
||||||
|
node_modules/
|
||||||
|
server/node_modules/
|
||||||
|
db_data/
|
||||||
|
uploads/
|
||||||
|
server/uploads/
|
||||||
|
*.log
|
||||||
|
server/.env
|
||||||
|
|||||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
FROM node:20-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Build deps for sharp on alpine
|
||||||
|
RUN apk add --no-cache python3 make g++ libc6-compat vips-dev
|
||||||
|
|
||||||
|
# Install dependencies first (better layer caching)
|
||||||
|
COPY server/package*.json ./server/
|
||||||
|
WORKDIR /app/server
|
||||||
|
RUN npm install --production
|
||||||
|
|
||||||
|
# Copy the rest of the app (frontend + backend)
|
||||||
|
WORKDIR /app
|
||||||
|
COPY . .
|
||||||
|
WORKDIR /app/server
|
||||||
|
|
||||||
|
EXPOSE 4000
|
||||||
|
CMD ["npm", "start"]
|
||||||
34
README.md
34
README.md
@ -21,6 +21,40 @@ python3 -m http.server 8080
|
|||||||
- Service worker requires an HTTP/HTTPS context; use a local server to test install/offline.
|
- Service worker requires an HTTP/HTTPS context; use a local server to test install/offline.
|
||||||
- Data is stored in `localStorage`; clear it to reset.
|
- Data is stored in `localStorage`; clear it to reset.
|
||||||
|
|
||||||
|
## Backend (optional sync)
|
||||||
|
|
||||||
|
Node + Docker demo backend lives in `server/`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Dev
|
||||||
|
cd server
|
||||||
|
npm install
|
||||||
|
npm run dev # http://localhost:4000
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
docker build -t toadstool-api .
|
||||||
|
docker run -p 4000:4000 toadstool-api
|
||||||
|
```
|
||||||
|
|
||||||
|
### Docker Compose (app + Postgres)
|
||||||
|
```bash
|
||||||
|
docker compose up --build
|
||||||
|
# App/API: http://localhost:4000
|
||||||
|
# Postgres: localhost:5432 (user/pass/db: toadstool)
|
||||||
|
```
|
||||||
|
|
||||||
|
API (in-memory, demo):
|
||||||
|
- `POST /api/signup` `{ email, password, displayName? }` -> `{ token, email }`
|
||||||
|
- `POST /api/login` `{ email, password }` -> `{ token, email }`
|
||||||
|
- `POST /api/logout` (Bearer token)
|
||||||
|
- `GET /api/sync?since=...` (Bearer token) -> `{ projects, patterns }`
|
||||||
|
- `POST /api/sync` (Bearer token) `{ projects, patterns }`
|
||||||
|
- `GET /api/me`, `POST /api/me` (profile)
|
||||||
|
- `POST /api/patterns/:id/share` -> `{ token, url }`, `GET /share/:token` -> `{ pattern }`
|
||||||
|
- `POST /api/upload` (Bearer token, multipart `file`) -> `{ url }` (resizes/compresses to `/uploads`)
|
||||||
|
|
||||||
|
Replace with real auth/storage before production.
|
||||||
|
|
||||||
## PWA Notes
|
## PWA Notes
|
||||||
- Manifest: `assets/site.webmanifest`
|
- Manifest: `assets/site.webmanifest`
|
||||||
- Service worker: `sw.js`
|
- Service worker: `sw.js`
|
||||||
|
|||||||
3434
assets/app.js
3434
assets/app.js
File diff suppressed because it is too large
Load Diff
1761
assets/app.min.js
vendored
Normal file
1761
assets/app.min.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1391
assets/style.css
1391
assets/style.css
File diff suppressed because it is too large
Load Diff
899
assets/style.min.css
vendored
Normal file
899
assets/style.min.css
vendored
Normal file
@ -0,0 +1,899 @@
|
|||||||
|
:root {
|
||||||
|
/* --- Woodland Theme (Light) --- */
|
||||||
|
--bg: #e6e0d0; /* parchment */
|
||||||
|
--card-bg: #f9f4e6; /* cream */
|
||||||
|
--header-bg: #8a6b52; /* warm oak */
|
||||||
|
--header-text: #fdf8f0; /* linen */
|
||||||
|
--text: #433628; /* cocoa */
|
||||||
|
--text-muted: #7a6d5c;
|
||||||
|
--border: #d6cabc;
|
||||||
|
--shadow: 0 4px 10px rgba(67, 54, 40, 0.12);
|
||||||
|
--seed-opacity: 0.06;
|
||||||
|
|
||||||
|
|
||||||
|
--modal-bg: #f8f5e6;
|
||||||
|
--input-bg: #fffdf5;
|
||||||
|
--input-border: #d1c7b7;
|
||||||
|
|
||||||
|
--bg-finished: #dbe4ce; /* Muted sage green */
|
||||||
|
--lock-btn-bg: #ebe7da;
|
||||||
|
--lock-btn-text: #9c8e7e;
|
||||||
|
--btn-secondary-bg: #fdfcf5;
|
||||||
|
--btn-secondary-text: #4a3b2a;
|
||||||
|
|
||||||
|
/* Status Colors (Muted earthy tones) */
|
||||||
|
--danger: #b56b54; /* Rusty red/orange */
|
||||||
|
--success: #7a8b4f; /* Mossy green */
|
||||||
|
|
||||||
|
/* Dynamic Project Color (Default Rust) */
|
||||||
|
--project-color: #b56b54;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- Woodland Theme (Dark) --- */
|
||||||
|
body.dark-mode {
|
||||||
|
--bg: #2c3327; /* Deep forest background */
|
||||||
|
--card-bg: #3b342c; /* Dark wood card */
|
||||||
|
--header-bg: #4b3829; /* Darker wood header */
|
||||||
|
--header-text: #e9e4d7;
|
||||||
|
--text: #e9e4d7; /* Cream text */
|
||||||
|
--text-muted: #b5aa9b;
|
||||||
|
--border: #5f5245;
|
||||||
|
--shadow: 0 4px 10px rgba(0,0,0,0.45);
|
||||||
|
|
||||||
|
--modal-bg: #3d362d;
|
||||||
|
--input-bg: #2c2720;
|
||||||
|
--input-border: #594e3f;
|
||||||
|
|
||||||
|
--bg-finished: #2a382a; /* Dark moss */
|
||||||
|
--lock-btn-bg: #4a4238;
|
||||||
|
--lock-btn-text: #8c8276;
|
||||||
|
--btn-secondary-bg: #4a4238;
|
||||||
|
--btn-secondary-text: #d1c7b7;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Nunito', "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||||
|
background-color: var(--bg);
|
||||||
|
min-height: 100vh;
|
||||||
|
color: var(--text);
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow-x: hidden;
|
||||||
|
scrollbar-gutter: stable; /* Prevent layout shift when scrollbar appears/disappears */
|
||||||
|
transition: background-color 0.3s, color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.theme-animating { animation: themeSwap 0.7s ease-in-out; }
|
||||||
|
@keyframes themeSwap {
|
||||||
|
0% { filter: brightness(1.08) saturate(1.06); opacity: 0.85; }
|
||||||
|
45% { filter: brightness(1.03) saturate(1.12) contrast(1.04); opacity: 0.92; }
|
||||||
|
75% { filter: brightness(0.98) saturate(1.04); opacity: 0.97; }
|
||||||
|
100% { filter: brightness(1) saturate(1); opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
background-color: var(--header-bg);
|
||||||
|
color: var(--header-text);
|
||||||
|
padding: 0.8rem 1rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 100;
|
||||||
|
border-bottom: 2px solid rgba(0,0,0,0.05);
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.3rem;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
color: var(--header-text);
|
||||||
|
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
|
||||||
|
font-family: 'Playfair Display', Georgia, serif;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand { display: flex; align-items: center; gap: 10px; }
|
||||||
|
|
||||||
|
.brand-icon {
|
||||||
|
width: 52px; height: 52px; border-radius: 8px;
|
||||||
|
object-fit: contain; display: block;
|
||||||
|
background: rgba(255,255,255,0.12); padding: 4px;
|
||||||
|
box-shadow: inset 0 1px 2px rgba(0,0,0,0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-controls { display: flex; gap: 10px; }
|
||||||
|
|
||||||
|
.header-btn {
|
||||||
|
background: rgba(255,255,255,0.2);
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--header-text);
|
||||||
|
transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.2s;
|
||||||
|
transform: translateY(0);
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
.header-btn:hover { transform: translateY(-1px) scale(1.03); box-shadow: 0 6px 14px rgba(0,0,0,0.12); }
|
||||||
|
.header-btn:active { transform: translateY(0) scale(0.96); box-shadow: none; }
|
||||||
|
|
||||||
|
.header-btn.is-active { background: var(--header-text); color: var(--header-bg); }
|
||||||
|
.hidden { display: none !important; }
|
||||||
|
.hidden-input { display: none; }
|
||||||
|
|
||||||
|
.fab-pattern { right: auto; left: 22px; background: var(--text); }
|
||||||
|
.fab-pattern:hover { transform: scale(1.07); }
|
||||||
|
|
||||||
|
/* Pattern Composer Overlay */
|
||||||
|
.pattern-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(44, 35, 25, 0.55);
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 215;
|
||||||
|
padding: 14px;
|
||||||
|
}
|
||||||
|
.pattern-overlay.active { display: flex; }
|
||||||
|
.pattern-sheet {
|
||||||
|
width: min(1280px, 96vw);
|
||||||
|
max-height: 92vh;
|
||||||
|
overflow: auto;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 16px;
|
||||||
|
box-shadow: 0 16px 40px rgba(0,0,0,0.25);
|
||||||
|
}
|
||||||
|
.pattern-sheet-header {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr auto auto auto;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.pattern-sheet-title h2 { margin: 0; font-size: 1.2rem; color: var(--text); }
|
||||||
|
.pattern-sheet-subtitle { margin: 2px 0 0; color: var(--text-muted); font-size: 0.9rem; }
|
||||||
|
.pattern-sheet-header h2 { margin: 0; font-size: 1.2rem; color: var(--text); }
|
||||||
|
.pattern-close {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.pattern-close:hover { color: var(--project-color); }
|
||||||
|
.pattern-modes { display: flex; gap: 8px; justify-content: flex-end; }
|
||||||
|
.pattern-mode { border: 1px solid var(--border); background: var(--input-bg); color: var(--text); padding: 6px 10px; border-radius: 10px; cursor: pointer; }
|
||||||
|
.pattern-mode.is-active { background: var(--project-color); color: var(--card-bg); border-color: var(--project-color); }
|
||||||
|
.pattern-save-indicator { color: var(--text-muted); font-size: 0.9rem; }
|
||||||
|
.pattern-body { display: grid; gap: 12px; }
|
||||||
|
.pattern-row-info { color: var(--text-muted); font-size: 0.95rem; }
|
||||||
|
.pattern-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||||
|
.pattern-buttons button { padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); cursor: pointer; color: #fff; }
|
||||||
|
.pattern-buttons button:hover { border-color: var(--project-color); color: var(--project-color); }
|
||||||
|
.pattern-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
|
||||||
|
.pattern-tab {
|
||||||
|
background: var(--input-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.pattern-tab.is-active { background: var(--project-color); color: var(--card-bg); border-color: var(--project-color); }
|
||||||
|
.pattern-section { display: none; border: 1px dashed var(--border); padding: 12px; border-radius: 12px; background: var(--card-bg); }
|
||||||
|
.pattern-section.is-active { display: block; }
|
||||||
|
.field-label { display: block; margin: 8px 0 4px; color: var(--text-muted); font-size: 0.9rem; }
|
||||||
|
.pattern-section input, .pattern-section textarea {
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--input-bg);
|
||||||
|
color: var(--text);
|
||||||
|
padding: 10px;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
.field-group-inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; align-items: center; }
|
||||||
|
.pattern-row-editor textarea,
|
||||||
|
.pattern-output textarea {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 60px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--input-bg);
|
||||||
|
color: #fff;
|
||||||
|
padding: 10px;
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
.pattern-row-editor { display: grid; gap: 8px; }
|
||||||
|
.pattern-row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
|
||||||
|
.pattern-row-actions .primary { background: var(--project-color); color: var(--card-bg); border: none; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
|
||||||
|
.pattern-row-actions .secondary { background: var(--input-bg); color: var(--text); border: 1px solid var(--border); padding: 8px 12px; border-radius: 10px; cursor: pointer; }
|
||||||
|
.pattern-footer { justify-content: space-between; border-top: 1px solid var(--border); padding-top: 8px; }
|
||||||
|
.pattern-output { display: grid; gap: 6px; }
|
||||||
|
.pattern-steps-head { display: flex; align-items: center; justify-content: space-between; }
|
||||||
|
.pattern-step-card {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
transition: box-shadow 0.2s ease, transform 0.18s ease;
|
||||||
|
}
|
||||||
|
.pattern-step-card.card-pop { animation: cardPop 0.28s ease; }
|
||||||
|
.pattern-step-card:hover { box-shadow: 0 8px 18px rgba(0,0,0,0.08); transform: translateY(-1px); }
|
||||||
|
.pattern-row-list { display: grid; gap: 6px; }
|
||||||
|
.row-item { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; }
|
||||||
|
.row-item label { color: var(--text-muted); font-size: 0.9rem; }
|
||||||
|
.row-item input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 6px 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--input-bg);
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.row-item button { border: 1px solid var(--border); background: var(--btn-secondary-bg); color: var(--text); border-radius: 8px; padding: 4px 8px; cursor: pointer; }
|
||||||
|
.pattern-step-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
|
||||||
|
.add-step-row { display: flex; justify-content: center; padding: 10px; border: 1px dashed var(--border); background: var(--card-bg); }
|
||||||
|
.add-step-row .add-step-btn { padding: 10px 16px; border-radius: 12px; border: none; background: var(--project-color); color: var(--card-bg); cursor: pointer; font-weight: 700; }
|
||||||
|
.add-step-row .add-step-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(0,0,0,0.12); }
|
||||||
|
.add-step-row .add-step-btn:active { transform: translateY(0); box-shadow: none; }
|
||||||
|
.step-number {
|
||||||
|
font-weight: 800;
|
||||||
|
color: var(--project-color);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
@keyframes cardPop {
|
||||||
|
0% { transform: translateY(6px) scale(0.97); opacity: 0; }
|
||||||
|
60% { transform: translateY(-2px) scale(1.01); opacity: 1; }
|
||||||
|
100% { transform: translateY(0) scale(1); opacity: 1; }
|
||||||
|
}
|
||||||
|
.abbrev-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||||
|
.abbrev-group { border: 1px solid var(--border); border-radius: 12px; margin: 6px 0; background: var(--card-bg); }
|
||||||
|
.abbrev-group[open] > summary { border-bottom: 1px solid var(--border); }
|
||||||
|
.abbrev-group summary {
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 8px 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text);
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
.abbrev-group summary::-webkit-details-marker { display: none; }
|
||||||
|
.abbrev-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
|
||||||
|
gap: 6px;
|
||||||
|
padding: 8px 10px 10px;
|
||||||
|
}
|
||||||
|
.abbrev-pill {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
background: var(--input-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.92rem;
|
||||||
|
transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
|
||||||
|
}
|
||||||
|
.abbrev-pill:hover { transform: translateY(-1px); border-color: var(--project-color); }
|
||||||
|
.abbrev-pill.is-selected {
|
||||||
|
background: var(--project-color);
|
||||||
|
border-color: var(--project-color);
|
||||||
|
color: var(--card-bg);
|
||||||
|
}
|
||||||
|
.abbrev-pill .code { font-weight: 700; color: inherit; }
|
||||||
|
.abbrev-pill .desc { color: inherit; opacity: 0.85; font-size: 0.85rem; }
|
||||||
|
.selected-abbrev {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
margin: 6px 0 10px;
|
||||||
|
}
|
||||||
|
.selected-abbrev .pill {
|
||||||
|
background: var(--project-color);
|
||||||
|
color: var(--card-bg);
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.color-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(44, 35, 25, 0.55);
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 210;
|
||||||
|
padding: 20px;
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
.color-overlay.active { display: flex; }
|
||||||
|
.color-modal {
|
||||||
|
background: var(--card-bg);
|
||||||
|
color: var(--text);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 18px 18px 14px;
|
||||||
|
width: min(420px, 90vw);
|
||||||
|
box-shadow: 0 10px 30px rgba(0,0,0,0.25);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.color-title { margin: 0 0 12px; font-family: 'Playfair Display', Georgia, serif; }
|
||||||
|
.color-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.color-custom {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
.color-custom input[type="color"] {
|
||||||
|
width: 42px;
|
||||||
|
height: 32px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.color-swatch {
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 2px solid var(--border);
|
||||||
|
cursor: pointer;
|
||||||
|
box-shadow: inset 0 0 0 2px rgba(255,255,255,0.55);
|
||||||
|
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||||
|
}
|
||||||
|
.color-swatch:hover { transform: translateY(-1px) scale(1.02); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.8); }
|
||||||
|
.color-swatch:active { transform: scale(0.98); }
|
||||||
|
.color-swatch.custom {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text);
|
||||||
|
background: linear-gradient(45deg, #f4ead8, #d6cabc);
|
||||||
|
box-shadow: inset 0 0 0 2px rgba(0,0,0,0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(44, 35, 25, 0.55);
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 210;
|
||||||
|
padding: 20px;
|
||||||
|
backdrop-filter: blur(2px);
|
||||||
|
}
|
||||||
|
.save-overlay.active { display: flex; }
|
||||||
|
.save-modal {
|
||||||
|
background: var(--card-bg);
|
||||||
|
color: var(--text);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 18px 18px 14px;
|
||||||
|
width: min(420px, 90vw);
|
||||||
|
box-shadow: 0 10px 30px rgba(0,0,0,0.25);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.save-subtext { margin: 0 0 8px; color: var(--text-muted); }
|
||||||
|
.save-list { display: grid; gap: 8px; max-height: 220px; overflow-y: auto; margin-bottom: 10px; }
|
||||||
|
.save-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--input-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.save-item input { width: 18px; height: 18px; }
|
||||||
|
.save-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
||||||
|
.icon-woodland { width: 22px; height: 22px; }
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 1.5rem 1.25rem calc(120px + env(safe-area-inset-bottom, 0px));
|
||||||
|
position: relative;
|
||||||
|
z-index: 1; /* Keep cards above background */
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.projects-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
align-items: start; /* Prevent shorter cards from stretching to tallest row mate */
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1280px) {
|
||||||
|
.projects-grid {
|
||||||
|
grid-template-columns: repeat(3, minmax(320px, 1fr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- PROJECT CONTAINER --- */
|
||||||
|
.project-container {
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 18px;
|
||||||
|
padding: 5px 15px 15px 15px;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-header {
|
||||||
|
display: flex; justify-content: space-between; align-items: center;
|
||||||
|
padding: 15px 5px; margin-bottom: 10px; gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-title-group { display: flex; align-items: center; gap: 10px; }
|
||||||
|
|
||||||
|
.project-title {
|
||||||
|
font-size: 1.4rem; font-weight: 800; color: var(--project-color);
|
||||||
|
text-transform: uppercase; letter-spacing: 1px;
|
||||||
|
font-family: 'Playfair Display', Georgia, serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-toggle-project {
|
||||||
|
background: none; border: none; color: var(--project-color);
|
||||||
|
font-size: 1.2rem; cursor: pointer; transition: transform 0.2s; padding: 5px;
|
||||||
|
}
|
||||||
|
.part-list { max-height: 2000px; opacity: 1; transition: max-height 0.35s ease, opacity 0.3s ease; overflow: hidden; }
|
||||||
|
.project-collapsed .btn-toggle-project { transform: rotate(-90deg); }
|
||||||
|
.project-collapsed .part-list { max-height: 0; opacity: 0; pointer-events: none; }
|
||||||
|
.project-collapsed { margin-bottom: 1rem; opacity: 0.8; box-shadow: none; }
|
||||||
|
|
||||||
|
.project-actions { display: flex; gap: 8px; align-items: center; }
|
||||||
|
|
||||||
|
.btn-add-part {
|
||||||
|
background: var(--project-color); color: var(--card-bg); border: none;
|
||||||
|
border-radius: 20px; padding: 6px 16px; font-size: 0.9rem; font-weight: bold;
|
||||||
|
cursor: pointer; box-shadow: 0 3px 8px rgba(0,0,0,0.1); transition: transform 0.1s;
|
||||||
|
}
|
||||||
|
.btn-add-part:active { transform: scale(0.95); }
|
||||||
|
.btn-save-pattern {
|
||||||
|
background: none; border: 1px dashed var(--border); color: var(--text-muted);
|
||||||
|
border-radius: 14px; padding: 6px 10px; font-size: 0.9rem; cursor: pointer;
|
||||||
|
}
|
||||||
|
.btn-save-pattern:hover { color: var(--project-color); border-color: var(--project-color); }
|
||||||
|
|
||||||
|
.btn-delete-project {
|
||||||
|
background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 5px;
|
||||||
|
}
|
||||||
|
.btn-delete-project:hover { color: var(--danger); }
|
||||||
|
|
||||||
|
.btn-rename-project {
|
||||||
|
background: none; border: none; color: var(--text-muted);
|
||||||
|
padding: 5px 8px; border-radius: 8px; font-size: 1rem; cursor: pointer;
|
||||||
|
}
|
||||||
|
.btn-rename-project:hover { color: var(--project-color); }
|
||||||
|
.icon-pencil { display: inline-block; transform: scaleX(-1); }
|
||||||
|
|
||||||
|
.btn-color {
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 2px solid var(--border);
|
||||||
|
background: var(--project-color);
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
box-shadow: inset 0 0 0 2px var(--card-bg);
|
||||||
|
}
|
||||||
|
.btn-color:hover { box-shadow: inset 0 0 0 2px var(--project-color); }
|
||||||
|
|
||||||
|
/* --- PART CARD --- */
|
||||||
|
.part-card {
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 14px;
|
||||||
|
padding: 1rem;
|
||||||
|
margin-bottom: 0.8rem;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
position: relative;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
overflow: hidden;
|
||||||
|
border-left: 7px solid var(--project-color);
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-card.is-locked { background-color: var(--bg); opacity: 0.9; }
|
||||||
|
|
||||||
|
.part-card.is-finished {
|
||||||
|
background-color: var(--bg-finished);
|
||||||
|
border-left-color: var(--success);
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
.finish-shimmer { animation: finishShimmer 0.8s ease; }
|
||||||
|
@keyframes finishShimmer {
|
||||||
|
0% { box-shadow: var(--shadow), 0 0 0 0 rgba(122, 139, 79, 0.32); }
|
||||||
|
60% { box-shadow: var(--shadow), 0 0 0 16px rgba(122, 139, 79, 0); }
|
||||||
|
100% { box-shadow: var(--shadow), 0 0 0 0 rgba(122, 139, 79, 0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-card.is-minimized { padding: 0.8rem 1rem; }
|
||||||
|
.part-card.is-minimized .count-display,
|
||||||
|
.part-card.is-minimized .controls { display: none; }
|
||||||
|
.part-card.is-minimized .part-mini-count { display: inline-block; }
|
||||||
|
.part-card.is-minimized .btn-toggle-part { transform: rotate(-90deg); }
|
||||||
|
.part-card.is-minimized .count-subtext,
|
||||||
|
.part-card.is-minimized .btn-reset-part,
|
||||||
|
.part-card.is-minimized .btn-delete-part { display: none; }
|
||||||
|
|
||||||
|
.part-header { display: flex; justify-content: space-between; align-items: center; }
|
||||||
|
.part-card:not(.is-minimized) .part-header { margin-bottom: 15px; }
|
||||||
|
|
||||||
|
.part-name-group { display: flex; align-items: center; gap: 12px; flex-grow: 1; }
|
||||||
|
|
||||||
|
.check-container { position: relative; cursor: pointer; width: 26px; height: 26px; flex-shrink: 0; }
|
||||||
|
.check-container input { opacity: 0; cursor: pointer; height: 0; width: 0; }
|
||||||
|
.checkmark {
|
||||||
|
position: absolute; top: 0; left: 0; height: 26px; width: 26px;
|
||||||
|
background-color: var(--card-bg); border-radius: 50%; border: 2px solid var(--text-muted); transition: all 0.2s;
|
||||||
|
}
|
||||||
|
.check-container input:checked ~ .checkmark { background-color: var(--success); border-color: var(--success); }
|
||||||
|
.checkmark:after { content: ""; position: absolute; display: none; }
|
||||||
|
.check-container input:checked ~ .checkmark:after { display: block; }
|
||||||
|
.check-container .checkmark:after {
|
||||||
|
left: 9px; top: 5px; width: 6px; height: 12px;
|
||||||
|
border: solid var(--card-bg); border-width: 0 2px 2px 0; transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-name {
|
||||||
|
font-size: 1.1rem; font-weight: 700; color: var(--text);
|
||||||
|
border-bottom: 2px dashed var(--project-color); /* Dashed looks more like stitching */
|
||||||
|
cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.part-mini-count {
|
||||||
|
display: none; font-weight: 800; color: var(--project-color); margin-left: 8px; font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-finished .part-name { text-decoration: line-through; color: var(--success); border-bottom: none; }
|
||||||
|
.is-finished .part-mini-count { color: var(--success); }
|
||||||
|
|
||||||
|
.part-actions { display: flex; gap: 8px; align-items: center; }
|
||||||
|
.part-actions { justify-content: flex-end; min-width: 120px; }
|
||||||
|
.icon-btn {
|
||||||
|
background: none; border: none; font-size: 1.3rem; padding: 5px; color: var(--text-muted);
|
||||||
|
cursor: pointer; transition: color 0.2s;
|
||||||
|
display: inline-flex; align-items: center; justify-content: center;
|
||||||
|
width: 32px; height: 32px;
|
||||||
|
}
|
||||||
|
.icon-btn:disabled { opacity: 0.4; pointer-events: none; }
|
||||||
|
.btn-delete-part:hover { color: var(--danger); }
|
||||||
|
.btn-toggle-part { transition: transform 0.2s; }
|
||||||
|
|
||||||
|
.count-display {
|
||||||
|
font-size: 3.5rem; font-weight: 800; text-align: center; color: var(--project-color); margin: 0.5rem 0 0.4rem 0; touch-action: manipulation;
|
||||||
|
text-shadow: 1px 1px 0px var(--card-bg);
|
||||||
|
}
|
||||||
|
.is-locked .count-display { color: var(--lock-btn-text); pointer-events: none; }
|
||||||
|
.is-finished .count-display { color: var(--success); pointer-events: none; }
|
||||||
|
|
||||||
|
.count-subtext {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin: 0 0 0.6rem 0;
|
||||||
|
}
|
||||||
|
.count-subtext strong { color: var(--project-color); }
|
||||||
|
.count-bump-up { animation: countUp 0.26s ease; }
|
||||||
|
.count-bump-down { animation: countDown 0.26s ease; }
|
||||||
|
@keyframes countUp {
|
||||||
|
0% { transform: scale(0.95); color: var(--btn-secondary-text); }
|
||||||
|
60% { transform: scale(1.08); color: var(--project-color); }
|
||||||
|
100% { transform: scale(1); color: var(--project-color); }
|
||||||
|
}
|
||||||
|
@keyframes countDown {
|
||||||
|
0% { transform: scale(1.05); color: var(--project-color); }
|
||||||
|
60% { transform: scale(0.9); color: var(--text-muted); }
|
||||||
|
100% { transform: scale(1); color: var(--project-color); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-toggle {
|
||||||
|
background: none; border: 1px dashed var(--border); color: var(--text-muted);
|
||||||
|
padding: 4px 10px; border-radius: 10px; cursor: pointer; font-size: 0.9rem;
|
||||||
|
margin: 12px auto 6px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.note-toggle:hover { color: var(--project-color); border-color: var(--project-color); }
|
||||||
|
|
||||||
|
.note-area {
|
||||||
|
display: none;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.note-area.show { display: block; }
|
||||||
|
.note-area textarea {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 90px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--input-bg);
|
||||||
|
color: var(--text);
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
.controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; padding: 0 5px; }
|
||||||
|
|
||||||
|
button.action-btn {
|
||||||
|
border: none; border-radius: 12px; padding: 12px 0; font-size: 1.5rem;
|
||||||
|
cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.1s;
|
||||||
|
box-shadow: 0 3px 6px rgba(0,0,0,0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-minus { background-color: var(--btn-secondary-bg); color: var(--btn-secondary-text); border: 1px solid var(--border); }
|
||||||
|
.btn-plus { background-color: var(--project-color); color: var(--card-bg); }
|
||||||
|
.btn-lock { background-color: var(--lock-btn-bg); color: var(--lock-btn-text); font-size: 1.1rem; }
|
||||||
|
.btn-lock.locked-active { background-color: var(--border); color: var(--text-muted); border: 2px solid var(--text-muted); box-shadow: none;}
|
||||||
|
|
||||||
|
.hidden-controls { visibility: hidden; pointer-events: none; }
|
||||||
|
.dimmed { opacity: 0.4; pointer-events: none; }
|
||||||
|
button:active { transform: scale(0.97); box-shadow: none; }
|
||||||
|
|
||||||
|
/* Floating Add Project Button */
|
||||||
|
.fab {
|
||||||
|
position: fixed; bottom: 30px; right: 30px;
|
||||||
|
background-color: var(--text); color: var(--bg); /* Adapts to mode */
|
||||||
|
width: 65px; height: 65px; border-radius: 50%;
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
font-size: 2.2rem; box-shadow: 0 6px 15px rgba(74, 59, 42, 0.3);
|
||||||
|
border: none; z-index: 3; transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||||
|
}
|
||||||
|
.fab:hover { transform: translateY(-3px) scale(1.04) rotate(-2deg); box-shadow: 0 10px 24px rgba(0,0,0,0.18); }
|
||||||
|
.fab:active { transform: translateY(0) scale(0.94); box-shadow: 0 3px 8px rgba(0,0,0,0.2); }
|
||||||
|
.fab { z-index: 2; }
|
||||||
|
|
||||||
|
/* --- MODAL --- */
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
||||||
|
background-color: rgba(44, 35, 25, 0.6); z-index: 200; align-items: center; justify-content: center; backdrop-filter: blur(2px);
|
||||||
|
display: flex; opacity: 0; visibility: hidden; pointer-events: none;
|
||||||
|
transition: opacity 0.3s ease, visibility 0.3s ease;
|
||||||
|
}
|
||||||
|
.modal-overlay.active { opacity: 1; visibility: visible; pointer-events: auto; }
|
||||||
|
.modal-content {
|
||||||
|
background: var(--modal-bg); color: var(--text);
|
||||||
|
padding: 25px; border-radius: 20px; width: 85%; max-width: 400px;
|
||||||
|
animation: none; box-shadow: var(--shadow); border: 1px solid var(--border);
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
.modal-overlay.active .modal-content { animation: modalIn 0.32s ease; }
|
||||||
|
@keyframes modalIn {
|
||||||
|
0% { transform: translateY(10px) scale(0.96); opacity: 0; }
|
||||||
|
60% { transform: translateY(-4px) scale(1.02); opacity: 1; }
|
||||||
|
100% { transform: translateY(0) scale(1); opacity: 1; }
|
||||||
|
}
|
||||||
|
.modal-title { margin: 0 0 15px 0; font-size: 1.3rem; color: var(--text); font-weight: 800; }
|
||||||
|
.modal-input {
|
||||||
|
width: 100%; padding: 15px; font-size: 1.2rem;
|
||||||
|
background: var(--input-bg); color: var(--text);
|
||||||
|
border: 2px solid var(--input-border); border-radius: 12px; margin-bottom: 25px; outline: none; transition: border-color 0.2s;
|
||||||
|
}
|
||||||
|
.modal-input:focus { border-color: var(--project-color); }
|
||||||
|
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
|
||||||
|
.modal-btn { padding: 12px 24px; border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; }
|
||||||
|
.btn-cancel { background: var(--lock-btn-bg); color: var(--text-muted); }
|
||||||
|
.btn-save { background: var(--text); color: var(--bg); }
|
||||||
|
.pattern-picker { display: none; margin: 12px 0 6px; }
|
||||||
|
.pattern-picker label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
.pattern-picker select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
background: var(--input-bg);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state { text-align: center; color: var(--text-muted); margin-top: 80px; font-size: 1.2rem; font-style: italic;}
|
||||||
|
|
||||||
|
.footer-bg {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: -180px;
|
||||||
|
height: clamp(760px, 1200px, 1200px);
|
||||||
|
background: url('textures/mushroom.svg') no-repeat center bottom;
|
||||||
|
background-size: cover;
|
||||||
|
opacity: 1;
|
||||||
|
width: 125vw;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.firefly-wrap {
|
||||||
|
position: fixed;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
animation: fireflyGlide var(--fly-duration, 14s) linear forwards;
|
||||||
|
z-index: 0; /* Drift beneath page content */
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.firefly {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: radial-gradient(circle, rgba(255,245,200,0.9) 0%, rgba(255,245,200,0.4) 45%, rgba(255,245,200,0.1) 70%, rgba(255,245,200,0) 85%);
|
||||||
|
opacity: 0.9;
|
||||||
|
mix-blend-mode: screen;
|
||||||
|
filter: blur(1px) drop-shadow(0 0 14px rgba(255, 245, 200, 0.8)) brightness(1.15);
|
||||||
|
animation: fireflyFlutter 1.6s ease-in-out infinite alternate, fireflyFlicker 1.1s ease-in-out infinite alternate;
|
||||||
|
}
|
||||||
|
|
||||||
|
.seed-wrap {
|
||||||
|
position: fixed;
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
animation: seedGlide var(--seed-duration, 16s) linear forwards;
|
||||||
|
z-index: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.seed {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
background: url('textures/seed.svg') no-repeat center/contain;
|
||||||
|
opacity: var(--seed-opacity, 0.07);
|
||||||
|
mix-blend-mode: screen;
|
||||||
|
filter: drop-shadow(0 4px 10px rgba(200, 190, 160, 0.55));
|
||||||
|
animation: seedDrift 2.6s ease-in-out infinite alternate,
|
||||||
|
seedFlicker 1.4s ease-in-out infinite alternate,
|
||||||
|
seedFlip var(--seed-flip-duration, 6s) ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes fireflyGlide {
|
||||||
|
0% { transform: translate3d(var(--fly-start-x, -10vw), var(--fly-start-y, 0), 0) scale(var(--fly-scale, 1)); opacity: 0; }
|
||||||
|
12% { opacity: 0.55; }
|
||||||
|
35% { transform: translate3d(var(--fly-mid-x, 25vw), var(--fly-mid-y, -6px), 0) scale(var(--fly-scale, 1)); opacity: 0.65; }
|
||||||
|
65% { transform: translate3d(var(--fly-mid2-x, 65vw), var(--fly-mid2-y, 6px), 0) scale(var(--fly-scale, 1)); opacity: 0.55; }
|
||||||
|
90% { opacity: 0.35; }
|
||||||
|
100% { transform: translate3d(var(--fly-end-x, 110vw), var(--fly-end-y, 0), 0) scale(var(--fly-scale, 1)); opacity: 0; }
|
||||||
|
}
|
||||||
|
@keyframes fireflyFlutter {
|
||||||
|
0% { transform: translateY(-2px) translateX(-3px) scale(0.95); }
|
||||||
|
50% { transform: translateY(3px) translateX(2px) scale(1.05); }
|
||||||
|
100% { transform: translateY(-2px) translateX(1px) scale(0.97); }
|
||||||
|
}
|
||||||
|
@keyframes fireflyFlicker {
|
||||||
|
0% { opacity: 0.65; filter: blur(1px) drop-shadow(0 0 10px rgba(255,245,200,0.65)); }
|
||||||
|
50% { opacity: 1; filter: blur(0.5px) drop-shadow(0 0 16px rgba(255,245,200,1)); }
|
||||||
|
100% { opacity: 0.75; filter: blur(1px) drop-shadow(0 0 12px rgba(255,245,200,0.75)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes seedGlide {
|
||||||
|
0% { transform: translate3d(var(--seed-start, -12vw), 0, 0) scale(var(--seed-scale, 1)); opacity: 0; }
|
||||||
|
10% { opacity: 0.35; }
|
||||||
|
40% { transform: translate3d(calc(var(--seed-mid, 30vw)), -10px, 0) scale(var(--seed-scale, 1)); opacity: 0.5; }
|
||||||
|
70% { transform: translate3d(calc(var(--seed-mid, 30vw) * 2), 8px, 0) scale(var(--seed-scale, 1)); opacity: 0.4; }
|
||||||
|
100% { transform: translate3d(var(--seed-end, 110vw), -6px, 0) scale(var(--seed-scale, 1)); opacity: 0; }
|
||||||
|
}
|
||||||
|
@keyframes seedDrift {
|
||||||
|
0% { transform: translateY(-4px) translateX(calc(var(--seed-sway, 6px) * -1)) rotate(calc(var(--seed-tilt, 10deg) * -0.6)) scale(0.94); opacity: 0.65; }
|
||||||
|
50% { transform: translateY(5px) translateX(calc(var(--seed-sway, 6px) * 0.8)) rotate(calc(var(--seed-tilt, 10deg))) scale(1.05); opacity: 0.9; }
|
||||||
|
100% { transform: translateY(-3px) translateX(calc(var(--seed-sway, 6px) * 0.4)) rotate(calc(var(--seed-tilt, 10deg) * 0.2)) scale(0.97); opacity: 0.7; }
|
||||||
|
}
|
||||||
|
@keyframes seedFlicker {
|
||||||
|
0% { opacity: 0.65; filter: drop-shadow(0 2px 4px rgba(200,190,160,0.35)); }
|
||||||
|
50% { opacity: 0.9; filter: drop-shadow(0 4px 8px rgba(200,190,160,0.5)); }
|
||||||
|
100% { opacity: 0.7; filter: drop-shadow(0 3px 6px rgba(200,190,160,0.4)); }
|
||||||
|
}
|
||||||
|
@keyframes seedFlip {
|
||||||
|
0% { transform: rotate(0deg) scale(1); }
|
||||||
|
20% { transform: rotate(8deg) scale(1.02); }
|
||||||
|
40% { transform: rotate(-10deg) scale(0.98); }
|
||||||
|
60% { transform: rotate(14deg) scale(1.03); }
|
||||||
|
80% { transform: rotate(-6deg) scale(0.99); }
|
||||||
|
100% { transform: rotate(0deg) scale(1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.footer-bg {
|
||||||
|
bottom: -40px;
|
||||||
|
height: clamp(260px, 24vh, 450px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) and (min-width: 769px) {
|
||||||
|
.container {
|
||||||
|
padding: 1.5rem 1.25rem calc(140px + env(safe-area-inset-bottom, 0px));
|
||||||
|
}
|
||||||
|
.footer-bg {
|
||||||
|
height: clamp(300px, 28vh, 480px);
|
||||||
|
bottom: -180px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Sweet-ish alerts */
|
||||||
|
.swal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(44, 35, 25, 0.55);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 300;
|
||||||
|
padding: 20px;
|
||||||
|
animation: overlayFade 0.22s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swal-dialog {
|
||||||
|
background: var(--card-bg);
|
||||||
|
color: var(--text);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 22px 20px 18px;
|
||||||
|
width: min(420px, 90vw);
|
||||||
|
box-shadow: 0 10px 30px rgba(0,0,0,0.25);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
text-align: center;
|
||||||
|
position: relative;
|
||||||
|
animation: dialogPop 0.28s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swal-title {
|
||||||
|
font-family: 'Playfair Display', Georgia, serif;
|
||||||
|
font-size: 1.4rem;
|
||||||
|
margin: 0 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swal-text { margin: 0 0 16px; color: var(--text-muted); }
|
||||||
|
|
||||||
|
.swal-actions { display: flex; justify-content: center; gap: 10px; }
|
||||||
|
|
||||||
|
.swal-btn {
|
||||||
|
border: none;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 12px 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
cursor: pointer;
|
||||||
|
min-width: 110px;
|
||||||
|
transition: transform 0.08s;
|
||||||
|
}
|
||||||
|
.swal-btn:active { transform: scale(0.97); }
|
||||||
|
.swal-confirm { background: var(--project-color); color: var(--card-bg); }
|
||||||
|
.swal-cancel { background: var(--lock-btn-bg); color: var(--text); }
|
||||||
|
.swal-danger { background: var(--danger); color: var(--card-bg); }
|
||||||
|
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
|
||||||
|
@keyframes dialogPop {
|
||||||
|
0% { transform: translateY(8px) scale(0.96); opacity: 0; }
|
||||||
|
60% { transform: translateY(-3px) scale(1.02); opacity: 1; }
|
||||||
|
100% { transform: translateY(0) scale(1); opacity: 1; }
|
||||||
|
}
|
||||||
@ -24,9 +24,9 @@
|
|||||||
inkscape:deskcolor="#d1d1d1"
|
inkscape:deskcolor="#d1d1d1"
|
||||||
inkscape:document-units="in"
|
inkscape:document-units="in"
|
||||||
showgrid="true"
|
showgrid="true"
|
||||||
inkscape:zoom="1.1206597"
|
inkscape:zoom="0.34361842"
|
||||||
inkscape:cx="69.155693"
|
inkscape:cx="618.41853"
|
||||||
inkscape:cy="576"
|
inkscape:cy="598.0471"
|
||||||
inkscape:window-width="2560"
|
inkscape:window-width="2560"
|
||||||
inkscape:window-height="1532"
|
inkscape:window-height="1532"
|
||||||
inkscape:window-x="0"
|
inkscape:window-x="0"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
41
docker-compose.yml
Normal file
41
docker-compose.yml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:15-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: toadstool
|
||||||
|
POSTGRES_PASSWORD: toadstool
|
||||||
|
POSTGRES_DB: toadstool
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/postgresql/data
|
||||||
|
ports:
|
||||||
|
- "5440:5432"
|
||||||
|
|
||||||
|
api:
|
||||||
|
build: .
|
||||||
|
# restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgres://toadstool:toadstool@db:5432/toadstool
|
||||||
|
PORT: 4000
|
||||||
|
UPLOAD_DIR: /app/server/uploads
|
||||||
|
ADMIN_EMAIL: chris@chrisedwards.tech
|
||||||
|
ADMIN_PASSWORD: R4e3w2q1
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- /app/server/node_modules
|
||||||
|
- /app/node_modules
|
||||||
|
working_dir: /app
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "4000:4000"
|
||||||
|
- "8080:8080"
|
||||||
|
command: >
|
||||||
|
sh -c "
|
||||||
|
npm install &&
|
||||||
|
cd server && npm install && cd .. &&
|
||||||
|
npm run dev
|
||||||
|
"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
306
index.html
306
index.html
@ -6,7 +6,7 @@
|
|||||||
<title>Toadstool Cottage Counter</title>
|
<title>Toadstool Cottage Counter</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;700&family=Quicksand:wght@400;600;700&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer">
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="assets/icons/appicon-32x32.png">
|
<link rel="icon" type="image/png" sizes="32x32" href="assets/icons/appicon-32x32.png">
|
||||||
<link rel="icon" type="image/png" sizes="128x128" href="assets/icons/appicon-128x128.png">
|
<link rel="icon" type="image/png" sizes="128x128" href="assets/icons/appicon-128x128.png">
|
||||||
@ -23,11 +23,12 @@
|
|||||||
<h1 id="appTitle">Toadstool Cottage Counter</h1>
|
<h1 id="appTitle">Toadstool Cottage Counter</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="header-controls">
|
<div class="header-controls">
|
||||||
|
<button class="sync-banner" id="syncBanner" onclick="openAuthModal()" title="Sign in to sync">Local-only mode</button>
|
||||||
<button class="header-btn hidden" id="installBtn" title="Install app"><i class="fa-solid fa-download"></i></button>
|
<button class="header-btn hidden" id="installBtn" title="Install app"><i class="fa-solid fa-download"></i></button>
|
||||||
<button class="header-btn" id="motionBtn" onclick="toggleAnimations()" title="Toggle Animations"><i class="fa-solid fa-wand-magic-sparkles"></i></button>
|
<button class="header-btn" id="settingsBtn" onclick="openSettingsModal()" title="Settings"><i class="fa-solid fa-gear"></i></button>
|
||||||
<button class="header-btn" id="themeBtn" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa-solid fa-moon"></i></button>
|
|
||||||
<button class="header-btn" id="focusBtn" onclick="toggleFocusMode()" title="Focus Mode (Keeps Screen On)"><i class="fa-solid fa-eye"></i></button>
|
<button class="header-btn" id="focusBtn" onclick="toggleFocusMode()" title="Focus Mode (Keeps Screen On)"><i class="fa-solid fa-eye"></i></button>
|
||||||
<button class="header-btn" id="saveLoadBtn" onclick="openSaveModal()" title="Save/Load"><i class="fa-solid fa-floppy-disk"></i></button>
|
<button class="header-btn" id="saveLoadBtn" onclick="openSaveModal()" title="Save/Load"><i class="fa-solid fa-floppy-disk"></i></button>
|
||||||
|
<button class="header-btn" id="authBtn" onclick="openAuthModal()" title="Sign in to sync"><i class="fa-solid fa-user"></i></button>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<input type="file" id="importFile" accept="application/json" class="hidden-input" />
|
<input type="file" id="importFile" accept="application/json" class="hidden-input" />
|
||||||
@ -35,11 +36,18 @@
|
|||||||
<div class="container" id="app"></div>
|
<div class="container" id="app"></div>
|
||||||
|
|
||||||
<button class="fab" onclick="openModal('addProject')">+</button>
|
<button class="fab" onclick="openModal('addProject')">+</button>
|
||||||
|
<button class="fab fab-pattern" id="patternFab" onclick="openPatternComposer()" title="Open Pattern Composer"><i class="fa-solid fa-swatchbook"></i></button>
|
||||||
|
|
||||||
<div class="modal-overlay" id="modalOverlay">
|
<div class="modal-overlay" id="modalOverlay">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<h3 class="modal-title" id="modalTitle">Title</h3>
|
<h3 class="modal-title" id="modalTitle">Title</h3>
|
||||||
<input type="text" class="modal-input" id="modalInput" autocomplete="off">
|
<input type="text" class="modal-input" id="modalInput" autocomplete="off">
|
||||||
|
<div class="pattern-picker" id="patternPicker">
|
||||||
|
<label for="patternSelect">Pattern (optional)</label>
|
||||||
|
<select id="patternSelect">
|
||||||
|
<option value="">No pattern</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="modal-actions">
|
<div class="modal-actions">
|
||||||
<button class="modal-btn btn-cancel" onclick="closeModal()">Cancel</button>
|
<button class="modal-btn btn-cancel" onclick="closeModal()">Cancel</button>
|
||||||
<button class="modal-btn btn-save" onclick="saveModal()">Save</button>
|
<button class="modal-btn btn-save" onclick="saveModal()">Save</button>
|
||||||
@ -80,7 +88,297 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="assets/app.js"></script>
|
<div class="settings-overlay" id="settingsOverlay">
|
||||||
|
<div class="settings-modal">
|
||||||
|
<div class="settings-head">
|
||||||
|
<h3 class="color-title">Settings</h3>
|
||||||
|
<button class="pattern-close" onclick="closeSettingsModal()">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="settings-body">
|
||||||
|
<label class="settings-toggle">
|
||||||
|
<span>Dark mode</span>
|
||||||
|
<input type="checkbox" id="settingDarkMode" onchange="setDarkMode(this.checked)">
|
||||||
|
</label>
|
||||||
|
<p class="settings-note">Use a darker theme that is easier on the eyes at night.</p>
|
||||||
|
<label class="settings-toggle">
|
||||||
|
<span>Animations</span>
|
||||||
|
<input type="checkbox" id="settingAnimations" onchange="setAnimations(this.checked)">
|
||||||
|
</label>
|
||||||
|
<p class="settings-note">Toggle ambient motion like fireflies and micro-animations.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="auth-overlay" id="authOverlay">
|
||||||
|
<div class="auth-modal">
|
||||||
|
<div class="auth-modal-head">
|
||||||
|
<div>
|
||||||
|
<h3 class="color-title">Account</h3>
|
||||||
|
<p class="auth-subtext">Sign in to sync across devices.</p>
|
||||||
|
</div>
|
||||||
|
<button class="pattern-close" onclick="closeAuthModal()">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="auth-status">
|
||||||
|
<span id="authStatusBadge" class="status-pill">Signed out</span>
|
||||||
|
<span id="authLastSync" class="status-subtext">Status: unknown</span>
|
||||||
|
</div>
|
||||||
|
<div class="auth-tabs">
|
||||||
|
<button class="auth-tab active" data-mode="login" onclick="setAuthMode('login')">Login</button>
|
||||||
|
<button class="auth-tab" data-mode="signup" onclick="setAuthMode('signup')">Sign up</button>
|
||||||
|
<button class="auth-tab" data-mode="reset" onclick="setAuthMode('reset')">Reset</button>
|
||||||
|
<button class="auth-tab" id="profileTabBtn" data-mode="profile" onclick="setAuthMode('profile')" style="display:none;">Profile</button>
|
||||||
|
<button class="auth-tab" id="adminTabBtn" data-mode="admin" onclick="setAuthMode('admin')" style="display:none;">Admin</button>
|
||||||
|
</div>
|
||||||
|
<div class="auth-content">
|
||||||
|
<div id="loginContent" class="auth-tab-content active">
|
||||||
|
<form class="auth-form" onsubmit="return submitAuth(event, 'login')">
|
||||||
|
<label class="field-label" for="loginEmail">Email</label>
|
||||||
|
<input id="loginEmail" type="email" placeholder="you@example.com" autocomplete="email" required>
|
||||||
|
<label class="field-label" for="loginPassword">Password</label>
|
||||||
|
<input id="loginPassword" type="password" placeholder="••••••••" autocomplete="current-password" required>
|
||||||
|
<div class="auth-actions">
|
||||||
|
<button type="button" class="modal-btn btn-secondary" onclick="setAuthMode('reset')">Forgot password?</button>
|
||||||
|
<button type="button" class="modal-btn btn-cancel" onclick="closeAuthModal()">Cancel</button>
|
||||||
|
<button type="submit" class="modal-btn btn-save">Login</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div id="signupContent" class="auth-tab-content">
|
||||||
|
<form class="auth-form" onsubmit="return submitAuth(event, 'signup')">
|
||||||
|
<label class="field-label" for="signupEmail">Email</label>
|
||||||
|
<input id="signupEmail" type="email" placeholder="you@example.com" autocomplete="email" required>
|
||||||
|
<label class="field-label" for="signupPassword">Password</label>
|
||||||
|
<input id="signupPassword" type="password" placeholder="••••••••" autocomplete="new-password" required>
|
||||||
|
<label class="field-label" for="signupConfirmPassword">Confirm Password</label>
|
||||||
|
<input id="signupConfirmPassword" type="password" placeholder="••••••••" autocomplete="new-password" required>
|
||||||
|
<div class="auth-actions">
|
||||||
|
<button type="button" class="modal-btn btn-cancel" onclick="closeAuthModal()">Cancel</button>
|
||||||
|
<button type="submit" class="modal-btn btn-save">Sign Up</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div id="resetContent" class="auth-tab-content">
|
||||||
|
<form class="auth-form" onsubmit="return requestPasswordReset(event)">
|
||||||
|
<label class="field-label" for="resetEmail">Email</label>
|
||||||
|
<input id="resetEmail" type="email" placeholder="you@example.com" autocomplete="email" required>
|
||||||
|
<div class="auth-actions">
|
||||||
|
<button type="button" class="modal-btn btn-cancel" onclick="setAuthMode('login')">Back to login</button>
|
||||||
|
<button type="submit" class="modal-btn btn-save">Send reset</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<hr class="auth-divider">
|
||||||
|
<form id="resetConfirmForm" class="auth-form" onsubmit="return confirmPasswordReset(event)">
|
||||||
|
<label class="field-label" for="resetToken">Reset Token</label>
|
||||||
|
<input id="resetToken" type="text" placeholder="Paste your reset token" autocomplete="one-time-code" required>
|
||||||
|
<label class="field-label" for="resetPassword">New Password</label>
|
||||||
|
<input id="resetPassword" type="password" placeholder="••••••••" autocomplete="new-password" required>
|
||||||
|
<label class="field-label" for="resetConfirmPassword">Confirm New Password</label>
|
||||||
|
<input id="resetConfirmPassword" type="password" placeholder="••••••••" autocomplete="new-password" required>
|
||||||
|
<div class="auth-actions">
|
||||||
|
<button type="submit" class="modal-btn btn-save">Update password</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div id="adminContent" class="auth-tab-content">
|
||||||
|
<div id="adminPanel" class="admin-panel">
|
||||||
|
<h4>Pending Approvals</h4>
|
||||||
|
<div class="admin-actions">
|
||||||
|
<button type="button" class="modal-btn btn-secondary" onclick="fetchPendingUsers()">Refresh Pending</button>
|
||||||
|
</div>
|
||||||
|
<div id="pendingList" class="admin-list"></div>
|
||||||
|
|
||||||
|
<h4 style="margin-top:16px;">User Management</h4>
|
||||||
|
<div class="admin-actions">
|
||||||
|
<button type="button" class="modal-btn btn-secondary" onclick="fetchAllUsers()">Load All Users</button>
|
||||||
|
</div>
|
||||||
|
<div id="allUsersList" class="admin-list"></div>
|
||||||
|
|
||||||
|
<h4 style="margin-top:16px;">System Data</h4>
|
||||||
|
<div class="admin-actions">
|
||||||
|
<button type="button" class="modal-btn btn-secondary" onclick="downloadBackup()">Backup Data</button>
|
||||||
|
<label class="modal-btn btn-secondary">
|
||||||
|
Restore
|
||||||
|
<input type="file" id="restoreInput" accept="application/json,application/sql,.sql" style="display:none;" onchange="uploadRestore(event)">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form class="auth-profile" onsubmit="return saveProfile(event)">
|
||||||
|
<h4 class="auth-section-title">Profile Settings</h4>
|
||||||
|
|
||||||
|
<div class="auth-profile-body">
|
||||||
|
<label class="field-label" for="authDisplayName">Display Name</label>
|
||||||
|
<input id="authDisplayName" type="text" placeholder="Your name">
|
||||||
|
|
||||||
|
<label class="field-label" for="authNote">Profile Note</label>
|
||||||
|
<textarea id="authNote" rows="2" placeholder="Add a note for your patterns..."></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="auth-sync-section">
|
||||||
|
<p class="auth-hint">Sync your projects to the cloud to access them anywhere.</p>
|
||||||
|
<button type="button" class="modal-btn btn-secondary" onclick="autoSync()"><i class="fa-solid fa-rotate"></i> Sync Now</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="auth-actions modal-footer">
|
||||||
|
<button type="button" class="modal-btn btn-cancel danger-text" onclick="logoutAuth()">Log Out</button>
|
||||||
|
<button type="submit" class="modal-btn btn-save">Save Changes</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pattern-overlay" id="patternOverlay">
|
||||||
|
<div class="pattern-sheet">
|
||||||
|
<div class="pattern-sheet-header">
|
||||||
|
<div class="header-main">
|
||||||
|
<h2 class="pattern-sheet-title">Pattern Composer</h2>
|
||||||
|
<div class="pattern-modes">
|
||||||
|
<button class="pattern-mode" data-mode="crochet" onclick="setPatternMode('crochet')">Crochet</button>
|
||||||
|
<button class="pattern-mode" data-mode="knit" onclick="setPatternMode('knit')">Knit</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<span class="pattern-save-indicator" id="patternSaveIndicator">Saved</span>
|
||||||
|
<button class="icon-action" onclick="savePatternDraft()" title="Save to Basket"><i class="fa-solid fa-bookmark"></i></button>
|
||||||
|
<button class="icon-action" onclick="savePatternAndStartProject()" title="Save & Start Project"><i class="fa-solid fa-play"></i></button>
|
||||||
|
<button class="icon-action" onclick="exportPatternPDF()" title="Export PDF"><i class="fa-solid fa-file-pdf"></i></button>
|
||||||
|
<button class="icon-action" onclick="sharePattern()" title="Share Link"><i class="fa-solid fa-link"></i></button>
|
||||||
|
<button class="icon-action danger" onclick="clearPatternOutput()" title="Clear Draft"><i class="fa-solid fa-eraser"></i></button>
|
||||||
|
<button class="pattern-close" onclick="closePatternComposer()">×</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pattern-nav">
|
||||||
|
<button class="nav-item active" data-tab="info" onclick="showPatternTab('info')">Specs</button>
|
||||||
|
<button class="nav-item" data-tab="steps" onclick="showPatternTab('steps')">Draft</button>
|
||||||
|
<button class="nav-item" data-tab="view" onclick="showPatternTab('view')">Read</button>
|
||||||
|
<button class="nav-item" data-tab="library" onclick="showPatternTab('library')">Shelf</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pattern-body">
|
||||||
|
<div class="pattern-section active" data-section="info">
|
||||||
|
<div class="card-grid">
|
||||||
|
<div class="input-card">
|
||||||
|
<h4 class="card-head">Basic Details</h4>
|
||||||
|
<div class="form-row">
|
||||||
|
<label class="field-label" for="patternTitle">Title</label>
|
||||||
|
<input id="patternTitle" type="text" placeholder="e.g., Baby Fox Plush">
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label class="field-label" for="patternDesigner">Designer</label>
|
||||||
|
<input id="patternDesigner" type="text" placeholder="Your name or shop">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-card">
|
||||||
|
<h4 class="card-head">Yarn & Tools</h4>
|
||||||
|
<label class="field-label">Yarns</label>
|
||||||
|
<div id="yarnList" class="yarn-list-container">
|
||||||
|
<!-- Populated by JS -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label class="field-label" style="margin-top: 10px;">Hooks / Needles</label>
|
||||||
|
<div id="hookList" class="hook-list-container">
|
||||||
|
<!-- Populated by JS -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field-group-inline" style="margin-top: 10px;">
|
||||||
|
<div>
|
||||||
|
<label class="field-label" for="patternGaugeSts">Sts / 4in</label>
|
||||||
|
<input id="patternGaugeSts" type="text" placeholder="e.g., 16 sc">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="field-label" for="patternGaugeRows">Rows / 4in</label>
|
||||||
|
<input id="patternGaugeRows" type="text" placeholder="e.g., 18 rows">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label class="field-label" for="patternGauge">Gauge Notes</label>
|
||||||
|
<textarea id="patternGauge" rows="2" placeholder="Magic ring start; or any extra gauge notes"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-card full-width">
|
||||||
|
<h4 class="card-head">Materials & Notes</h4>
|
||||||
|
<label class="field-label" for="patternMaterials">Materials (one per line)</label>
|
||||||
|
<textarea id="patternMaterials" rows="3" placeholder="• 1 skein Worsted Weight Yarn (Main Color) • 4.0mm Hook • Tapestry Needle • Polyester Fiberfill"></textarea>
|
||||||
|
|
||||||
|
<label class="field-label" for="patternNotes">Notes / Finishing</label>
|
||||||
|
<textarea id="patternNotes" rows="2" placeholder="Assembly, finishing, safety warnings, credits..."></textarea>
|
||||||
|
|
||||||
|
<label class="field-label" style="margin-top: 10px;">Finished Photos</label>
|
||||||
|
<div id="finishedPhotoList" class="finished-photo-list"></div>
|
||||||
|
<button class="secondary small" type="button" onclick="addFinishedPhoto()">Add Photo</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-card full-width">
|
||||||
|
<div class="abbrev-head">
|
||||||
|
<h4 class="card-head" style="margin:0;">Abbreviations</h4>
|
||||||
|
<button class="secondary small" onclick="openAbbrevModal()">Edit / Add</button>
|
||||||
|
</div>
|
||||||
|
<div id="abbrevSummary" class="selected-abbrev">
|
||||||
|
<!-- Selected pills will appear here -->
|
||||||
|
<span class="text-muted" style="font-size: 0.9rem;">No stitches selected.</span>
|
||||||
|
</div>
|
||||||
|
<textarea id="patternAbbrev" rows="3" placeholder="Selected abbreviations will appear here..." readonly></textarea>
|
||||||
|
<label class="field-label" for="patternStitches">Special Stitches / Notes</label>
|
||||||
|
<textarea id="patternStitches" rows="2" placeholder="Magic ring: ... Invisible decrease: ..."></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="pattern-footer-actions">
|
||||||
|
<button class="secondary" onclick="importPatternJSON()">Import JSON</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pattern-section" data-section="steps">
|
||||||
|
<div class="pattern-steps-head">
|
||||||
|
<div>
|
||||||
|
<h4>Pattern Steps</h4>
|
||||||
|
<p class="muted small">Build steps and rows in order. Collapse steps to stay focused.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="patternSteps"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pattern-section" data-section="library">
|
||||||
|
<div class="pattern-steps-head">
|
||||||
|
<div>
|
||||||
|
<h4>Saved Patterns</h4>
|
||||||
|
<p class="muted small">Search, load, or start a project.</p>
|
||||||
|
</div>
|
||||||
|
<button class="primary" onclick="savePatternDraft()">Save Current Draft</button>
|
||||||
|
</div>
|
||||||
|
<div class="pattern-library-controls">
|
||||||
|
<input id="patternSearch" type="text" placeholder="Search patterns..." oninput="renderPatternLibrary()">
|
||||||
|
<select id="patternSort" onchange="renderPatternLibrary()">
|
||||||
|
<option value="recent">Most recent</option>
|
||||||
|
<option value="name">Name A–Z</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div id="patternLibrary" class="pattern-library"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pattern-section" data-section="view">
|
||||||
|
<div id="patternView" class="pattern-view"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-overlay" id="abbrevModal">
|
||||||
|
<div class="modal-content" style="width: min(800px, 94vw); max-height: 85vh; display: flex; flex-direction: column;">
|
||||||
|
<h3 class="modal-title">Select Abbreviations</h3>
|
||||||
|
<div class="abbrev-controls" style="margin-bottom: 12px;">
|
||||||
|
<input type="text" id="abbrevSearch" placeholder="Search stitches..." oninput="filterAbbrev()">
|
||||||
|
<button class="secondary small" onclick="loadDefaultAbbrev()">Reset to Defaults</button>
|
||||||
|
</div>
|
||||||
|
<div id="patternAbbrevList" class="abbrev-grid" style="overflow-y: auto; flex: 1;"></div>
|
||||||
|
<div class="modal-actions" style="margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px;">
|
||||||
|
<button class="modal-btn btn-save" onclick="closeAbbrevModal()">Done</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="assets/app.js?v=3"></script>
|
||||||
<footer class="footer-bg" aria-hidden="true"></footer>
|
<footer class="footer-bg" aria-hidden="true"></footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
15
live-server.js
Normal file
15
live-server.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
var liveServer = require("live-server");
|
||||||
|
|
||||||
|
var params = {
|
||||||
|
port: 8080,
|
||||||
|
host: "0.0.0.0",
|
||||||
|
ignore: 'db_data,server/uploads',
|
||||||
|
file: "index.html",
|
||||||
|
wait: 500,
|
||||||
|
proxy: [
|
||||||
|
['/api', 'http://127.0.0.1:4000/api'],
|
||||||
|
['/uploads', 'http://127.0.0.1:4000/uploads']
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
liveServer.start(params);
|
||||||
2726
package-lock.json
generated
Normal file
2726
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
package.json
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "toadstooltally",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "PWA-friendly, cottagecore row counter for crochet/knitting projects. Manage projects and parts, set max stitches, lock/finish, and enjoy a themed experience with install support and offline caching.",
|
||||||
|
"main": "sw.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"dev-frontend": "node live-server.js",
|
||||||
|
"dev": "cd server && npm install && cd .. && concurrently \"npm:dev-frontend\" \"cd server && npm run dev\""
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"concurrently": "^9.2.1",
|
||||||
|
"live-server": "^1.2.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
307
pattern-viewer.html
Normal file
307
pattern-viewer.html
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Pattern Viewer</title>
|
||||||
|
<link rel="stylesheet" href="assets/style.css">
|
||||||
|
<style>
|
||||||
|
body { background: var(--bg); color: var(--text); padding: 16px; }
|
||||||
|
.viewer { max-width: 720px; margin: 0 auto; padding: 16px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 24px rgba(0,0,0,0.1); }
|
||||||
|
.viewer h1 { margin: 0 0 6px; color: var(--project-color); }
|
||||||
|
.viewer h3 { margin: 12px 0 6px; }
|
||||||
|
.viewer pre { white-space: pre-wrap; background: var(--input-bg); padding: 10px; border-radius: 10px; border: 1px solid var(--border); }
|
||||||
|
.step-list { display: grid; gap: 12px; margin: 12px 0; }
|
||||||
|
.step-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--card-bg); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
|
||||||
|
.step-card.collapsed .step-body { display: none; }
|
||||||
|
.step-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: pointer; }
|
||||||
|
.step-title .title { font-weight: 700; }
|
||||||
|
.step-title .caret { color: var(--text-muted); transition: transform 0.2s ease; }
|
||||||
|
.step-card.collapsed .step-title .caret { transform: rotate(-90deg); }
|
||||||
|
.step-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
|
||||||
|
.step-title input { margin-right: 8px; }
|
||||||
|
.step-rows { margin-top: 8px; display: grid; gap: 6px; }
|
||||||
|
.step-row { cursor: pointer; }
|
||||||
|
.step-row.is-done { text-decoration: line-through; color: var(--text-muted); }
|
||||||
|
.step-title-bar {
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--card-bg);
|
||||||
|
background: var(--project-color);
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.step-media { margin-top: 8px; }
|
||||||
|
.step-media img { max-width: 260px; max-height: 260px; width: auto; height: auto; border-radius: 10px; border: 1px solid var(--border); display: block; cursor: zoom-in; }
|
||||||
|
.note-box { width: 100%; min-height: 80px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); padding: 8px; }
|
||||||
|
.meta { display: grid; gap: 6px; margin: 10px 0; font-size: 0.95rem; }
|
||||||
|
.pill { display: inline-block; padding: 4px 8px; border-radius: 999px; background: var(--input-bg); border: 1px solid var(--border); font-size: 0.85rem; margin-right: 6px; margin-bottom: 4px; }
|
||||||
|
.top-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
||||||
|
.back-link { text-decoration: none; color: var(--text); font-weight: 700; }
|
||||||
|
.back-link:hover { color: var(--project-color); }
|
||||||
|
.list { margin: 0; padding-left: 18px; }
|
||||||
|
.list li { margin-bottom: 4px; }
|
||||||
|
.color-swatch { display: inline-flex; align-items: center; gap: 6px; }
|
||||||
|
.swatch-dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border); display: inline-block; }
|
||||||
|
.image-preview-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(44, 35, 25, 0.7);
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 400;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
.image-preview-overlay.active { display: flex; }
|
||||||
|
.image-preview-dialog {
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
padding: 12px;
|
||||||
|
max-width: min(920px, 92vw);
|
||||||
|
max-height: 90vh;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.image-preview-img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: calc(90vh - 40px);
|
||||||
|
display: block;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
.image-preview-close {
|
||||||
|
position: absolute;
|
||||||
|
top: 6px;
|
||||||
|
right: 8px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
font-size: 1.6rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.image-preview-close:hover { color: var(--text); }
|
||||||
|
.viewer-photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
|
||||||
|
.viewer-photo { max-width: 100%; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; }
|
||||||
|
@media (max-width: 600px) { .viewer { padding: 12px; } }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="viewer">
|
||||||
|
<div class="top-actions">
|
||||||
|
<a class="back-link" href="./">← Back to app</a>
|
||||||
|
<span id="viewerStatus" class="pill">Progress saved locally</span>
|
||||||
|
</div>
|
||||||
|
<h1 id="pvTitle">Pattern</h1>
|
||||||
|
<div id="pvDesigner" class="meta"></div>
|
||||||
|
<div id="pvGauge" class="meta"></div>
|
||||||
|
<div id="pvMaterials"></div>
|
||||||
|
<div id="pvTools"></div>
|
||||||
|
<div id="pvPalette"></div>
|
||||||
|
<div id="pvFinishedPhotos"></div>
|
||||||
|
<div id="pvAbbrev"></div>
|
||||||
|
<div id="pvStitches"></div>
|
||||||
|
<div id="pvRows"></div>
|
||||||
|
<h3>Steps</h3>
|
||||||
|
<div id="pvSteps" class="step-list"></div>
|
||||||
|
<h3>Notes</h3>
|
||||||
|
<textarea id="pvNotes" class="note-box" placeholder="Your notes..." aria-label="Notes"></textarea>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
const data = params.get('data');
|
||||||
|
const token = params.get('token');
|
||||||
|
let patternDraft = null;
|
||||||
|
function renderError(message) {
|
||||||
|
document.body.innerHTML = `<div style="padding:20px;">Failed to load pattern: ${message}</div>`;
|
||||||
|
}
|
||||||
|
function resolveImageUrl(url) {
|
||||||
|
if (!url) return '';
|
||||||
|
if (/^https?:\/\//i.test(url) || url.startsWith('data:')) return url;
|
||||||
|
if (url.startsWith('/uploads/')) {
|
||||||
|
return `${window.location.origin}${url}`;
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openImagePreview(url) {
|
||||||
|
if (!url) return;
|
||||||
|
let overlay = document.getElementById('imagePreviewOverlay');
|
||||||
|
if (!overlay) {
|
||||||
|
overlay = document.createElement('div');
|
||||||
|
overlay.id = 'imagePreviewOverlay';
|
||||||
|
overlay.className = 'image-preview-overlay';
|
||||||
|
overlay.innerHTML = `
|
||||||
|
<div class="image-preview-dialog">
|
||||||
|
<button class="image-preview-close" type="button" aria-label="Close preview">×</button>
|
||||||
|
<img class="image-preview-img" alt="Preview">
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
document.body.appendChild(overlay);
|
||||||
|
overlay.addEventListener('click', (e) => {
|
||||||
|
if (e.target === overlay) overlay.classList.remove('active');
|
||||||
|
});
|
||||||
|
overlay.querySelector('.image-preview-close').addEventListener('click', () => {
|
||||||
|
overlay.classList.remove('active');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const img = overlay.querySelector('.image-preview-img');
|
||||||
|
if (img) img.src = url;
|
||||||
|
overlay.classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPattern() {
|
||||||
|
try {
|
||||||
|
if (data) {
|
||||||
|
const json = decodeURIComponent(escape(atob(data)));
|
||||||
|
const parsed = JSON.parse(json);
|
||||||
|
if (!parsed.patternDraft) throw new Error('Invalid payload');
|
||||||
|
return parsed.patternDraft;
|
||||||
|
}
|
||||||
|
if (token) {
|
||||||
|
const resp = await fetch(`/share/${encodeURIComponent(token)}`);
|
||||||
|
const payload = await resp.json();
|
||||||
|
if (!resp.ok) throw new Error(payload.error || 'Share link invalid');
|
||||||
|
const serverData = payload.pattern?.data?.draft || payload.pattern?.data;
|
||||||
|
if (!serverData) throw new Error('Missing pattern data');
|
||||||
|
return serverData;
|
||||||
|
}
|
||||||
|
throw new Error('Missing pattern data');
|
||||||
|
} catch (e) {
|
||||||
|
renderError(e.message);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let progress = {};
|
||||||
|
let storageKey = '';
|
||||||
|
function saveProgress() {
|
||||||
|
localStorage.setItem(storageKey, JSON.stringify(progress));
|
||||||
|
}
|
||||||
|
const weightLabels = new Map([
|
||||||
|
['0', 'Lace (0)'],
|
||||||
|
['1', 'Super Fine (1)'],
|
||||||
|
['2', 'Fine (2)'],
|
||||||
|
['3', 'Light (3)'],
|
||||||
|
['4', 'Medium (4)'],
|
||||||
|
['5', 'Bulky (5)'],
|
||||||
|
['6', 'Super Bulky (6)'],
|
||||||
|
['7', 'Jumbo (7)']
|
||||||
|
]);
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
document.getElementById('pvTitle').textContent = patternDraft.meta?.title || 'Pattern';
|
||||||
|
document.getElementById('pvDesigner').textContent = patternDraft.meta?.designer || '';
|
||||||
|
const gaugeBlock = [
|
||||||
|
patternDraft.gaugeSts || '',
|
||||||
|
patternDraft.gaugeRows ? ' - ' + patternDraft.gaugeRows : '',
|
||||||
|
patternDraft.gaugeHook ? ' - ' + patternDraft.gaugeHook : ''
|
||||||
|
].filter(Boolean).join('');
|
||||||
|
document.getElementById('pvGauge').innerHTML = gaugeBlock || patternDraft.size
|
||||||
|
? `<div><strong>Gauge / Size:</strong> ${[gaugeBlock, patternDraft.gauge || '', patternDraft.size || ''].filter(Boolean).join(' | ')}</div>`
|
||||||
|
: '';
|
||||||
|
const mats = patternDraft.materials || '';
|
||||||
|
document.getElementById('pvMaterials').innerHTML = mats ? `<h3>Materials</h3><pre>${mats}</pre>` : '';
|
||||||
|
const yarns = (patternDraft.yarns || []).map(y => {
|
||||||
|
const weightKey = y.weight !== undefined && y.weight !== null ? String(y.weight) : '';
|
||||||
|
const weightLabel = weightLabels.get(weightKey) || (weightKey ? `Weight ${weightKey}` : '');
|
||||||
|
const label = `${y.note || 'Yarn'}${weightLabel ? `: ${weightLabel}` : ''}`.trim();
|
||||||
|
return `<li>${label}${y.color ? ` <span class="color-swatch"><span class="swatch-dot" style="background:${y.color}"></span></span>` : ''}</li>`;
|
||||||
|
}).join('');
|
||||||
|
const hooks = (patternDraft.hooks || []).map(h => `<li>${h.size || ''}${h.note ? ` (${h.note})` : ''}</li>`).join('');
|
||||||
|
document.getElementById('pvTools').innerHTML = (yarns || hooks)
|
||||||
|
? `<h3>Yarns & Hooks</h3>${yarns ? `<ul class="list">${yarns}</ul>` : ''}${hooks ? `<p><strong>Hooks:</strong></p><ul class="list">${hooks}</ul>` : ''}`
|
||||||
|
: '';
|
||||||
|
const palette = (patternDraft.palette || []).map(c => `<li class="color-swatch"><span class="swatch-dot" style="background:${c}"></span></li>`).join('');
|
||||||
|
document.getElementById('pvPalette').innerHTML = palette ? `<h3>Palette</h3><ul class="list">${palette}</ul>` : '';
|
||||||
|
const finishedPhotos = (patternDraft.finishedPhotos || []).map(p => {
|
||||||
|
const url = resolveImageUrl(p.url);
|
||||||
|
return `<img class="viewer-photo" src="${url}" alt="Finished photo" onclick="openImagePreview('${url}')">`;
|
||||||
|
}).join('');
|
||||||
|
document.getElementById('pvFinishedPhotos').innerHTML = finishedPhotos ? `<h3>Finished Photos</h3><div class="viewer-photo-grid">${finishedPhotos}</div>` : '';
|
||||||
|
const customMap = new Map((patternDraft.customAbbrev || []).map(item => [item.code, item.desc]));
|
||||||
|
const selected = (patternDraft.abbrevSelection || []).map(code => {
|
||||||
|
const desc = customMap.get(code) || '';
|
||||||
|
return desc ? `<li>${code} - ${desc}</li>` : `<li>${code}</li>`;
|
||||||
|
}).join('');
|
||||||
|
const abbrevText = (patternDraft.abbrev || '').trim();
|
||||||
|
document.getElementById('pvAbbrev').innerHTML = abbrevText || selected
|
||||||
|
? `<h3>Abbreviations</h3>${abbrevText ? `<pre>${abbrevText}</pre>` : `<ul class="list">${selected}</ul>`}`
|
||||||
|
: '';
|
||||||
|
const stitches = (patternDraft.stitches || '').trim();
|
||||||
|
document.getElementById('pvStitches').innerHTML = stitches ? `<h3>Stitch Guide</h3><pre>${stitches}</pre>` : '';
|
||||||
|
const rowsOutput = (patternDraft.output || '').trim();
|
||||||
|
document.getElementById('pvRows').innerHTML = rowsOutput ? `<h3>Rows</h3><pre>${rowsOutput}</pre>` : '';
|
||||||
|
const stepsEl = document.getElementById('pvSteps');
|
||||||
|
stepsEl.innerHTML = '';
|
||||||
|
(patternDraft.steps || []).forEach((step, idx) => {
|
||||||
|
const card = document.createElement('div');
|
||||||
|
const isCollapsed = progress[idx]?.collapsed;
|
||||||
|
card.className = `step-card ${isCollapsed ? 'collapsed' : ''}`;
|
||||||
|
const rows = (step.rows || []).map((r,i) => {
|
||||||
|
const done = progress[idx]?.rows?.[i];
|
||||||
|
return `<div class="step-row ${done ? 'is-done' : ''}" data-step="${idx}" data-row="${i}">Row ${i+1}: ${r}</div>`;
|
||||||
|
}).join('');
|
||||||
|
const note = step.note ? `<p><strong>Step Note:</strong> ${step.note}</p>` : '';
|
||||||
|
const imgUrl = resolveImageUrl(step.image);
|
||||||
|
const img = step.image ? `<div class="step-media"><img src="${imgUrl}" alt="Step ${idx + 1} image" onclick="openImagePreview('${imgUrl}')"></div>` : '';
|
||||||
|
card.innerHTML = `
|
||||||
|
<div class="step-title" data-step="${idx}">
|
||||||
|
<div class="title">Step ${idx+1}${step.title ? ` – ${step.title}` : ''}</div>
|
||||||
|
<div class="caret">▾</div>
|
||||||
|
</div>
|
||||||
|
<div class="step-body">
|
||||||
|
<div class="step-title-bar">${step.title || `Step ${idx + 1}`}</div>
|
||||||
|
<div class="step-rows">${rows || '<em>No rows yet.</em>'}</div>
|
||||||
|
${note}
|
||||||
|
${img}
|
||||||
|
<div style="margin-top:6px;">
|
||||||
|
<label>Notes</label>
|
||||||
|
<textarea data-step="${idx}" class="note-box" placeholder="Notes for this step...">${progress[idx]?.note || ''}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
stepsEl.appendChild(card);
|
||||||
|
});
|
||||||
|
const pvNotes = document.getElementById('pvNotes');
|
||||||
|
pvNotes.value = progress.globalNote || '';
|
||||||
|
}
|
||||||
|
document.addEventListener('click', (e) => {
|
||||||
|
if (e.target.matches('.step-title')) {
|
||||||
|
const s = Number(e.target.dataset.step);
|
||||||
|
progress[s] = progress[s] || { rows: {} };
|
||||||
|
progress[s].collapsed = !progress[s].collapsed;
|
||||||
|
saveProgress();
|
||||||
|
const card = e.target.closest('.step-card');
|
||||||
|
if (card) card.classList.toggle('collapsed', progress[s].collapsed);
|
||||||
|
}
|
||||||
|
if (e.target.matches('.step-row')) {
|
||||||
|
const s = Number(e.target.dataset.step);
|
||||||
|
const r = Number(e.target.dataset.row);
|
||||||
|
progress[s] = progress[s] || { rows: {} };
|
||||||
|
progress[s].rows = progress[s].rows || {};
|
||||||
|
progress[s].rows[r] = !progress[s].rows[r];
|
||||||
|
saveProgress();
|
||||||
|
e.target.classList.toggle('is-done', progress[s].rows[r]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.addEventListener('input', (e) => {
|
||||||
|
if (e.target.matches('textarea[data-step]')) {
|
||||||
|
const s = Number(e.target.dataset.step);
|
||||||
|
progress[s] = progress[s] || { rows: {} };
|
||||||
|
progress[s].note = e.target.value;
|
||||||
|
saveProgress();
|
||||||
|
}
|
||||||
|
if (e.target.id === 'pvNotes') {
|
||||||
|
progress.globalNote = e.target.value;
|
||||||
|
saveProgress();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
(async function init() {
|
||||||
|
patternDraft = await loadPattern();
|
||||||
|
storageKey = `pattern-viewer-${patternDraft.meta?.title || 'pattern'}`;
|
||||||
|
progress = JSON.parse(localStorage.getItem(storageKey) || '{}');
|
||||||
|
render();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
4
server/.env.example
Normal file
4
server/.env.example
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
DATABASE_URL=postgres://user:pass@localhost:5432/toadstool
|
||||||
|
JWT_SECRET=change-me
|
||||||
|
PORT=4000
|
||||||
|
UPLOAD_DIR=./uploads
|
||||||
3276
server/package-lock.json
generated
Normal file
3276
server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
server/package.json
Normal file
26
server/package.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"name": "toadstooltally-backend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Backend API for Toadstool Cottage Counter (auth demo + sync endpoints).",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node src/index.js",
|
||||||
|
"dev": "nodemon src/index.js",
|
||||||
|
"lint": "eslint ."
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"multer": "^1.4.5-lts.1",
|
||||||
|
"sharp": "^0.33.3",
|
||||||
|
"pg": "^8.12.0",
|
||||||
|
"uuid": "^9.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "^8.57.0",
|
||||||
|
"nodemon": "^3.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
}
|
||||||
336
server/src/db.js
Normal file
336
server/src/db.js
Normal file
@ -0,0 +1,336 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
connectionString: process.env.DATABASE_URL,
|
||||||
|
ssl: process.env.DATABASE_URL?.includes('sslmode=require') ? { rejectUnauthorized: false } : false
|
||||||
|
});
|
||||||
|
|
||||||
|
async function initDb(retries = 10) {
|
||||||
|
let attempt = 0;
|
||||||
|
while (attempt < retries) {
|
||||||
|
try {
|
||||||
|
await pool.query(`
|
||||||
|
create table if not exists users (
|
||||||
|
id uuid primary key,
|
||||||
|
email text unique not null,
|
||||||
|
password_hash text not null,
|
||||||
|
display_name text default '',
|
||||||
|
note text default '',
|
||||||
|
created_at timestamptz not null default now(),
|
||||||
|
updated_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
await pool.query(`alter table users add column if not exists is_admin boolean not null default false`);
|
||||||
|
await pool.query(`alter table users add column if not exists status text not null default 'pending'`);
|
||||||
|
await pool.query(`create index if not exists users_email_lower_idx on users (lower(email))`);
|
||||||
|
await pool.query(`
|
||||||
|
create table if not exists sessions (
|
||||||
|
token uuid primary key,
|
||||||
|
user_id uuid references users(id) on delete cascade,
|
||||||
|
created_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
await pool.query(`
|
||||||
|
create table if not exists projects (
|
||||||
|
id text primary key,
|
||||||
|
user_id uuid references users(id) on delete cascade,
|
||||||
|
data jsonb not null,
|
||||||
|
updated_at timestamptz not null default now(),
|
||||||
|
deleted_at timestamptz
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
await pool.query(`
|
||||||
|
create table if not exists patterns (
|
||||||
|
id text primary key,
|
||||||
|
user_id uuid references users(id) on delete cascade,
|
||||||
|
data jsonb not null,
|
||||||
|
updated_at timestamptz not null default now(),
|
||||||
|
deleted_at timestamptz
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
// Migrate legacy UUID columns to text to allow non-UUID ids
|
||||||
|
await pool.query(`drop table if exists pattern_shares cascade`);
|
||||||
|
await pool.query(`alter table if exists projects alter column id type text using id::text`);
|
||||||
|
await pool.query(`alter table if exists patterns alter column id type text using id::text`);
|
||||||
|
await pool.query(`alter table patterns add column if not exists title text not null default ''`);
|
||||||
|
await pool.query(`alter table patterns add column if not exists slug text`);
|
||||||
|
await pool.query(`create unique index if not exists patterns_user_slug_idx on patterns(user_id, slug) where slug is not null`);
|
||||||
|
await pool.query(`
|
||||||
|
create table if not exists pattern_shares (
|
||||||
|
id uuid primary key,
|
||||||
|
pattern_id text,
|
||||||
|
token text unique not null,
|
||||||
|
is_public boolean default true,
|
||||||
|
expires_at timestamptz,
|
||||||
|
created_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
await pool.query(`
|
||||||
|
create table if not exists password_resets (
|
||||||
|
token uuid primary key,
|
||||||
|
user_id uuid references users(id) on delete cascade,
|
||||||
|
expires_at timestamptz not null,
|
||||||
|
created_at timestamptz not null default now()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
// Backfill existing users to active and non-admin
|
||||||
|
await pool.query(`update users set status='active' where status is null or status=''`);
|
||||||
|
return;
|
||||||
|
} catch (err) {
|
||||||
|
attempt += 1;
|
||||||
|
if (attempt >= retries) throw err;
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`DB not ready, retrying (${attempt}/${retries})...`);
|
||||||
|
await new Promise(r => setTimeout(r, 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeEmail(email) {
|
||||||
|
return String(email || '').trim().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function withClient(fn) {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
return await fn(client);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hashPassword(pw) {
|
||||||
|
return crypto.createHash('sha256').update(pw).digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createUser(email, password) {
|
||||||
|
const normalizedEmail = normalizeEmail(email);
|
||||||
|
const id = crypto.randomUUID();
|
||||||
|
const password_hash = hashPassword(password);
|
||||||
|
const existing = await pool.query(
|
||||||
|
`select id, email, display_name, note, is_admin, status from users where lower(email)=$1`,
|
||||||
|
[normalizedEmail]
|
||||||
|
);
|
||||||
|
if (existing.rows.length) {
|
||||||
|
return { existing: true, ...existing.rows[0] };
|
||||||
|
}
|
||||||
|
const countRes = await pool.query(`select count(*)::int as c from users`);
|
||||||
|
const isFirst = countRes.rows[0].c === 0;
|
||||||
|
await pool.query(
|
||||||
|
`insert into users (id, email, password_hash, status, is_admin) values ($1, $2, $3, $4, $5)
|
||||||
|
on conflict (email) do nothing`,
|
||||||
|
[id, normalizedEmail, password_hash, isFirst ? 'active' : 'pending', isFirst]
|
||||||
|
);
|
||||||
|
const row = await pool.query(
|
||||||
|
`select id, email, display_name, note, is_admin, status from users where lower(email)=$1`,
|
||||||
|
[normalizedEmail]
|
||||||
|
);
|
||||||
|
return { existing: false, ...row.rows[0] };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function verifyUser(email, password) {
|
||||||
|
const normalizedEmail = normalizeEmail(email);
|
||||||
|
const row = await pool.query(`select * from users where lower(email)=$1`, [normalizedEmail]);
|
||||||
|
if (!row.rows.length) return null;
|
||||||
|
const user = row.rows[0];
|
||||||
|
if (user.password_hash !== hashPassword(password)) return null;
|
||||||
|
if (user.status !== 'active') {
|
||||||
|
return { pending: true, status: user.status };
|
||||||
|
}
|
||||||
|
return { id: user.id, email: user.email, display_name: user.display_name, note: user.note, is_admin: user.is_admin };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createSession(userId) {
|
||||||
|
const token = crypto.randomUUID();
|
||||||
|
await pool.query(`insert into sessions (token, user_id) values ($1, $2)`, [token, userId]);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getSession(token) {
|
||||||
|
const row = await pool.query(
|
||||||
|
`select s.token, u.id as user_id, u.email, u.is_admin, u.status from sessions s join users u on u.id=s.user_id where s.token=$1`,
|
||||||
|
[token]
|
||||||
|
);
|
||||||
|
return row.rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteSession(token) {
|
||||||
|
await pool.query(`delete from sessions where token=$1`, [token]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function upsertProfile(userId, displayName, note) {
|
||||||
|
await pool.query(
|
||||||
|
`update users set display_name=$2, note=$3, updated_at=now() where id=$1`,
|
||||||
|
[userId, displayName, note]
|
||||||
|
);
|
||||||
|
const row = await pool.query(`select email, display_name, note from users where id=$1`, [userId]);
|
||||||
|
return row.rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getProfile(userId) {
|
||||||
|
const row = await pool.query(`select email, display_name, note, is_admin, status from users where id=$1`, [userId]);
|
||||||
|
return row.rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getUserByEmail(email) {
|
||||||
|
const normalizedEmail = normalizeEmail(email);
|
||||||
|
const res = await pool.query(
|
||||||
|
`select id, email, display_name, note, is_admin, status from users where lower(email)=$1`,
|
||||||
|
[normalizedEmail]
|
||||||
|
);
|
||||||
|
return res.rows[0] || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function upsertItems(table, userId, items = []) {
|
||||||
|
if (!items.length) return;
|
||||||
|
if (table === 'patterns') {
|
||||||
|
for (const item of items) {
|
||||||
|
const title = item.title || '';
|
||||||
|
const slug = item.slug || null;
|
||||||
|
const deleted = item.deleted_at || null;
|
||||||
|
await pool.query(
|
||||||
|
`insert into patterns (id, user_id, title, slug, data, updated_at, deleted_at)
|
||||||
|
values ($1, $2, $3, $4, $5, now(), $6)
|
||||||
|
on conflict (id) do update set title=excluded.title, slug=excluded.slug, data=excluded.data, updated_at=now(), deleted_at=excluded.deleted_at`,
|
||||||
|
[item.id, userId, title, slug, item.data || {}, deleted]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const item of items) {
|
||||||
|
const deleted = item.deleted_at || null;
|
||||||
|
await pool.query(
|
||||||
|
`insert into projects (id, user_id, data, updated_at, deleted_at)
|
||||||
|
values ($1, $2, $3, now(), $4)
|
||||||
|
on conflict (id) do update set data=excluded.data, updated_at=now(), deleted_at=excluded.deleted_at`,
|
||||||
|
[item.id, userId, item.data || {}, deleted]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchItemsSince(table, userId, since) {
|
||||||
|
if (table === 'patterns') {
|
||||||
|
const res = await pool.query(
|
||||||
|
`select id, title, slug, data, updated_at, deleted_at from patterns
|
||||||
|
where user_id=$1 and updated_at >= coalesce($2::timestamptz, 'epoch'::timestamptz)
|
||||||
|
order by updated_at asc`,
|
||||||
|
[userId, since || null]
|
||||||
|
);
|
||||||
|
return res.rows;
|
||||||
|
}
|
||||||
|
const res = await pool.query(
|
||||||
|
`select id, data, updated_at, deleted_at from projects
|
||||||
|
where user_id=$1 and updated_at >= coalesce($2::timestamptz, 'epoch'::timestamptz)
|
||||||
|
order by updated_at asc`,
|
||||||
|
[userId, since || null]
|
||||||
|
);
|
||||||
|
return res.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createShare(patternId, token, isPublic = true, expiresAt = null) {
|
||||||
|
await pool.query(
|
||||||
|
`insert into pattern_shares (id, pattern_id, token, is_public, expires_at)
|
||||||
|
values ($1, $2, $3, $4, $5)`,
|
||||||
|
[crypto.randomUUID(), patternId, token, isPublic, expiresAt]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function patternOwnedByUser(patternId, userId) {
|
||||||
|
const res = await pool.query(
|
||||||
|
`select id from patterns where id=$1 and user_id=$2 and deleted_at is null`,
|
||||||
|
[patternId, userId]
|
||||||
|
);
|
||||||
|
return res.rows.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getSharedPattern(token) {
|
||||||
|
const res = await pool.query(
|
||||||
|
`select p.id, p.title, p.slug, p.data, p.updated_at
|
||||||
|
from pattern_shares s
|
||||||
|
join patterns p on p.id = s.pattern_id
|
||||||
|
where s.token=$1 and (s.expires_at is null or s.expires_at > now()) and s.is_public = true
|
||||||
|
limit 1`,
|
||||||
|
[token]
|
||||||
|
);
|
||||||
|
return res.rows[0] || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listPendingUsers() {
|
||||||
|
const res = await pool.query(`select id, email, display_name, note, created_at from users where status='pending' order by created_at asc`);
|
||||||
|
return res.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setUserStatus(userId, status) {
|
||||||
|
await pool.query(`update users set status=$2, updated_at=now() where id=$1`, [userId, status]);
|
||||||
|
}
|
||||||
|
async function setUserAdmin(userId, isAdmin) {
|
||||||
|
await pool.query(`update users set is_admin=$2, updated_at=now() where id=$1`, [userId, isAdmin]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bootstrapAdmin(email, password) {
|
||||||
|
if (!email || !password) return;
|
||||||
|
const hash = hashPassword(password);
|
||||||
|
const existing = await pool.query(`select id from users where email=$1`, [email]);
|
||||||
|
if (existing.rows.length) {
|
||||||
|
await pool.query(`update users set password_hash=$2, is_admin=true, status='active', updated_at=now() where email=$1`, [email, hash]);
|
||||||
|
} else {
|
||||||
|
const id = crypto.randomUUID();
|
||||||
|
await pool.query(
|
||||||
|
`insert into users (id, email, password_hash, is_admin, status) values ($1, $2, $3, true, 'active')`,
|
||||||
|
[id, email, hash]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function listAllUsers() {
|
||||||
|
const res = await pool.query(`select id, email, display_name, status, is_admin, created_at from users order by created_at asc`);
|
||||||
|
return res.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setPassword(userId, newPassword) {
|
||||||
|
const hash = hashPassword(newPassword);
|
||||||
|
await pool.query(`update users set password_hash=$2, updated_at=now() where id=$1`, [userId, hash]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createResetToken(userId, ttlMinutes = 60) {
|
||||||
|
const token = crypto.randomUUID();
|
||||||
|
const expires = new Date(Date.now() + ttlMinutes * 60 * 1000);
|
||||||
|
await pool.query(`insert into password_resets (token, user_id, expires_at) values ($1, $2, $3)`, [token, userId, expires]);
|
||||||
|
return { token, expires };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function consumeResetToken(token) {
|
||||||
|
const res = await pool.query(`select token, user_id, expires_at from password_resets where token=$1`, [token]);
|
||||||
|
if (!res.rows.length) return null;
|
||||||
|
const row = res.rows[0];
|
||||||
|
await pool.query(`delete from password_resets where token=$1`, [token]);
|
||||||
|
if (new Date(row.expires_at) < new Date()) return null;
|
||||||
|
return row.user_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
withClient,
|
||||||
|
initDb,
|
||||||
|
createUser,
|
||||||
|
verifyUser,
|
||||||
|
createSession,
|
||||||
|
getSession,
|
||||||
|
deleteSession,
|
||||||
|
upsertItems,
|
||||||
|
fetchItemsSince,
|
||||||
|
upsertProfile,
|
||||||
|
getProfile,
|
||||||
|
createShare,
|
||||||
|
getSharedPattern,
|
||||||
|
patternOwnedByUser,
|
||||||
|
listPendingUsers,
|
||||||
|
setUserStatus,
|
||||||
|
setUserAdmin,
|
||||||
|
bootstrapAdmin,
|
||||||
|
listAllUsers,
|
||||||
|
setPassword,
|
||||||
|
createResetToken,
|
||||||
|
consumeResetToken,
|
||||||
|
getUserByEmail
|
||||||
|
};
|
||||||
457
server/src/index.js
Normal file
457
server/src/index.js
Normal file
@ -0,0 +1,457 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
const { v4: uuid } = require('uuid');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const multer = require('multer');
|
||||||
|
const sharp = require('sharp');
|
||||||
|
const {
|
||||||
|
initDb,
|
||||||
|
withClient,
|
||||||
|
createUser,
|
||||||
|
verifyUser,
|
||||||
|
createSession,
|
||||||
|
getSession,
|
||||||
|
deleteSession,
|
||||||
|
upsertItems,
|
||||||
|
fetchItemsSince,
|
||||||
|
upsertProfile,
|
||||||
|
getProfile,
|
||||||
|
createShare,
|
||||||
|
getSharedPattern,
|
||||||
|
patternOwnedByUser,
|
||||||
|
listPendingUsers,
|
||||||
|
setUserStatus,
|
||||||
|
bootstrapAdmin,
|
||||||
|
listAllUsers,
|
||||||
|
setPassword,
|
||||||
|
createResetToken,
|
||||||
|
consumeResetToken,
|
||||||
|
setUserAdmin,
|
||||||
|
getUserByEmail
|
||||||
|
} = require('./db');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const PORT = process.env.PORT || 4000;
|
||||||
|
const UPLOAD_DIR = process.env.UPLOAD_DIR || path.join(__dirname, '..', 'uploads');
|
||||||
|
|
||||||
|
if (!fs.existsSync(UPLOAD_DIR)) fs.mkdirSync(UPLOAD_DIR, { recursive: true });
|
||||||
|
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json({ limit: '50mb' }));
|
||||||
|
|
||||||
|
// Init DB
|
||||||
|
initDb().catch((err) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('DB init failed', err);
|
||||||
|
process.exit(1);
|
||||||
|
}).then(() => {
|
||||||
|
if (process.env.ADMIN_EMAIL && process.env.ADMIN_PASSWORD) {
|
||||||
|
bootstrapAdmin(process.env.ADMIN_EMAIL, process.env.ADMIN_PASSWORD)
|
||||||
|
.then(() => console.log('Admin bootstrap ready'))
|
||||||
|
.catch((err) => console.error('Admin bootstrap failed', err));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const requireAuth = (req, res, next) => {
|
||||||
|
const token = req.headers.authorization?.replace('Bearer ', '');
|
||||||
|
if (!token) return res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
getSession(token)
|
||||||
|
.then(session => {
|
||||||
|
if (!session) return res.status(401).json({ error: 'Unauthorized' });
|
||||||
|
req.user = { id: session.user_id, email: session.email, token, is_admin: session.is_admin, status: session.status };
|
||||||
|
if (req.user.status !== 'active') return res.status(403).json({ error: 'Account not active', status: req.user.status });
|
||||||
|
return next();
|
||||||
|
})
|
||||||
|
.catch(() => res.status(401).json({ error: 'Unauthorized' }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const requireAdmin = (req, res, next) => {
|
||||||
|
if (!req.user?.is_admin) return res.status(403).json({ error: 'Admin only' });
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
|
app.get('/api/health', (_req, res) => {
|
||||||
|
res.json({ status: 'ok', version: '0.1.0', time: new Date().toISOString() });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Serve static front-end from project root (../)
|
||||||
|
const clientDir = path.join(__dirname, '..', '..');
|
||||||
|
app.use(express.static(clientDir));
|
||||||
|
app.use('/uploads', express.static(UPLOAD_DIR));
|
||||||
|
|
||||||
|
app.get('/', (_req, res) => {
|
||||||
|
res.sendFile(path.join(clientDir, 'index.html'));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/signup', (req, res) => {
|
||||||
|
const { email, password, displayName = '' } = req.body || {};
|
||||||
|
if (!email || !password) return res.status(400).json({ error: 'Email and password required' });
|
||||||
|
if (password.length < 8) return res.status(400).json({ error: 'Password must be at least 8 characters' });
|
||||||
|
createUser(email, password)
|
||||||
|
.then(async (user) => {
|
||||||
|
if (user.existing) {
|
||||||
|
return res.status(409).json({ error: 'Account already exists. Please log in instead.' });
|
||||||
|
}
|
||||||
|
await upsertProfile(user.id, displayName, '');
|
||||||
|
if (user.status !== 'active') {
|
||||||
|
return res.status(202).json({ status: user.status });
|
||||||
|
}
|
||||||
|
const token = await createSession(user.id);
|
||||||
|
return res.json({ token, email: user.email, status: user.status });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: 'Signup failed' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/login', (req, res) => {
|
||||||
|
const { email, password } = req.body || {};
|
||||||
|
if (!email || !password) return res.status(400).json({ error: 'Email and password required' });
|
||||||
|
verifyUser(email, password)
|
||||||
|
.then(async (user) => {
|
||||||
|
if (!user) return res.status(401).json({ error: 'Invalid credentials' });
|
||||||
|
if (user.pending) return res.status(403).json({ error: 'Account not active', status: user.status });
|
||||||
|
const token = await createSession(user.id);
|
||||||
|
return res.json({ token, email: user.email, is_admin: user.is_admin });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: 'Login failed' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/logout', requireAuth, (req, res) => {
|
||||||
|
const token = req.headers.authorization?.replace('Bearer ', '');
|
||||||
|
deleteSession(token).finally(() => res.json({ ok: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/sync', requireAuth, async (req, res) => {
|
||||||
|
const since = req.query.since;
|
||||||
|
try {
|
||||||
|
const projects = await fetchItemsSince('projects', req.user.id, since);
|
||||||
|
const patterns = await fetchItemsSince('patterns', req.user.id, since);
|
||||||
|
res.json({ projects, patterns, since: since || null, serverTime: new Date().toISOString() });
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Sync fetch failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/sync', requireAuth, async (req, res) => {
|
||||||
|
const { projects = [], patterns = [] } = req.body || {};
|
||||||
|
try {
|
||||||
|
await upsertItems('projects', req.user.id, projects);
|
||||||
|
await upsertItems('patterns', req.user.id, patterns);
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Sync failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/me', requireAuth, (req, res) => {
|
||||||
|
getProfile(req.user.id)
|
||||||
|
.then(profile => res.json({ profile: profile || { email: req.user.email, displayName: '', note: '', is_admin: req.user.is_admin, status: req.user.status } }))
|
||||||
|
.catch(err => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Profile fetch failed' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/me', requireAuth, (req, res) => {
|
||||||
|
const { displayName = '', note = '' } = req.body || {};
|
||||||
|
upsertProfile(req.user.id, displayName, note)
|
||||||
|
.then(profile => res.json({ profile }))
|
||||||
|
.catch(err => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Profile update failed' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/patterns/:id/share', requireAuth, async (req, res) => {
|
||||||
|
const patternId = req.params.id;
|
||||||
|
const { isPublic = true, expiresAt = null } = req.body || {};
|
||||||
|
try {
|
||||||
|
const owns = await patternOwnedByUser(patternId, req.user.id);
|
||||||
|
if (!owns) return res.status(404).json({ error: 'Pattern not found' });
|
||||||
|
const token = uuid();
|
||||||
|
await createShare(patternId, token, isPublic, expiresAt);
|
||||||
|
res.json({ token, url: `/share/${token}` });
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Share failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/share/:token', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const shared = await getSharedPattern(req.params.token);
|
||||||
|
if (!shared) return res.status(404).json({ error: 'Not found' });
|
||||||
|
res.json({ pattern: shared });
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Share fetch failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Upload route: save to /uploads, return URL (Optimized with sharp, fallback to raw)
|
||||||
|
const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 10 * 1024 * 1024 } }); // Bumped limit slightly
|
||||||
|
app.post('/api/upload', requireAuth, upload.single('file'), async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req.file) return res.status(400).json({ error: 'File required' });
|
||||||
|
const filename = `${Date.now()}-${uuid()}.webp`;
|
||||||
|
const outPath = path.join(UPLOAD_DIR, filename);
|
||||||
|
await sharp(req.file.buffer)
|
||||||
|
.rotate() // Auto-rotate based on EXIF
|
||||||
|
.resize({ width: 1200, height: 1200, fit: 'inside', withoutEnlargement: true })
|
||||||
|
.webp({ quality: 80 })
|
||||||
|
.toFile(outPath);
|
||||||
|
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
||||||
|
const url = `${baseUrl}/uploads/${filename}`;
|
||||||
|
res.json({ url });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Image processing failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: list pending users
|
||||||
|
app.get('/api/admin/users/pending', requireAuth, requireAdmin, async (_req, res) => {
|
||||||
|
try {
|
||||||
|
const users = await listPendingUsers();
|
||||||
|
res.json({ users });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'List pending failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: update user status
|
||||||
|
app.post('/api/admin/users/:id/status', requireAuth, requireAdmin, async (req, res) => {
|
||||||
|
const { status } = req.body || {};
|
||||||
|
if (!['pending', 'active', 'suspended'].includes(status)) return res.status(400).json({ error: 'Invalid status' });
|
||||||
|
try {
|
||||||
|
await setUserStatus(req.params.id, status);
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Update status failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: set/unset admin
|
||||||
|
app.post('/api/admin/users/:id/admin', requireAuth, requireAdmin, async (req, res) => {
|
||||||
|
const { is_admin } = req.body || {};
|
||||||
|
try {
|
||||||
|
await setUserAdmin(req.params.id, !!is_admin);
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Update admin failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: list all users
|
||||||
|
app.get('/api/admin/users', requireAuth, requireAdmin, async (_req, res) => {
|
||||||
|
try {
|
||||||
|
const users = await listAllUsers();
|
||||||
|
res.json({ users });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'List users failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Password reset request (demo: returns token, logs it)
|
||||||
|
app.post('/api/password-reset/request', async (req, res) => {
|
||||||
|
const { email } = req.body || {};
|
||||||
|
if (!email) return res.status(400).json({ error: 'Email required' });
|
||||||
|
try {
|
||||||
|
const userRow = await getUserByEmail(email);
|
||||||
|
if (!userRow) return res.json({ ok: true }); // don't leak
|
||||||
|
const reset = await createResetToken(userRow.id);
|
||||||
|
console.log(`Password reset token for ${email}: ${reset.token}`);
|
||||||
|
// TODO: send via mail backend
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Reset request failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/password-reset/confirm', async (req, res) => {
|
||||||
|
const { token, password } = req.body || {};
|
||||||
|
if (!token || !password) return res.status(400).json({ error: 'Token and password required' });
|
||||||
|
if (password.length < 8) return res.status(400).json({ error: 'Password must be at least 8 characters' });
|
||||||
|
try {
|
||||||
|
const userId = await consumeResetToken(token);
|
||||||
|
if (!userId) return res.status(400).json({ error: 'Invalid or expired token' });
|
||||||
|
await setPassword(userId, password);
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Reset failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: backup (SQL Dump)
|
||||||
|
app.get('/api/admin/backup', requireAuth, requireAdmin, async (_req, res) => {
|
||||||
|
try {
|
||||||
|
// Let's use direct DB queries to get everything.
|
||||||
|
const allUsers = await withClient(c => c.query('select * from users order by created_at'));
|
||||||
|
const allProjects = await withClient(c => c.query('select * from projects order by updated_at'));
|
||||||
|
const allPatterns = await withClient(c => c.query('select * from patterns order by updated_at'));
|
||||||
|
|
||||||
|
let sql = `-- Toadstool Tally Database Dump\n-- Exported: ${new Date().toISOString()}\n\n`;
|
||||||
|
|
||||||
|
const escape = (val) => {
|
||||||
|
if (val === null || val === undefined) return 'NULL';
|
||||||
|
if (typeof val === 'boolean') return val ? 'TRUE' : 'FALSE';
|
||||||
|
if (typeof val === 'number') return val;
|
||||||
|
if (val instanceof Date) return `'${val.toISOString()}'`;
|
||||||
|
if (typeof val === 'object') return `'${JSON.stringify(val).replace(/'/g, "''")}'`; // JSON columns
|
||||||
|
return `'${String(val).replace(/'/g, "''")}'`;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (allUsers.rows.length) {
|
||||||
|
sql += `-- Users\n`;
|
||||||
|
for (const row of allUsers.rows) {
|
||||||
|
sql += `INSERT INTO users (id, email, password_hash, display_name, note, created_at, updated_at, is_admin, status) VALUES (${escape(row.id)}, ${escape(row.email)}, ${escape(row.password_hash)}, ${escape(row.display_name)}, ${escape(row.note)}, ${escape(row.created_at)}, ${escape(row.updated_at)}, ${escape(row.is_admin)}, ${escape(row.status)}) ON CONFLICT (id) DO NOTHING;\n`;
|
||||||
|
}
|
||||||
|
sql += `\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allProjects.rows.length) {
|
||||||
|
sql += `-- Projects\n`;
|
||||||
|
for (const row of allProjects.rows) {
|
||||||
|
sql += `INSERT INTO projects (id, user_id, data, updated_at, deleted_at) VALUES (${escape(row.id)}, ${escape(row.user_id)}, ${escape(row.data)}, ${escape(row.updated_at)}, ${escape(row.deleted_at)}) ON CONFLICT (id) DO NOTHING;\n`;
|
||||||
|
}
|
||||||
|
sql += `\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allPatterns.rows.length) {
|
||||||
|
sql += `-- Patterns\n`;
|
||||||
|
for (const row of allPatterns.rows) {
|
||||||
|
sql += `INSERT INTO patterns (id, user_id, data, updated_at, deleted_at, title, slug) VALUES (${escape(row.id)}, ${escape(row.user_id)}, ${escape(row.data)}, ${escape(row.updated_at)}, ${escape(row.deleted_at)}, ${escape(row.title)}, ${escape(row.slug)}) ON CONFLICT (id) DO NOTHING;\n`;
|
||||||
|
}
|
||||||
|
sql += `\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', `attachment; filename="toadstool_backup_${new Date().toISOString().split('T')[0]}.sql"`);
|
||||||
|
res.setHeader('Content-Type', 'application/sql; charset=utf-8');
|
||||||
|
// res.setHeader('Content-Length', Buffer.byteLength(sql)); // Let Express handle this
|
||||||
|
res.end(sql);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: err.message, stack: err.stack });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: restore (overwrite)
|
||||||
|
app.post('/api/admin/restore', requireAuth, requireAdmin, async (req, res) => {
|
||||||
|
const { users = [], projects = [], patterns = [] } = req.body || {};
|
||||||
|
try {
|
||||||
|
await withClient(async (client) => {
|
||||||
|
await client.query('begin');
|
||||||
|
await client.query('truncate table sessions cascade');
|
||||||
|
await client.query('truncate table users cascade');
|
||||||
|
await client.query('truncate table projects cascade');
|
||||||
|
await client.query('truncate table patterns cascade');
|
||||||
|
for (const u of users) {
|
||||||
|
await client.query(
|
||||||
|
`insert into users (id, email, password_hash, display_name, note, is_admin, status, created_at, updated_at)
|
||||||
|
values ($1,$2,$3,$4,$5,$6,$7,$8,$9)`,
|
||||||
|
[u.id, u.email, u.password_hash || '', u.display_name || '', u.note || '', u.is_admin || false, u.status || 'active', u.created_at || new Date(), u.updated_at || new Date()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const p of projects) {
|
||||||
|
await client.query(
|
||||||
|
`insert into projects (id, user_id, data, updated_at, deleted_at) values ($1,$2,$3,$4,$5)`,
|
||||||
|
[p.id, p.user_id, p.data || {}, p.updated_at || new Date(), p.deleted_at || null]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const p of patterns) {
|
||||||
|
await client.query(
|
||||||
|
`insert into patterns (id, user_id, title, slug, data, updated_at, deleted_at) values ($1,$2,$3,$4,$5,$6,$7)`,
|
||||||
|
[p.id, p.user_id, p.title || '', p.slug || null, p.data || {}, p.updated_at || new Date(), p.deleted_at || null]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await client.query('commit');
|
||||||
|
});
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Restore failed' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Admin: restore from SQL dump (Base64 JSON)
|
||||||
|
app.post('/api/admin/restore-sql', requireAuth, requireAdmin, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { sql } = req.body || {};
|
||||||
|
if (!sql || typeof sql !== 'string') {
|
||||||
|
return res.status(400).json({
|
||||||
|
error: 'SQL dump (base64) required',
|
||||||
|
debug: {
|
||||||
|
keys: Object.keys(req.body || {}),
|
||||||
|
contentType: req.headers['content-type'],
|
||||||
|
bodyType: typeof req.body
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const sqlDump = Buffer.from(sql, 'base64').toString('utf-8');
|
||||||
|
|
||||||
|
if (!sqlDump || sqlDump.trim().length === 0) {
|
||||||
|
return res.status(400).json({ error: 'Decoded SQL is empty' });
|
||||||
|
}
|
||||||
|
|
||||||
|
await withClient(async (client) => {
|
||||||
|
await client.query('BEGIN'); // Start transaction
|
||||||
|
// Clear existing data before restoring
|
||||||
|
await client.query('TRUNCATE table sessions CASCADE');
|
||||||
|
await client.query('TRUNCATE table users CASCADE');
|
||||||
|
await client.query('TRUNCATE table projects CASCADE');
|
||||||
|
await client.query('TRUNCATE table patterns CASCADE');
|
||||||
|
await client.query('TRUNCATE table pattern_shares CASCADE'); // Assuming pattern_shares also needs to be cleared
|
||||||
|
await client.query('TRUNCATE table password_resets CASCADE'); // Assuming password_resets also needs to be cleared
|
||||||
|
|
||||||
|
// Execute the SQL dump. This is inherently risky with untrusted input.
|
||||||
|
// For this project context, it's assumed admin is trusted.
|
||||||
|
await client.query(sqlDump);
|
||||||
|
await client.query('COMMIT'); // Commit transaction
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json({ ok: true, message: 'Database restored successfully from SQL dump.' });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
// Rollback on error
|
||||||
|
await withClient(async (client) => {
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
});
|
||||||
|
res.status(500).json({ error: err.message, stack: err.stack, message: 'SQL Restore failed, transaction rolled back.' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use((err, _req, res, _next) => {
|
||||||
|
// Basic error guard
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).json({ error: 'Internal error' });
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`API listening on http://localhost:${PORT}`);
|
||||||
|
});
|
||||||
5
sw.js
5
sw.js
@ -1,9 +1,9 @@
|
|||||||
const CACHE_NAME = 'toadstool-tally-v1';
|
const CACHE_NAME = 'toadstool-tally-v2';
|
||||||
const ASSETS = [
|
const ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
'/assets/style.css',
|
'/assets/style.css',
|
||||||
'/assets/app.js',
|
'/assets/app.js?v=3',
|
||||||
'/assets/textures/mushroom.svg',
|
'/assets/textures/mushroom.svg',
|
||||||
'/assets/icons/favicon-96x96.png',
|
'/assets/icons/favicon-96x96.png',
|
||||||
'/assets/icons/favicon.ico',
|
'/assets/icons/favicon.ico',
|
||||||
@ -18,6 +18,7 @@ self.addEventListener('install', (event) => {
|
|||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
|
||||||
);
|
);
|
||||||
|
self.skipWaiting();
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('activate', (event) => {
|
self.addEventListener('activate', (event) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user