Riscrivi backend per hosting Node/MariaDB/PM2 (no Cloudflare)
L'utente ha un hosting Virtualmin esistente (musictools.djluza.com)
con Apache + Node 20 + MariaDB + PM2. Tutta l'infrastruttura
Cloudflare (Workers/D1/R2/Pages) e' rimpiazzata con un backend
Express che gira sul server gia' presente, a costo zero.
Cambia:
- server/src/*.ts (Workers) -> server/src/*.js (Node ESM puro)
- D1 (sqlite) -> MariaDB 10.11 via mysql2/promise
- R2 (storage) -> filesystem locale ~/builds/ + signed URL HMAC
- wrangler.toml -> ecosystem.config.cjs (PM2)
- Aggiunto src/migrate.js: runner SQL idempotente
Endpoints invariati - l'app desktop non vede differenze:
- POST /api/license/{activate,validate,deactivate}
- GET /api/latest, /api/download
- POST /api/webhook/lemonsqueezy
- GET /api/health
README riscritto con istruzioni complete: creazione DB,
deploy via rsync/git, config Apache reverse proxy via
Virtualmin, gestione PM2, backup, workflow release.
Email rimane su Resend (deliverability) - free tier sufficiente.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
339dd4f3cc
commit
2d8290579b
22 files changed
+892
-790
No files matched your search
@@ -1,42 +1,49 @@
|
||||
-- Schema iniziale licenze MusicTools
|
||||
-- Schema MariaDB iniziale per MusicTools licenze.
|
||||
-- Tutto utf8mb4 + InnoDB con FK abilitate.
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS licenses (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
license_key TEXT NOT NULL UNIQUE,
|
||||
email TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'active', -- active | revoked | refunded
|
||||
source TEXT, -- es. 'lemonsqueezy', 'manual'
|
||||
order_id TEXT, -- id dell'ordine LS
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_licenses_email ON licenses(email);
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
license_key VARCHAR(64) NOT NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
status ENUM('active','revoked','refunded') NOT NULL DEFAULT 'active',
|
||||
source VARCHAR(32) NULL,
|
||||
order_id VARCHAR(64) NULL,
|
||||
created_at BIGINT UNSIGNED NOT NULL,
|
||||
updated_at BIGINT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_licenses_key (license_key),
|
||||
KEY idx_licenses_email (email),
|
||||
KEY idx_licenses_order_id (order_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS activations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
license_id INTEGER NOT NULL REFERENCES licenses(id) ON DELETE CASCADE,
|
||||
device_id TEXT NOT NULL,
|
||||
device_name TEXT,
|
||||
app_version TEXT,
|
||||
activated_at INTEGER NOT NULL,
|
||||
last_seen_at INTEGER NOT NULL,
|
||||
revoked_at INTEGER,
|
||||
UNIQUE (license_id, device_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_activations_license ON activations(license_id);
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
license_id INT UNSIGNED NOT NULL,
|
||||
device_id VARCHAR(64) NOT NULL,
|
||||
device_name VARCHAR(255) NULL,
|
||||
app_version VARCHAR(32) NULL,
|
||||
activated_at BIGINT UNSIGNED NOT NULL,
|
||||
last_seen_at BIGINT UNSIGNED NOT NULL,
|
||||
revoked_at BIGINT UNSIGNED NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_activations_lic_dev (license_id, device_id),
|
||||
KEY idx_activations_license (license_id),
|
||||
CONSTRAINT fk_activations_license
|
||||
FOREIGN KEY (license_id) REFERENCES licenses(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS releases (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
version TEXT NOT NULL,
|
||||
platform TEXT NOT NULL, -- macos | windows
|
||||
r2_key TEXT NOT NULL, -- chiave dentro il bucket R2
|
||||
size_bytes INTEGER,
|
||||
sha256 TEXT,
|
||||
notes TEXT,
|
||||
published_at INTEGER NOT NULL,
|
||||
UNIQUE (version, platform)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_releases_platform_pub ON releases(platform, published_at DESC);
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
version VARCHAR(32) NOT NULL,
|
||||
platform ENUM('macos','windows') NOT NULL,
|
||||
file_path VARCHAR(512) NOT NULL,
|
||||
size_bytes BIGINT UNSIGNED NULL,
|
||||
sha256 CHAR(64) NULL,
|
||||
notes TEXT NULL,
|
||||
published_at BIGINT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_releases_ver_plat (version, platform),
|
||||
KEY idx_releases_platform_pub (platform, published_at DESC)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
Reference in new issue
Block a user