From 5ced6b4a86810c098ae6bda289eb46b16066699f Mon Sep 17 00:00:00 2001
From: poli0981 <127664709+poli0981@users.noreply.github.com>
Date: Wed, 30 Sep 2026 19:26:40 +0700
Subject: [PATCH] feat(web): Turnstile gate, in-site legal pages and clean URLs
on ytgenerator.stream
A Worker (worker/) now sits in front of the static build, configured from the
same wrangler.jsonc. Cloudflare builds and deploys it; nothing in GitHub
Actions does.
Gate
- First visit shows a branded check page (8 languages, Accept-Language) with
Cloudflare Turnstile. The token is verified server-side against
TURNSTILE_SECRET: success, hostname, action "enter", age <= 300 s. Only
Cloudflare's own test-key results skip the hostname/action check, so
`npm run cf:dev` works with the published test keys.
- Pass -> `__Host-ytg_gate` (HttpOnly, Secure, SameSite=Lax, 24 h): an HMAC
over expiry + a user-agent hash, keyed from the Turnstile secret, so no
second secret exists and a cookie copied into a scraper is useless.
- The page reloads in place instead of redirecting, so there is no `next`
parameter to open-redirect with; /__gate/status lets the page tell a
cookie-blocking browser what is wrong instead of looping; after one
failure it waits for a click rather than resubmitting.
- Missing secret = deployment mistake: the site stays up without the gate and
the Worker logs it, instead of locking every visitor out.
- The agree box on the gate records `ytg_terms`, which the app reads on boot
so web visitors meet one blocking screen, not two.
Headers and static files
- worker/headers.ts sets CSP (nonce + strict-dynamic on the gate, no script
at all on legal pages), nosniff, Referrer-Policy, Permissions-Policy, COOP,
CORP, X-Frame-Options on everything the Worker returns; _headers covers
the files served directly; a test keeps the two baselines identical.
- `not_found_handling: "404-page"` (a static 404.html) instead of the SPA
fallback, which would have handed index.html past the gate for any
excluded path. The Worker serves the shell itself by fetching "/" - not
"/index.html", which html_handling would 307 back to the home page.
- security.txt (RFC 9116) is generated per build so Expires stays ~6 months
ahead; the Web Analytics beacon is injected into the web build only.
- theme-init.js applies the saved theme before first paint (no inline script).
Legal in-site
- build-plugins/legal-docs.ts renders TERMS, PRIVACY, DISCLAIMER (+ vi),
LICENSE, THIRD_PARTY_NOTICES, SECURITY, NOTICE and CODE_OF_CONDUCT at build
time into static /legal pages (public, before the gate) and a lazy
`virtual:legal-docs` module for the in-app Legal Center, which works
offline on desktop and Android and never leaves the webview.
- PRIVACY, TERMS and SECURITY rewritten for Cloudflare hosting, Turnstile,
Web Analytics and the two cookies; contacts moved to the poli0981.dev
aliases (privacy@, legal@, dmca@, copyright@, security@, code@).
- CURRENT_TERMS_VERSION 1 -> 2: the Privacy Policy changed materially.
App
- Web uses BrowserRouter (real paths; analytics can count them), Tauri keeps
HashRouter; old /#/x bookmarks are rewritten to /x before the router reads
them. Consent is a layout route; /legal sits outside it.
- follows the UI language; a stale chunk after a deploy triggers
one reload instead of an error page.
.gitattributes pins LF everywhere so Windows checkouts stop failing Prettier.
Co-Authored-By: Claude Opus 5.5
---
.dev.vars.example | 5 +
.gitattributes | 13 ++
CODE_OF_CONDUCT.md | 2 +-
MAINTAINERS.md | 5 +-
PRIVACY.md | 108 +++++----
SECURITY.md | 26 ++-
TERMS.md | 35 +--
build-plugins/legal-docs.ts | 333 ++++++++++++++++++++++++++++
build-plugins/web-only.ts | 67 ++++++
index.html | 1 +
knip.json | 4 +-
package-lock.json | 14 ++
package.json | 9 +-
public/404.html | 57 +++++
public/theme-init.js | 20 ++
src-tauri/installer-license.txt | 16 +-
src/App.tsx | 266 +++++++++++-----------
src/components/ConsentGate.tsx | 30 +--
src/components/errors/ErrorPage.tsx | 21 +-
src/config/brand.ts | 13 ++
src/config/error-pages.ts | 4 +-
src/config/legal.ts | 105 +++++++--
src/i18n/locales/_schema.json | 7 +-
src/i18n/locales/en/ui.json | 38 +++-
src/i18n/locales/es/ui.json | 38 +++-
src/i18n/locales/id/ui.json | 38 +++-
src/i18n/locales/ja/ui.json | 38 +++-
src/i18n/locales/ko/ui.json | 38 +++-
src/i18n/locales/pt-BR/ui.json | 38 +++-
src/i18n/locales/vi/ui.json | 38 +++-
src/i18n/locales/zh/ui.json | 38 +++-
src/main.tsx | 60 +++++
src/pages/AboutPage.tsx | 21 +-
src/pages/LegalPage.tsx | 192 ++++++++++++++++
src/styles/globals.css | 106 +++++++++
src/vite-env.d.ts | 16 ++
tests/build/legal-docs.test.ts | 97 ++++++++
tests/build/web-only.test.ts | 58 +++++
tests/config/legal.test.ts | 75 ++++++-
tests/worker/cookie.test.ts | 73 ++++++
tests/worker/gate-i18n.test.ts | 84 +++++++
tests/worker/headers.test.ts | 68 ++++++
tests/worker/router.test.ts | 316 ++++++++++++++++++++++++++
tests/worker/turnstile.test.ts | 130 +++++++++++
tsconfig.check.json | 2 +-
vite.config.ts | 13 +-
worker/cookie.ts | 113 ++++++++++
worker/env.ts | 55 +++++
worker/gate-i18n.ts | 243 ++++++++++++++++++++
worker/gate-page.ts | 208 +++++++++++++++++
worker/headers.ts | 105 +++++++++
worker/index.ts | 17 ++
worker/router.ts | 235 ++++++++++++++++++++
worker/turnstile.ts | 87 ++++++++
wrangler.jsonc | 36 ++-
55 files changed, 3547 insertions(+), 328 deletions(-)
create mode 100644 .dev.vars.example
create mode 100644 .gitattributes
create mode 100644 build-plugins/legal-docs.ts
create mode 100644 build-plugins/web-only.ts
create mode 100644 public/404.html
create mode 100644 public/theme-init.js
create mode 100644 src/config/brand.ts
create mode 100644 src/pages/LegalPage.tsx
create mode 100644 tests/build/legal-docs.test.ts
create mode 100644 tests/build/web-only.test.ts
create mode 100644 tests/worker/cookie.test.ts
create mode 100644 tests/worker/gate-i18n.test.ts
create mode 100644 tests/worker/headers.test.ts
create mode 100644 tests/worker/router.test.ts
create mode 100644 tests/worker/turnstile.test.ts
create mode 100644 worker/cookie.ts
create mode 100644 worker/env.ts
create mode 100644 worker/gate-i18n.ts
create mode 100644 worker/gate-page.ts
create mode 100644 worker/headers.ts
create mode 100644 worker/index.ts
create mode 100644 worker/router.ts
create mode 100644 worker/turnstile.ts
diff --git a/.dev.vars.example b/.dev.vars.example
new file mode 100644
index 0000000..26c1460
--- /dev/null
+++ b/.dev.vars.example
@@ -0,0 +1,5 @@
+# Copy to .dev.vars for `npm run cf:dev`. These are Cloudflare's public
+# Turnstile TEST keys: the widget always passes and the secret accepts only the
+# dummy token it produces. Never put the real secret in a file.
+TURNSTILE_SITE_KEY=1x00000000000000000000AA
+TURNSTILE_SECRET=1x0000000000000000000000000000000AA
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..bd3b517
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,13 @@
+# LF in the repository and in every checkout, on every OS. Prettier enforces
+# `endOfLine: "lf"`, and a Windows checkout with core.autocrlf=true otherwise
+# turns every file it touches (checkout, stash, rebase) into a formatting
+# failure that CI never sees.
+* text=auto eol=lf
+
+# Binary assets — never touch.
+*.png binary
+*.ico binary
+*.icns binary
+*.jks binary
+*.keystore binary
+*.woff2 binary
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
index 273f773..7aae0aa 100644
--- a/CODE_OF_CONDUCT.md
+++ b/CODE_OF_CONDUCT.md
@@ -6,7 +6,7 @@ By participating in this project — opening issues, submitting pull requests, c
## Reporting
-Report violations privately to the maintainer: `lopop05905@proton.me`.
+Report violations privately to the maintainer: `code@poli0981.dev`.
All reports are reviewed and investigated promptly and fairly. The maintainer is obligated to respect the privacy and security of the reporter.
diff --git a/MAINTAINERS.md b/MAINTAINERS.md
index 1b76115..da95119 100644
--- a/MAINTAINERS.md
+++ b/MAINTAINERS.md
@@ -6,7 +6,8 @@
- **GitHub**:
- **YouTube** (reference channel):
-- **Email** (security & private contact): `lopop05905@proton.me`
+- **Website**: · all channels at
+- **Email**: `code@poli0981.dev` (project) · `security@poli0981.dev` (vulnerabilities, see [SECURITY.md](./SECURITY.md))
- **Areas of responsibility**: all — core engine, locale management, UI, Tauri desktop shell, releases, CI/CD.
## Maintainer Responsibilities
@@ -19,7 +20,7 @@
## Becoming a Maintainer
-There is currently no formal pathway. The project has been solo since inception. If you'd like to help maintain a specific area — most realistically, native-speaker review for one of the AI-translated locales (JA / ES / KO / ZH) — open an issue describing what you'd like to take on.
+There is currently no formal pathway. The project has been solo since inception. If you'd like to help maintain a specific area — most realistically, native-speaker review for one of the AI-translated locales (JA / ES / KO / ZH / PT-BR / ID) — open an issue describing what you'd like to take on.
Persistent, high-quality contributions over time are the path. There is no application form.
diff --git a/PRIVACY.md b/PRIVACY.md
index 0812b8e..29456f9 100644
--- a/PRIVACY.md
+++ b/PRIVACY.md
@@ -1,75 +1,95 @@
# Privacy Policy
-**Effective:** 2026-05-14
+**Effective:** 2026-09-30
-YTDescGen is an **offline-first** template engine for generating YouTube video metadata. This document describes what data the application handles, where it lives, and what it never collects.
+This policy covers YTDescGen — the web app at **https://ytgenerator.stream** and the desktop (Windows, macOS, Linux) and Android apps built from the same source. It is maintained by **poli0981 (SkullMute)**, who is responsible for it. Questions and requests: **privacy@poli0981.dev**.
-## What We Collect
+## In short
-**Nothing.** The application sends no data to any server controlled by the maintainer.
+- There is **no account** and **no YTDescGen server that receives your work**. Everything you type — profiles, presets, templates, drafts, history — is stored **on your own device** and nowhere else.
+- The **web app** is delivered through **Cloudflare**. To do that, Cloudflare necessarily sees technical request data (such as your IP address), runs a one-time **Turnstile** bot check before you enter, and provides **cookieless** visit statistics (**Cloudflare Web Analytics**).
+- The **desktop and Android apps** have none of that: no analytics, no bot check, no telemetry.
+- Nothing is sold, shared for advertising, or used to profile you.
-There is no analytics provider, no telemetry, no crash reporter, no A/B testing, no advertising network, no behavioral tracking. There is no backend.
+## 1. What stays on your device
-## What Stays on Your Device
+### Web app
-### Web version (GitHub Pages)
+Your work is saved in your browser's **`localStorage`** for `ytgenerator.stream`:
-The web build stores your work in your browser's **`localStorage`** only. Keys used:
-
-| Key prefix | Purpose |
+| Key | Contents |
| --- | --- |
-| `ytdesc:editor` | Current editor draft |
-| `ytdesc:settings` | Theme, default language, accordion state, hashtag preferences |
-| `ytdesc:profiles` | Saved channel / social / rig profiles |
-| `ytdesc:presets` | Saved game presets |
-| `ytdesc:templates` | Saved full-form snapshots |
-| `ytdesc:history` | Recently generated outputs |
-| `ytdesc:logs` | Application event log |
+| `ytdescgen-settings` | Theme, languages, editor preferences, the version of these terms you accepted and when |
+| `ytdescgen-profiles` | Saved channel profiles (channel name, social links, contact emails, PC rig) |
+| `ytdescgen-presets` | Saved game presets (game name, genres, store links) |
+| `ytdescgen-templates` | Saved full-form templates |
+| `ytdescgen-history` | Recently generated titles, descriptions and tags |
+| `ytdescgen-editor-draft` | The draft currently open in the editor |
+| `ytdescgen-logs` | The app's own event log (errors, imports, exports) |
-`localStorage` is scoped to the origin and never transmitted. Clearing your browser data, browsing in a private/incognito window, or signing out wipes all of it.
+This data never leaves your browser unless **you** export it. Clearing site data, using a private window, or a "clear cookies and site data on exit" setting erases it.
-### Desktop version (Tauri)
+### Desktop and Android apps
-The desktop build uses the operating system's standard application-data directory:
+The apps keep the same data in the app's own WebView storage and application-data folder (the event log and automatic backups live there too):
-- **Windows**: `%APPDATA%\com.skullmute.ytdescgen`
-- **macOS**: `~/Library/Application Support/com.skullmute.ytdescgen`
-- **Linux**: `~/.config/com.skullmute.ytdescgen`
+- **Windows:** `%APPDATA%\com.skullmute.ytdescgen` and `%LOCALAPPDATA%\com.skullmute.ytdescgen`
+- **macOS:** `~/Library/Application Support/com.skullmute.ytdescgen`
+- **Linux:** `~/.local/share/com.skullmute.ytdescgen`
+- **Android:** the app's private storage (removed when you uninstall the app or clear its data)
-The same key set as the web version is stored as JSON files there. Uninstalling the application or deleting that directory removes everything.
+Uninstalling the app or deleting those folders removes everything. The apps make no network requests of their own; links you choose to open (store pages, donation pages, this policy on the web) open in your browser.
-## Third-Party Services
+## 2. What the web app's hosting provider processes
-The application does **not** call third-party APIs at runtime.
+The web app is hosted on **Cloudflare Workers**. Cloudflare acts as a service provider (processor) for the site and handles:
-Optional links you may click — donation buttons, store links you paste into a draft, social links you save to your profile — navigate **away** from the application to third-party sites. Those sites have their own privacy policies; the maintainer is not responsible for them.
+- **Delivery and security.** Every request carries technical data — IP address, browser user-agent, requested URL, referrer, date and time. Cloudflare uses it to deliver the site, keep it available and protect it from abuse. Error and request logs for the site's Worker (Cloudflare Workers Logs) are kept by Cloudflare for a short period (currently up to 7 days) and are used only to fix problems.
+- **Turnstile bot check.** Before you enter, [Cloudflare Turnstile](https://www.cloudflare.com/products/turnstile/) runs a check — usually invisible — that evaluates technical browser and device signals and your IP address to tell people from automated traffic. Its data handling is described in Cloudflare's [Turnstile Privacy Addendum](https://www.cloudflare.com/turnstile-privacy-policy/). YTDescGen receives only a pass/fail result.
+- **Cloudflare Web Analytics.** Aggregate, **cookieless** statistics: page views, referrer, country, browser, operating system and device type, and page-load performance. It sets no cookies, uses no local storage and does not fingerprint visitors. See [Cloudflare's Web Analytics privacy notes](https://www.cloudflare.com/web-analytics/) and the [Cloudflare Privacy Policy](https://www.cloudflare.com/privacypolicy/).
-YouTube oEmbed, the Steam store API, Twitch helix, and similar services are **not** fetched by this application.
+Cloudflare operates a global network, so this data may be processed outside your country under Cloudflare's data-processing terms (including the EU Standard Contractual Clauses).
-## Cookies / Local Storage Distinction
+## 3. Cookies
-The web version uses **`localStorage`**, not cookies. No cookie is set by the application. GitHub Pages itself may issue a session cookie at the platform level — that is GitHub's, not ours, and is governed by [GitHub's Privacy Statement](https://docs.github.com/en/site-policy/privacy-policies/github-general-privacy-statement).
+The web app sets exactly two cookies, both first-party and both needed for the bot check:
-The first-run consent acknowledgement (added in v0.28.0) is recorded **inside the existing settings record** — a `legalConsentVersion` number plus a local timestamp — not as a separate cookie or storage key. It never leaves your device.
+| Cookie | Purpose | Lifetime |
+| --- | --- | --- |
+| `__Host-ytg_gate` | Remembers that this browser passed the Turnstile check. Contains only an expiry time, a shortened one-way hash of your browser's user-agent string and a signature — no identifier. `HttpOnly`, `Secure`. | 24 hours |
+| `ytg_terms` | Records which version of these Terms and this Privacy Policy you agreed to on the check page, so the app does not ask twice. | 1 year |
-## Children's Privacy
+There are no advertising, tracking or third-party analytics cookies. Cloudflare's own security systems may set strictly necessary cookies of their own as described in Cloudflare's [cookie policy](https://www.cloudflare.com/cookie-policy/).
-This application is not directed at children under 13 and does not knowingly process any personal data from anyone.
+## 4. Legal bases (EEA/UK)
-## GDPR / CCPA / Equivalent Rights
+- Operating and securing the web app, including the bot check and its cookies: **legitimate interests** (Art. 6(1)(f) GDPR); the cookies are strictly necessary for a service you request, so they need no separate consent.
+- Aggregate, cookieless visit statistics: **legitimate interests** in understanding how the site is used.
+- Everything in section 1 is processed only on your device, by you.
-Because no data ever leaves your device:
+## 5. What is never done
-- **Right to access**: your data is already accessible — open DevTools → Application → Local Storage on the web, or browse the application-data directory on desktop.
-- **Right to erasure**: clear your browser's site data (web) or delete the application-data directory / uninstall the app (desktop).
-- **Right to portability**: use the in-app **Export** action in `Profiles` / `Presets` / `Templates` / `History` / `Logs` to download JSON.
-- **Right to object / restrict processing**: not applicable — no processing happens off-device.
-- **Right to know what is sold or shared**: nothing. Nothing is sold or shared.
+- No selling or renting of data, no advertising networks, no behavioural profiling.
+- No YouTube, Google, Steam or other third-party account access — the app never sees your channel.
+- No crash reporting or telemetry from the desktop or Android apps.
-## Changes to This Policy
+## 6. Your rights
-If this policy changes, the change is committed to the repository under `PRIVACY.md` with the `Effective` date updated. There is no notification mechanism because the application has no way to reach you.
+- **Access and portability:** your content is already on your device; use the export buttons in **Settings** and **Profiles** to save it as a file.
+- **Erasure:** clear site data (web) or uninstall the app / delete its folders (desktop, Android).
+- **Data processed by Cloudflare:** write to **privacy@poli0981.dev**. Because YTDescGen has no accounts, it holds no data that can be looked up by your name or email; requests about Cloudflare's own processing can also go to Cloudflare directly.
+- You may also complain to your local data-protection authority.
-## Contact
+## 7. Children
-`lopop05905@proton.me`
+YTDescGen is not directed at children under 13 (or the minimum age of digital consent in your country) and does not knowingly process their personal data.
+
+## 8. Changes
+
+Changes are published at [ytgenerator.stream/legal/privacy](https://ytgenerator.stream/legal/privacy) and in the repository's `PRIVACY.md`, with the **Effective** date updated. When a change is material, the app asks you to review and accept it again on your next visit.
+
+## 9. Contact
+
+- Privacy and data requests: **privacy@poli0981.dev**
+- Security issues: **security@poli0981.dev** (see the [Security Policy](SECURITY.md))
+- Everything else: **contact@poli0981.dev** · [poli0981.dev/links](https://poli0981.dev/links/)
diff --git a/SECURITY.md b/SECURITY.md
index c008c81..129d0ef 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -2,12 +2,12 @@
## Supported Versions
-Only the latest released version of YTDescGen receives security updates. This is a solo open-source project; there are no LTS branches.
+Only the latest released version of YTDescGen receives security updates, and the web app at https://ytgenerator.stream always runs the latest `main`. This is a solo open-source project; there are no LTS branches.
| Version | Supported |
| ------- | --------- |
-| 0.13.x | ✅ |
-| < 0.13 | ❌ |
+| 1.0.x | ✅ |
+| < 1.0 | ❌ |
## Reporting a Vulnerability
@@ -15,14 +15,16 @@ Please report security issues **privately**. Do not open a public issue.
**Preferred channels (in order):**
-1. **GitHub Security Advisory** — open a draft advisory in this repository's `Security` tab.
-2. **Email** — `lopop05905@proton.me` with subject prefix `[SECURITY]`.
+1. **GitHub Security Advisory** — [open a draft advisory](https://github.com/poli0981/youtube-generator/security/advisories/new) in this repository.
+2. **Email** — **security@poli0981.dev** with the subject prefix `[SECURITY]`.
+
+The same contacts are published in [`/.well-known/security.txt`](https://ytgenerator.stream/.well-known/security.txt) (RFC 9116).
Include:
- A description of the issue and its potential impact.
- Steps to reproduce, ideally a minimal proof-of-concept.
-- The affected version (`node -p "require('./package.json').version"`).
+- The affected version (About page, or `node -p "require('./package.json').version"`) or URL.
- Whether the issue is already public.
## Response Timeline
@@ -35,16 +37,22 @@ Include:
In scope:
-- The web bundle deployed to GitHub Pages.
-- The Tauri desktop binaries (Windows, macOS, Linux).
+- The web app at `ytgenerator.stream`, including its Cloudflare Worker (`worker/`): the Turnstile gate, its cookies, and the security headers.
+- The desktop binaries (Windows, macOS, Linux) and the Android APK published on the GitHub releases page, including the Tauri commands in `src-tauri/`.
- CI/CD workflows in `.github/workflows/`.
Out of scope:
- Vulnerabilities in third-party dependencies — report those upstream and we'll bump.
-- Issues requiring physical access to the user's device.
+- Cloudflare's own platform (Turnstile, Workers, the CDN) — report to [Cloudflare](https://www.cloudflare.com/disclosure/).
+- Volumetric denial-of-service, rate-limit or spam findings, and automated scanner output without a demonstrated impact.
+- Issues requiring physical access to the user's device, or a malicious browser extension.
- Self-XSS in user-supplied template content (the app deliberately renders user input as plain text in the preview).
+## Safe Harbour
+
+Good-faith research that follows this policy — no data destruction, no privacy violations of other users, no service degradation, and private reporting — will not be pursued.
+
## No Bounty
This is a solo open-source project. Credit in release notes and a thank-you in `MAINTAINERS.md` is the only reward we can offer.
diff --git a/TERMS.md b/TERMS.md
index 8f9ca99..4b30a84 100644
--- a/TERMS.md
+++ b/TERMS.md
@@ -1,14 +1,14 @@
# Terms of Use
-**Effective:** 2026-05-14
+**Effective:** 2026-09-30
-These terms govern your use of YTDescGen — both the web version hosted at the project's GitHub Pages URL and any Tauri desktop binaries distributed under this project.
+These terms govern your use of YTDescGen — the web app at **https://ytgenerator.stream** and the desktop and Android apps distributed from this project's [GitHub releases](https://github.com/poli0981/youtube-generator/releases). By using YTDescGen you agree to them, together with the [Privacy Policy](PRIVACY.md) and the [Disclaimer](DISCLAIMER.md).
## License
-YTDescGen is licensed under the **[Apache License 2.0](./LICENSE)**. You may use, modify, and redistribute it under those terms.
+YTDescGen's source code is licensed under the **[Apache License 2.0](LICENSE)**. You may use, modify, and redistribute it under those terms.
-Apache 2.0 grants a patent license (Section 3) and an irrevocable copyright license (Section 2). It does **not** grant trademark rights — see Section 6 of the LICENSE.
+Apache 2.0 grants a patent license (Section 3) and an irrevocable copyright license (Section 2). It does **not** grant trademark rights — see Section 6 of the LICENSE. The name "YTDescGen" and its logo identify this project; forks should use their own name.
## Acceptable Use
@@ -21,18 +21,19 @@ You may use YTDescGen for any lawful purpose. You may **not** use it to:
- Violate applicable law in your jurisdiction, including but not limited to **GDPR** (EU), **CCPA / CPRA** (California), **PIPL** (China), **LGPD** (Brazil), the **Vietnamese Cybersecurity Law**, or equivalent data-protection / cybercrime regulation in your country.
- Bypass YouTube's policies on metadata (misleading thumbnails / titles / tags) using the application.
-## GitHub Terms
+## The web app
-If you use the web version hosted on GitHub Pages, your use is also subject to:
+The web app is hosted on Cloudflare. To keep it available for people, it asks each browser to pass a short **Cloudflare Turnstile** check before entering. When using the web app you must not:
-- [GitHub's Terms of Service](https://docs.github.com/en/site-policy/github-terms/github-terms-of-service)
-- [GitHub's Acceptable Use Policies](https://docs.github.com/en/site-policy/acceptable-use-policies)
+- Attempt to bypass, automate, or defeat the check, or reuse its cookies outside the browser that earned them.
+- Scrape, crawl at volume, load-test, or otherwise place an unreasonable load on the site.
+- Probe for vulnerabilities outside the process in the [Security Policy](SECURITY.md).
-These apply alongside this document; in case of conflict, GitHub's policies govern the hosted artifact.
+The web app is provided free of charge and may be changed, rate-limited, or taken offline at any time without notice. The desktop and Android apps work without it.
## No Warranty
-See [DISCLAIMER.md](./DISCLAIMER.md) and `LICENSE` §§ 7–8. The software is provided **as-is** with no warranty of any kind, express or implied.
+See [DISCLAIMER.md](DISCLAIMER.md) and `LICENSE` §§ 7–8. The software is provided **as-is** with no warranty of any kind, express or implied.
## Generated Content
@@ -43,6 +44,10 @@ YTDescGen produces text intended to be pasted into YouTube descriptions. **You
- Not including misleading information, copyright-infringing material, or any prohibited content listed in YouTube's policies.
- Truthful representation of run-type, difficulty, blind status, mod / cheat usage, and similar disclosures the application optionally exposes.
+## Copyright Complaints
+
+If you believe material in this project's repository, releases or website infringes your copyright, send a notice to **dmca@poli0981.dev** with: identification of the work, the location of the material, your contact details, a good-faith statement that the use is not authorised, and a statement — under penalty of perjury — that the notice is accurate and that you are the owner or authorised to act for the owner. Licensing and attribution questions go to **copyright@poli0981.dev**.
+
## Contributions
By submitting a contribution (issue, pull request, comment, locale translation, screenshot, log dump), you agree:
@@ -50,18 +55,18 @@ By submitting a contribution (issue, pull request, comment, locale translation,
1. Your contribution is licensed under Apache 2.0, the same as the project.
2. You have the right to grant that license (you wrote it, or it's compatibly licensed and credited).
3. You will not include malicious code or knowingly vulnerable dependencies.
-4. You will follow the [Code of Conduct](./CODE_OF_CONDUCT.md) and [Contributing Guide](./CONTRIBUTING.md).
+4. You will follow the [Code of Conduct](CODE_OF_CONDUCT.md) and [Contributing Guide](CONTRIBUTING.md).
-Violations may result in your contribution being closed and, in severe cases, a permanent ban from the repository — see `CONTRIBUTING.md` § "Auto-ignored Contributions".
+Violations may result in your contribution being closed and, in severe cases, a permanent ban from the repository — see `CONTRIBUTING.md` § "Auto-ignored Contributions". Contributions made on GitHub are also subject to [GitHub's Terms of Service](https://docs.github.com/en/site-policy/github-terms/github-terms-of-service).
## Termination
-These terms remain in effect for as long as you use the software. Your rights under Apache 2.0 are perpetual subject to that license's termination clauses (notably § 3 patent retaliation).
+These terms remain in effect for as long as you use the software. Your rights under Apache 2.0 are perpetual subject to that license's termination clauses (notably § 3 patent retaliation). Access to the web app may be refused to anyone who breaks the rules in "The web app" above.
## Changes
-Updates to these terms are committed under `TERMS.md` with the `Effective` date updated. Continued use of the software after a change constitutes acceptance.
+Updates are published at [ytgenerator.stream/legal/terms](https://ytgenerator.stream/legal/terms) and in the repository's `TERMS.md`, with the `Effective` date updated. When a change is material, the app asks you to review and accept it again; continued use after that constitutes acceptance.
## Contact
-`lopop05905@proton.me`
+Legal questions: **legal@poli0981.dev** · Everything else: **contact@poli0981.dev**
diff --git a/build-plugins/legal-docs.ts b/build-plugins/legal-docs.ts
new file mode 100644
index 0000000..a61f7ef
--- /dev/null
+++ b/build-plugins/legal-docs.ts
@@ -0,0 +1,333 @@
+import { readFileSync } from "fs";
+import { posix, resolve } from "path";
+import { Marked, type Tokens } from "marked";
+import type { Plugin } from "vite";
+import { LOGO_SVG, SITE_ORIGIN } from "../src/config/brand.ts";
+import { LEGAL_DOCS, legalDocPath, type LegalDoc, type LegalDocId } from "../src/config/legal.ts";
+
+/**
+ * Renders the repo-root legal documents at build time, twice:
+ *
+ * 1. `virtual:legal-docs` — { [id]: { title, effective, html: { en, vi? } } },
+ * imported lazily by the in-app Legal Center, so desktop and Android carry
+ * the documents offline and nothing is fetched from GitHub any more.
+ * 2. `dist/legal/.html` (+ `.vi.html`, `index.html`) — plain pages
+ * with no script, which the Cloudflare Worker serves to anyone, before the
+ * Turnstile gate: people must be able to read the Terms and the Privacy
+ * Policy before they are asked to agree to them.
+ *
+ * `marked` runs only here, in Node — it adds nothing to the app bundle.
+ */
+
+const VIRTUAL_ID = "virtual:legal-docs";
+const RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`;
+const REPO_BLOB = "https://github.com/poli0981/youtube-generator/blob/main/";
+const ROOT = resolve(import.meta.dirname, "..");
+
+type DocLang = "en" | "vi";
+
+export interface RenderedLegalDoc {
+ title: string;
+ /** ISO date from an `**Effective:**` / `**Last updated:**` line, if any. */
+ effective: string | null;
+ html: Partial>;
+}
+
+/** Repo-relative source file → document id, for cross-document links. */
+const SOURCE_TO_ID: ReadonlyMap = new Map(
+ LEGAL_DOCS.flatMap((doc): [string, LegalDocId][] =>
+ doc.sourceVi
+ ? [
+ [doc.source, doc.id],
+ [doc.sourceVi, doc.id],
+ ]
+ : [[doc.source, doc.id]],
+ ),
+);
+
+/** Titles for the plain-text sources, which have no heading to read. */
+const PLAIN_TEXT_TITLES: Partial> = {
+ license: "Apache License 2.0",
+ notice: "NOTICE",
+};
+
+const HTML_ESCAPES: Readonly> = {
+ "&": "&",
+ "<": "<",
+ ">": ">",
+ '"': """,
+ "'": "'",
+};
+
+export function escapeHtml(text: string): string {
+ return text.replace(/[&<>"']/g, (ch) => HTML_ESCAPES[ch] ?? ch);
+}
+
+/** Point relative links at the in-site page, or at GitHub for anything else. */
+export function rewriteHref(href: string, fromFile: string): string {
+ if (/^(?:[a-z][a-z0-9+.-]*:|#)/i.test(href)) return href;
+ const hashAt = href.indexOf("#");
+ const pathPart = hashAt >= 0 ? href.slice(0, hashAt) : href;
+ const hash = hashAt >= 0 ? href.slice(hashAt) : "";
+ const resolved = posix.normalize(posix.join(posix.dirname(fromFile), pathPart));
+ const id = SOURCE_TO_ID.get(resolved);
+ return id ? `${legalDocPath(id)}${hash}` : `${REPO_BLOB}${resolved}${hash}`;
+}
+
+function slugify(text: string): string {
+ return text
+ .toLowerCase()
+ .replace(/<[^>]+>/g, "")
+ .replace(/[`*_~[\]()]/g, "")
+ .trim()
+ .replace(/[^\p{L}\p{N}]+/gu, "-")
+ .replace(/^-+|-+$/g, "");
+}
+
+function stripInlineMarkdown(text: string): string {
+ return text
+ .replace(/[`*_~]/g, "")
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
+ .trim();
+}
+
+export function renderMarkdown(source: string, fromFile: string): { title: string; html: string } {
+ // Links are rewritten in the renderer rather than a `walkTokens` hook: that
+ // hook only runs inside `marked.parse()`, and this renders via
+ // `lexer()` + `parser()` so it can read the title from the tokens.
+ const marked = new Marked({
+ gfm: true,
+ renderer: {
+ heading({ tokens, depth, text }) {
+ const inner = this.parser.parseInline(tokens);
+ return `${inner}\n`;
+ },
+ link({ href, title, tokens }) {
+ const inner = this.parser.parseInline(tokens);
+ const target = rewriteHref(href, fromFile);
+ const external = /^https?:/i.test(target);
+ const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
+ const rel = external ? ` target="_blank" rel="noopener noreferrer"` : "";
+ return `${inner}`;
+ },
+ },
+ });
+ const tokens = marked.lexer(source);
+ const h1 = tokens.find((t): t is Tokens.Heading => t.type === "heading" && t.depth === 1);
+ const html = marked.parser(tokens);
+ return { title: h1 ? stripInlineMarkdown(h1.text) : "", html };
+}
+
+export function extractEffectiveDate(source: string): string | null {
+ const match =
+ /\*\*(?:Effective(?: date)?|Last updated|Ngày hiệu lực|Cập nhật lần cuối):?\*\*:?\s*(\d{4}-\d{2}-\d{2})/i.exec(
+ source,
+ );
+ return match?.[1] ?? null;
+}
+
+function readSource(file: string): string {
+ return readFileSync(resolve(ROOT, file), "utf8").replace(/\r\n/g, "\n");
+}
+
+function renderSource(doc: LegalDoc, file: string): { title: string; html: string } {
+ const text = readSource(file);
+ if (file.endsWith(".md")) return renderMarkdown(text, file);
+ return {
+ title: PLAIN_TEXT_TITLES[doc.id] ?? doc.id,
+ html: `
${escapeHtml(text.trim())}
`,
+ };
+}
+
+export function renderAllLegalDocs(): Record {
+ const out = {} as Record;
+ for (const doc of LEGAL_DOCS) {
+ const en = renderSource(doc, doc.source);
+ const rendered: RenderedLegalDoc = {
+ title: en.title,
+ effective: extractEffectiveDate(readSource(doc.source)),
+ html: { en: en.html },
+ };
+ if (doc.sourceVi) rendered.html.vi = renderSource(doc, doc.sourceVi).html;
+ out[doc.id] = rendered;
+ }
+ return out;
+}
+
+// ---------------------------------------------------------------------------
+// Static pages
+
+const PAGE_CSS = `
+:root{color-scheme:dark light;--bg:#0b0b12;--card:#12121a;--border:#262636;--text:#e7e7ef;--muted:#9a9ab0;--link:#a5a6fb;--code:#1b1b27;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif}
+@media (prefers-color-scheme:light){:root{--bg:#f7f7fb;--card:#fff;--border:#e3e3ee;--text:#17171f;--muted:#5b5b70;--link:#4f46e5;--code:#f1f1f7}}
+*{box-sizing:border-box}
+body{margin:0;background:var(--bg);color:var(--text);line-height:1.65}
+a{color:var(--link)}
+a:focus-visible{outline:2px solid var(--link);outline-offset:2px}
+.top{position:sticky;top:0;z-index:1;display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 20px;background:color-mix(in srgb,var(--bg) 86%,transparent);backdrop-filter:blur(10px);border-bottom:1px solid var(--border)}
+.brand{display:flex;align-items:center;gap:10px;color:var(--text);text-decoration:none;font-weight:700;letter-spacing:-.01em}
+.brand svg{width:28px;height:28px}
+.open{font-size:14px;font-weight:600;text-decoration:none;padding:7px 14px;border-radius:10px;color:#fff;background:linear-gradient(135deg,#6366f1,#a855f7)}
+.layout{display:grid;grid-template-columns:220px minmax(0,1fr);gap:32px;max-width:1080px;margin:0 auto;padding:32px 20px 64px}
+nav p{margin:0 0 8px;font-size:12px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--muted)}
+nav ul{list-style:none;margin:0;padding:0;position:sticky;top:76px}
+nav a{display:block;padding:6px 10px;border-radius:8px;color:var(--muted);text-decoration:none;font-size:14px}
+nav a:hover{color:var(--text);background:var(--card)}
+nav a[aria-current=page]{color:var(--text);background:var(--card);font-weight:600}
+article{min-width:0;background:var(--card);border:1px solid var(--border);border-radius:16px;padding:28px 32px}
+.meta{display:flex;flex-wrap:wrap;gap:8px 16px;margin:0 0 20px;font-size:13px;color:var(--muted)}
+article h1{font-size:28px;line-height:1.25;margin:0 0 8px;letter-spacing:-.015em}
+article h2{font-size:20px;margin:32px 0 10px;padding-top:8px;border-top:1px solid var(--border)}
+article h3{font-size:16px;margin:24px 0 8px}
+article p,article li{font-size:15px}
+article table{width:100%;border-collapse:collapse;margin:16px 0;font-size:14px;display:block;overflow-x:auto}
+article th,article td{text-align:left;padding:8px 10px;border-bottom:1px solid var(--border);vertical-align:top}
+article code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.88em;background:var(--code);padding:.12em .38em;border-radius:6px}
+article pre{background:var(--code);padding:16px;border-radius:12px;overflow-x:auto;font-size:13px;line-height:1.55}
+article pre code{background:none;padding:0}
+article pre.plain{white-space:pre-wrap;word-break:break-word}
+article blockquote{margin:16px 0;padding:4px 16px;border-left:3px solid #6366f1;color:var(--muted)}
+.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:12px;margin-top:20px}
+.cards a{display:block;padding:16px;border:1px solid var(--border);border-radius:12px;text-decoration:none;color:var(--text);background:var(--bg)}
+.cards a:hover{border-color:#6366f1}
+.cards span{display:block;font-size:13px;color:var(--muted);margin-top:4px;line-height:1.5}
+footer{max-width:1080px;margin:0 auto;padding:0 20px 40px;font-size:13px;color:var(--muted)}
+@media (max-width:760px){.layout{grid-template-columns:1fr;padding-top:20px}nav ul{position:static;display:flex;flex-wrap:wrap;gap:4px}article{padding:20px 18px}}
+`;
+
+/** One-line summaries for the static Legal index (English, like the pages). */
+const DOC_SUMMARIES: Readonly> = {
+ terms: "What you may and may not do with YTDescGen and what it generates.",
+ privacy: "What stays on your device, and what Cloudflare processes on the web.",
+ disclaimer: "No warranty, AI-assisted development and translations, no affiliation.",
+ license: "The Apache License 2.0 the source code is released under.",
+ "third-party": "Open-source libraries, fonts and services YTDescGen relies on.",
+ security: "How to report a vulnerability privately, and what is in scope.",
+ notice: "The Apache-2.0 NOTICE file with copyright and attribution.",
+ conduct: "Contributor Covenant rules for the project's community spaces.",
+};
+
+function pageShell(options: {
+ title: string;
+ canonicalPath: string;
+ description: string;
+ activeId: LegalDocId | null;
+ body: string;
+ lang: DocLang;
+}): string {
+ const nav = LEGAL_DOCS.map((doc) => {
+ const current = doc.id === options.activeId ? ' aria-current="page"' : "";
+ return `