diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..f11030d836b8e995b617f38ed5e012bb98857939 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +node_modules +.output +.git +.env +.env.* +.lovable +.vite +dist +*.log diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..37a6109a0a2c755c5c115456ada66c6a37b91220 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,35 +1,2 @@ -*.7z filter=lfs diff=lfs merge=lfs -text -*.arrow filter=lfs diff=lfs merge=lfs -text -*.bin filter=lfs diff=lfs merge=lfs -text -*.bz2 filter=lfs diff=lfs merge=lfs -text -*.ckpt filter=lfs diff=lfs merge=lfs -text -*.ftz filter=lfs diff=lfs merge=lfs -text -*.gz filter=lfs diff=lfs merge=lfs -text -*.h5 filter=lfs diff=lfs merge=lfs -text -*.joblib filter=lfs diff=lfs merge=lfs -text -*.lfs.* filter=lfs diff=lfs merge=lfs -text -*.mlmodel filter=lfs diff=lfs merge=lfs -text -*.model filter=lfs diff=lfs merge=lfs -text -*.msgpack filter=lfs diff=lfs merge=lfs -text -*.npy filter=lfs diff=lfs merge=lfs -text -*.npz filter=lfs diff=lfs merge=lfs -text -*.onnx filter=lfs diff=lfs merge=lfs -text -*.ot filter=lfs diff=lfs merge=lfs -text -*.parquet filter=lfs diff=lfs merge=lfs -text -*.pb filter=lfs diff=lfs merge=lfs -text -*.pickle filter=lfs diff=lfs merge=lfs -text -*.pkl filter=lfs diff=lfs merge=lfs -text -*.pt filter=lfs diff=lfs merge=lfs -text -*.pth filter=lfs diff=lfs merge=lfs -text -*.rar filter=lfs diff=lfs merge=lfs -text -*.safetensors filter=lfs diff=lfs merge=lfs -text -saved_model/**/* filter=lfs diff=lfs merge=lfs -text -*.tar.* filter=lfs diff=lfs merge=lfs -text -*.tar filter=lfs diff=lfs merge=lfs -text -*.tflite filter=lfs diff=lfs merge=lfs -text -*.tgz filter=lfs diff=lfs merge=lfs -text -*.wasm filter=lfs diff=lfs merge=lfs -text -*.xz filter=lfs diff=lfs merge=lfs -text -*.zip filter=lfs diff=lfs merge=lfs -text -*.zst filter=lfs diff=lfs merge=lfs -text -*tfevents* filter=lfs diff=lfs merge=lfs -text +_gitdownloads_grabberintanstack.rar filter=lfs diff=lfs merge=lfs -text +hf_archived_difffree.rar filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..6f1bad13cd6f8958ef81a199c433260746f3aa93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +.output +.vinxi +.tanstack/** +.nitro +*.local + +# Wrangler / Cloudflare +.wrangler/ +.dev.vars + +# Tags directory +/tags + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.lovable/plan.md b/.lovable/plan.md new file mode 100644 index 0000000000000000000000000000000000000000..1aece0a04d8429d0db083a6c08b05a723a96ba30 --- /dev/null +++ b/.lovable/plan.md @@ -0,0 +1,78 @@ +## Goal + +For every image included in the downloaded ZIP, also add: + +- `.txt` — UTF-8 tags file (space-separated, one line, matches the image filename exactly except for extension). +- `.md` — human-readable markdown containing all extracted post metadata (all tags, source link — blank if missing, file size, sample link, original file link, rating, score, dimensions, uploader, created date, md5, etc.). + +## Approach + +The server currently only receives `{id, fileUrl, ext}` per post. To write rich metadata into the ZIP without a second network round-trip per post, the frontend will forward the full normalized post (plus a raw metadata bag) to `/api/download-zip`, and the server will emit the extra files alongside each image. + +To capture "any data related to that post", `searchPosts` will additionally return the raw JSON entry for each post (as `raw: unknown`). The Markdown generator will pretty-print known fields first, then append the full raw JSON as a fenced code block so nothing is lost. + +New optional fields (`sampleUrl`, `fileSize`, `width`, `height`, `md5`, `uploader`, `createdAt`) get added to `SiteConfig.fields` as optional dotted paths, defaulted for the built-in e621 site. Existing custom sites keep working because every new field is optional. + +## Files to change + +### `src/lib/grabber/sites.ts` + +- Extend `FieldMap` with optional: `sampleUrl?`, `fileSize?`, `width?`, `height?`, `md5?`, `uploader?`, `createdAt?`. +- Extend `NormalizedPost` with the same optional fields plus `raw: unknown`. +- Update `normalizePost()` to resolve each new path when present and attach `raw` (the original entry). +- Update `BUILTIN_SITES` e621 entry `fields` with: `sampleUrl: "sample.url"`, `fileSize: "file.size"`, `width: "file.width"`, `height: "file.height"`, `md5: "file.md5"`, `uploader: "uploader_id"`, `createdAt: "created_at"`. + +### `src/lib/grabber/search.functions.ts` + +- Extend the `SiteSchema.fields` zod object with the new optional string paths. +- No handler logic changes needed — normalization already carries `raw` and new fields through. + +### `src/components/grabber/AddSiteDialog.tsx` + +- Add the new optional field keys to the `(["id",...] as const)` list on line 73 so users can map them for custom sites (`sampleUrl`, `fileSize`, `width`, `height`, `md5`, `uploader`, `createdAt`). +- Extend `DEFAULT` (lines 22–31) with sensible Danbooru mappings (`sampleUrl: "large_file_url"`, `fileSize: "file_size"`, `width: "image_width"`, `height: "image_height"`, `md5: "md5"`, `uploader: "uploader_name"`, `createdAt: "created_at"`). + +### `src/routes/api/download-zip.ts` (major rewrite) + +- Expand `BodySchema.posts` item to accept the full normalized post shape (all new optional fields + `tags: string[]` + `raw: unknown`). +- For each post: + 1. Fetch the image bytes as today. Build image filename `base = "_"` and `.`. + 2. Write `.txt` — `strToU8(tags.join(" "))` (UTF-8). Uses the exact same basename as the image so tag files pair 1:1. + 3. Write `.md` — pretty markdown with: + - `# Post ` heading + - Table/list of: Source (blank line if missing), Rating, Score, Dimensions (`width x height`), File size (human-readable KB/MB), MD5, Uploader, Created at, Original file URL, Sample URL, Preview URL, Ext. + - `## Tags` section with the tags space-separated. + - `## Raw metadata` fenced ```json block containing `JSON.stringify(raw, null, 2)`. +- Keep the existing `_errors.txt` behavior and 200-post cap. +- Sanitizer stays the same; md/txt names use `sanitize(id)` so filenames match the image exactly. + +### `src/routes/index.tsx` + +- In `downloadZip()` (the `fetch("/api/download-zip", …)` call), send the full post objects instead of a stripped `{id,fileUrl,ext}` triple. Change: + ``` + posts: chosen.map((p) => ({ id: p.id, fileUrl: p.fileUrl, ext: p.ext })), + ``` + to: + ``` + posts: chosen, // full NormalizedPost incl. tags + raw + optional metadata + ``` +- No other UI changes. + +## ZIP layout example + +```text +grabber-2026-07-17T...zip +├── e621_1234567.jpg +├── e621_1234567.txt ← "tag1 tag2 tag3 ..." +├── 1234567.md ← human-readable metadata + raw JSON +├── e621_1234568.png +├── e621_1234568.txt +├── 1234568.md +└── _errors.txt (only if any fetch failed) +``` + +## Notes / non-goals + +- No new dependencies (still `fflate` + `zod`). +- No DB, no auth, no schema changes — this is presentation + payload shape only. +- Custom sites without the new mappings still work; missing fields render as blank lines in the `.md` and the raw JSON section still contains everything from the API. diff --git a/.lovable/project.json b/.lovable/project.json new file mode 100644 index 0000000000000000000000000000000000000000..22d11d01f809397ac1160f39942580b999f1313f --- /dev/null +++ b/.lovable/project.json @@ -0,0 +1,5 @@ +{ + "schemaVersion": 1, + "template": "tanstack_start_ts_current", + "revision": "tanstack_start_ts_current-fa3af8ca0703" +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000000000000000000000000000000000000..be49b2655e2222e8a688f616a5c13500298801a0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +node_modules +dist +.output +.vinxi +pnpm-lock.yaml +package-lock.json +bun.lock +routeTree.gen.ts diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000000000000000000000000000000000..90abee2393e79dff7ec36856c94f662a263f0107 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "printWidth": 100, + "semi": true, + "singleQuote": false, + "trailingComma": "all" +} diff --git a/.workspace/0 b/.workspace/0 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.workspace/git/0 b/.workspace/git/0 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000000000000000000000000000000000000..f59511a66eb985d4a2fe4095d2723a65ac52689c --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,12 @@ + + +> [!IMPORTANT] +> This project is connected to [Lovable](https://lovable.dev). Avoid rewriting +> published git history — force pushing, or rebasing/amending/squashing commits +> that are already pushed — as it rewrites history on Lovable's side and the +> user will likely lose their project history. +> +> Commits you push to the connected branch sync back to Lovable and show up in +> the editor, so keep the branch in a working state. + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..ce4d4938d20cf8180d04b36dc715c9c5fa1b058e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Build stage +FROM node:22-slim AS build +WORKDIR /app +RUN corepack enable && npm install -g bun@1.3.3 +COPY package.json bun.lock ./ +RUN bun install --frozen-lockfile +COPY . . +# Build with the Node server preset so the output runs in a plain Docker container +ENV NITRO_PRESET=node-server +RUN bun run build + +# Runtime stage +FROM node:22-slim AS runtime +WORKDIR /app +ENV NODE_ENV=production \ + PORT=7860 \ + HOST=0.0.0.0 + +# Install Python 3 and huggingface_hub library +RUN apt-get update && apt-get install -y python3 python3-pip && rm -rf /var/lib/apt/lists/* +RUN pip3 install --break-system-packages huggingface_hub + +COPY --from=build /app/.output ./.output +EXPOSE 7860 +CMD ["node", ".output/server/index.mjs"] diff --git a/README.md b/README.md index ab24e5b89531e5acbcb8a0519f063ef15aa50f43..5aeeb79995e92d0b1182350d2f50a4bea43021d4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,66 @@ --- -title: Grabber In Tanstack CPU -emoji: ⚡ -colorFrom: purple -colorTo: red +title: Imageboard Grabber +emoji: 🖼️ +colorFrom: indigo +colorTo: purple sdk: docker -pinned: false +app_port: 7860 +pinned: true --- -Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference +# Imageboard Grabber + +Booru-style imageboard grabber (inspired by Bionus/Grabber): tag search, thumbnail grid, multi-select, server-side batch ZIP download. Ships with **e621** preconfigured and a **schema-based "Add site" panel** for Danbooru/Gelbooru/Safebooru/etc. + +## Features + +- **Tag exclusion on ZIP download:** Specify custom tags to filter out of the compiled ZIP's `.txt` tag list and markdown meta files. +- **Direct Hugging Face dataset upload:** Enter your Hugging Face write token and desired dataset repository name to instantly package and upload your compiled archives to a Hugging Face dataset. Creates the dataset automatically if it does not already exist. + +## Run locally with Docker + +```bash +docker build -t grabber . +docker run --rm -p 7860:7860 grabber +``` + +Then open http://localhost:7860. + +## Deploy to Hugging Face Spaces + +1. Push this repo to GitHub (Lovable → GitHub sync, or `git push`). +2. Create a new Space on Hugging Face → **SDK: Docker**. +3. Link the GitHub repo (or add the Space as a remote and push). + +The frontmatter above tells HF Spaces to build the `Dockerfile` and serve on port `7860`. + +## Adding a custom site + +Click **+ Add site** and paste the site's API schema: + +- **Base URL / Search Path** — e.g. `https://danbooru.donmai.us` + `/posts.json` +- **Param names** for tags / page / limit +- **JSON path** to the posts array (empty = root) +- **Field mappings** (dotted paths) for `id`, `previewUrl`, `fileUrl`, `ext`, `tags`, `source`, `rating`, `score` + +Example (Danbooru): + +``` +baseUrl: https://danbooru.donmai.us +searchPath: /posts.json +postsPath: (empty) +fields.id: id +fields.previewUrl: preview_file_url +fields.fileUrl: file_url +fields.ext: file_ext +fields.tags: tag_string_general +fields.source: source +fields.rating: rating +fields.score: score +``` + +## Tech + +- TanStack Start (React 19, Vite 7) + Tailwind v4 + shadcn/ui +- Server-side image fetching and streaming ZIP via `fflate` +- Node server build via nitro `node-server` preset \ No newline at end of file diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000000000000000000000000000000000000..be59b8b573e27cb498f5e16a43174971cf89ee06 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,81 @@ +# Imageboard Grabber - Further Development & Roadmap + +This document outlines a roadmap and future development plan for the **Imageboard Grabber** application on Hugging Face Spaces. + +--- + +## 🚀 1. Feature Enhancements + +### 1.1 Support for Authenticated APIs (API Keys & Username) + +- **Goal:** Allow users to safely search and download from private or rate-limited sites (like Danbooru premium tiers, e621 personal accounts). +- **Implementation:** + - Add credential fields (API Key / Password Hash, Username) to the **Add Site** dialog. + - Securely transmit credentials to the server using HTTP headers or request bodies. + - Store credentials locally in the browser's `localStorage` or session-only cookies so they are never stored globally on the server. + +### 1.2 Persistent Site Configuration + +- **Goal:** Avoid losing newly added schemas when refreshing or clearing session storage. +- **Implementation:** + - Sync the list of added custom sites with IndexedDB or `localStorage`. + - Provide an **Export/Import Sites** button to allow users to backup their custom configurations as JSON. + +### 1.3 Advanced Query Builder + +- **Goal:** Help non-technical users build complex booru search queries. +- **Implementation:** + - Add UI controls for searching by rating (Safe, Questionable, Explicit), score range, upload date, or file extension. + - Autocomplete / tag suggestion box by querying the active site's tag API endpoint (e.g., `/tags.json?search[name_matches]=*`). + +### 1.4 Enhanced Lightbox & Media Viewer + +- **Goal:** Support video playback and metadata exploration. +- **Implementation:** + - Auto-detect video extensions (`.webm`, `.mp4`) in the Lightbox and render a native HTML `