Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d58fff4a7 | ||
|
|
f67a544d7a |
@@ -66,6 +66,9 @@ export const api = {
|
||||
joinCollection: (id) => request('POST', `/collections/${id}/join`),
|
||||
regenerateShareLink: (id) => request('POST', `/collections/${id}/share-link/regenerate`),
|
||||
|
||||
// ── Bot ───────────────────────────────────────────────────────────────────
|
||||
getBotInfo: () => request('GET', '/bot/info'),
|
||||
|
||||
// ── Invites ───────────────────────────────────────────────────────────────
|
||||
getInvites: (collectionId) => request('GET', `/collections/${collectionId}/invites`),
|
||||
createInvite: (collectionId, role, expiresAt) =>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { Pencil, Trash2, Star, Check, X, EyeOff, Copy } from 'lucide-svelte'
|
||||
import { Pencil, Trash2, Star, Check, X, EyeOff, Copy, Link, Plus, UserCheck } from 'lucide-svelte'
|
||||
import { api } from '../lib/api.js'
|
||||
import { showAlert } from '../lib/telegram.js'
|
||||
|
||||
let botUsername = $state('')
|
||||
|
||||
let collections = $state([])
|
||||
let loading = $state(true)
|
||||
let error = $state(null)
|
||||
@@ -23,9 +25,35 @@
|
||||
// Клонирование: id коллекции, которая клонируется прямо сейчас
|
||||
let cloning = $state(null)
|
||||
|
||||
// Управление инвайтами: id раскрытой коллекции
|
||||
let invitesPanelId = $state(null)
|
||||
// { [collectionId]: CollectionInviteDto[] }
|
||||
let invitesByCol = $state({})
|
||||
let invitesLoading = $state(false)
|
||||
// Форма создания инвайта: { role: 0|1, expiresAt: string|null }
|
||||
let newInvite = $state({ role: 0, expiresAt: '' })
|
||||
let creatingInvite = $state(false)
|
||||
|
||||
let deleteTarget = $derived(collections.find(c => c.id === confirmDelete))
|
||||
let inboxTarget = $derived(collections.find(c => c.id === confirmInbox))
|
||||
|
||||
// CollectionRole: Viewer=0, Manager=1, Owner=2
|
||||
const ROLE_OWNER = 2
|
||||
|
||||
function inviteLink(token) {
|
||||
if (!botUsername) return null
|
||||
return `https://t.me/${botUsername}?start=inv_${token}`
|
||||
}
|
||||
|
||||
function roleLabel(role) {
|
||||
return role === 0 ? 'Читатель' : 'Менеджер'
|
||||
}
|
||||
|
||||
function formatExpiry(expiresAt) {
|
||||
if (!expiresAt) return null
|
||||
return new Date(expiresAt).toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' })
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading = true; error = null
|
||||
try { collections = await api.getCollections() }
|
||||
@@ -50,6 +78,7 @@
|
||||
itemCount: 0,
|
||||
visibility: 0,
|
||||
shareToken: null,
|
||||
myRole: ROLE_OWNER,
|
||||
createdAt: new Date().toISOString(),
|
||||
}]
|
||||
} catch (e) {
|
||||
@@ -129,7 +158,87 @@
|
||||
}
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
// ── Инвайты ────────────────────────────────────────────────────────────────
|
||||
async function toggleInvitesPanel(colId) {
|
||||
if (invitesPanelId === colId) {
|
||||
invitesPanelId = null
|
||||
return
|
||||
}
|
||||
invitesPanelId = colId
|
||||
newInvite = { role: 0, expiresAt: '' }
|
||||
if (invitesByCol[colId]) return // уже загружены
|
||||
|
||||
invitesLoading = true
|
||||
try {
|
||||
invitesByCol = { ...invitesByCol, [colId]: await api.getInvites(colId) }
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
invitesPanelId = null
|
||||
} finally {
|
||||
invitesLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createInvite(colId) {
|
||||
creatingInvite = true
|
||||
try {
|
||||
const expiresAt = newInvite.expiresAt
|
||||
? new Date(newInvite.expiresAt).toISOString()
|
||||
: null
|
||||
const { token } = await api.createInvite(colId, newInvite.role, expiresAt)
|
||||
const created = {
|
||||
id: crypto.randomUUID(), // placeholder до перезагрузки
|
||||
token,
|
||||
role: newInvite.role,
|
||||
isRevoked: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
revokedAt: null,
|
||||
expiresAt: expiresAt,
|
||||
}
|
||||
invitesByCol = {
|
||||
...invitesByCol,
|
||||
[colId]: [created, ...(invitesByCol[colId] ?? [])],
|
||||
}
|
||||
newInvite = { role: 0, expiresAt: '' }
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
} finally {
|
||||
creatingInvite = false
|
||||
}
|
||||
}
|
||||
|
||||
async function revokeInvite(colId, inviteId) {
|
||||
try {
|
||||
await api.revokeInvite(colId, inviteId)
|
||||
invitesByCol = {
|
||||
...invitesByCol,
|
||||
[colId]: invitesByCol[colId].filter(i => i.id !== inviteId),
|
||||
}
|
||||
} catch (e) {
|
||||
showAlert(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
async function copyToClipboard(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
} catch {
|
||||
// fallback для старых WebView
|
||||
const el = document.createElement('textarea')
|
||||
el.value = text
|
||||
document.body.appendChild(el)
|
||||
el.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(el)
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
load()
|
||||
api.getBotInfo()
|
||||
.then(r => { botUsername = r?.username ?? '' })
|
||||
.catch(() => {})
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="page">
|
||||
@@ -208,6 +317,16 @@
|
||||
>
|
||||
<Copy size={16}/>
|
||||
</button>
|
||||
{#if col.myRole === ROLE_OWNER}
|
||||
<button
|
||||
class="icon-btn invite"
|
||||
class:invite--on={invitesPanelId === col.id}
|
||||
onclick={() => toggleInvitesPanel(col.id)}
|
||||
title="Управление приглашениями"
|
||||
>
|
||||
<Link size={16}/>
|
||||
</button>
|
||||
{/if}
|
||||
{#if !col.isInbox}
|
||||
<button class="icon-btn" onclick={() => startEdit(col)} title="Переименовать">
|
||||
<Pencil size={16}/>
|
||||
@@ -223,6 +342,91 @@
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<!-- Панель инвайтов -->
|
||||
{#if invitesPanelId === col.id}
|
||||
<li class="invites-panel">
|
||||
<div class="invites-header">
|
||||
<UserCheck size={14}/> Приглашения
|
||||
</div>
|
||||
|
||||
{#if invitesLoading}
|
||||
<div class="invites-loading">Загрузка…</div>
|
||||
{:else}
|
||||
<!-- Список активных инвайтов -->
|
||||
{#if invitesByCol[col.id]?.length > 0}
|
||||
<ul class="invites-list">
|
||||
{#each invitesByCol[col.id] as inv (inv.id)}
|
||||
<li class="invite-item">
|
||||
<span class="invite-role-badge">{roleLabel(inv.role)}</span>
|
||||
{#if inviteLink(inv.token)}
|
||||
<button
|
||||
class="invite-link-btn"
|
||||
onclick={() => copyToClipboard(inviteLink(inv.token))}
|
||||
title="Скопировать ссылку"
|
||||
>
|
||||
<Copy size={12}/> Копировать
|
||||
</button>
|
||||
{:else}
|
||||
<button
|
||||
class="invite-link-btn"
|
||||
onclick={() => copyToClipboard(inv.token)}
|
||||
title="Скопировать токен"
|
||||
>
|
||||
<Copy size={12}/> Токен
|
||||
</button>
|
||||
{/if}
|
||||
{#if inv.expiresAt}
|
||||
<span class="invite-expiry">до {formatExpiry(inv.expiresAt)}</span>
|
||||
{/if}
|
||||
<button
|
||||
class="icon-btn del invite-revoke"
|
||||
onclick={() => revokeInvite(col.id, inv.id)}
|
||||
title="Отозвать"
|
||||
>
|
||||
<X size={14}/>
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else}
|
||||
<div class="invites-empty">Нет активных приглашений</div>
|
||||
{/if}
|
||||
|
||||
<!-- Форма создания нового инвайта -->
|
||||
<div class="invite-create">
|
||||
<div class="invite-create-row">
|
||||
<div class="role-toggle">
|
||||
<button
|
||||
class="role-btn"
|
||||
class:role-btn--active={newInvite.role === 0}
|
||||
onclick={() => newInvite = { ...newInvite, role: 0 }}
|
||||
>Читатель</button>
|
||||
<button
|
||||
class="role-btn"
|
||||
class:role-btn--active={newInvite.role === 1}
|
||||
onclick={() => newInvite = { ...newInvite, role: 1 }}
|
||||
>Менеджер</button>
|
||||
</div>
|
||||
<input
|
||||
class="expiry-input"
|
||||
type="date"
|
||||
bind:value={newInvite.expiresAt}
|
||||
title="Срок действия (необязательно)"
|
||||
/>
|
||||
<button
|
||||
class="invite-add-btn"
|
||||
onclick={() => createInvite(col.id)}
|
||||
disabled={creatingInvite}
|
||||
title="Создать ссылку-приглашение"
|
||||
>
|
||||
<Plus size={14}/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</li>
|
||||
{/if}
|
||||
|
||||
<!-- Подтверждение удаления -->
|
||||
{#if confirmDelete === col.id && deleteTarget}
|
||||
<li class="confirm-panel">
|
||||
@@ -335,6 +539,9 @@
|
||||
.icon-btn.nsfw { color: var(--tg-hint, #999); }
|
||||
.icon-btn.nsfw:hover { color: #e53935; background: var(--tg-secondary-bg, #e8e8e8); }
|
||||
.icon-btn.nsfw--on { color: #e53935; }
|
||||
.icon-btn.invite { color: var(--tg-hint, #999); }
|
||||
.icon-btn.invite:hover { color: var(--tg-button, #2196f3); }
|
||||
.icon-btn.invite--on { color: var(--tg-button, #2196f3); }
|
||||
|
||||
/* Подтверждение */
|
||||
.confirm-panel {
|
||||
@@ -353,4 +560,97 @@
|
||||
.btn-primary { background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff); }
|
||||
.btn-ghost { background: none; color: var(--tg-hint, #888); }
|
||||
.btn-ghost:hover { background: var(--tg-secondary-bg, #e8e8e8); }
|
||||
|
||||
/* ── Панель инвайтов ─────────────────────────────────────────────────────── */
|
||||
.invites-panel {
|
||||
background: var(--tg-secondary-bg, #f5f5f5);
|
||||
border-radius: 10px; padding: 10px 12px;
|
||||
border-left: 3px solid var(--tg-button, #2196f3);
|
||||
display: flex; flex-direction: column; gap: 8px;
|
||||
}
|
||||
|
||||
.invites-header {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
font-size: 12px; font-weight: 600; color: var(--tg-hint, #888);
|
||||
text-transform: uppercase; letter-spacing: .05em;
|
||||
}
|
||||
|
||||
.invites-loading { font-size: 13px; color: var(--tg-hint, #888); }
|
||||
.invites-empty { font-size: 13px; color: var(--tg-hint, #888); text-align: center; padding: 4px 0; }
|
||||
|
||||
.invites-list {
|
||||
list-style: none; margin: 0; padding: 0;
|
||||
display: flex; flex-direction: column; gap: 4px;
|
||||
}
|
||||
|
||||
.invite-item {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
background: var(--tg-bg, #fff);
|
||||
border-radius: 8px; padding: 6px 8px;
|
||||
}
|
||||
|
||||
.invite-role-badge {
|
||||
font-size: 11px; font-weight: 600;
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
border-radius: 4px; padding: 1px 6px;
|
||||
white-space: nowrap; flex-shrink: 0;
|
||||
}
|
||||
|
||||
.invite-link-btn {
|
||||
display: flex; align-items: center; gap: 4px;
|
||||
padding: 3px 8px; border-radius: 6px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-text, #000); font-size: 12px; cursor: pointer;
|
||||
white-space: nowrap; flex-shrink: 0;
|
||||
transition: background .12s;
|
||||
}
|
||||
.invite-link-btn:hover { background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff); }
|
||||
|
||||
.invite-expiry {
|
||||
font-size: 11px; color: var(--tg-hint, #888);
|
||||
white-space: nowrap; flex-shrink: 0; margin-left: auto;
|
||||
}
|
||||
|
||||
.invite-revoke {
|
||||
width: 26px; height: 26px; flex-shrink: 0;
|
||||
color: var(--tg-hint, #999);
|
||||
}
|
||||
.invite-revoke:hover { color: #e53935; }
|
||||
|
||||
/* Форма создания инвайта */
|
||||
.invite-create { margin-top: 2px; }
|
||||
.invite-create-row {
|
||||
display: flex; gap: 6px; align-items: center;
|
||||
}
|
||||
|
||||
.role-toggle {
|
||||
display: flex; border-radius: 8px; overflow: hidden;
|
||||
border: 1px solid var(--tg-hint, #ccc);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.role-btn {
|
||||
padding: 5px 10px; border: none; font-size: 12px; font-weight: 500;
|
||||
background: none; color: var(--tg-hint, #888); cursor: pointer;
|
||||
transition: background .12s, color .12s;
|
||||
}
|
||||
.role-btn:first-child { border-right: 1px solid var(--tg-hint, #ccc); }
|
||||
.role-btn--active {
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
}
|
||||
|
||||
.expiry-input {
|
||||
flex: 1; min-width: 0; padding: 5px 8px; border-radius: 8px;
|
||||
border: 1px solid var(--tg-hint, #ccc);
|
||||
background: var(--tg-bg, #fff); color: var(--tg-text, #000);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.invite-add-btn {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
width: 32px; height: 32px; border-radius: 8px; border: none;
|
||||
background: var(--tg-button, #2196f3); color: var(--tg-btn-text, #fff);
|
||||
cursor: pointer; flex-shrink: 0;
|
||||
transition: opacity .12s;
|
||||
}
|
||||
.invite-add-btn:disabled { opacity: .4; cursor: default; }
|
||||
</style>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
let items = $state([])
|
||||
let query = $state('')
|
||||
let includeNsfw = $state(false)
|
||||
let loading = $state(true)
|
||||
let error = $state(null)
|
||||
let sending = $state(null) // id медиа, которое сейчас отправляется
|
||||
@@ -26,7 +27,7 @@
|
||||
async function load() {
|
||||
loading = true; error = null; previews = {}
|
||||
try {
|
||||
items = await api.getMedia(query)
|
||||
items = await api.getMedia(query, includeNsfw)
|
||||
for (const item of items) {
|
||||
if (PREVIEWABLE.has(item.mediaType)) loadPreview(item.id)
|
||||
}
|
||||
@@ -76,6 +77,11 @@
|
||||
searchTimer = setTimeout(load, 400)
|
||||
}
|
||||
|
||||
function toggleNsfw() {
|
||||
includeNsfw = !includeNsfw
|
||||
load()
|
||||
}
|
||||
|
||||
onMount(load)
|
||||
</script>
|
||||
|
||||
@@ -96,12 +102,20 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="search-row">
|
||||
<input
|
||||
class="search"
|
||||
placeholder="Поиск: #мем -#кот слово"
|
||||
bind:value={query}
|
||||
oninput={onSearch}
|
||||
/>
|
||||
<button
|
||||
class="nsfw-btn"
|
||||
class:nsfw-btn--active={includeNsfw}
|
||||
onclick={toggleNsfw}
|
||||
title={includeNsfw ? 'Скрыть 18+' : 'Показать 18+'}
|
||||
>18+</button>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<div class="hint">Загрузка…</div>
|
||||
@@ -180,13 +194,30 @@
|
||||
}
|
||||
.chat-name :global(svg) { flex-shrink: 0; color: var(--tg-hint, #888); }
|
||||
|
||||
.search-row {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
margin: 4px 8px 6px;
|
||||
}
|
||||
.search {
|
||||
margin: 4px 8px 6px; width: calc(100% - 16px);
|
||||
flex: 1; min-width: 0;
|
||||
padding: 8px 12px; border-radius: 8px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-text, #000); font-size: 14px;
|
||||
}
|
||||
|
||||
.nsfw-btn {
|
||||
flex-shrink: 0;
|
||||
padding: 8px 10px; border-radius: 8px; border: none;
|
||||
background: var(--tg-secondary-bg, #f0f0f0);
|
||||
color: var(--tg-hint, #888); font-size: 13px; font-weight: 600;
|
||||
cursor: pointer; transition: background .15s, color .15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.nsfw-btn--active {
|
||||
background: var(--tg-button, #2196f3);
|
||||
color: var(--tg-btn-text, #fff);
|
||||
}
|
||||
|
||||
.hint { text-align: center; padding: 32px; color: var(--tg-hint, #888); }
|
||||
.error { color: #e53935; }
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using MemeVault.Api.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MemeVault.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/bot")]
|
||||
public sealed class BotController(BotInfoService botInfo) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Возвращает публичный username бота.
|
||||
/// Не требует авторизации — username бота публичен.
|
||||
/// </summary>
|
||||
[HttpGet("info")]
|
||||
public async Task<IActionResult> GetInfo(CancellationToken ct)
|
||||
{
|
||||
var username = await botInfo.GetBotUsernameAsync();
|
||||
return Ok(new { username });
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using MemeVault.Api.Middleware;
|
||||
using MemeVault.Api.Auth;
|
||||
using MemeVault.Api.Services;
|
||||
using System.Text;
|
||||
using MemeVault.Api.Options;
|
||||
using MemeVault.Infrastructure;
|
||||
@@ -29,6 +30,7 @@ builder.Services.Configure<JwtOptions>(
|
||||
builder.Services.AddSingleton<TelegramInitDataValidator>();
|
||||
builder.Services.AddSingleton<InlineAuthValidator>();
|
||||
builder.Services.AddSingleton<JwtTokenService>();
|
||||
builder.Services.AddSingleton<BotInfoService>();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddScoped<CurrentUser>();
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace MemeVault.Api.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Кэширует username бота на весь lifetime процесса.
|
||||
/// GetMeAsync вызывается ровно один раз при первом обращении.
|
||||
/// </summary>
|
||||
public sealed class BotInfoService
|
||||
{
|
||||
private readonly Lazy<Task<string>> _username;
|
||||
|
||||
public BotInfoService(ITelegramBotClient botClient)
|
||||
{
|
||||
_username = new Lazy<Task<string>>(
|
||||
() => FetchAsync(botClient),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
}
|
||||
|
||||
private static async Task<string> FetchAsync(ITelegramBotClient botClient)
|
||||
{
|
||||
var me = await botClient.GetMe();
|
||||
return me.Username ?? string.Empty;
|
||||
}
|
||||
|
||||
public Task<string> GetBotUsernameAsync() => _username.Value;
|
||||
}
|
||||
@@ -15,5 +15,6 @@ public sealed record CollectionDto(
|
||||
bool IsNsfw,
|
||||
string? ShareToken,
|
||||
int ItemCount,
|
||||
DateTimeOffset CreatedAt
|
||||
DateTimeOffset CreatedAt,
|
||||
CollectionRole MyRole
|
||||
);
|
||||
|
||||
+3
-1
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using MemeVault.Domain.Enums;
|
||||
using MemeVault.Domain.Repositories;
|
||||
|
||||
namespace MemeVault.Application.Queries.GetUserCollections;
|
||||
@@ -35,7 +36,8 @@ public sealed class GetUserCollectionsQueryHandler(
|
||||
c.IsNsfw,
|
||||
c.ShareToken,
|
||||
countByCollection.GetValueOrDefault(c.Id, 0),
|
||||
c.CreatedAt
|
||||
c.CreatedAt,
|
||||
c.GetRole(request.OwnerTelegramId) ?? CollectionRole.Viewer
|
||||
)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user