Transforme XIP en réseau social satirique complet : monnaie fictive, marketplace, cosmétiques visibles de tous, messages riches sandboxés, pubs pilotées par les données, et tous les compteurs mock rendus réels. Backend (Bun + Hono + Prisma + Redis) - Économie par IP : modèles Wallet/Purchase/Entitlement, lib/wallet.ts avec spend() atomique (point unique du paywall) + recharge gratuite. - isLocalhost() → mode gratuit (README « si localhost: pas de paywall »). - Marketplace : lib/catalog.ts (achat transactionnel, stock limité, limites par IP) + routes/shop.ts ; 10 produits seedés (idempotent). - Perks : lib/perks.ts (cache Redis busté à l'achat) ; authorPerks injecté dans les payloads messages + endpoint batch /api/perks ; frame WS « perks » global pour MAJ live des messages déjà affichés. - Messages riches : Message.richMode/richContent, gating par entitlement. - Pubs réelles : modèle Ad seedé avec les 4 pubs (ex-hardcodées), rotation par API, comptage d'impressions réel + réconciliation. - WebSocket : IP capturée par connexion → broadcastToIp / broadcast ; frames wallet/perks/ads/alert. - Pièces jointes : lib/storage.ts (UUID, jamais exécuté) + routes/uploads.ts (limite 1 Mo sauf déblocage/localhost, Content-Disposition: attachment). - Alerte audio : routes/alert.ts (cooldown serveur Redis NX, clamp durée). - Compteur « argent extorqué » réel : impressions×CPM + crédits dépensés. Frontend (Vue 3 + Vite) - /shop : ShopPage + ProductCard fidèles aux maquettes ; composables useWallet/useShop/usePerks/useAds/useAttachments/useAlert. - UI de réponse (bannière + sous-threads), solde + lien Shop dans le header. - Perks rendus : Style Doré (or), Pets autour de l'IP, NoAds masque les pubs. - RichContent.vue : iframe sandbox verrouillée (htmlcss sans script ; js allow-scripts seul, jamais allow-same-origin) + CSP. - AdBand/InlineCasinoAd pilotés par l'API ; barre de saisie avec 📎, compteur de caractères, composer riche et bouton alerte. Infra - Migration economy_ads_attachments_rich ; seed idempotent (produits+pubs). - vite.config : usePolling (HMR fiable sur /mnt/c via WSL). - backend/.gitignore : uploads/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { Hono } from "hono";
|
|
import { getClientIp, isLocalhost } from "../lib/ip";
|
|
import { prisma } from "../lib/prisma";
|
|
import { redis } from "../lib/redis";
|
|
import { spend } from "../lib/wallet";
|
|
import { broadcast } from "../realtime";
|
|
|
|
const alert = new Hono();
|
|
|
|
const COOLDOWN_MS = 60_000; // server-enforced global cooldown
|
|
const MAX_DURATION_MS = 5_000; // server clamps how long the sound may play
|
|
const ALERT_PRICE = 999; // centi-credits per fire (consumable)
|
|
const COOLDOWN_KEY = "xip:alert:cooldown";
|
|
|
|
// POST /api/alert { soundUrl? }
|
|
alert.post("/", async (c) => {
|
|
const ip = getClientIp(c);
|
|
|
|
let body: { soundUrl?: string } = {};
|
|
try {
|
|
body = await c.req.json();
|
|
} catch {
|
|
/* no body is fine */
|
|
}
|
|
|
|
// Must own the audio-alert entitlement (localhost bypasses).
|
|
if (!isLocalhost(ip)) {
|
|
const owned = await prisma.entitlement.findFirst({
|
|
where: { ip, kind: "audio-alert", active: true },
|
|
});
|
|
if (!owned) {
|
|
return c.json({ error: "Débloque l'alerte audio dans le Shop" }, 402);
|
|
}
|
|
}
|
|
|
|
// Global cooldown via Redis NX+PX.
|
|
const ok = await redis
|
|
.set(COOLDOWN_KEY, ip, "PX", COOLDOWN_MS, "NX")
|
|
.catch(() => null);
|
|
if (ok !== "OK") {
|
|
const ttl = await redis.pttl(COOLDOWN_KEY).catch(() => 0);
|
|
return c.json({ error: "Cooldown actif", retryInMs: Math.max(0, ttl) }, 429);
|
|
}
|
|
|
|
// Charge the consumable (skipped for localhost free mode).
|
|
try {
|
|
await spend(ip, ALERT_PRICE, "audio-alert");
|
|
} catch {
|
|
await redis.del(COOLDOWN_KEY).catch(() => {});
|
|
return c.json({ error: "Crédits insuffisants" }, 402);
|
|
}
|
|
|
|
// Validate a supplied mp3 URL (must be one of our own /api/uploads/ paths).
|
|
let soundUrl: string | undefined;
|
|
if (typeof body.soundUrl === "string" && body.soundUrl.includes("/api/uploads/")) {
|
|
soundUrl = body.soundUrl;
|
|
}
|
|
|
|
broadcast({
|
|
type: "alert",
|
|
data: { ip, soundUrl, maxDurationMs: MAX_DURATION_MS, volume: 1 },
|
|
});
|
|
|
|
return c.json({ ok: true });
|
|
});
|
|
|
|
export default alert;
|