Compare commits
4 Commits
b6b1ee9ceb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b569fc6067 | |||
| 4f6361b4ba | |||
| 25134ecc36 | |||
| 7fba3645c3 |
@@ -15,11 +15,11 @@ jobs:
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.alwisp.com
|
||||
username: ${{ gitea.repository_owner }}
|
||||
registry: registry.alwisp.com
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and Push
|
||||
run: |
|
||||
docker build -t git.alwisp.com/${{ gitea.repository_owner }}/${{ gitea.repository }}:latest .
|
||||
docker push git.alwisp.com/${{ gitea.repository_owner }}/${{ gitea.repository }}:latest
|
||||
docker build -t registry.alwisp.com/${{ gitea.repository_owner }}/${{ gitea.repository }}:latest .
|
||||
docker push registry.alwisp.com/${{ gitea.repository_owner }}/${{ gitea.repository }}:latest
|
||||
@@ -43,6 +43,11 @@ db.exec(`
|
||||
name TEXT UNIQUE NOT NULL COLLATE NOCASE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS meme_tags (
|
||||
meme_id TEXT NOT NULL REFERENCES memes(id) ON DELETE CASCADE,
|
||||
tag_id INTEGER NOT NULL REFERENCES tags(id) ON DELETE CASCADE,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { authRoutes } from './routes/auth.js';
|
||||
import { collectionsRoutes } from './routes/collections.js';
|
||||
import { adminRoutes } from './routes/admin.js';
|
||||
import { shareRoutes } from './routes/share.js';
|
||||
import { settingsRoutes } from './routes/settings.js';
|
||||
|
||||
// Ensure data dirs exist
|
||||
ensureImagesDir();
|
||||
@@ -46,6 +47,7 @@ await app.register(tagsRoutes);
|
||||
await app.register(adminRoutes);
|
||||
|
||||
await app.register(shareRoutes);
|
||||
await app.register(settingsRoutes);
|
||||
|
||||
// SPA fallback — serve index.html for all non-API, non-image routes
|
||||
app.setNotFoundHandler(async (req, reply) => {
|
||||
|
||||
38
backend/src/routes/settings.ts
Normal file
38
backend/src/routes/settings.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import db from '../db.js';
|
||||
import { requireAuth } from '../auth.js';
|
||||
|
||||
type SettingsRow = { key: string; value: string };
|
||||
|
||||
function getAllSettings(): Record<string, string> {
|
||||
const rows = db.prepare('SELECT key, value FROM settings').all() as SettingsRow[];
|
||||
return Object.fromEntries(rows.map((r) => [r.key, r.value]));
|
||||
}
|
||||
|
||||
export async function settingsRoutes(app: FastifyInstance) {
|
||||
// Public — anyone can read settings (needed to render logo for guests)
|
||||
app.get('/api/settings', async () => {
|
||||
return getAllSettings();
|
||||
});
|
||||
|
||||
// Admin — update one or more settings keys
|
||||
app.put<{ Body: Record<string, string> }>(
|
||||
'/api/settings',
|
||||
{ preHandler: requireAuth },
|
||||
async (req) => {
|
||||
const allowed = new Set(['logo_url']);
|
||||
const stmt = db.prepare(
|
||||
'INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'
|
||||
);
|
||||
for (const [key, value] of Object.entries(req.body)) {
|
||||
if (!allowed.has(key)) continue;
|
||||
if (value === '' || value == null) {
|
||||
db.prepare('DELETE FROM settings WHERE key = ?').run(key);
|
||||
} else {
|
||||
stmt.run(key, String(value));
|
||||
}
|
||||
}
|
||||
return getAllSettings();
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
<meta property="og:image" content="${escapeHtml(imageUrl)}" />
|
||||
<meta property="og:image:width" content="${meme.width}" />
|
||||
<meta property="og:image:height" content="${meme.height}" />
|
||||
<meta property="og:site_name" content="Memer" />
|
||||
<meta property="og:site_name" content="MEMER" />
|
||||
|
||||
<!-- Twitter / X card -->
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
@@ -114,7 +114,7 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
<p class="title">${title}</p>
|
||||
<a class="btn" href="${escapeHtml(galleryUrl)}">
|
||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
|
||||
Open in Memer
|
||||
Open in MEMER
|
||||
</a>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Memer</title>
|
||||
<title>MEMER</title>
|
||||
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🎭</text></svg>" />
|
||||
</head>
|
||||
<body class="bg-zinc-950 text-zinc-100 min-h-screen">
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { Gallery } from './pages/Gallery';
|
||||
import { useSettings } from './hooks/useSettings';
|
||||
|
||||
function FaviconUpdater() {
|
||||
const { data: settings } = useSettings();
|
||||
|
||||
useEffect(() => {
|
||||
const logoUrl = settings?.logo_url;
|
||||
if (!logoUrl) return;
|
||||
|
||||
let link = document.querySelector<HTMLLinkElement>('link[rel~="icon"]');
|
||||
if (!link) {
|
||||
link = document.createElement('link');
|
||||
link.rel = 'icon';
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
link.href = logoUrl;
|
||||
}, [settings?.logo_url]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/" element={<Gallery />} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
<>
|
||||
<FaviconUpdater />
|
||||
<Routes>
|
||||
<Route path="/" element={<Gallery />} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -147,6 +147,19 @@ export const api = {
|
||||
},
|
||||
},
|
||||
|
||||
settings: {
|
||||
get(): Promise<Record<string, string>> {
|
||||
return apiFetch('/api/settings');
|
||||
},
|
||||
update(body: Record<string, string>): Promise<Record<string, string>> {
|
||||
return apiFetch('/api/settings', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
admin: {
|
||||
reindexStatus(): Promise<{ pending: number; indexed: number }> {
|
||||
return apiFetch('/api/admin/reindex/status');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { X, ScanText, Database, RefreshCw, CheckCircle2, AlertCircle, Loader2, Share2, MousePointerClick } from 'lucide-react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { X, ScanText, Database, RefreshCw, CheckCircle2, AlertCircle, Loader2, Share2, MousePointerClick, ImageIcon, Save } from 'lucide-react';
|
||||
import { useReindexStatus, useReindex, useCollections, useTags, useMemes, useAdminStats } from '../hooks/useMemes';
|
||||
import { useSettings, useUpdateSettings } from '../hooks/useSettings';
|
||||
|
||||
interface Props {
|
||||
onClose: () => void;
|
||||
@@ -13,14 +14,32 @@ export function SettingsModal({ onClose }: Props) {
|
||||
const { data: tags } = useTags();
|
||||
const { data: allMemes } = useMemes({ parent_only: false, limit: 1 });
|
||||
const { data: adminStats } = useAdminStats();
|
||||
const { data: settings } = useSettings();
|
||||
const updateSettings = useUpdateSettings();
|
||||
|
||||
const [logoInput, setLogoInput] = useState('');
|
||||
const [logoPreviewError, setLogoPreviewError] = useState(false);
|
||||
|
||||
// Populate field when settings load
|
||||
useEffect(() => {
|
||||
if (settings?.logo_url !== undefined) {
|
||||
setLogoInput(settings.logo_url ?? '');
|
||||
}
|
||||
}, [settings?.logo_url]);
|
||||
|
||||
async function handleReindex() {
|
||||
await reindex.mutateAsync();
|
||||
refetchStatus();
|
||||
}
|
||||
|
||||
async function saveLogo() {
|
||||
await updateSettings.mutateAsync({ logo_url: logoInput.trim() });
|
||||
}
|
||||
|
||||
const logoChanged = logoInput.trim() !== (settings?.logo_url ?? '');
|
||||
const hasPending = (status?.pending ?? 0) > 0;
|
||||
const reindexResult = reindex.data;
|
||||
const previewUrl = logoInput.trim();
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -37,6 +56,54 @@ export function SettingsModal({ onClose }: Props) {
|
||||
</div>
|
||||
|
||||
<div className="overflow-y-auto flex-1 p-5 space-y-6">
|
||||
|
||||
{/* Branding */}
|
||||
<section>
|
||||
<h3 className="text-xs font-semibold text-zinc-500 uppercase tracking-wider mb-3 flex items-center gap-1.5">
|
||||
<ImageIcon size={12} /> Branding
|
||||
</h3>
|
||||
|
||||
<label className="block text-xs text-zinc-500 mb-1.5">Logo URL</label>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="url"
|
||||
value={logoInput}
|
||||
onChange={(e) => { setLogoInput(e.target.value); setLogoPreviewError(false); }}
|
||||
placeholder="https://example.com/logo.png"
|
||||
className="flex-1 bg-zinc-800 border border-zinc-700 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-accent placeholder-zinc-600"
|
||||
/>
|
||||
<button
|
||||
onClick={saveLogo}
|
||||
disabled={!logoChanged || updateSettings.isPending}
|
||||
className="flex items-center gap-1.5 px-3 py-2 rounded-lg bg-accent hover:bg-accent-hover text-white text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed flex-shrink-0"
|
||||
>
|
||||
{updateSettings.isPending ? <Loader2 size={14} className="animate-spin" /> : <Save size={14} />}
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Live preview */}
|
||||
{previewUrl && !logoPreviewError && (
|
||||
<div className="mt-3 flex items-center gap-3 bg-zinc-800/60 rounded-lg px-4 py-3">
|
||||
<img
|
||||
src={previewUrl}
|
||||
alt="Logo preview"
|
||||
className="h-8 w-auto object-contain"
|
||||
onError={() => setLogoPreviewError(true)}
|
||||
/>
|
||||
<span className="text-xs text-zinc-500">Header & favicon preview</span>
|
||||
</div>
|
||||
)}
|
||||
{previewUrl && logoPreviewError && (
|
||||
<p className="mt-2 text-xs text-red-400">Could not load image — check the URL.</p>
|
||||
)}
|
||||
{!previewUrl && settings?.logo_url == null && (
|
||||
<p className="mt-2 text-xs text-zinc-600">Leave blank to use the default 🎭 emoji logo.</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<div className="border-t border-zinc-800" />
|
||||
|
||||
{/* Library Stats */}
|
||||
<section>
|
||||
<h3 className="text-xs font-semibold text-zinc-500 uppercase tracking-wider mb-3 flex items-center gap-1.5">
|
||||
@@ -69,7 +136,6 @@ export function SettingsModal({ onClose }: Props) {
|
||||
<ScanText size={12} /> OCR Index
|
||||
</h3>
|
||||
|
||||
{/* Status row */}
|
||||
<div className="flex items-center justify-between bg-zinc-800/60 rounded-lg px-4 py-3 mb-3">
|
||||
{statusLoading ? (
|
||||
<span className="text-sm text-zinc-500">Checking…</span>
|
||||
@@ -96,7 +162,6 @@ export function SettingsModal({ onClose }: Props) {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Result banner */}
|
||||
{reindexResult && !reindex.isPending && (
|
||||
<div className={`flex items-start gap-2.5 rounded-lg px-4 py-3 mb-3 text-sm ${
|
||||
reindexResult.no_text_found > 0
|
||||
|
||||
20
frontend/src/hooks/useSettings.ts
Normal file
20
frontend/src/hooks/useSettings.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '../api/client';
|
||||
|
||||
export function useSettings() {
|
||||
return useQuery({
|
||||
queryKey: ['settings'],
|
||||
queryFn: () => api.settings.get(),
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateSettings() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (body: Record<string, string>) => api.settings.update(body),
|
||||
onSuccess: (data) => {
|
||||
qc.setQueryData(['settings'], data);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { LoginModal } from '../components/LoginModal';
|
||||
import { SharePanel } from '../components/SharePanel';
|
||||
import { CollectionBar } from '../components/CollectionBar';
|
||||
import { SettingsModal } from '../components/SettingsModal';
|
||||
import { useSettings } from '../hooks/useSettings';
|
||||
import type { Meme } from '../api/client';
|
||||
|
||||
const PAGE_SIZE = 100;
|
||||
@@ -30,6 +31,8 @@ export function Gallery() {
|
||||
const { data: auth } = useAuth();
|
||||
const logout = useLogout();
|
||||
const isAdmin = auth?.authenticated === true;
|
||||
const { data: settings } = useSettings();
|
||||
const logoUrl = settings?.logo_url;
|
||||
|
||||
const { data: collections } = useCollections();
|
||||
|
||||
@@ -99,8 +102,14 @@ export function Gallery() {
|
||||
<div className="max-w-screen-2xl mx-auto px-4 py-3 flex items-center gap-3">
|
||||
{/* Logo */}
|
||||
<div className="flex items-center gap-2 mr-2 flex-shrink-0">
|
||||
<span className="text-2xl">🎭</span>
|
||||
<span className="font-bold text-lg tracking-tight hidden sm:block">Memer</span>
|
||||
{logoUrl ? (
|
||||
<img src={logoUrl} alt="Logo" className="h-8 w-auto object-contain" />
|
||||
) : (
|
||||
<>
|
||||
<span className="text-2xl">🎭</span>
|
||||
<span className="font-bold text-lg tracking-tight hidden sm:block">MEMER</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Search */}
|
||||
|
||||
Reference in New Issue
Block a user