fix(appstore): рендер markdown/скриншотов, фильтр категорий, локализация ошибки, ширина карточек
- Описания приложений: безопасный рендер markdown + HTML (react-markdown + remark-gfm + rehype-raw + rehype-sanitize), скриншоты отображаются как картинки - Фильтр по категории: переведён на надёжную фильтрацию в Python (JSONB-оператор на generic JSON-колонке отрабатывал ненадёжно) - Ошибка отсутствия золотого шаблона локализована (i18n appstore.golden_missing) - Каталог: карточки шире (макс 3 колонки вместо 4), описание в 3 строки Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from sqlalchemy import func, or_
|
from sqlalchemy import or_
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ...auth import PermissionChecker
|
from ...auth import PermissionChecker
|
||||||
@@ -48,17 +48,21 @@ def list_catalog(
|
|||||||
CatalogApp.short_desc.ilike(like),
|
CatalogApp.short_desc.ilike(like),
|
||||||
CatalogApp.app_id.ilike(like),
|
CatalogApp.app_id.ilike(like),
|
||||||
))
|
))
|
||||||
if category:
|
|
||||||
# categories — JSONB-массив строк; оператор ? (jsonb_exists) проверяет наличие элемента
|
|
||||||
query = query.filter(func.jsonb_exists(CatalogApp.categories, category))
|
|
||||||
|
|
||||||
total = query.count()
|
rows = query.order_by(CatalogApp.name.asc()).all()
|
||||||
rows = query.order_by(CatalogApp.name.asc()).offset(offset).limit(limit).all()
|
|
||||||
|
# Фильтр по категории — в Python: categories хранится как JSON-массив строк,
|
||||||
|
# это надёжнее JSONB-операторов на generic JSON-колонке (независимо от диалекта).
|
||||||
|
if category:
|
||||||
|
rows = [r for r in rows if category in (r.categories or [])]
|
||||||
|
|
||||||
|
total = len(rows)
|
||||||
|
page = rows[offset:offset + limit]
|
||||||
return {
|
return {
|
||||||
"total": total,
|
"total": total,
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
"items": [a.to_dict(light=True) for a in rows],
|
"items": [a.to_dict(light=True) for a in page],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1658
frontend/package-lock.json
generated
1658
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,12 @@
|
|||||||
"react": "^19.2.4",
|
"react": "^19.2.4",
|
||||||
"react-dom": "^19.2.4",
|
"react-dom": "^19.2.4",
|
||||||
"react-i18next": "^17.0.2",
|
"react-i18next": "^17.0.2",
|
||||||
|
"react-markdown": "^9.1.0",
|
||||||
"react-router": "^7.14.0",
|
"react-router": "^7.14.0",
|
||||||
"recharts": "^3.8.1",
|
"recharts": "^3.8.1",
|
||||||
|
"rehype-raw": "^7.0.0",
|
||||||
|
"rehype-sanitize": "^6.0.0",
|
||||||
|
"remark-gfm": "^4.0.1",
|
||||||
"shadcn": "^4.1.2",
|
"shadcn": "^4.1.2",
|
||||||
"sonner": "^2.0.7",
|
"sonner": "^2.0.7",
|
||||||
"tailwind-merge": "^3.5.0",
|
"tailwind-merge": "^3.5.0",
|
||||||
|
|||||||
58
frontend/src/components/shared/Markdown.tsx
Normal file
58
frontend/src/components/shared/Markdown.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import ReactMarkdown from 'react-markdown';
|
||||||
|
import remarkGfm from 'remark-gfm';
|
||||||
|
import rehypeRaw from 'rehype-raw';
|
||||||
|
import rehypeSanitize from 'rehype-sanitize';
|
||||||
|
|
||||||
|
// react-markdown передаёт служебный проп `node` — вырезаем его, чтобы он не
|
||||||
|
// попал на DOM-элемент (иначе React warning про неизвестный атрибут).
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
function clean(p: any) {
|
||||||
|
const { node, ...rest } = p;
|
||||||
|
void node;
|
||||||
|
return rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Безопасный рендер markdown + встроенного HTML (описания приложений из README
|
||||||
|
* сторонних репозиториев). rehype-raw парсит HTML, rehype-sanitize вычищает
|
||||||
|
* потенциально опасные теги/атрибуты (защита от XSS).
|
||||||
|
*/
|
||||||
|
export function Markdown({ content, className = '' }: { content: string; className?: string }) {
|
||||||
|
return (
|
||||||
|
<div className={`text-sm leading-relaxed text-foreground/90 ${className}`}>
|
||||||
|
<ReactMarkdown
|
||||||
|
remarkPlugins={[remarkGfm]}
|
||||||
|
rehypePlugins={[rehypeRaw, rehypeSanitize]}
|
||||||
|
components={{
|
||||||
|
h1: (p) => <h1 className="mt-4 mb-2 text-lg font-semibold" {...clean(p)} />,
|
||||||
|
h2: (p) => <h2 className="mt-4 mb-2 text-base font-semibold" {...clean(p)} />,
|
||||||
|
h3: (p) => <h3 className="mt-3 mb-1.5 text-sm font-semibold" {...clean(p)} />,
|
||||||
|
h4: (p) => <h4 className="mt-3 mb-1.5 text-sm font-medium" {...clean(p)} />,
|
||||||
|
p: (p) => <p className="my-2" {...clean(p)} />,
|
||||||
|
a: (p) => <a target="_blank" rel="noreferrer" className="text-primary hover:underline" {...clean(p)} />,
|
||||||
|
img: (p) => <img loading="lazy" className="my-2 max-w-full rounded-md border" {...clean(p)} />,
|
||||||
|
ul: (p) => <ul className="my-2 list-disc space-y-1 pl-5" {...clean(p)} />,
|
||||||
|
ol: (p) => <ol className="my-2 list-decimal space-y-1 pl-5" {...clean(p)} />,
|
||||||
|
li: (p) => <li className="marker:text-muted-foreground" {...clean(p)} />,
|
||||||
|
pre: (p) => <pre className="my-2 overflow-x-auto rounded-md bg-muted/60 p-3 text-xs" {...clean(p)} />,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
code: (p: any) => {
|
||||||
|
const { node, className: cn, children, ...rest } = p;
|
||||||
|
void node;
|
||||||
|
const inline = !cn?.includes('language-');
|
||||||
|
return inline
|
||||||
|
? <code className="rounded bg-muted px-1.5 py-0.5 text-xs" {...rest}>{children}</code>
|
||||||
|
: <code className={`${cn} text-xs`} {...rest}>{children}</code>;
|
||||||
|
},
|
||||||
|
blockquote: (p) => <blockquote className="my-2 border-l-2 border-border pl-3 text-muted-foreground" {...clean(p)} />,
|
||||||
|
table: (p) => <div className="my-2 overflow-x-auto"><table className="w-full text-xs" {...clean(p)} /></div>,
|
||||||
|
th: (p) => <th className="border-b px-2 py-1 text-left font-medium" {...clean(p)} />,
|
||||||
|
td: (p) => <td className="border-b px-2 py-1" {...clean(p)} />,
|
||||||
|
hr: (p) => <hr className="my-3 border-border" {...clean(p)} />,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</ReactMarkdown>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button';
|
|||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Card } from '@/components/ui/card';
|
import { Card } from '@/components/ui/card';
|
||||||
import { useCatalogApp } from '@/hooks/use-appstore';
|
import { useCatalogApp } from '@/hooks/use-appstore';
|
||||||
|
import { Markdown } from '@/components/shared/Markdown';
|
||||||
import InstallWizard from './InstallWizard';
|
import InstallWizard from './InstallWizard';
|
||||||
|
|
||||||
export default function AppDetailPage() {
|
export default function AppDetailPage() {
|
||||||
@@ -82,7 +83,7 @@ export default function AppDetailPage() {
|
|||||||
|
|
||||||
{app.description_md && (
|
{app.description_md && (
|
||||||
<Card className="p-4">
|
<Card className="p-4">
|
||||||
<div className="whitespace-pre-wrap text-sm leading-relaxed text-foreground/90">{app.description_md}</div>
|
<Markdown content={app.description_md} />
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export default function AppStorePage() {
|
|||||||
<p>{t('appstore.no_apps')}</p>
|
<p>{t('appstore.no_apps')}</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
<div className="grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
|
||||||
{items.map((app) => (
|
{items.map((app) => (
|
||||||
<Card
|
<Card
|
||||||
key={app.app_id}
|
key={app.app_id}
|
||||||
@@ -120,7 +120,7 @@ export default function AppStorePage() {
|
|||||||
<Badge variant="secondary" className="shrink-0">{t('appstore.installed_badge')}</Badge>
|
<Badge variant="secondary" className="shrink-0">{t('appstore.installed_badge')}</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="line-clamp-2 text-xs text-muted-foreground">{app.short_desc}</p>
|
<p className="line-clamp-3 text-xs text-muted-foreground">{app.short_desc}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-auto flex flex-wrap items-center gap-1">
|
<div className="mt-auto flex flex-wrap items-center gap-1">
|
||||||
|
|||||||
@@ -88,7 +88,14 @@ export default function InstallWizard({ app, open, onOpenChange }: Props) {
|
|||||||
setPhase('progress');
|
setPhase('progress');
|
||||||
toast.success(t('appstore.install_started'));
|
toast.success(t('appstore.install_started'));
|
||||||
},
|
},
|
||||||
onError: (e) => toast.error((e as Error).message || t('appstore.install_failed')),
|
onError: (e) => {
|
||||||
|
const msg = (e as Error).message || '';
|
||||||
|
toast.error(
|
||||||
|
msg.includes('APPSTORE_GOLDEN_TEMPLATE')
|
||||||
|
? t('appstore.golden_missing')
|
||||||
|
: (msg || t('appstore.install_failed')),
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
"update_started": "Update started",
|
"update_started": "Update started",
|
||||||
"rollback_started": "Rollback started",
|
"rollback_started": "Rollback started",
|
||||||
"powered_by": "Powered by Runtipi appstore",
|
"powered_by": "Powered by Runtipi appstore",
|
||||||
|
"golden_missing": "Golden LXC template is not configured. Set the APPSTORE_GOLDEN_TEMPLATE variable (see docs/golden-template.md).",
|
||||||
"install_title": "Install {{name}}",
|
"install_title": "Install {{name}}",
|
||||||
"step_advanced": "Advanced (LXC resources)",
|
"step_advanced": "Advanced (LXC resources)",
|
||||||
"server": "Server",
|
"server": "Server",
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
"update_started": "Обновление запущено",
|
"update_started": "Обновление запущено",
|
||||||
"rollback_started": "Откат запущен",
|
"rollback_started": "Откат запущен",
|
||||||
"powered_by": "Powered by Runtipi appstore",
|
"powered_by": "Powered by Runtipi appstore",
|
||||||
|
"golden_missing": "Не настроен золотой LXC-шаблон. Задайте переменную APPSTORE_GOLDEN_TEMPLATE (см. docs/golden-template.md).",
|
||||||
"install_title": "Установка {{name}}",
|
"install_title": "Установка {{name}}",
|
||||||
"step_advanced": "Дополнительно (ресурсы LXC)",
|
"step_advanced": "Дополнительно (ресурсы LXC)",
|
||||||
"server": "Сервер",
|
"server": "Сервер",
|
||||||
|
|||||||
Reference in New Issue
Block a user