Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f17d79b236 | ||
|
|
b05d572221 | ||
|
|
4789d19d06 | ||
|
|
430c4de0f4 | ||
|
|
8408d01197 | ||
|
|
ac65c1eb9d | ||
|
|
270af4e707 |
No files matched your search
@@ -35,3 +35,6 @@
|
|||||||
|
|
||||||
# 仅本地开发:设为 true 可绕过登录验证(跳过 /setup,一般无需开启)
|
# 仅本地开发:设为 true 可绕过登录验证(跳过 /setup,一般无需开启)
|
||||||
# DEV_BYPASS_ACCESS=false
|
# DEV_BYPASS_ACCESS=false
|
||||||
|
|
||||||
|
# 登录人机验证(滑块 / Turnstile / Cap)在后台「设置 → 访问控制」配置,无环境变量。
|
||||||
|
# 配置错误无法登录时:docker exec pichost slider(或 npm run slider)恢复为本地滑块。
|
||||||
@@ -4,6 +4,79 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [1.3.0] - 2026-09-07
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- **站点备份**:存储页导出 `.phost.tar.gz`(含 `pichost.db` 与全部图片),支持下载与任务进度
|
||||||
|
- **站点恢复**:存储页或 setup 未初始化时从备份包恢复,支持预检与跳过/覆盖冲突
|
||||||
|
- **跨后端同步**:在已配置存储后端之间拷贝图片并更新索引;后端卡片快捷「迁入 / 迁出」
|
||||||
|
- **任务中心**:`backup_jobs` 记录最近导出/恢复/同步任务,失败可重试;列表分页
|
||||||
|
- 运维 CLI:`backup-export`、`backup-restore`、`storage-sync`(`docker exec pichost …`)
|
||||||
|
|
||||||
|
### 移除
|
||||||
|
|
||||||
|
- 遗留目录迁移 CLI `migrate` / `migrate-to-single-images.mjs`(由启动索引同步与整站备份恢复替代)
|
||||||
|
|
||||||
|
### 文档
|
||||||
|
|
||||||
|
- [存储](./docs-site/guide/storage.md) 补充备份与迁移说明;更新截图;移除 v1.2 迁移专页
|
||||||
|
|
||||||
|
## [1.2.8] - 2026-09-04
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- 双域名:保存或初始化时弹出风险确认(说明可能锁死及 `clear-domains` 恢复方式),不再强制校验当前 Host
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- 运维 CLI `clear-domains`:清除数据库中的网站域 / 图片域配置(`docker exec pichost clear-domains`)
|
||||||
|
|
||||||
|
### 文档
|
||||||
|
|
||||||
|
- FAQ、双域名、反向代理文档补充锁死原因与恢复步骤
|
||||||
|
|
||||||
|
## [1.2.7] - 2026-09-03
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- 登录/注册人机验证:本地滑块、Cloudflare Turnstile、Cap;管理员在「设置 → 访问控制」中切换
|
||||||
|
- 运维 CLI `slider`:将登录验证重置为本地滑块(`docker exec pichost slider`)
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- 登出后登录页验证码可正常重新加载
|
||||||
|
|
||||||
|
## [1.2.6] - 2026-09-01
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- 设置、API、图库、存储页 UI 重构(侧栏导航、统计卡片、在线调试等)
|
||||||
|
- 图库筛选增加存储后端下拉
|
||||||
|
- 新建对象存储后端按类型生成存储标识:`r2-*`、`cos-*`、`oss-*`、`s3-*`
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- 操作日志表格:操作/来源标签同行展示,路径列省略号截断、无横向滚动条
|
||||||
|
- 存储后端卡片:存储标识与类型同一行左对齐排列
|
||||||
|
- README 与文档站截图、导航说明同步新界面
|
||||||
|
|
||||||
|
## [1.2.5] - 2026-08-31
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- 图库页(`/gallery`)替代原「统计」导航;图片点击放大详情弹层(尺寸、上传方式、存储路径、链接复制)
|
||||||
|
- 图库列表支持全选、反选;单张删除移至详情弹层
|
||||||
|
- 图片列表 API 返回上传来源(网页 / API,来自活动日志)
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- README 补充技术栈说明
|
||||||
|
|
||||||
|
### 移除
|
||||||
|
|
||||||
|
- `/stats` 路由(不再兼容跳转)
|
||||||
|
|
||||||
## [1.2.4] - 2026-08-31
|
## [1.2.4] - 2026-08-31
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
@@ -64,7 +137,6 @@
|
|||||||
- CLI 迁移工具:`docker exec pichost migrate` / `migrate --apply`(`server/cli/migrate-to-single-images.mjs`)
|
- CLI 迁移工具:`docker exec pichost migrate` / `migrate --apply`(`server/cli/migrate-to-single-images.mjs`)
|
||||||
- 扫描 `data/` 下除 `images` 外所有顶层目录中的图片,输出 `data/mapping.json`
|
- 扫描 `data/` 下除 `images` 外所有顶层目录中的图片,输出 `data/mapping.json`
|
||||||
- 启动时自动同步图片索引(扫描磁盘、归一化遗留 key、清理孤儿记录),并打印同步日志
|
- 启动时自动同步图片索引(扫描磁盘、归一化遗留 key、清理孤儿记录),并打印同步日志
|
||||||
- 迁移文档:[文档站 · v1.2 迁移](https://o96u.github.io/PicHost/guide/migration)
|
|
||||||
|
|
||||||
### 改进
|
### 改进
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,16 @@ ENV NODE_ENV=production \
|
|||||||
DATA_DIR=/data
|
DATA_DIR=/data
|
||||||
|
|
||||||
COPY --from=build /app/.output ./.output
|
COPY --from=build /app/.output ./.output
|
||||||
|
COPY --from=build /app/server/utils ./server/utils
|
||||||
|
COPY --from=build /app/node_modules ./node_modules
|
||||||
|
COPY --from=build /app/package.json ./package.json
|
||||||
COPY server/cli/reset-password.mjs ./server/cli/reset-password.mjs
|
COPY server/cli/reset-password.mjs ./server/cli/reset-password.mjs
|
||||||
COPY server/cli/migrate-to-single-images.mjs ./server/cli/migrate-to-single-images.mjs
|
COPY server/cli/slider.mjs ./server/cli/slider.mjs
|
||||||
|
COPY server/cli/clear-domains.mjs ./server/cli/clear-domains.mjs
|
||||||
|
COPY server/cli/backup-cli-loader.mjs ./server/cli/backup-cli-loader.mjs
|
||||||
|
COPY server/cli/backup-export.mjs ./server/cli/backup-export.mjs
|
||||||
|
COPY server/cli/backup-restore.mjs ./server/cli/backup-restore.mjs
|
||||||
|
COPY server/cli/storage-sync.mjs ./server/cli/storage-sync.mjs
|
||||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
RUN chmod +x /docker-entrypoint.sh
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
<a href="https://o96u.github.io/PicHost/en/">Docs</a> ·
|
<a href="https://o96u.github.io/PicHost/en/">Docs</a> ·
|
||||||
<a href="#screenshots">Screenshots</a> ·
|
<a href="#screenshots">Screenshots</a> ·
|
||||||
<a href="#features">Features</a> ·
|
<a href="#features">Features</a> ·
|
||||||
|
<a href="#tech-stack">Tech Stack</a> ·
|
||||||
<a href="#quick-start">Quick Start</a> ·
|
<a href="#quick-start">Quick Start</a> ·
|
||||||
<a href="README.md">简体中文</a>
|
<a href="README.md">简体中文</a>
|
||||||
</p>
|
</p>
|
||||||
@@ -30,23 +31,41 @@
|
|||||||
|
|
||||||
**main** has no public demo. **cloudflare** branch live demo: [pic.roven.cc](https://pic.roven.cc)
|
**main** has no public demo. **cloudflare** branch live demo: [pic.roven.cc](https://pic.roven.cc)
|
||||||
|
|
||||||
| Home | Storage |
|
| API | Gallery (detail) |
|
||||||
| :--: | :-----: |
|
| :--: | :--------------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| Stats | Settings |
|
| Storage | Settings |
|
||||||
| :---: | :-------: |
|
| :-----: | :-------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
|
| First-time setup | Restore from backup |
|
||||||
|
| :--------------: | :-----------------: |
|
||||||
|
|  |  |
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Drag, click, or Ctrl+V paste** — server-side WebP, Referer hotlink protection
|
- **Drag, click, or Ctrl+V paste** — server-side WebP, Referer hotlink protection
|
||||||
- **Multi-user** — login with slider captcha, optional registration; users see only their images
|
- **Multi-user** — login with slider, Turnstile, or Cap verification; optional registration; users see only their images
|
||||||
- **Multi-backend storage** — local disk + S3-compatible (R2 / COS / OSS / AWS); hybrid `proxy` / `public` URLs
|
- **Multi-backend storage** — local disk + S3-compatible (R2 / COS / OSS / AWS); hybrid `proxy` / `public` URLs
|
||||||
- **Gallery & stats** — browse, search, batch delete; upload trends and source breakdown
|
- **Gallery** — browse, search, filter by storage/source, grid/list views, batch delete; stats overview and source breakdown; image detail modal with link formats
|
||||||
|
- **Backup & migration** — full-site export/restore (`.phost.tar.gz`), cross-backend sync; restore from backup on uninitialized `/setup`
|
||||||
- **API & Twikoo** — global / per-user tokens; `POST /api/index.php` compatible
|
- **API & Twikoo** — global / per-user tokens; `POST /api/index.php` compatible
|
||||||
- **Zero-config Docker** — first-run web wizard, no secrets upfront
|
- **Zero-config Docker** — first-run web wizard, no secrets upfront
|
||||||
|
|
||||||
|
## Tech Stack
|
||||||
|
|
||||||
|
| Layer | Technologies |
|
||||||
|
| ----- | ------------ |
|
||||||
|
| Frontend | [Nuxt 4](https://nuxt.com) · [Nuxt UI 4](https://ui.nuxt.com) · [Vue 3](https://vuejs.org) · [Tailwind CSS 4](https://tailwindcss.com) · TypeScript |
|
||||||
|
| Backend | [Nitro](https://nitro.build) (`node-server`) · REST API |
|
||||||
|
| Data | SQLite · local `data/pichost.db` |
|
||||||
|
| Images | [sharp](https://sharp.pixelplumbing.com) (server-side WebP) |
|
||||||
|
| Storage | Local disk · S3-compatible ([AWS SDK](https://aws.amazon.com/sdk-for-javascript/) · R2 / COS / OSS, etc.) |
|
||||||
|
| i18n | [@nuxtjs/i18n](https://i18n.nuxtjs.org) (zh-CN / English) |
|
||||||
|
| Quality & docs | [Vitest](https://vitest.dev) · [VitePress](https://vitepress.dev) docs site |
|
||||||
|
| Deploy | Docker · Node.js 22 |
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
<a href="https://o96u.github.io/PicHost/">文档</a> ·
|
<a href="https://o96u.github.io/PicHost/">文档</a> ·
|
||||||
<a href="#界面预览">预览</a> ·
|
<a href="#界面预览">预览</a> ·
|
||||||
<a href="#特性">特性</a> ·
|
<a href="#特性">特性</a> ·
|
||||||
|
<a href="#技术栈">技术栈</a> ·
|
||||||
<a href="#快速开始">快速开始</a> ·
|
<a href="#快速开始">快速开始</a> ·
|
||||||
<a href="README.en.md">English</a>
|
<a href="README.en.md">English</a>
|
||||||
</p>
|
</p>
|
||||||
@@ -30,23 +31,41 @@
|
|||||||
|
|
||||||
**main** 分支暂无公网演示;**cloudflare** 分支在线体验:[pic.roven.cc](https://pic.roven.cc)
|
**main** 分支暂无公网演示;**cloudflare** 分支在线体验:[pic.roven.cc](https://pic.roven.cc)
|
||||||
|
|
||||||
| 首页 | 存储 |
|
| API | 图库(详情) |
|
||||||
| :--: | :--: |
|
| :--: | :--: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| 统计 | 设置 |
|
| 存储 | 设置 |
|
||||||
| :--: | :--: |
|
| :--: | :--: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
|
| 首次设置 | 从备份恢复 |
|
||||||
|
| :--: | :--: |
|
||||||
|
|  |  |
|
||||||
|
|
||||||
## 特性
|
## 特性
|
||||||
|
|
||||||
- **拖拽 / 点击 / Ctrl+V 粘贴**上传;服务端 WebP 压缩、Referer 防盗链
|
- **拖拽 / 点击 / Ctrl+V 粘贴**上传;服务端 WebP 压缩、Referer 防盗链
|
||||||
- **多用户**:账号密码登录(滑动验证)、可选开放注册;普通用户仅见自己的图片
|
- **多用户**:账号密码登录(滑块 / Turnstile / Cap 人机验证)、可选开放注册;普通用户仅见自己的图片
|
||||||
- **多后端存储**:本地磁盘 + S3 兼容(R2 / COS / OSS / AWS);混合直链 `proxy` / `public`
|
- **多后端存储**:本地磁盘 + S3 兼容(R2 / COS / OSS / AWS);混合直链 `proxy` / `public`
|
||||||
- **图库与统计**:浏览、搜索、批量删除;上传趋势与来源分布
|
- **图库**:浏览、搜索、按存储/来源筛选、网格/列表切换、批量删除;统计概览与来源分布;点击图片查看详情与多格式链接
|
||||||
|
- **备份与迁移**:整站导出/恢复(`.phost.tar.gz`)、跨后端同步;setup 未初始化时可从备份恢复
|
||||||
- **API 与 Twikoo**:全局 / 个人 Token;`POST /api/index.php` 兼容
|
- **API 与 Twikoo**:全局 / 个人 Token;`POST /api/index.php` 兼容
|
||||||
- **Docker 零配置**:首次访问 Web 引导创建管理员
|
- **Docker 零配置**:首次访问 Web 引导创建管理员
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
|
||||||
|
| 层级 | 技术 |
|
||||||
|
| ---- | ---- |
|
||||||
|
| 前端 | [Nuxt 4](https://nuxt.com) · [Nuxt UI 4](https://ui.nuxt.com) · [Vue 3](https://vuejs.org) · [Tailwind CSS 4](https://tailwindcss.com) · TypeScript |
|
||||||
|
| 后端 | [Nitro](https://nitro.build)(`node-server`)· REST API |
|
||||||
|
| 数据 | SQLite · 本地 `data/pichost.db` |
|
||||||
|
| 图片处理 | [sharp](https://sharp.pixelplumbing.com)(服务端 WebP 压缩) |
|
||||||
|
| 存储 | 本地磁盘 · S3 兼容([AWS SDK](https://aws.amazon.com/sdk-for-javascript/) · R2 / COS / OSS 等) |
|
||||||
|
| 国际化 | [@nuxtjs/i18n](https://i18n.nuxtjs.org)(简体中文 / English) |
|
||||||
|
| 质量与文档 | [Vitest](https://vitest.dev) · [VitePress](https://vitepress.dev) 文档站 |
|
||||||
|
| 部署 | Docker · Node.js 22 |
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -60,7 +79,7 @@ docker run -d \
|
|||||||
|
|
||||||
浏览器打开 `http://<主机IP>:6892`,按引导完成设置即可。
|
浏览器打开 `http://<主机IP>:6892`,按引导完成设置即可。
|
||||||
|
|
||||||
**详细说明**(环境变量、升级迁移、双域名、API、Twikoo、反向代理、本地开发等)见 **[用户文档](https://o96u.github.io/PicHost/)**。
|
**详细说明**(环境变量、双域名、API、Twikoo、反向代理、本地开发等)见 **[用户文档](https://o96u.github.io/PicHost/)**。
|
||||||
|
|
||||||
| 分支 | 说明 |
|
| 分支 | 说明 |
|
||||||
| ---- | ---- |
|
| ---- | ---- |
|
||||||
|
|||||||
@@ -106,3 +106,21 @@
|
|||||||
.upload-settings-btn:hover .upload-settings-icon {
|
.upload-settings-btn:hover .upload-settings-icon {
|
||||||
transform: rotate(90deg);
|
transform: rotate(90deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.api-debug-response {
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgb(82 82 82) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-debug-response::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-debug-response::-webkit-scrollbar-thumb {
|
||||||
|
border-radius: 9999px;
|
||||||
|
background-color: rgb(82 82 82);
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-debug-response::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import logoLight from '~/assets/image/logo-light.png'
|
import logoLight from '~/assets/image/logo-light.png'
|
||||||
import logoDark from '~/assets/image/logo-dark.png'
|
import logoDark from '~/assets/image/logo-dark.png'
|
||||||
|
import type { LoginVerificationPayload } from '~/types/auth'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { login, fetchStatus, authStatus } = useAuth()
|
const { login, fetchStatus, authStatus } = useAuth()
|
||||||
@@ -11,45 +12,53 @@ const username = ref('')
|
|||||||
const password = ref('')
|
const password = ref('')
|
||||||
const secret = ref('')
|
const secret = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const captchaRef = ref<{ reset: () => Promise<void> } | null>(null)
|
const verificationRef = ref<{ reset: () => Promise<void> } | null>(null)
|
||||||
const captchaPayload = ref<{ captchaId: string, captchaPosition: number } | null>(null)
|
const verificationPayload = ref<LoginVerificationPayload | null>(null)
|
||||||
|
const verificationMountKey = ref(0)
|
||||||
|
|
||||||
const legacyMode = computed(() => authStatus.value?.legacyMode ?? false)
|
const legacyMode = computed(() => authStatus.value?.legacyMode ?? false)
|
||||||
const allowRegistration = computed(() => authStatus.value?.allowRegistration ?? false)
|
const allowRegistration = computed(() => authStatus.value?.allowRegistration ?? false)
|
||||||
|
const loginVerification = computed(() =>
|
||||||
|
authStatus.value?.loginVerification ?? { method: 'slider' as const }
|
||||||
|
)
|
||||||
|
|
||||||
const canSubmit = computed(() =>
|
const canSubmit = computed(() =>
|
||||||
Boolean(captchaPayload.value)
|
Boolean(verificationPayload.value)
|
||||||
&& (legacyMode.value ? Boolean(secret.value) : Boolean(username.value && password.value))
|
&& (legacyMode.value ? Boolean(secret.value) : Boolean(username.value && password.value))
|
||||||
)
|
)
|
||||||
|
|
||||||
function onCaptchaVerified(payload: { id: string, positionPercent: number }) {
|
function onVerificationVerified(payload: LoginVerificationPayload) {
|
||||||
captchaPayload.value = {
|
verificationPayload.value = payload
|
||||||
captchaId: payload.id,
|
|
||||||
captchaPosition: payload.positionPercent
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resetCaptcha() {
|
function onVerificationCleared() {
|
||||||
captchaPayload.value = null
|
verificationPayload.value = null
|
||||||
await captchaRef.value?.reset()
|
}
|
||||||
|
|
||||||
|
async function resetVerification() {
|
||||||
|
verificationPayload.value = null
|
||||||
|
await verificationRef.value?.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
verificationPayload.value = null
|
||||||
|
verificationMountKey.value += 1
|
||||||
const status = await fetchStatus()
|
const status = await fetchStatus()
|
||||||
if (!status.initialized && !status.legacyMode) {
|
if (!status.initialized && !status.legacyMode) {
|
||||||
await router.replace('/setup')
|
await router.replace('/setup')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!canSubmit.value || loading.value || !captchaPayload.value) return
|
if (!canSubmit.value || loading.value || !verificationPayload.value) return
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const captcha = captchaPayload.value
|
const verification = verificationPayload.value
|
||||||
const result = legacyMode.value
|
const result = legacyMode.value
|
||||||
? await login({ secret: secret.value }, captcha)
|
? await login({ secret: secret.value }, verification)
|
||||||
: await login({ username: username.value.trim(), password: password.value }, captcha)
|
: await login({ username: username.value.trim(), password: password.value }, verification)
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
if (result.needsMigration) {
|
if (result.needsMigration) {
|
||||||
@@ -59,10 +68,10 @@ async function submit() {
|
|||||||
username.value = ''
|
username.value = ''
|
||||||
password.value = ''
|
password.value = ''
|
||||||
secret.value = ''
|
secret.value = ''
|
||||||
await resetCaptcha()
|
await resetVerification()
|
||||||
toast.add({ title: t('auth.loginSuccess'), color: 'success' })
|
toast.add({ title: t('auth.loginSuccess'), color: 'success' })
|
||||||
} else {
|
} else {
|
||||||
await resetCaptcha()
|
await resetVerification()
|
||||||
toast.add({
|
toast.add({
|
||||||
title: result.error ?? (legacyMode.value ? t('auth.loginFailedSecret') : t('auth.loginFailedCredentials')),
|
title: result.error ?? (legacyMode.value ? t('auth.loginFailedSecret') : t('auth.loginFailedCredentials')),
|
||||||
color: 'error'
|
color: 'error'
|
||||||
@@ -170,9 +179,14 @@ async function submit() {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<SliderCaptcha
|
<LoginVerification
|
||||||
ref="captchaRef"
|
:key="verificationMountKey"
|
||||||
@verified="onCaptchaVerified"
|
ref="verificationRef"
|
||||||
|
:method="loginVerification.method"
|
||||||
|
:turnstile-site-key="loginVerification.turnstileSiteKey"
|
||||||
|
:cap-api-endpoint="loginVerification.capApiEndpoint"
|
||||||
|
@verified="onVerificationVerified"
|
||||||
|
@cleared="onVerificationCleared"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<UButton
|
<UButton
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ const props = withDefaults(
|
|||||||
defineProps<{
|
defineProps<{
|
||||||
code: string
|
code: string
|
||||||
scrollable?: boolean
|
scrollable?: boolean
|
||||||
|
lang?: string
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
scrollable: true
|
scrollable: true,
|
||||||
|
lang: ''
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,6 +36,12 @@ async function copyCode() {
|
|||||||
<span class="size-3 rounded-full border border-black/15 bg-[#ff5f56]" />
|
<span class="size-3 rounded-full border border-black/15 bg-[#ff5f56]" />
|
||||||
<span class="size-3 rounded-full border border-black/15 bg-[#ffbd2e]" />
|
<span class="size-3 rounded-full border border-black/15 bg-[#ffbd2e]" />
|
||||||
<span class="size-3 rounded-full border border-black/15 bg-[#27c93f]" />
|
<span class="size-3 rounded-full border border-black/15 bg-[#27c93f]" />
|
||||||
|
<span
|
||||||
|
v-if="lang"
|
||||||
|
class="ml-1 text-[10px] font-medium tracking-wide text-neutral-500 uppercase"
|
||||||
|
>
|
||||||
|
{{ lang }}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<UButton
|
<UButton
|
||||||
icon="i-lucide-copy"
|
icon="i-lucide-copy"
|
||||||
@@ -47,7 +55,7 @@ async function copyCode() {
|
|||||||
</div>
|
</div>
|
||||||
<pre
|
<pre
|
||||||
class="overflow-auto p-4 text-xs leading-relaxed text-neutral-100"
|
class="overflow-auto p-4 text-xs leading-relaxed text-neutral-100"
|
||||||
:class="props.scrollable ? 'max-h-80' : ''"
|
:class="scrollable ? 'max-h-80' : ''"
|
||||||
><code class="font-mono">{{ props.code }}</code></pre>
|
><code class="font-mono whitespace-pre">{{ code }}</code></pre>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -13,21 +13,16 @@ const mobileUserOpen = ref(false)
|
|||||||
const navItems = computed(() => {
|
const navItems = computed(() => {
|
||||||
const items = [
|
const items = [
|
||||||
{ label: t('nav.api'), to: '/api', icon: 'i-lucide-code-2' },
|
{ label: t('nav.api'), to: '/api', icon: 'i-lucide-code-2' },
|
||||||
{ label: t('nav.stats'), to: '/stats', icon: 'i-lucide-chart-column' }
|
{ label: t('nav.gallery'), to: '/gallery', icon: 'i-lucide-images' }
|
||||||
]
|
]
|
||||||
if (isAdmin.value) {
|
if (isAdmin.value) {
|
||||||
items.push({ label: t('nav.storage'), to: '/storage', icon: 'i-lucide-hard-drive' })
|
items.push({ label: t('nav.storage'), to: '/storage', icon: 'i-lucide-hard-drive' })
|
||||||
items.push({ label: t('nav.settings'), to: '/settings', icon: 'i-lucide-settings' })
|
|
||||||
}
|
}
|
||||||
|
items.push({ label: t('nav.settings'), to: '/settings', icon: 'i-lucide-settings' })
|
||||||
return items
|
return items
|
||||||
})
|
})
|
||||||
|
|
||||||
const accountMenuItems = computed<DropdownMenuItem[]>(() => [
|
const accountMenuItems = computed<DropdownMenuItem[]>(() => [
|
||||||
{
|
|
||||||
label: t('nav.logs'),
|
|
||||||
icon: 'i-lucide-scroll-text',
|
|
||||||
to: '/logs'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: t('nav.changePassword'),
|
label: t('nav.changePassword'),
|
||||||
icon: 'i-lucide-key-round',
|
icon: 'i-lucide-key-round',
|
||||||
@@ -48,7 +43,7 @@ const desktopUserMenuItems = computed<DropdownMenuItem[][]>(() => [
|
|||||||
|
|
||||||
function isNavActive(to: string) {
|
function isNavActive(to: string) {
|
||||||
if (to === '/settings') {
|
if (to === '/settings') {
|
||||||
return route.path === '/settings'
|
return route.path.startsWith('/settings')
|
||||||
}
|
}
|
||||||
return route.path.startsWith(to)
|
return route.path.startsWith(to)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import 'cap-widget'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
apiEndpoint: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
verified: [payload: { capToken: string }]
|
||||||
|
cleared: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const widgetRef = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
|
function onSolve(event: Event) {
|
||||||
|
const token = (event as CustomEvent<{ token: string }>).detail?.token
|
||||||
|
if (token) {
|
||||||
|
emit('verified', { capToken: token })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError() {
|
||||||
|
emit('cleared')
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
const widget = widgetRef.value as (HTMLElement & { reset?: () => void }) | null
|
||||||
|
widget?.reset?.()
|
||||||
|
emit('cleared')
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ reset })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ClientOnly>
|
||||||
|
<cap-widget
|
||||||
|
ref="widgetRef"
|
||||||
|
:data-cap-api-endpoint="props.apiEndpoint"
|
||||||
|
:data-cap-i18n-initial-state="t('auth.capInitialState')"
|
||||||
|
:data-cap-i18n-verifying-label="t('auth.capVerifying')"
|
||||||
|
:data-cap-i18n-solved-label="t('auth.capSolved')"
|
||||||
|
:data-cap-i18n-error-label="t('auth.capError')"
|
||||||
|
@solve="onSolve"
|
||||||
|
@error="onError"
|
||||||
|
/>
|
||||||
|
</ClientOnly>
|
||||||
|
</template>
|
||||||
@@ -6,6 +6,8 @@ const props = defineProps<{
|
|||||||
icon?: string
|
icon?: string
|
||||||
block?: boolean
|
block?: boolean
|
||||||
successTitle?: string
|
successTitle?: string
|
||||||
|
variant?: 'solid' | 'outline' | 'soft' | 'subtle' | 'ghost' | 'link'
|
||||||
|
color?: 'primary' | 'secondary' | 'success' | 'info' | 'warning' | 'error' | 'neutral'
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -76,7 +78,8 @@ async function copy() {
|
|||||||
<template>
|
<template>
|
||||||
<UButton
|
<UButton
|
||||||
size="xs"
|
size="xs"
|
||||||
variant="soft"
|
:variant="variant ?? 'soft'"
|
||||||
|
:color="color"
|
||||||
:loading="copying"
|
:loading="copying"
|
||||||
:disabled="!value"
|
:disabled="!value"
|
||||||
:label="iconOnly ? undefined : label"
|
:label="iconOnly ? undefined : label"
|
||||||
|
|||||||
@@ -5,25 +5,30 @@ import type { CopyFormat } from '~/composables/useUploadPreferences'
|
|||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
image: ImageItem
|
image: ImageItem
|
||||||
selected: boolean
|
selected: boolean
|
||||||
deleting?: boolean
|
|
||||||
selectable?: boolean
|
selectable?: boolean
|
||||||
showKey?: boolean
|
showKey?: boolean
|
||||||
showStorage?: boolean
|
showStorage?: boolean
|
||||||
compact?: boolean
|
compact?: boolean
|
||||||
|
gallery?: boolean
|
||||||
|
allowDelete?: boolean
|
||||||
}>(), {
|
}>(), {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
showKey: true,
|
showKey: true,
|
||||||
showStorage: false,
|
showStorage: false,
|
||||||
compact: false
|
compact: false,
|
||||||
|
gallery: false,
|
||||||
|
allowDelete: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
'update:selected': [value: boolean]
|
'update:selected': [value: boolean]
|
||||||
|
'preview': []
|
||||||
'delete': []
|
'delete': []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const { formatFileSize } = useFileSize()
|
const { formatFileSize } = useFileSize()
|
||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
|
const toast = useToast()
|
||||||
const { copyFormat } = useUploadPreferences()
|
const { copyFormat } = useUploadPreferences()
|
||||||
const imageError = ref(false)
|
const imageError = ref(false)
|
||||||
const retryCount = ref(0)
|
const retryCount = ref(0)
|
||||||
@@ -111,21 +116,174 @@ const storageIcon = computed(() =>
|
|||||||
props.image.storage?.type === 'local' ? 'i-lucide-hard-drive' : 'i-lucide-cloud'
|
props.image.storage?.type === 'local' ? 'i-lucide-hard-drive' : 'i-lucide-cloud'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const uploadSourceLabel = computed(() => {
|
||||||
|
switch (props.image.uploadSource) {
|
||||||
|
case 'web':
|
||||||
|
return t('stats.tagWeb')
|
||||||
|
case 'api':
|
||||||
|
return t('stats.tagApi')
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
function toggleSelected(value: boolean | 'indeterminate') {
|
function toggleSelected(value: boolean | 'indeterminate') {
|
||||||
emit('update:selected', value === true)
|
emit('update:selected', value === true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const copyingUrl = ref(false)
|
||||||
|
|
||||||
|
async function copyGalleryUrl() {
|
||||||
|
if (copyingUrl.value || !props.image.url) return
|
||||||
|
copyingUrl.value = true
|
||||||
|
try {
|
||||||
|
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||||
|
await navigator.clipboard.writeText(props.image.url)
|
||||||
|
} else {
|
||||||
|
const textarea = document.createElement('textarea')
|
||||||
|
textarea.value = props.image.url
|
||||||
|
textarea.setAttribute('readonly', '')
|
||||||
|
textarea.style.position = 'fixed'
|
||||||
|
textarea.style.left = '-9999px'
|
||||||
|
document.body.appendChild(textarea)
|
||||||
|
textarea.select()
|
||||||
|
document.execCommand('copy')
|
||||||
|
document.body.removeChild(textarea)
|
||||||
|
}
|
||||||
|
toast.add({ title: t('copy.copiedUrl'), color: 'success' })
|
||||||
|
} catch {
|
||||||
|
toast.add({ title: t('copy.failedManual'), color: 'error' })
|
||||||
|
} finally {
|
||||||
|
copyingUrl.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col overflow-hidden rounded-xl border border-default bg-elevated shadow-sm">
|
<div
|
||||||
<div class="relative aspect-square shrink-0 overflow-hidden bg-muted">
|
v-if="gallery"
|
||||||
|
class="flex flex-col overflow-hidden rounded-xl border border-default bg-elevated"
|
||||||
|
>
|
||||||
|
<div class="relative aspect-[4/3] shrink-0 overflow-hidden bg-muted">
|
||||||
<img
|
<img
|
||||||
v-if="!imageError"
|
v-if="!imageError"
|
||||||
:key="`${image.key}-${retryCount}`"
|
:key="`${image.key}-${retryCount}`"
|
||||||
:src="previewSrc"
|
:src="previewSrc"
|
||||||
:alt="image.originalName"
|
:alt="image.originalName"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
class="absolute inset-0 size-full object-cover object-center"
|
class="size-full cursor-zoom-in object-cover object-center"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
:aria-label="t('image.openPreview')"
|
||||||
|
@click="emit('preview')"
|
||||||
|
@keydown.enter="emit('preview')"
|
||||||
|
@keydown.space.prevent="emit('preview')"
|
||||||
|
@error="onPreviewError"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex size-full items-center justify-center text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ t('image.previewFailed') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="selectable"
|
||||||
|
class="absolute top-2 left-2"
|
||||||
|
@click.stop
|
||||||
|
>
|
||||||
|
<UCheckbox
|
||||||
|
:model-value="selected"
|
||||||
|
:ui="{ base: 'shadow-none' }"
|
||||||
|
@update:model-value="toggleSelected"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1.5 p-3">
|
||||||
|
<p
|
||||||
|
class="truncate text-sm font-semibold"
|
||||||
|
:title="image.originalName"
|
||||||
|
>
|
||||||
|
{{ image.originalName }}
|
||||||
|
</p>
|
||||||
|
<p class="truncate text-xs text-muted">
|
||||||
|
{{ uploadedLabel }} · {{ formatFileSize(image.size) }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-if="uploadSourceLabel || (showStorage && image.storage)"
|
||||||
|
class="flex flex-wrap gap-1.5"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-if="uploadSourceLabel"
|
||||||
|
class="inline-flex rounded-md bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary"
|
||||||
|
>
|
||||||
|
{{ uploadSourceLabel }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="showStorage && image.storage"
|
||||||
|
class="inline-flex max-w-full items-center gap-1 rounded-md border border-default px-2 py-0.5 text-xs text-muted"
|
||||||
|
:title="image.storage.name"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="storageIcon"
|
||||||
|
class="size-3 shrink-0"
|
||||||
|
/>
|
||||||
|
<span class="truncate">{{ image.storage.name }}</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-around border-t border-default px-2 py-2 text-muted">
|
||||||
|
<UButton
|
||||||
|
icon="i-lucide-link"
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
size="sm"
|
||||||
|
:loading="copyingUrl"
|
||||||
|
:aria-label="t('common.copy')"
|
||||||
|
@click="copyGalleryUrl"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
icon="i-lucide-eye"
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
size="sm"
|
||||||
|
:aria-label="t('image.openPreview')"
|
||||||
|
@click="emit('preview')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="allowDelete"
|
||||||
|
icon="i-lucide-trash-2"
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
size="sm"
|
||||||
|
:aria-label="t('common.delete')"
|
||||||
|
@click="emit('delete')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex flex-col overflow-hidden rounded-xl border border-default bg-elevated shadow-sm"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="relative aspect-square shrink-0 overflow-hidden bg-muted"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
:aria-label="t('image.openPreview')"
|
||||||
|
@click="emit('preview')"
|
||||||
|
@keydown.enter="emit('preview')"
|
||||||
|
@keydown.space.prevent="emit('preview')"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="!imageError"
|
||||||
|
:key="`${image.key}-${retryCount}`"
|
||||||
|
:src="previewSrc"
|
||||||
|
:alt="image.originalName"
|
||||||
|
loading="lazy"
|
||||||
|
class="absolute inset-0 size-full cursor-zoom-in object-cover object-center"
|
||||||
@error="onPreviewError"
|
@error="onPreviewError"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -137,26 +295,17 @@ function toggleSelected(value: boolean | 'indeterminate') {
|
|||||||
<div
|
<div
|
||||||
v-if="selectable"
|
v-if="selectable"
|
||||||
class="absolute top-2 left-2"
|
class="absolute top-2 left-2"
|
||||||
|
@click.stop
|
||||||
>
|
>
|
||||||
<UCheckbox
|
<UCheckbox
|
||||||
:model-value="selected"
|
:model-value="selected"
|
||||||
@update:model-value="toggleSelected"
|
@update:model-value="toggleSelected"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="absolute top-2 right-2">
|
|
||||||
<UButton
|
|
||||||
size="xs"
|
|
||||||
color="error"
|
|
||||||
variant="solid"
|
|
||||||
icon="i-lucide-trash-2"
|
|
||||||
:aria-label="t('common.delete')"
|
|
||||||
:loading="deleting"
|
|
||||||
@click="emit('delete')"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
v-if="image.owner"
|
v-if="image.owner"
|
||||||
class="absolute bottom-2 left-2 max-w-[calc(50%-0.5rem)]"
|
class="absolute bottom-2 left-2 max-w-[calc(50%-0.5rem)]"
|
||||||
|
@click.stop
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="inline-flex max-w-full items-center gap-1 rounded-md bg-black/65 px-2 py-0.5 text-xs font-medium text-white shadow-sm backdrop-blur-sm"
|
class="inline-flex max-w-full items-center gap-1 rounded-md bg-black/65 px-2 py-0.5 text-xs font-medium text-white shadow-sm backdrop-blur-sm"
|
||||||
@@ -173,6 +322,7 @@ function toggleSelected(value: boolean | 'indeterminate') {
|
|||||||
v-if="showStorage && image.storage"
|
v-if="showStorage && image.storage"
|
||||||
class="absolute bottom-2 max-w-[calc(50%-0.5rem)]"
|
class="absolute bottom-2 max-w-[calc(50%-0.5rem)]"
|
||||||
:class="image.owner ? 'right-2' : 'left-2'"
|
:class="image.owner ? 'right-2' : 'left-2'"
|
||||||
|
@click.stop
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
class="inline-flex max-w-full items-center gap-1 rounded-md bg-black/65 px-2 py-0.5 text-xs font-medium text-white shadow-sm backdrop-blur-sm"
|
class="inline-flex max-w-full items-center gap-1 rounded-md bg-black/65 px-2 py-0.5 text-xs font-medium text-white shadow-sm backdrop-blur-sm"
|
||||||
|
|||||||
@@ -4,24 +4,39 @@ import type { ImageItem } from '~/types/image'
|
|||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
items: ImageItem[]
|
items: ImageItem[]
|
||||||
selectedKeys: Set<string>
|
selectedKeys: Set<string>
|
||||||
deletingKeys: Set<string>
|
|
||||||
selectable?: boolean
|
selectable?: boolean
|
||||||
showKey?: boolean
|
showKey?: boolean
|
||||||
showStorage?: boolean
|
showStorage?: boolean
|
||||||
emptyText?: string
|
emptyText?: string
|
||||||
dense?: boolean
|
dense?: boolean
|
||||||
compact?: boolean
|
compact?: boolean
|
||||||
|
/** 图库:5 列 × 2 行,缩略图略扁 */
|
||||||
|
gallery?: boolean
|
||||||
|
allowDelete?: boolean
|
||||||
}>(), {
|
}>(), {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
showKey: true,
|
showKey: true,
|
||||||
showStorage: false,
|
showStorage: false,
|
||||||
dense: false,
|
dense: false,
|
||||||
compact: false
|
compact: false,
|
||||||
|
gallery: false,
|
||||||
|
allowDelete: true
|
||||||
|
})
|
||||||
|
|
||||||
|
const gridClass = computed(() => {
|
||||||
|
if (props.gallery) {
|
||||||
|
return 'grid items-start grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5'
|
||||||
|
}
|
||||||
|
if (props.dense) {
|
||||||
|
return 'grid items-start grid-cols-2 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4'
|
||||||
|
}
|
||||||
|
return 'grid items-start grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4'
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
'update:selectedKeys': [value: Set<string>]
|
'update:selectedKeys': [value: Set<string>]
|
||||||
'delete': [key: string]
|
'preview': [image: ImageItem]
|
||||||
|
'delete': [image: ImageItem]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -39,21 +54,23 @@ function updateSelection(key: string, selected: boolean) {
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-if="items.length"
|
v-if="items.length"
|
||||||
class="grid items-start sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
|
class="items-start"
|
||||||
:class="dense ? 'grid-cols-2 gap-3' : 'grid-cols-1 gap-4'"
|
:class="gridClass"
|
||||||
>
|
>
|
||||||
<ImageCard
|
<ImageCard
|
||||||
v-for="image in items"
|
v-for="image in items"
|
||||||
:key="image.key"
|
:key="image.key"
|
||||||
:image="image"
|
:image="image"
|
||||||
:selected="selectedKeys.has(image.key)"
|
:selected="selectedKeys.has(image.key)"
|
||||||
:deleting="deletingKeys.has(image.key)"
|
|
||||||
:selectable="selectable"
|
:selectable="selectable"
|
||||||
:show-key="showKey"
|
:show-key="showKey"
|
||||||
:show-storage="showStorage"
|
:show-storage="showStorage"
|
||||||
:compact="compact"
|
:compact="compact"
|
||||||
|
:gallery="gallery"
|
||||||
|
:allow-delete="allowDelete"
|
||||||
@update:selected="updateSelection(image.key, $event)"
|
@update:selected="updateSelection(image.key, $event)"
|
||||||
@delete="emit('delete', image.key)"
|
@preview="emit('preview', image)"
|
||||||
|
@delete="emit('delete', image)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -0,0 +1,426 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ImageItem } from '~/types/image'
|
||||||
|
import type { CopyFormat } from '~/composables/useUploadPreferences'
|
||||||
|
import { formatImageDimensions } from '~/utils/image-display'
|
||||||
|
|
||||||
|
type EmbedFormat = CopyFormat | 'bbcode'
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<{
|
||||||
|
open: boolean
|
||||||
|
image: ImageItem | null
|
||||||
|
showStorage?: boolean
|
||||||
|
deleting?: boolean
|
||||||
|
allowDelete?: boolean
|
||||||
|
}>(), {
|
||||||
|
showStorage: false,
|
||||||
|
allowDelete: true
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:open': [value: boolean]
|
||||||
|
'delete': []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const toast = useToast()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
const { t, locale } = useI18n()
|
||||||
|
const { copyFormat } = useUploadPreferences()
|
||||||
|
|
||||||
|
const naturalWidth = ref<number | null>(null)
|
||||||
|
const naturalHeight = ref<number | null>(null)
|
||||||
|
const dimensionsLoaded = ref(false)
|
||||||
|
const copyingUrl = ref(false)
|
||||||
|
const embedFormat = ref<EmbedFormat>('url')
|
||||||
|
|
||||||
|
const embedFormatItems = computed(() => [
|
||||||
|
{ label: t('copy.url'), value: 'url' as const },
|
||||||
|
{ label: t('copy.markdown'), value: 'markdown' as const },
|
||||||
|
{ label: t('copy.html'), value: 'html' as const },
|
||||||
|
{ label: t('copy.bbcode'), value: 'bbcode' as const }
|
||||||
|
])
|
||||||
|
|
||||||
|
const uploadedLabel = computed(() => {
|
||||||
|
if (!props.image) return '—'
|
||||||
|
try {
|
||||||
|
const date = new Date(props.image.uploadedAt)
|
||||||
|
const y = date.getFullYear()
|
||||||
|
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
const d = String(date.getDate()).padStart(2, '0')
|
||||||
|
const h = String(date.getHours()).padStart(2, '0')
|
||||||
|
const min = String(date.getMinutes()).padStart(2, '0')
|
||||||
|
const s = String(date.getSeconds()).padStart(2, '0')
|
||||||
|
return `${y}/${m}/${d} ${h}:${min}:${s}`
|
||||||
|
} catch {
|
||||||
|
return props.image.uploadedAt
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const sizeLabel = computed(() => {
|
||||||
|
if (!props.image) return '—'
|
||||||
|
return t('image.previewSizeDetail', {
|
||||||
|
size: formatFileSize(props.image.size),
|
||||||
|
bytes: props.image.size.toLocaleString(locale.value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const bbcodeValue = computed(() => {
|
||||||
|
if (!props.image) return ''
|
||||||
|
return `[img]${props.image.url}[/img]`
|
||||||
|
})
|
||||||
|
|
||||||
|
const previewValue = computed(() => {
|
||||||
|
if (!props.image) return ''
|
||||||
|
switch (embedFormat.value) {
|
||||||
|
case 'markdown':
|
||||||
|
return props.image.markdown
|
||||||
|
case 'html':
|
||||||
|
return props.image.html
|
||||||
|
case 'bbcode':
|
||||||
|
return bbcodeValue.value
|
||||||
|
default:
|
||||||
|
return props.image.url
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const copySuccessTitle = computed(() => {
|
||||||
|
switch (embedFormat.value) {
|
||||||
|
case 'markdown':
|
||||||
|
return t('copy.copiedMarkdown')
|
||||||
|
case 'html':
|
||||||
|
return t('copy.copiedHtml')
|
||||||
|
case 'bbcode':
|
||||||
|
return t('copy.copiedBbcode')
|
||||||
|
default:
|
||||||
|
return t('copy.copiedUrl')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const storageIcon = computed(() =>
|
||||||
|
props.image?.storage?.type === 'local' ? 'i-lucide-hard-drive' : 'i-lucide-cloud'
|
||||||
|
)
|
||||||
|
|
||||||
|
const uploadSourceTag = computed(() => {
|
||||||
|
switch (props.image?.uploadSource) {
|
||||||
|
case 'web':
|
||||||
|
return t('stats.tagWeb')
|
||||||
|
case 'api':
|
||||||
|
return t('stats.tagApi')
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dimensionsLabel = computed(() => {
|
||||||
|
const formatted = formatImageDimensions(naturalWidth.value, naturalHeight.value)
|
||||||
|
if (formatted) return formatted
|
||||||
|
return dimensionsLoaded.value ? '—' : t('image.previewDimensionsUnknown')
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => props.image?.key, () => {
|
||||||
|
naturalWidth.value = null
|
||||||
|
naturalHeight.value = null
|
||||||
|
dimensionsLoaded.value = false
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => props.open, (open) => {
|
||||||
|
if (open) {
|
||||||
|
embedFormat.value = copyFormat.value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function selectEmbedFormat(value: EmbedFormat) {
|
||||||
|
embedFormat.value = value
|
||||||
|
if (value !== 'bbcode') {
|
||||||
|
copyFormat.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyText(text: string, successTitle: string) {
|
||||||
|
if (!text) return false
|
||||||
|
try {
|
||||||
|
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
||||||
|
await navigator.clipboard.writeText(text)
|
||||||
|
toast.add({ title: successTitle, color: 'success' })
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// fallback below
|
||||||
|
}
|
||||||
|
|
||||||
|
const textarea = document.createElement('textarea')
|
||||||
|
textarea.value = text
|
||||||
|
textarea.setAttribute('readonly', '')
|
||||||
|
textarea.style.position = 'fixed'
|
||||||
|
textarea.style.left = '-9999px'
|
||||||
|
document.body.appendChild(textarea)
|
||||||
|
textarea.select()
|
||||||
|
let ok = false
|
||||||
|
try {
|
||||||
|
ok = document.execCommand('copy')
|
||||||
|
} catch {
|
||||||
|
ok = false
|
||||||
|
} finally {
|
||||||
|
document.body.removeChild(textarea)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok) {
|
||||||
|
toast.add({ title: successTitle, color: 'success' })
|
||||||
|
} else {
|
||||||
|
toast.add({ title: t('copy.failedManual'), color: 'error' })
|
||||||
|
}
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyLink() {
|
||||||
|
if (!props.image?.url || copyingUrl.value) return
|
||||||
|
copyingUrl.value = true
|
||||||
|
try {
|
||||||
|
await copyText(props.image.url, t('copy.copiedUrl'))
|
||||||
|
} finally {
|
||||||
|
copyingUrl.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openInNewTab() {
|
||||||
|
if (!props.image?.url) return
|
||||||
|
window.open(props.image.url, '_blank', 'noopener,noreferrer')
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadOriginal() {
|
||||||
|
if (!props.image?.url) return
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = props.image.url
|
||||||
|
link.download = props.image.originalName || 'image'
|
||||||
|
link.rel = 'noopener'
|
||||||
|
link.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestDelete() {
|
||||||
|
emit('delete')
|
||||||
|
}
|
||||||
|
|
||||||
|
function onImageLoad(event: Event) {
|
||||||
|
const img = event.target as HTMLImageElement
|
||||||
|
naturalWidth.value = img.naturalWidth
|
||||||
|
naturalHeight.value = img.naturalHeight
|
||||||
|
dimensionsLoaded.value = true
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UModal
|
||||||
|
:open="open && !!image"
|
||||||
|
:title="t('image.previewTitle')"
|
||||||
|
:description="t('image.previewSubtitle')"
|
||||||
|
:ui="{ content: 'max-w-5xl' }"
|
||||||
|
@update:open="emit('update:open', $event)"
|
||||||
|
>
|
||||||
|
<template
|
||||||
|
v-if="image"
|
||||||
|
#body
|
||||||
|
>
|
||||||
|
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.15fr)] lg:items-start">
|
||||||
|
<div class="preview-checkerboard flex items-center justify-center overflow-hidden rounded-xl border border-default p-4">
|
||||||
|
<img
|
||||||
|
:src="image.url"
|
||||||
|
:alt="image.originalName"
|
||||||
|
class="max-h-[min(60vh,24rem)] w-full object-contain"
|
||||||
|
@load="onImageLoad"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-col gap-5">
|
||||||
|
<dl class="divide-y divide-default text-sm">
|
||||||
|
<div class="flex gap-4 py-2.5 first:pt-0">
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewOriginalName') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1 break-all font-medium">
|
||||||
|
{{ image.originalName }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-4 py-2.5">
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewUploadedAt') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
{{ uploadedLabel }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-4 py-2.5">
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewSize') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
{{ sizeLabel }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-4 py-2.5">
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewDimensions') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
{{ dimensionsLabel }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-4 py-2.5">
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewContentType') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
{{ image.contentType }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="showStorage && image.storage"
|
||||||
|
class="flex gap-4 py-2.5"
|
||||||
|
>
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewStorage') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
<span class="inline-flex items-center gap-1.5">
|
||||||
|
<UIcon
|
||||||
|
:name="storageIcon"
|
||||||
|
class="size-3.5 shrink-0 text-muted"
|
||||||
|
/>
|
||||||
|
{{ image.storage.name }}
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="uploadSourceTag"
|
||||||
|
class="flex gap-4 py-2.5"
|
||||||
|
>
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewUploadSource') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
<span class="inline-flex rounded-md bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary">
|
||||||
|
{{ uploadSourceTag }}
|
||||||
|
</span>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="image.owner"
|
||||||
|
class="flex gap-4 py-2.5"
|
||||||
|
>
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewOwner') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="min-w-0 flex-1">
|
||||||
|
{{ image.owner.username }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-4 py-2.5 last:pb-0">
|
||||||
|
<dt class="w-20 shrink-0 text-muted">
|
||||||
|
{{ t('image.previewKey') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="flex min-w-0 flex-1 items-start gap-2">
|
||||||
|
<span class="min-w-0 flex-1 break-all font-mono text-xs text-dimmed">
|
||||||
|
{{ image.key }}
|
||||||
|
</span>
|
||||||
|
<CopyButton
|
||||||
|
icon="i-lucide-copy"
|
||||||
|
icon-only
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
class="shrink-0"
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:value="image.key"
|
||||||
|
:success-title="t('copy.copied')"
|
||||||
|
/>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<div class="border-t border-default pt-4">
|
||||||
|
<p class="mb-2.5 text-sm font-medium">
|
||||||
|
{{ t('image.previewLinks') }}
|
||||||
|
</p>
|
||||||
|
<div class="flex gap-1 rounded-lg border border-default bg-default p-0.5">
|
||||||
|
<UButton
|
||||||
|
v-for="item in embedFormatItems"
|
||||||
|
:key="item.value"
|
||||||
|
size="xs"
|
||||||
|
class="flex-1 justify-center"
|
||||||
|
:variant="embedFormat === item.value ? 'solid' : 'ghost'"
|
||||||
|
:color="embedFormat === item.value ? 'primary' : 'neutral'"
|
||||||
|
:label="item.label"
|
||||||
|
@click="selectEmbedFormat(item.value)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 flex items-center gap-2">
|
||||||
|
<UInput
|
||||||
|
:model-value="previewValue"
|
||||||
|
readonly
|
||||||
|
size="sm"
|
||||||
|
class="min-w-0 flex-1 font-mono text-xs"
|
||||||
|
/>
|
||||||
|
<CopyButton
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:value="previewValue"
|
||||||
|
:success-title="copySuccessTitle"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template
|
||||||
|
v-if="image"
|
||||||
|
#footer
|
||||||
|
>
|
||||||
|
<div class="flex w-full flex-wrap justify-end gap-1.5">
|
||||||
|
<UButton
|
||||||
|
:label="t('image.previewOpen')"
|
||||||
|
icon="i-lucide-external-link"
|
||||||
|
color="neutral"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
@click="openInNewTab"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('image.previewDownload')"
|
||||||
|
icon="i-lucide-download"
|
||||||
|
color="neutral"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
@click="downloadOriginal"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('image.previewCopyLink')"
|
||||||
|
icon="i-lucide-link"
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
:loading="copyingUrl"
|
||||||
|
@click="copyLink"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="allowDelete"
|
||||||
|
:label="t('common.delete')"
|
||||||
|
icon="i-lucide-trash-2"
|
||||||
|
color="error"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
:loading="deleting"
|
||||||
|
@click="requestDelete"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.preview-checkerboard {
|
||||||
|
background-color: var(--ui-bg-muted);
|
||||||
|
background-image:
|
||||||
|
linear-gradient(45deg, color-mix(in oklab, var(--ui-border) 28%, transparent) 25%, transparent 25%),
|
||||||
|
linear-gradient(-45deg, color-mix(in oklab, var(--ui-border) 28%, transparent) 25%, transparent 25%),
|
||||||
|
linear-gradient(45deg, transparent 75%, color-mix(in oklab, var(--ui-border) 28%, transparent) 75%),
|
||||||
|
linear-gradient(-45deg, transparent 75%, color-mix(in oklab, var(--ui-border) 28%, transparent) 75%);
|
||||||
|
background-size: 14px 14px;
|
||||||
|
background-position: 0 0, 0 7px, 7px -7px, -7px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type {
|
||||||
|
LoginVerificationMethod,
|
||||||
|
LoginVerificationPayload
|
||||||
|
} from '~/types/auth'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
method: LoginVerificationMethod
|
||||||
|
turnstileSiteKey?: string
|
||||||
|
capApiEndpoint?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
verified: [payload: LoginVerificationPayload]
|
||||||
|
cleared: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const sliderRef = ref<{ reset: () => Promise<void> } | null>(null)
|
||||||
|
const turnstileRef = ref<{ reset: () => void } | null>(null)
|
||||||
|
const capRef = ref<{ reset: () => void } | null>(null)
|
||||||
|
|
||||||
|
function onSliderVerified(payload: { id: string, positionPercent: number }) {
|
||||||
|
emit('verified', {
|
||||||
|
method: 'slider',
|
||||||
|
captchaId: payload.id,
|
||||||
|
captchaPosition: payload.positionPercent
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTurnstileVerified(payload: { turnstileToken: string }) {
|
||||||
|
emit('verified', {
|
||||||
|
method: 'turnstile',
|
||||||
|
turnstileToken: payload.turnstileToken
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCapVerified(payload: { capToken: string }) {
|
||||||
|
emit('verified', {
|
||||||
|
method: 'cap',
|
||||||
|
capToken: payload.capToken
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCleared() {
|
||||||
|
emit('cleared')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reset() {
|
||||||
|
emit('cleared')
|
||||||
|
if (props.method === 'slider') {
|
||||||
|
await sliderRef.value?.reset()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (props.method === 'turnstile') {
|
||||||
|
turnstileRef.value?.reset()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
capRef.value?.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ reset })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SliderCaptcha
|
||||||
|
v-if="method === 'slider'"
|
||||||
|
ref="sliderRef"
|
||||||
|
@verified="onSliderVerified"
|
||||||
|
/>
|
||||||
|
<TurnstileCaptcha
|
||||||
|
v-else-if="method === 'turnstile' && turnstileSiteKey"
|
||||||
|
ref="turnstileRef"
|
||||||
|
:site-key="turnstileSiteKey"
|
||||||
|
@verified="onTurnstileVerified"
|
||||||
|
@cleared="onCleared"
|
||||||
|
/>
|
||||||
|
<CapCaptcha
|
||||||
|
v-else-if="method === 'cap' && capApiEndpoint"
|
||||||
|
ref="capRef"
|
||||||
|
:api-endpoint="capApiEndpoint"
|
||||||
|
@verified="onCapVerified"
|
||||||
|
@cleared="onCleared"
|
||||||
|
/>
|
||||||
|
<p
|
||||||
|
v-else
|
||||||
|
class="rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-xs text-warning"
|
||||||
|
>
|
||||||
|
{{ $t('auth.verificationMisconfigured') }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
@@ -136,24 +136,6 @@ function toggleOpen() {
|
|||||||
{{ t('nav.account') }}
|
{{ t('nav.account') }}
|
||||||
</h3>
|
</h3>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<NuxtLink
|
|
||||||
to="/logs"
|
|
||||||
class="flex items-center justify-between rounded-lg border border-default px-3.5 py-2.5 text-sm text-highlighted transition-colors hover:bg-elevated"
|
|
||||||
@click="open = false"
|
|
||||||
>
|
|
||||||
<span class="flex items-center gap-2.5">
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-scroll-text"
|
|
||||||
class="size-4 opacity-70"
|
|
||||||
/>
|
|
||||||
{{ t('nav.logs') }}
|
|
||||||
</span>
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-chevron-right"
|
|
||||||
class="size-4 text-muted"
|
|
||||||
/>
|
|
||||||
</NuxtLink>
|
|
||||||
|
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
to="/account/password"
|
to="/account/password"
|
||||||
class="flex items-center justify-between rounded-lg border border-default px-3.5 py-2.5 text-sm text-highlighted transition-colors hover:bg-elevated"
|
class="flex items-center justify-between rounded-lg border border-default px-3.5 py-2.5 text-sm text-highlighted transition-colors hover:bg-elevated"
|
||||||
|
|||||||
@@ -1,124 +1,250 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const props = defineProps<{
|
type PageItem = number | 'ellipsis'
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<{
|
||||||
page: number
|
page: number
|
||||||
totalPages: number
|
totalPages: number
|
||||||
total: number
|
total: number
|
||||||
unit?: string
|
unit?: string
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
}>()
|
pageSize?: number
|
||||||
|
pageSizeOptions?: number[]
|
||||||
|
}>(), {
|
||||||
|
loading: false,
|
||||||
|
pageSizeOptions: () => [10, 20, 30, 50]
|
||||||
|
})
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
'update:page': [page: number]
|
'update:page': [page: number]
|
||||||
|
'update:pageSize': [pageSize: number]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const unitLabel = computed(() => props.unit ?? t('common.itemsUnit'))
|
const unitLabel = computed(() => props.unit ?? t('common.itemsUnit'))
|
||||||
const jumpInput = ref('')
|
const jumpPageInput = ref('')
|
||||||
|
|
||||||
|
const showMobilePageNumbers = computed(() => props.totalPages <= 5)
|
||||||
|
|
||||||
|
const visiblePages = computed<PageItem[]>(() => {
|
||||||
|
const total = Math.max(1, props.totalPages)
|
||||||
|
const current = Math.min(Math.max(1, props.page), total)
|
||||||
|
|
||||||
|
if (total <= 7) {
|
||||||
|
return Array.from({ length: total }, (_, index) => index + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const pages = new Set<number>([1, total])
|
||||||
|
for (let page = current - 1; page <= current + 1; page++) {
|
||||||
|
if (page >= 1 && page <= total) pages.add(page)
|
||||||
|
}
|
||||||
|
|
||||||
|
const sorted = [...pages].sort((a, b) => a - b)
|
||||||
|
const items: PageItem[] = []
|
||||||
|
|
||||||
|
for (let index = 0; index < sorted.length; index++) {
|
||||||
|
const page = sorted[index]!
|
||||||
|
const prev = sorted[index - 1]
|
||||||
|
if (prev !== undefined && page - prev > 1) {
|
||||||
|
items.push('ellipsis')
|
||||||
|
}
|
||||||
|
items.push(page)
|
||||||
|
}
|
||||||
|
|
||||||
|
return items
|
||||||
|
})
|
||||||
|
|
||||||
|
const pageSizeItems = computed(() =>
|
||||||
|
props.pageSizeOptions.map(size => ({
|
||||||
|
label: t('pagination.perPage', { size }),
|
||||||
|
value: size
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.page,
|
||||||
|
(page) => {
|
||||||
|
jumpPageInput.value = String(page)
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
function goTo(target: number) {
|
function goTo(target: number) {
|
||||||
if (target < 1 || target > props.totalPages || props.loading) {
|
if (target < 1 || target > props.totalPages || props.loading) return
|
||||||
return
|
if (target === props.page) return
|
||||||
}
|
|
||||||
if (target === props.page) {
|
|
||||||
jumpInput.value = ''
|
|
||||||
return
|
|
||||||
}
|
|
||||||
emit('update:page', target)
|
emit('update:page', target)
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitJump() {
|
function onPageSizeChange(value: unknown) {
|
||||||
const raw = String(jumpInput.value ?? '').trim()
|
const size = Number(value)
|
||||||
if (!raw) return
|
if (!Number.isFinite(size) || size <= 0 || size === props.pageSize) return
|
||||||
const parsed = Number.parseInt(raw, 10)
|
emit('update:pageSize', size)
|
||||||
if (!Number.isFinite(parsed)) return
|
|
||||||
goTo(parsed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => props.page, () => {
|
function jumpToPage() {
|
||||||
jumpInput.value = ''
|
const target = Number.parseInt(jumpPageInput.value, 10)
|
||||||
})
|
if (!Number.isFinite(target)) return
|
||||||
|
goTo(target)
|
||||||
|
}
|
||||||
|
|
||||||
|
function pageButtonClass(target: number) {
|
||||||
|
return target === props.page
|
||||||
|
? 'border-primary bg-primary/10 text-primary font-medium'
|
||||||
|
: 'border-default bg-elevated text-default hover:bg-muted'
|
||||||
|
}
|
||||||
|
|
||||||
|
const navButtonClass = 'inline-flex items-center justify-center rounded-md border border-default bg-elevated text-default transition-colors hover:bg-muted disabled:pointer-events-none disabled:opacity-40'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
v-if="total > 0"
|
v-if="total > 0"
|
||||||
class="flex flex-col items-center gap-2 border-t border-default pt-4 sm:flex-row sm:justify-between"
|
class="border-t border-default pt-4"
|
||||||
>
|
>
|
||||||
<p
|
<div class="flex flex-col gap-3">
|
||||||
v-if="totalPages > 1"
|
<div class="flex items-center justify-between gap-2 sm:hidden">
|
||||||
class="text-sm text-muted"
|
<p class="text-sm text-muted">
|
||||||
>
|
{{ t('pagination.totalCount', { total, unit: unitLabel }) }}
|
||||||
{{ t('pagination.pageOf', { page, totalPages, total, unit: unitLabel }) }}
|
|
||||||
</p>
|
</p>
|
||||||
<p
|
<USelect
|
||||||
v-else
|
v-if="pageSize !== undefined"
|
||||||
class="text-sm text-muted"
|
:model-value="pageSize"
|
||||||
>
|
:items="pageSizeItems"
|
||||||
{{ t('pagination.totalOnly', { total, unit: unitLabel }) }}
|
value-key="value"
|
||||||
|
size="sm"
|
||||||
|
class="w-[6.5rem] shrink-0"
|
||||||
|
:aria-label="t('pagination.pageSize')"
|
||||||
|
:disabled="loading"
|
||||||
|
@update:model-value="onPageSizeChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<p class="hidden text-sm text-muted sm:block">
|
||||||
|
{{ t('pagination.totalCount', { total, unit: unitLabel }) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div
|
<div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-end sm:gap-3">
|
||||||
v-if="totalPages > 1"
|
<USelect
|
||||||
class="flex flex-wrap items-center justify-center gap-1"
|
v-if="pageSize !== undefined"
|
||||||
>
|
:model-value="pageSize"
|
||||||
<UButton
|
:items="pageSizeItems"
|
||||||
icon="i-lucide-chevrons-left"
|
value-key="value"
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
size="sm"
|
||||||
|
class="hidden w-[7.5rem] shrink-0 sm:block"
|
||||||
|
:aria-label="t('pagination.pageSize')"
|
||||||
|
:disabled="loading"
|
||||||
|
@update:model-value="onPageSizeChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-center gap-1 sm:justify-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[navButtonClass, 'hidden size-8 sm:inline-flex']"
|
||||||
:aria-label="t('pagination.first')"
|
:aria-label="t('pagination.first')"
|
||||||
:disabled="page <= 1 || loading"
|
:disabled="page <= 1 || loading"
|
||||||
@click="goTo(1)"
|
@click="goTo(1)"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-chevrons-left"
|
||||||
|
class="size-4"
|
||||||
/>
|
/>
|
||||||
<UButton
|
</button>
|
||||||
icon="i-lucide-chevron-left"
|
<button
|
||||||
variant="outline"
|
type="button"
|
||||||
size="sm"
|
:class="[navButtonClass, 'size-9 sm:size-8']"
|
||||||
:aria-label="t('pagination.prev')"
|
:aria-label="t('pagination.prev')"
|
||||||
:disabled="page <= 1 || loading"
|
:disabled="page <= 1 || loading"
|
||||||
@click="goTo(page - 1)"
|
@click="goTo(page - 1)"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-chevron-left"
|
||||||
|
class="size-4"
|
||||||
/>
|
/>
|
||||||
<UButton
|
</button>
|
||||||
icon="i-lucide-chevron-right"
|
|
||||||
variant="outline"
|
<p
|
||||||
size="sm"
|
v-if="!showMobilePageNumbers"
|
||||||
|
class="min-w-[5.5rem] px-1 text-center text-sm text-muted sm:hidden"
|
||||||
|
>
|
||||||
|
{{ t('pagination.pageStatus', { page, totalPages }) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template
|
||||||
|
v-for="(target, index) in visiblePages"
|
||||||
|
:key="`${target}-${index}`"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
v-if="target === 'ellipsis'"
|
||||||
|
class="inline-flex size-9 items-center justify-center text-sm text-muted sm:size-8"
|
||||||
|
:class="showMobilePageNumbers ? '' : 'hidden sm:inline-flex'"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
…
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
type="button"
|
||||||
|
class="inline-flex items-center justify-center rounded-md border text-sm transition-colors disabled:pointer-events-none disabled:opacity-40"
|
||||||
|
:class="[
|
||||||
|
pageButtonClass(target),
|
||||||
|
showMobilePageNumbers ? 'size-9 sm:size-8' : 'hidden size-8 sm:inline-flex'
|
||||||
|
]"
|
||||||
|
:aria-label="t('pagination.pageNumber', { page: target })"
|
||||||
|
:aria-current="target === page ? 'page' : undefined"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="goTo(target)"
|
||||||
|
>
|
||||||
|
{{ target }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[navButtonClass, 'size-9 sm:size-8']"
|
||||||
:aria-label="t('pagination.next')"
|
:aria-label="t('pagination.next')"
|
||||||
:disabled="page >= totalPages || loading"
|
:disabled="page >= totalPages || loading"
|
||||||
@click="goTo(page + 1)"
|
@click="goTo(page + 1)"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-chevron-right"
|
||||||
|
class="size-4"
|
||||||
/>
|
/>
|
||||||
<UButton
|
</button>
|
||||||
icon="i-lucide-chevrons-right"
|
<button
|
||||||
variant="outline"
|
type="button"
|
||||||
size="sm"
|
:class="[navButtonClass, 'hidden size-8 sm:inline-flex']"
|
||||||
:aria-label="t('pagination.last')"
|
:aria-label="t('pagination.last')"
|
||||||
:disabled="page >= totalPages || loading"
|
:disabled="page >= totalPages || loading"
|
||||||
@click="goTo(totalPages)"
|
@click="goTo(totalPages)"
|
||||||
/>
|
|
||||||
<form
|
|
||||||
class="ml-1 flex items-center gap-1"
|
|
||||||
@submit.prevent="submitJump"
|
|
||||||
>
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-chevrons-right"
|
||||||
|
class="size-4"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
class="hidden items-center gap-1.5 text-sm text-muted sm:flex"
|
||||||
|
@submit.prevent="jumpToPage"
|
||||||
|
>
|
||||||
|
<span>{{ t('pagination.goToPrefix') }}</span>
|
||||||
<UInput
|
<UInput
|
||||||
v-model="jumpInput"
|
v-model="jumpPageInput"
|
||||||
type="number"
|
type="number"
|
||||||
:min="1"
|
min="1"
|
||||||
:max="totalPages"
|
:max="totalPages"
|
||||||
size="sm"
|
size="sm"
|
||||||
class="w-16"
|
class="w-14"
|
||||||
:placeholder="t('pagination.pagePlaceholder')"
|
|
||||||
:disabled="loading"
|
|
||||||
:aria-label="t('pagination.pagePlaceholder')"
|
:aria-label="t('pagination.pagePlaceholder')"
|
||||||
@keyup.enter="submitJump"
|
:disabled="loading"
|
||||||
/>
|
@blur="jumpToPage"
|
||||||
<UButton
|
|
||||||
type="button"
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
:label="t('pagination.goTo')"
|
|
||||||
:disabled="loading || !String(jumpInput ?? '').trim()"
|
|
||||||
@click="submitJump"
|
|
||||||
/>
|
/>
|
||||||
|
<span v-if="t('pagination.goToSuffix')">{{ t('pagination.goToSuffix') }}</span>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
siteKey: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
verified: [payload: { turnstileToken: string }]
|
||||||
|
cleared: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
interface TurnstileRenderOptions {
|
||||||
|
'sitekey': string
|
||||||
|
'action'?: string
|
||||||
|
'callback'?: (token: string) => void
|
||||||
|
'expired-callback'?: () => void
|
||||||
|
'error-callback'?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TurnstileApi {
|
||||||
|
render: (container: HTMLElement, options: TurnstileRenderOptions) => string
|
||||||
|
reset: (widgetId?: string) => void
|
||||||
|
remove: (widgetId: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
turnstile?: TurnstileApi
|
||||||
|
onTurnstileLoad?: () => void
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const containerRef = ref<HTMLElement | null>(null)
|
||||||
|
const widgetId = ref<string | null>(null)
|
||||||
|
const scriptLoaded = ref(false)
|
||||||
|
|
||||||
|
function onVerified(token: string) {
|
||||||
|
if (token) {
|
||||||
|
emit('verified', { turnstileToken: token })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCleared() {
|
||||||
|
emit('cleared')
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderWidget() {
|
||||||
|
if (!containerRef.value || !window.turnstile || !props.siteKey) return
|
||||||
|
if (widgetId.value) {
|
||||||
|
window.turnstile.remove(widgetId.value)
|
||||||
|
widgetId.value = null
|
||||||
|
}
|
||||||
|
widgetId.value = window.turnstile.render(containerRef.value, {
|
||||||
|
'sitekey': props.siteKey,
|
||||||
|
'action': 'login',
|
||||||
|
'callback': onVerified,
|
||||||
|
'expired-callback': onCleared,
|
||||||
|
'error-callback': onCleared
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function tryRenderWidget() {
|
||||||
|
if (scriptLoaded.value) {
|
||||||
|
renderWidget()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadScript() {
|
||||||
|
if (window.turnstile) {
|
||||||
|
scriptLoaded.value = true
|
||||||
|
tryRenderWidget()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
window.onTurnstileLoad = () => {
|
||||||
|
scriptLoaded.value = true
|
||||||
|
tryRenderWidget()
|
||||||
|
}
|
||||||
|
const existing = document.querySelector('script[data-turnstile]')
|
||||||
|
if (existing) {
|
||||||
|
if (window.turnstile) {
|
||||||
|
scriptLoaded.value = true
|
||||||
|
tryRenderWidget()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const script = document.createElement('script')
|
||||||
|
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=onTurnstileLoad'
|
||||||
|
script.async = true
|
||||||
|
script.defer = true
|
||||||
|
script.dataset.turnstile = 'true'
|
||||||
|
document.head.appendChild(script)
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
if (window.turnstile && widgetId.value) {
|
||||||
|
window.turnstile.reset(widgetId.value)
|
||||||
|
}
|
||||||
|
onCleared()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
loadScript()
|
||||||
|
await nextTick()
|
||||||
|
tryRenderWidget()
|
||||||
|
})
|
||||||
|
|
||||||
|
watch([containerRef, () => props.siteKey, scriptLoaded], () => {
|
||||||
|
tryRenderWidget()
|
||||||
|
}, { flush: 'post' })
|
||||||
|
|
||||||
|
defineExpose({ reset })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ClientOnly>
|
||||||
|
<div
|
||||||
|
ref="containerRef"
|
||||||
|
class="flex min-h-16 items-center justify-center"
|
||||||
|
/>
|
||||||
|
</ClientOnly>
|
||||||
|
</template>
|
||||||
@@ -1,13 +1,4 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
withDefaults(
|
|
||||||
defineProps<{
|
|
||||||
embedded?: boolean
|
|
||||||
}>(),
|
|
||||||
{
|
|
||||||
embedded: false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
back: []
|
back: []
|
||||||
}>()
|
}>()
|
||||||
@@ -57,17 +48,8 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div class="upload-card-surface upload-card-surface--panel flex max-sm:min-h-0 flex-col overflow-hidden max-sm:overflow-visible sm:h-full">
|
||||||
class="flex flex-col overflow-hidden max-sm:overflow-visible"
|
<div class="flex items-start justify-between gap-3 border-b border-default px-5 py-4 sm:px-6">
|
||||||
:class="
|
|
||||||
embedded
|
|
||||||
? ''
|
|
||||||
: 'upload-card-surface upload-card-surface--panel max-sm:min-h-0 sm:h-full'
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="flex items-start justify-between gap-3 border-b border-default px-5 py-4 sm:px-6"
|
|
||||||
>
|
|
||||||
<div class="flex min-w-0 items-start gap-2">
|
<div class="flex min-w-0 items-start gap-2">
|
||||||
<UIcon
|
<UIcon
|
||||||
name="i-lucide-settings-2"
|
name="i-lucide-settings-2"
|
||||||
@@ -83,7 +65,6 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<UButton
|
<UButton
|
||||||
v-if="!embedded"
|
|
||||||
:label="t('common.back')"
|
:label="t('common.back')"
|
||||||
icon="i-lucide-arrow-left"
|
icon="i-lucide-arrow-left"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -95,10 +76,7 @@ onMounted(() => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div class="flex flex-1 flex-col justify-center p-5 sm:p-6">
|
||||||
class="p-5 sm:p-6"
|
|
||||||
:class="embedded ? '' : 'flex flex-1 flex-col justify-center'"
|
|
||||||
>
|
|
||||||
<div class="grid gap-5 sm:grid-cols-3 sm:gap-6">
|
<div class="grid gap-5 sm:grid-cols-3 sm:gap-6">
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<h3 class="text-sm font-semibold">
|
<h3 class="text-sm font-semibold">
|
||||||
@@ -128,9 +106,7 @@ onMounted(() => {
|
|||||||
class="mt-0.5"
|
class="mt-0.5"
|
||||||
/>
|
/>
|
||||||
<span class="min-w-0 flex-1">
|
<span class="min-w-0 flex-1">
|
||||||
<span
|
<span class="flex flex-wrap items-center gap-x-1.5 gap-y-1 text-sm">
|
||||||
class="flex flex-wrap items-center gap-x-1.5 gap-y-1 text-sm"
|
|
||||||
>
|
|
||||||
<span>{{ t('preferences.autoDeletePrefix') }}</span>
|
<span>{{ t('preferences.autoDeletePrefix') }}</span>
|
||||||
<UInput
|
<UInput
|
||||||
v-model.number="userAutoDeleteDaysDraft"
|
v-model.number="userAutoDeleteDaysDraft"
|
||||||
@@ -139,11 +115,7 @@ onMounted(() => {
|
|||||||
max="3650"
|
max="3650"
|
||||||
size="xs"
|
size="xs"
|
||||||
class="w-14 tabular-nums"
|
class="w-14 tabular-nums"
|
||||||
:class="
|
:class="userAutoDeleteEnabled ? '' : 'pointer-events-none opacity-40'"
|
||||||
userAutoDeleteEnabled
|
|
||||||
? ''
|
|
||||||
: 'pointer-events-none opacity-40'
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
<span>{{ t('preferences.autoDeleteSuffix') }}</span>
|
<span>{{ t('preferences.autoDeleteSuffix') }}</span>
|
||||||
</span>
|
</span>
|
||||||
@@ -171,9 +143,7 @@ onMounted(() => {
|
|||||||
<p class="text-xs leading-relaxed text-muted">
|
<p class="text-xs leading-relaxed text-muted">
|
||||||
{{ t('preferences.webpQualityHint') }}
|
{{ t('preferences.webpQualityHint') }}
|
||||||
</p>
|
</p>
|
||||||
<div
|
<div class="flex items-center justify-between gap-2 text-sm text-muted">
|
||||||
class="flex items-center justify-between gap-2 text-sm text-muted"
|
|
||||||
>
|
|
||||||
<span>{{ t('preferences.current', { n: clientWebpQuality }) }}</span>
|
<span>{{ t('preferences.current', { n: clientWebpQuality }) }}</span>
|
||||||
<span>{{ clientQualityLevel }}</span>
|
<span>{{ clientQualityLevel }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,379 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ApiDocEndpoint, ApiDocParam } from '~/composables/useApiDocs'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
endpoint: ApiDocEndpoint
|
||||||
|
token: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
|
const authToken = ref('')
|
||||||
|
const paramValues = ref<Record<string, string>>({})
|
||||||
|
const fileValues = ref<Record<string, File | null>>({})
|
||||||
|
const fileInputRefs = ref<Record<string, HTMLInputElement | null>>({})
|
||||||
|
const sending = ref(false)
|
||||||
|
const responseStatus = ref<number | null>(null)
|
||||||
|
const responseBody = ref('')
|
||||||
|
const responseError = ref(false)
|
||||||
|
|
||||||
|
function isDebugParam(param: ApiDocParam) {
|
||||||
|
if (param.name === 'token' && props.endpoint.requiresAuth) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const debugQueryParams = computed(() =>
|
||||||
|
props.endpoint.params.filter(p => p.location === 'query' && isDebugParam(p))
|
||||||
|
)
|
||||||
|
|
||||||
|
const debugBodyParams = computed(() =>
|
||||||
|
props.endpoint.params.filter(p =>
|
||||||
|
(p.location === 'form-data' || p.location === 'body') && isDebugParam(p)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const showAuthHeader = computed(() => props.endpoint.requiresAuth)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.endpoint.id,
|
||||||
|
() => {
|
||||||
|
resetForm()
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.token,
|
||||||
|
(value) => {
|
||||||
|
if (value) {
|
||||||
|
authToken.value = value
|
||||||
|
if (!props.endpoint.requiresAuth && 'token' in paramValues.value) {
|
||||||
|
paramValues.value.token = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
const values: Record<string, string> = {}
|
||||||
|
const files: Record<string, File | null> = {}
|
||||||
|
for (const param of props.endpoint.params) {
|
||||||
|
if (!isDebugParam(param)) continue
|
||||||
|
if (param.type === 'file') {
|
||||||
|
files[param.name] = null
|
||||||
|
} else if (param.name === 'keys') {
|
||||||
|
values[param.name] = '["images/2026/08/example.webp"]'
|
||||||
|
} else if (param.name === 'token' && props.token) {
|
||||||
|
values[param.name] = props.token
|
||||||
|
} else {
|
||||||
|
values[param.name] = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paramValues.value = values
|
||||||
|
fileValues.value = files
|
||||||
|
responseStatus.value = null
|
||||||
|
responseBody.value = ''
|
||||||
|
responseError.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileLabel(name: string) {
|
||||||
|
return fileValues.value[name]?.name ?? t('api.debug.noFileSelected')
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerFilePick(name: string) {
|
||||||
|
fileInputRefs.value[name]?.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFileChange(name: string, event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
fileValues.value[name] = input.files?.[0] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
function isParamFilled(param: ApiDocParam) {
|
||||||
|
if (param.type === 'file') {
|
||||||
|
return fileValues.value[param.name] != null
|
||||||
|
}
|
||||||
|
const value = paramValues.value[param.name]?.trim() ?? ''
|
||||||
|
if (!value) return false
|
||||||
|
if (param.location === 'body' && param.name === 'keys') {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(value) as { keys?: unknown }
|
||||||
|
return Array.isArray(parsed.keys) && parsed.keys.length > 0
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const canSendRequest = computed(() => {
|
||||||
|
if (sending.value) return false
|
||||||
|
if (showAuthHeader.value && !authToken.value.trim()) return false
|
||||||
|
const params = [...debugQueryParams.value, ...debugBodyParams.value]
|
||||||
|
return params.every(param => !param.required || isParamFilled(param))
|
||||||
|
})
|
||||||
|
|
||||||
|
function buildUrl() {
|
||||||
|
const url = new URL(props.endpoint.path, window.location.origin)
|
||||||
|
for (const param of debugQueryParams.value) {
|
||||||
|
const value = paramValues.value[param.name]?.trim()
|
||||||
|
if (value) {
|
||||||
|
url.searchParams.set(param.name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendRequest() {
|
||||||
|
if (!canSendRequest.value) return
|
||||||
|
sending.value = true
|
||||||
|
responseStatus.value = null
|
||||||
|
responseBody.value = ''
|
||||||
|
responseError.value = false
|
||||||
|
|
||||||
|
try {
|
||||||
|
const headers: Record<string, string> = {}
|
||||||
|
if (showAuthHeader.value && authToken.value.trim()) {
|
||||||
|
headers['Auth-Token'] = authToken.value.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
let body: BodyInit | undefined
|
||||||
|
|
||||||
|
if (debugBodyParams.value.some(p => p.location === 'form-data')) {
|
||||||
|
const formData = new FormData()
|
||||||
|
for (const param of debugBodyParams.value) {
|
||||||
|
if (param.location !== 'form-data') continue
|
||||||
|
if (param.type === 'file') {
|
||||||
|
const file = fileValues.value[param.name]
|
||||||
|
if (file) formData.append(param.name, file)
|
||||||
|
} else {
|
||||||
|
const value = paramValues.value[param.name]?.trim()
|
||||||
|
if (value) formData.append(param.name, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
body = formData
|
||||||
|
} else if (debugBodyParams.value.some(p => p.location === 'body')) {
|
||||||
|
headers['Content-Type'] = 'application/json'
|
||||||
|
try {
|
||||||
|
body = JSON.stringify(JSON.parse(paramValues.value.keys || '{}'))
|
||||||
|
} catch {
|
||||||
|
toast.add({ title: t('api.debug.invalidJson'), color: 'error' })
|
||||||
|
sending.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(buildUrl(), {
|
||||||
|
method: props.endpoint.method,
|
||||||
|
headers,
|
||||||
|
body,
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
|
||||||
|
responseStatus.value = response.status
|
||||||
|
const text = await response.text()
|
||||||
|
try {
|
||||||
|
responseBody.value = JSON.stringify(JSON.parse(text), null, 2)
|
||||||
|
} catch {
|
||||||
|
responseBody.value = text
|
||||||
|
}
|
||||||
|
responseError.value = !response.ok
|
||||||
|
} catch {
|
||||||
|
responseError.value = true
|
||||||
|
responseBody.value = t('api.debug.networkError')
|
||||||
|
toast.add({ title: t('api.debug.sendFailed'), color: 'error' })
|
||||||
|
} finally {
|
||||||
|
sending.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseScrollable = computed(() => responseBody.value.split('\n').length > 14)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<aside class="flex w-full shrink-0 flex-col border-t border-default bg-default lg:w-72 lg:border-t-0 lg:border-l xl:w-80">
|
||||||
|
<div class="flex items-start gap-2 border-b border-default px-5 py-4 sm:px-6">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-flask-conical"
|
||||||
|
class="mt-0.5 size-5 shrink-0 text-primary"
|
||||||
|
/>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<h3 class="text-base font-semibold">
|
||||||
|
{{ t('api.debug.title') }}
|
||||||
|
</h3>
|
||||||
|
<div class="mt-1.5 flex flex-wrap items-center gap-2">
|
||||||
|
<ApiMethodBadge
|
||||||
|
:method="endpoint.method"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
<code class="truncate font-mono text-xs text-muted">
|
||||||
|
{{ endpoint.path }}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-1 flex-col">
|
||||||
|
<div class="space-y-3 p-5 sm:p-6">
|
||||||
|
<section
|
||||||
|
v-if="showAuthHeader"
|
||||||
|
class="rounded-xl border border-default p-3 sm:p-4"
|
||||||
|
>
|
||||||
|
<h4 class="mb-3 text-xs font-semibold text-highlighted">
|
||||||
|
{{ t('api.debug.headers') }}
|
||||||
|
</h4>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label class="text-xs text-muted">
|
||||||
|
Auth-Token
|
||||||
|
<span class="text-error">*</span>
|
||||||
|
</label>
|
||||||
|
<UInput
|
||||||
|
v-model="authToken"
|
||||||
|
size="sm"
|
||||||
|
class="font-mono text-xs"
|
||||||
|
:placeholder="t('api.debug.tokenPlaceholder')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section
|
||||||
|
v-if="debugQueryParams.length"
|
||||||
|
class="rounded-xl border border-default p-3 sm:p-4"
|
||||||
|
>
|
||||||
|
<h4 class="mb-3 text-xs font-semibold text-highlighted">
|
||||||
|
{{ t('api.debug.query') }}
|
||||||
|
</h4>
|
||||||
|
<div class="space-y-3">
|
||||||
|
<div
|
||||||
|
v-for="param in debugQueryParams"
|
||||||
|
:key="param.name"
|
||||||
|
class="space-y-1.5"
|
||||||
|
>
|
||||||
|
<label class="text-xs text-muted">
|
||||||
|
{{ param.name }}
|
||||||
|
<span
|
||||||
|
v-if="param.required"
|
||||||
|
class="text-error"
|
||||||
|
>*</span>
|
||||||
|
</label>
|
||||||
|
<UInput
|
||||||
|
v-model="paramValues[param.name]"
|
||||||
|
size="sm"
|
||||||
|
class="font-mono text-xs"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section
|
||||||
|
v-if="debugBodyParams.length"
|
||||||
|
class="rounded-xl border border-default p-3 sm:p-4"
|
||||||
|
>
|
||||||
|
<h4 class="mb-3 text-xs font-semibold text-highlighted">
|
||||||
|
{{ t('api.debug.body') }}
|
||||||
|
</h4>
|
||||||
|
<div class="space-y-3">
|
||||||
|
<div
|
||||||
|
v-for="param in debugBodyParams"
|
||||||
|
:key="param.name"
|
||||||
|
class="space-y-1.5"
|
||||||
|
>
|
||||||
|
<label class="text-xs text-muted">
|
||||||
|
{{ param.name }}
|
||||||
|
<span
|
||||||
|
v-if="param.required"
|
||||||
|
class="text-error"
|
||||||
|
>*</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="param.type === 'file'"
|
||||||
|
class="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
:ref="(el) => { fileInputRefs[param.name] = el as HTMLInputElement }"
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
class="hidden"
|
||||||
|
@change="onFileChange(param.name, $event)"
|
||||||
|
>
|
||||||
|
<UButton
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:label="t('api.debug.selectFile')"
|
||||||
|
@click="triggerFilePick(param.name)"
|
||||||
|
/>
|
||||||
|
<span class="min-w-0 truncate text-xs text-muted">
|
||||||
|
{{ fileLabel(param.name) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UTextarea
|
||||||
|
v-else-if="param.location === 'body'"
|
||||||
|
v-model="paramValues[param.name]"
|
||||||
|
:rows="3"
|
||||||
|
size="sm"
|
||||||
|
class="font-mono text-xs"
|
||||||
|
/>
|
||||||
|
<UInput
|
||||||
|
v-else
|
||||||
|
v-model="paramValues[param.name]"
|
||||||
|
size="sm"
|
||||||
|
class="font-mono text-xs"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<UButton
|
||||||
|
icon="i-lucide-send"
|
||||||
|
:label="t('api.debug.send')"
|
||||||
|
color="primary"
|
||||||
|
block
|
||||||
|
:loading="sending"
|
||||||
|
:disabled="!canSendRequest"
|
||||||
|
@click="sendRequest"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<section
|
||||||
|
v-if="responseStatus !== null || responseBody"
|
||||||
|
class="overflow-hidden rounded-xl border border-default"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between border-b border-default px-3 py-2">
|
||||||
|
<span class="text-xs font-semibold text-highlighted">
|
||||||
|
{{ t('api.debug.response') }}
|
||||||
|
</span>
|
||||||
|
<UBadge
|
||||||
|
v-if="responseStatus !== null"
|
||||||
|
:color="responseError ? 'error' : 'success'"
|
||||||
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{{ responseStatus }}
|
||||||
|
</UBadge>
|
||||||
|
</div>
|
||||||
|
<pre
|
||||||
|
class="api-debug-response bg-neutral-950 p-3 text-xs leading-relaxed text-neutral-100"
|
||||||
|
:class="responseScrollable ? 'max-h-64 overflow-y-auto' : ''"
|
||||||
|
><code class="font-mono whitespace-pre">{{ responseBody }}</code></pre>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-auto border-t border-default p-5 sm:p-6">
|
||||||
|
<h4 class="mb-2 text-xs font-semibold">
|
||||||
|
{{ t('api.debug.notesTitle') }}
|
||||||
|
</h4>
|
||||||
|
<ul class="space-y-1 text-xs leading-relaxed text-muted">
|
||||||
|
<li>{{ t('api.debug.noteSuccess') }}</li>
|
||||||
|
<li>{{ t('api.debug.noteError') }}</li>
|
||||||
|
<li>{{ t('api.debug.noteLimit') }}</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ApiDocEndpoint } from '~/composables/useApiDocs'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
endpoint: ApiDocEndpoint
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="p-5 sm:p-6">
|
||||||
|
<h2 class="text-base font-semibold">
|
||||||
|
{{ t(endpoint.titleKey) }}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="mt-2 flex flex-wrap items-center gap-2">
|
||||||
|
<ApiMethodBadge
|
||||||
|
:method="endpoint.method"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
<code class="rounded-md border border-primary/20 bg-primary/10 px-2 py-0.5 font-mono text-sm font-medium text-primary">
|
||||||
|
{{ endpoint.path }}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="mt-3 text-sm leading-relaxed text-muted">
|
||||||
|
{{ t(endpoint.descKey) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="endpoint.params.length"
|
||||||
|
class="mt-5 overflow-hidden rounded-xl border border-default"
|
||||||
|
>
|
||||||
|
<div class="border-b border-default bg-muted/20 px-4 py-2.5">
|
||||||
|
<h3 class="text-sm font-medium">
|
||||||
|
{{ t('api.requestParams') }}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="w-full min-w-[32rem] text-left text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr class="border-b border-default text-xs text-muted">
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
{{ t('api.paramName') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
{{ t('api.paramType') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
{{ t('api.paramLocation') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
{{ t('api.paramRequired') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2.5 font-medium">
|
||||||
|
{{ t('api.paramDescription') }}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr
|
||||||
|
v-for="param in endpoint.params"
|
||||||
|
:key="param.name"
|
||||||
|
class="border-b border-default last:border-b-0"
|
||||||
|
>
|
||||||
|
<td class="px-4 py-2.5 font-mono text-xs">
|
||||||
|
{{ param.name }}
|
||||||
|
<span
|
||||||
|
v-if="param.required"
|
||||||
|
class="text-error"
|
||||||
|
>*</span>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-2.5 text-muted">
|
||||||
|
{{ param.type }}
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-2.5 text-muted">
|
||||||
|
{{ param.location }}
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-2.5">
|
||||||
|
<UBadge
|
||||||
|
:color="param.required ? 'primary' : 'neutral'"
|
||||||
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{{ param.required ? t('api.required') : t('api.optional') }}
|
||||||
|
</UBadge>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-2.5 text-muted">
|
||||||
|
{{ t(param.descriptionKey) }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-5 space-y-4">
|
||||||
|
<div>
|
||||||
|
<p class="mb-2 text-xs font-medium text-muted">
|
||||||
|
{{ t('api.requestExample') }}
|
||||||
|
</p>
|
||||||
|
<ApiCurlBlock
|
||||||
|
:code="endpoint.curl"
|
||||||
|
lang="cURL"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="mb-2 text-xs font-medium text-muted">
|
||||||
|
{{ t('api.responseExample') }}
|
||||||
|
<span class="font-normal">200 OK</span>
|
||||||
|
</p>
|
||||||
|
<ApiCurlBlock
|
||||||
|
:code="endpoint.responseExample"
|
||||||
|
lang="JSON"
|
||||||
|
:scrollable="false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ApiDocMethod } from '~/composables/useApiDocs'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
method: ApiDocMethod
|
||||||
|
size?: 'xs' | 'sm'
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const colorClass = computed(() => {
|
||||||
|
switch (props.method) {
|
||||||
|
case 'GET':
|
||||||
|
return 'bg-sky-500/15 text-sky-700 dark:text-sky-300'
|
||||||
|
case 'POST':
|
||||||
|
return 'bg-primary/15 text-primary'
|
||||||
|
case 'DELETE':
|
||||||
|
return 'bg-red-500/15 text-red-700 dark:text-red-300'
|
||||||
|
default:
|
||||||
|
return 'bg-muted text-muted'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const sizeClass = computed(() =>
|
||||||
|
props.size === 'sm' ? 'px-2 py-0.5 text-xs' : 'px-1.5 py-0.5 text-[10px]'
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span
|
||||||
|
class="inline-flex shrink-0 rounded font-mono font-semibold leading-none"
|
||||||
|
:class="[colorClass, sizeClass]"
|
||||||
|
>
|
||||||
|
{{ method }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ApiDocCategory, ApiDocEndpoint } from '~/composables/useApiDocs'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
endpoints: ApiDocEndpoint[]
|
||||||
|
activeId: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
select: [id: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t, locale } = useI18n()
|
||||||
|
const search = ref('')
|
||||||
|
const docsUrl = computed(() =>
|
||||||
|
locale.value === 'en'
|
||||||
|
? 'https://o96u.github.io/PicHost/en/guide/api.html'
|
||||||
|
: 'https://o96u.github.io/PicHost/guide/api.html'
|
||||||
|
)
|
||||||
|
|
||||||
|
const categories: { key: ApiDocCategory, labelKey: string }[] = [
|
||||||
|
{ key: 'image', labelKey: 'api.categories.image' },
|
||||||
|
{ key: 'extension', labelKey: 'api.categories.extension' },
|
||||||
|
{ key: 'system', labelKey: 'api.categories.system' }
|
||||||
|
]
|
||||||
|
|
||||||
|
const filteredEndpoints = computed(() => {
|
||||||
|
const q = search.value.trim().toLowerCase()
|
||||||
|
if (!q) return props.endpoints
|
||||||
|
return props.endpoints.filter((endpoint) => {
|
||||||
|
const title = t(endpoint.titleKey).toLowerCase()
|
||||||
|
const path = endpoint.path.toLowerCase()
|
||||||
|
return title.includes(q) || path.includes(q) || endpoint.method.toLowerCase().includes(q)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function endpointsForCategory(category: ApiDocCategory) {
|
||||||
|
return filteredEndpoints.value.filter(endpoint => endpoint.category === category)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSelect(id: string) {
|
||||||
|
emit('select', id)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearchKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
search.value = ''
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const onGlobalKeydown = (event: KeyboardEvent) => {
|
||||||
|
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k') {
|
||||||
|
event.preventDefault()
|
||||||
|
document.getElementById('api-endpoint-search')?.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener('keydown', onGlobalKeydown)
|
||||||
|
onUnmounted(() => window.removeEventListener('keydown', onGlobalKeydown))
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<aside class="flex w-full shrink-0 flex-col border-b border-default bg-default lg:w-52 lg:border-b-0 lg:border-r lg:bg-neutral-50 dark:lg:bg-neutral-900/30 xl:w-56">
|
||||||
|
<div class="border-b border-default p-3 sm:p-4">
|
||||||
|
<UInput
|
||||||
|
id="api-endpoint-search"
|
||||||
|
v-model="search"
|
||||||
|
:placeholder="t('api.searchPlaceholder')"
|
||||||
|
icon="i-lucide-search"
|
||||||
|
size="sm"
|
||||||
|
@keydown="onSearchKeydown"
|
||||||
|
>
|
||||||
|
<template #trailing>
|
||||||
|
<UKbd
|
||||||
|
size="sm"
|
||||||
|
class="hidden sm:inline-flex"
|
||||||
|
>
|
||||||
|
⌘K
|
||||||
|
</UKbd>
|
||||||
|
</template>
|
||||||
|
</UInput>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav class="flex-1 overflow-y-auto p-2 sm:p-3">
|
||||||
|
<div
|
||||||
|
v-for="category in categories"
|
||||||
|
:key="category.key"
|
||||||
|
class="mb-4"
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
v-if="endpointsForCategory(category.key).length"
|
||||||
|
class="mb-1.5 px-2 text-xs font-medium text-muted"
|
||||||
|
>
|
||||||
|
{{ t(category.labelKey) }}
|
||||||
|
</p>
|
||||||
|
<ul class="space-y-0.5">
|
||||||
|
<li
|
||||||
|
v-for="endpoint in endpointsForCategory(category.key)"
|
||||||
|
:key="endpoint.id"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full items-center gap-2 rounded-lg px-2 py-2 text-left text-sm transition-colors"
|
||||||
|
:class="activeId === endpoint.id
|
||||||
|
? 'bg-primary/10 font-medium text-primary'
|
||||||
|
: 'text-muted hover:bg-muted/40 hover:text-highlighted'"
|
||||||
|
@click="onSelect(endpoint.id)"
|
||||||
|
>
|
||||||
|
<ApiMethodBadge :method="endpoint.method" />
|
||||||
|
<span class="min-w-0 truncate">{{ t(endpoint.titleKey) }}</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="hidden border-t border-default p-3 sm:p-4 lg:block">
|
||||||
|
<div class="rounded-xl border border-primary/15 bg-primary/5 p-3">
|
||||||
|
<div class="flex items-start gap-2.5">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-book-open"
|
||||||
|
class="mt-0.5 size-4 shrink-0 text-primary"
|
||||||
|
/>
|
||||||
|
<div class="min-w-0 space-y-2">
|
||||||
|
<p class="text-xs font-medium text-highlighted">
|
||||||
|
{{ t('api.helpTitle') }}
|
||||||
|
</p>
|
||||||
|
<p class="text-xs leading-relaxed text-muted">
|
||||||
|
{{ t('api.helpSubtitle') }}
|
||||||
|
</p>
|
||||||
|
<UButton
|
||||||
|
:label="t('api.viewDocs')"
|
||||||
|
icon="i-lucide-external-link"
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:to="docsUrl"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
token: string
|
||||||
|
loading: boolean
|
||||||
|
regenerating: boolean
|
||||||
|
canRegenerate: boolean
|
||||||
|
tokenSource?: 'env' | 'db' | 'none'
|
||||||
|
envTokenOverride?: boolean
|
||||||
|
isAdmin?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
regenerate: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const toast = useToast()
|
||||||
|
const tokenVisible = ref(false)
|
||||||
|
const copying = ref(false)
|
||||||
|
|
||||||
|
function toggleTokenVisible() {
|
||||||
|
tokenVisible.value = !tokenVisible.value
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayValue = computed(() => {
|
||||||
|
if (!props.token) return t('common.notConfigured')
|
||||||
|
if (tokenVisible.value) return props.token
|
||||||
|
return '•'.repeat(Math.min(props.token.length, 40))
|
||||||
|
})
|
||||||
|
|
||||||
|
function tokenSourceLabel(source: 'env' | 'db' | 'none' | undefined) {
|
||||||
|
switch (source) {
|
||||||
|
case 'env':
|
||||||
|
return t('api.tokenSourceEnv')
|
||||||
|
case 'db':
|
||||||
|
return t('api.tokenSourceDb')
|
||||||
|
default:
|
||||||
|
return t('api.tokenSourceNone')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyToken() {
|
||||||
|
if (!props.token || copying.value) return
|
||||||
|
copying.value = true
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(props.token)
|
||||||
|
toast.add({ title: t('copy.copied'), color: 'success' })
|
||||||
|
} catch {
|
||||||
|
toast.add({ title: t('copy.failed'), color: 'error' })
|
||||||
|
} finally {
|
||||||
|
copying.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="border-b border-default">
|
||||||
|
<div class="flex items-center gap-2 border-b border-default px-5 py-4 sm:px-6">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-key-round"
|
||||||
|
class="size-5 shrink-0 text-primary"
|
||||||
|
/>
|
||||||
|
<h2 class="text-base font-semibold">
|
||||||
|
{{ t('api.tokenTitle') }}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-4 p-5 sm:p-6">
|
||||||
|
<UAlert
|
||||||
|
v-if="envTokenOverride"
|
||||||
|
color="warning"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-triangle-alert"
|
||||||
|
:title="t('api.envOverrideTitle')"
|
||||||
|
:description="t('api.envOverrideDesc')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UAlert
|
||||||
|
v-else-if="!isAdmin"
|
||||||
|
color="info"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-info"
|
||||||
|
:title="t('api.personalTitle')"
|
||||||
|
:description="t('api.personalDesc')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UAlert
|
||||||
|
v-else-if="!token && !loading"
|
||||||
|
color="info"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-info"
|
||||||
|
:title="t('api.notConfiguredTitle')"
|
||||||
|
:description="t('api.notConfiguredDesc')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2 sm:flex-row sm:items-stretch">
|
||||||
|
<UInput
|
||||||
|
:model-value="displayValue"
|
||||||
|
readonly
|
||||||
|
class="min-w-0 flex-1 font-mono text-xs sm:text-sm"
|
||||||
|
:loading="loading"
|
||||||
|
/>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<UButton
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:label="tokenVisible ? t('api.hideToken') : t('api.showToken')"
|
||||||
|
@click="toggleTokenVisible"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:loading="copying"
|
||||||
|
:disabled="!token"
|
||||||
|
@click="copyToken"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
icon="i-lucide-refresh-cw"
|
||||||
|
:label="t('api.regenerate')"
|
||||||
|
color="primary"
|
||||||
|
variant="soft"
|
||||||
|
size="sm"
|
||||||
|
:loading="regenerating"
|
||||||
|
:disabled="!canRegenerate"
|
||||||
|
@click="emit('regenerate')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p
|
||||||
|
v-if="tokenSource"
|
||||||
|
class="text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ tokenSourceLabel(tokenSource) }}
|
||||||
|
· {{ t('api.tokenHeader') }}
|
||||||
|
<code class="font-mono">Auth-Token: <token></code>
|
||||||
|
<template v-if="token && !envTokenOverride">
|
||||||
|
· {{ t('api.tokenInvalidate') }}
|
||||||
|
</template>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = withDefaults(defineProps<{
|
||||||
|
searchQuery: string
|
||||||
|
storageBackend: string
|
||||||
|
storageBackendItems: Array<{ label: string, value: string }>
|
||||||
|
uploadSource: string
|
||||||
|
uploadSourceItems: Array<{ label: string, value: string }>
|
||||||
|
viewMode: 'grid' | 'list'
|
||||||
|
selectedCount?: number
|
||||||
|
loading?: boolean
|
||||||
|
showBatchDelete?: boolean
|
||||||
|
}>(), {
|
||||||
|
selectedCount: 0,
|
||||||
|
loading: false,
|
||||||
|
showBatchDelete: true
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:searchQuery': [value: string]
|
||||||
|
'update:storageBackend': [value: string]
|
||||||
|
'update:uploadSource': [value: string]
|
||||||
|
'update:viewMode': [mode: 'grid' | 'list']
|
||||||
|
'search': []
|
||||||
|
'reset': []
|
||||||
|
'batch-delete': []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
function setViewMode(mode: 'grid' | 'list') {
|
||||||
|
if (mode === props.viewMode || props.loading) return
|
||||||
|
emit('update:viewMode', mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
function viewButtonClass(active: boolean) {
|
||||||
|
return active
|
||||||
|
? 'border-primary bg-primary/10 text-primary'
|
||||||
|
: 'border-transparent bg-elevated text-muted hover:bg-muted hover:text-default'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<form
|
||||||
|
class="flex flex-nowrap items-center gap-2 overflow-x-auto pb-1"
|
||||||
|
@submit.prevent="emit('search')"
|
||||||
|
>
|
||||||
|
<UInput
|
||||||
|
:model-value="searchQuery"
|
||||||
|
icon="i-lucide-search"
|
||||||
|
:placeholder="t('stats.searchPlaceholder')"
|
||||||
|
class="w-40 shrink-0 sm:w-48"
|
||||||
|
size="sm"
|
||||||
|
:disabled="loading"
|
||||||
|
@update:model-value="emit('update:searchQuery', $event)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<USelect
|
||||||
|
:model-value="storageBackend"
|
||||||
|
:items="storageBackendItems"
|
||||||
|
class="w-28 shrink-0"
|
||||||
|
size="sm"
|
||||||
|
:aria-label="t('stats.storage')"
|
||||||
|
:disabled="loading"
|
||||||
|
@update:model-value="emit('update:storageBackend', $event)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<USelect
|
||||||
|
:model-value="uploadSource"
|
||||||
|
:items="uploadSourceItems"
|
||||||
|
class="w-28 shrink-0"
|
||||||
|
size="sm"
|
||||||
|
:aria-label="t('stats.filterSource')"
|
||||||
|
:disabled="loading"
|
||||||
|
@update:model-value="emit('update:uploadSource', $event)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UButton
|
||||||
|
type="submit"
|
||||||
|
icon="i-lucide-search"
|
||||||
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
class="shrink-0"
|
||||||
|
:aria-label="t('common.search')"
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
{{ t('common.search') }}
|
||||||
|
</UButton>
|
||||||
|
|
||||||
|
<UButton
|
||||||
|
type="button"
|
||||||
|
icon="i-lucide-rotate-ccw"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
class="shrink-0"
|
||||||
|
:aria-label="t('stats.resetFilters')"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="emit('reset')"
|
||||||
|
>
|
||||||
|
{{ t('stats.resetFilters') }}
|
||||||
|
</UButton>
|
||||||
|
|
||||||
|
<UButton
|
||||||
|
v-if="showBatchDelete"
|
||||||
|
type="button"
|
||||||
|
icon="i-lucide-trash-2"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="error"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="!selectedCount || loading"
|
||||||
|
@click="emit('batch-delete')"
|
||||||
|
>
|
||||||
|
{{ t('stats.batchDelete') }}
|
||||||
|
</UButton>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="inline-flex shrink-0 overflow-hidden rounded-md border border-default"
|
||||||
|
role="group"
|
||||||
|
:aria-label="t('stats.viewMode')"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex size-8 items-center justify-center border-r border-default transition-colors disabled:pointer-events-none disabled:opacity-40"
|
||||||
|
:class="viewButtonClass(viewMode === 'grid')"
|
||||||
|
:aria-label="t('stats.viewGrid')"
|
||||||
|
:aria-pressed="viewMode === 'grid'"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="setViewMode('grid')"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-layout-grid"
|
||||||
|
class="size-4"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex size-8 items-center justify-center transition-colors disabled:pointer-events-none disabled:opacity-40"
|
||||||
|
:class="viewButtonClass(viewMode === 'list')"
|
||||||
|
:aria-label="t('stats.viewList')"
|
||||||
|
:aria-pressed="viewMode === 'list'"
|
||||||
|
:disabled="loading"
|
||||||
|
@click="setViewMode('list')"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-list"
|
||||||
|
class="size-4"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ImageItem } from '~/types/image'
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<{
|
||||||
|
items: ImageItem[]
|
||||||
|
selectedKeys: Set<string>
|
||||||
|
selectable?: boolean
|
||||||
|
showStorage?: boolean
|
||||||
|
emptyText?: string
|
||||||
|
showDelete?: boolean
|
||||||
|
}>(), {
|
||||||
|
selectable: false,
|
||||||
|
showStorage: false,
|
||||||
|
showDelete: true
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:selectedKeys': [value: Set<string>]
|
||||||
|
'preview': [image: ImageItem]
|
||||||
|
'delete': [image: ImageItem]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
|
||||||
|
const displayEmptyText = computed(() => props.emptyText ?? t('image.empty'))
|
||||||
|
|
||||||
|
const allSelected = computed(() =>
|
||||||
|
props.items.length > 0 && props.items.every(item => props.selectedKeys.has(item.key))
|
||||||
|
)
|
||||||
|
|
||||||
|
const someSelected = computed(() =>
|
||||||
|
props.items.some(item => props.selectedKeys.has(item.key))
|
||||||
|
)
|
||||||
|
|
||||||
|
const headerIndeterminate = computed(() => someSelected.value && !allSelected.value)
|
||||||
|
|
||||||
|
function updateSelection(key: string, selected: boolean) {
|
||||||
|
const next = new Set(props.selectedKeys)
|
||||||
|
if (selected) next.add(key)
|
||||||
|
else next.delete(key)
|
||||||
|
emit('update:selectedKeys', next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAll(value: boolean | 'indeterminate') {
|
||||||
|
if (value === true) {
|
||||||
|
emit('update:selectedKeys', new Set(props.items.map(item => item.key)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('update:selectedKeys', new Set())
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatUploadedAt(value: string) {
|
||||||
|
try {
|
||||||
|
const date = new Date(value)
|
||||||
|
const y = date.getFullYear()
|
||||||
|
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
const d = String(date.getDate()).padStart(2, '0')
|
||||||
|
const h = String(date.getHours()).padStart(2, '0')
|
||||||
|
const min = String(date.getMinutes()).padStart(2, '0')
|
||||||
|
const s = String(date.getSeconds()).padStart(2, '0')
|
||||||
|
return `${y}/${m}/${d} ${h}:${min}:${s}`
|
||||||
|
} catch {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sourceLabel(image: ImageItem) {
|
||||||
|
switch (image.uploadSource) {
|
||||||
|
case 'web':
|
||||||
|
return t('stats.tagWeb')
|
||||||
|
case 'api':
|
||||||
|
return t('stats.tagApi')
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function typeLabel(image: ImageItem) {
|
||||||
|
if (props.showStorage && image.storage) return image.storage.name
|
||||||
|
return '—'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="items.length"
|
||||||
|
class="overflow-hidden rounded-xl border border-default bg-default"
|
||||||
|
>
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="min-w-full text-sm">
|
||||||
|
<thead class="border-b border-default text-xs text-muted">
|
||||||
|
<tr>
|
||||||
|
<th
|
||||||
|
v-if="selectable"
|
||||||
|
class="w-10 px-4 py-3 text-left font-medium"
|
||||||
|
>
|
||||||
|
<UCheckbox
|
||||||
|
:model-value="allSelected ? true : headerIndeterminate ? 'indeterminate' : false"
|
||||||
|
:aria-label="t('stats.selectAll')"
|
||||||
|
@update:model-value="toggleAll"
|
||||||
|
/>
|
||||||
|
</th>
|
||||||
|
<th class="min-w-[16rem] px-4 py-3 text-left font-medium">
|
||||||
|
{{ t('stats.colFilename') }}
|
||||||
|
</th>
|
||||||
|
<th class="hidden w-28 px-4 py-3 text-left font-medium sm:table-cell">
|
||||||
|
{{ t('stats.colSource') }}
|
||||||
|
</th>
|
||||||
|
<th class="w-24 px-4 py-3 text-left font-medium">
|
||||||
|
{{ t('stats.colSize') }}
|
||||||
|
</th>
|
||||||
|
<th class="hidden w-32 px-4 py-3 text-left font-medium md:table-cell">
|
||||||
|
{{ t('stats.colType') }}
|
||||||
|
</th>
|
||||||
|
<th class="hidden w-44 px-4 py-3 text-left font-medium lg:table-cell">
|
||||||
|
{{ t('stats.colUploadedAt') }}
|
||||||
|
</th>
|
||||||
|
<th class="w-28 px-4 py-3 text-right font-medium">
|
||||||
|
{{ t('stats.colActions') }}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-default">
|
||||||
|
<tr
|
||||||
|
v-for="image in items"
|
||||||
|
:key="image.key"
|
||||||
|
class="transition-colors hover:bg-muted/20"
|
||||||
|
>
|
||||||
|
<td
|
||||||
|
v-if="selectable"
|
||||||
|
class="px-4 py-3"
|
||||||
|
>
|
||||||
|
<UCheckbox
|
||||||
|
:model-value="selectedKeys.has(image.key)"
|
||||||
|
@update:model-value="updateSelection(image.key, $event === true)"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3">
|
||||||
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="relative size-10 shrink-0 overflow-hidden rounded-md border border-default bg-muted"
|
||||||
|
:aria-label="t('image.openPreview')"
|
||||||
|
@click="emit('preview', image)"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
:src="image.url"
|
||||||
|
:alt="image.originalName"
|
||||||
|
loading="lazy"
|
||||||
|
class="size-full object-cover"
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
<p
|
||||||
|
class="min-w-0 flex-1 truncate font-medium"
|
||||||
|
:title="image.originalName"
|
||||||
|
>
|
||||||
|
{{ image.originalName }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="hidden px-4 py-3 sm:table-cell">
|
||||||
|
<span
|
||||||
|
v-if="sourceLabel(image)"
|
||||||
|
class="inline-flex rounded-md bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary"
|
||||||
|
>
|
||||||
|
{{ sourceLabel(image) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="text-muted"
|
||||||
|
>—</span>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3 text-muted">
|
||||||
|
{{ formatFileSize(image.size) }}
|
||||||
|
</td>
|
||||||
|
<td class="hidden px-4 py-3 text-muted md:table-cell">
|
||||||
|
<span class="truncate">{{ typeLabel(image) }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="hidden px-4 py-3 text-muted lg:table-cell">
|
||||||
|
{{ formatUploadedAt(image.uploadedAt) }}
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3">
|
||||||
|
<div class="flex items-center justify-end gap-0.5 text-muted">
|
||||||
|
<CopyButton
|
||||||
|
icon="i-lucide-link"
|
||||||
|
icon-only
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:value="image.url"
|
||||||
|
:success-title="t('copy.copiedUrl')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
icon="i-lucide-eye"
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
size="xs"
|
||||||
|
:aria-label="t('image.openPreview')"
|
||||||
|
@click="emit('preview', image)"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="showDelete"
|
||||||
|
icon="i-lucide-trash-2"
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
size="xs"
|
||||||
|
:aria-label="t('common.delete')"
|
||||||
|
@click="emit('delete', image)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="rounded-xl border border-dashed border-default py-16 text-center text-sm text-muted"
|
||||||
|
>
|
||||||
|
{{ displayEmptyText }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ImageItem } from '~/types/image'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
items: ImageItem[]
|
||||||
|
selectedKeys: Set<string>
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:selectedKeys': [value: Set<string>]
|
||||||
|
'clear': []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const allSelected = computed(() =>
|
||||||
|
props.items.length > 0 && props.items.every(item => props.selectedKeys.has(item.key))
|
||||||
|
)
|
||||||
|
|
||||||
|
const someSelected = computed(() =>
|
||||||
|
props.items.some(item => props.selectedKeys.has(item.key))
|
||||||
|
)
|
||||||
|
|
||||||
|
const indeterminate = computed(() => someSelected.value && !allSelected.value)
|
||||||
|
|
||||||
|
function toggleAll(value: boolean | 'indeterminate') {
|
||||||
|
if (value === true) {
|
||||||
|
emit('update:selectedKeys', new Set(props.items.map(item => item.key)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('update:selectedKeys', new Set())
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
|
<UCheckbox
|
||||||
|
:model-value="allSelected ? true : indeterminate ? 'indeterminate' : false"
|
||||||
|
:disabled="!items.length"
|
||||||
|
:aria-label="t('stats.selectAll')"
|
||||||
|
@update:model-value="toggleAll"
|
||||||
|
/>
|
||||||
|
<p class="text-sm text-muted">
|
||||||
|
{{ t('stats.selectedItems', { n: selectedKeys.size }) }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="text-sm text-primary hover:underline disabled:pointer-events-none disabled:opacity-40"
|
||||||
|
:disabled="selectedKeys.size === 0"
|
||||||
|
@click="emit('clear')"
|
||||||
|
>
|
||||||
|
{{ t('stats.clear') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
export interface GalleryStatsData {
|
||||||
|
uploadToday: number
|
||||||
|
uploadYesterday: number
|
||||||
|
uploadMonth: number
|
||||||
|
uploadLastMonth: number
|
||||||
|
uploadTotal: number
|
||||||
|
storedCount: number
|
||||||
|
uploadBytesTotal: number
|
||||||
|
bySource: {
|
||||||
|
web: number
|
||||||
|
api: number
|
||||||
|
}
|
||||||
|
storageUsage: {
|
||||||
|
usedBytes: number
|
||||||
|
totalBytes: number | null
|
||||||
|
percent: number | null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
stats: GalleryStatsData | null
|
||||||
|
loading?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
|
||||||
|
const SOURCE_COLORS = ['var(--ui-primary)', '#10b981'] as const
|
||||||
|
|
||||||
|
const sourceItems = computed(() => {
|
||||||
|
const bySource = props.stats?.bySource
|
||||||
|
if (!bySource) return []
|
||||||
|
return [
|
||||||
|
{ key: 'web', label: t('stats.sourceWeb'), count: bySource.web, color: SOURCE_COLORS[0] },
|
||||||
|
{ key: 'api', label: t('stats.sourceApi'), count: bySource.api, color: SOURCE_COLORS[1] }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const sourceTotal = computed(() =>
|
||||||
|
sourceItems.value.reduce((sum, item) => sum + item.count, 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
function sourcePercent(count: number) {
|
||||||
|
if (!sourceTotal.value) return 0
|
||||||
|
return Math.round((count / sourceTotal.value) * 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTrend(current: number, previous: number) {
|
||||||
|
if (previous === 0) {
|
||||||
|
if (current === 0) {
|
||||||
|
return { text: t('stats.trendFlat'), tone: 'muted' as const }
|
||||||
|
}
|
||||||
|
return { text: t('stats.trendUp', { p: 100 }), tone: 'up' as const }
|
||||||
|
}
|
||||||
|
const change = Math.round(((current - previous) / previous) * 100)
|
||||||
|
if (change > 0) {
|
||||||
|
return { text: t('stats.trendUp', { p: change }), tone: 'up' as const }
|
||||||
|
}
|
||||||
|
if (change < 0) {
|
||||||
|
return { text: t('stats.trendDown', { p: Math.abs(change) }), tone: 'down' as const }
|
||||||
|
}
|
||||||
|
return { text: t('stats.trendFlat'), tone: 'muted' as const }
|
||||||
|
}
|
||||||
|
|
||||||
|
const todayTrend = computed(() =>
|
||||||
|
formatTrend(props.stats?.uploadToday ?? 0, props.stats?.uploadYesterday ?? 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
const monthTrend = computed(() =>
|
||||||
|
formatTrend(props.stats?.uploadMonth ?? 0, props.stats?.uploadLastMonth ?? 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
const usageLabel = computed(() => {
|
||||||
|
const usage = props.stats?.storageUsage
|
||||||
|
if (!usage) return '—'
|
||||||
|
const used = formatFileSize(usage.usedBytes)
|
||||||
|
if (usage.totalBytes) {
|
||||||
|
return `${used} / ${formatFileSize(usage.totalBytes)}`
|
||||||
|
}
|
||||||
|
return used
|
||||||
|
})
|
||||||
|
|
||||||
|
const usagePercent = computed(() => {
|
||||||
|
const percent = props.stats?.storageUsage.percent
|
||||||
|
if (percent == null) return null
|
||||||
|
return Math.min(percent, 100)
|
||||||
|
})
|
||||||
|
|
||||||
|
const usageBarWidth = computed(() => {
|
||||||
|
const usage = props.stats?.storageUsage
|
||||||
|
if (!usage?.totalBytes || usagePercent.value == null) return 0
|
||||||
|
return Math.max(usagePercent.value, usage.usedBytes > 0 ? 4 : 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
function displayValue(value: number | undefined) {
|
||||||
|
if (props.loading) return '—'
|
||||||
|
return value ?? '—'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="grid grid-cols-2 gap-3 sm:grid-cols-3 xl:grid-cols-6">
|
||||||
|
<div class="rounded-xl border border-default bg-elevated p-4">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('stats.uploadToday') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-2xl font-semibold tabular-nums text-highlighted">
|
||||||
|
{{ displayValue(stats?.uploadToday) }}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
class="mt-2 text-xs"
|
||||||
|
:class="{
|
||||||
|
'text-primary': todayTrend.tone === 'up',
|
||||||
|
'text-muted': todayTrend.tone === 'muted',
|
||||||
|
'text-orange-600 dark:text-orange-400': todayTrend.tone === 'down'
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ t('stats.vsYesterday') }} {{ todayTrend.text }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-default bg-elevated p-4">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('stats.uploadMonth') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-2xl font-semibold tabular-nums text-highlighted">
|
||||||
|
{{ displayValue(stats?.uploadMonth) }}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
class="mt-2 text-xs"
|
||||||
|
:class="{
|
||||||
|
'text-primary': monthTrend.tone === 'up',
|
||||||
|
'text-muted': monthTrend.tone === 'muted',
|
||||||
|
'text-orange-600 dark:text-orange-400': monthTrend.tone === 'down'
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ t('stats.vsLastMonth') }} {{ monthTrend.text }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-default bg-elevated p-4">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('stats.uploadTotal') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-2xl font-semibold tabular-nums text-highlighted">
|
||||||
|
{{ displayValue(stats?.uploadTotal) }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-xs text-muted">
|
||||||
|
{{ t('stats.totalFiles') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-default bg-elevated p-4">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('stats.storedCount') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-2xl font-semibold tabular-nums text-highlighted">
|
||||||
|
{{ displayValue(stats?.storedCount) }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-xs text-muted">
|
||||||
|
{{ stats ? t('stats.totalOccupied', { size: formatFileSize(stats.uploadBytesTotal) }) : '—' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-default bg-elevated p-4">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('stats.storageUsage') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-sm font-semibold tabular-nums text-highlighted sm:text-base">
|
||||||
|
{{ usageLabel }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-if="stats?.storageUsage.totalBytes"
|
||||||
|
class="mt-3 space-y-1"
|
||||||
|
>
|
||||||
|
<div class="h-1.5 overflow-hidden rounded-full bg-muted/50">
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full bg-primary transition-all"
|
||||||
|
:style="{ width: `${usageBarWidth}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<p class="text-right text-xs tabular-nums text-muted">
|
||||||
|
{{ usagePercent }}%
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-else
|
||||||
|
class="mt-2 text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ t('stats.noQuota') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-2 rounded-xl border border-default bg-elevated p-4 sm:col-span-1">
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('stats.sourceDistribution') }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-if="!sourceTotal"
|
||||||
|
class="mt-4 text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ t('stats.noData') }}
|
||||||
|
</div>
|
||||||
|
<ul
|
||||||
|
v-else
|
||||||
|
class="mt-3 space-y-3"
|
||||||
|
>
|
||||||
|
<li
|
||||||
|
v-for="item in sourceItems"
|
||||||
|
:key="item.key"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between gap-2 text-xs">
|
||||||
|
<span class="flex min-w-0 items-center gap-1.5">
|
||||||
|
<span
|
||||||
|
class="size-2 shrink-0 rounded-full"
|
||||||
|
:style="{ background: item.color }"
|
||||||
|
/>
|
||||||
|
<span class="truncate">{{ item.label }}</span>
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 tabular-nums text-muted">
|
||||||
|
{{ item.count }} ({{ sourcePercent(item.count) }}%)
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-muted/40">
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full transition-[width]"
|
||||||
|
:style="{
|
||||||
|
width: `${sourcePercent(item.count)}%`,
|
||||||
|
backgroundColor: item.color
|
||||||
|
}"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div class="divide-y divide-default overflow-hidden rounded-lg border border-default">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,554 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ActivityLogListResponse, ActivityLogStorage, LogAction, LogSource } from '~/types/logs'
|
||||||
|
|
||||||
|
const { isAuthenticated, handleAuthError, isAdmin } = useAuth()
|
||||||
|
const toast = useToast()
|
||||||
|
const { t, locale } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
|
||||||
|
const loading = ref(true)
|
||||||
|
const page = ref(1)
|
||||||
|
const actionFilter = ref<'all' | LogAction>('all')
|
||||||
|
const sourceFilter = ref<'all' | LogSource>('all')
|
||||||
|
const userFilter = ref<'all' | number>('all')
|
||||||
|
const searchQuery = ref('')
|
||||||
|
const activeSearch = ref('')
|
||||||
|
const listData = ref<ActivityLogListResponse | null>(null)
|
||||||
|
const imageLinkBase = ref('')
|
||||||
|
const hideFolderInUrl = ref(false)
|
||||||
|
|
||||||
|
const pageSize = 10
|
||||||
|
|
||||||
|
const summaryLabel = computed(() => {
|
||||||
|
const summary = listData.value?.summary
|
||||||
|
if (!summary) return ''
|
||||||
|
return t('logs.summaryAll', {
|
||||||
|
total: summary.total,
|
||||||
|
upload: summary.upload,
|
||||||
|
delete: summary.delete
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const actionItems = computed(() => [
|
||||||
|
{ label: t('logs.filterActionAll'), value: 'all' as const },
|
||||||
|
{ label: t('logs.actionUpload'), value: 'upload' as const },
|
||||||
|
{ label: t('logs.actionDelete'), value: 'delete' as const }
|
||||||
|
])
|
||||||
|
|
||||||
|
const sourceItems = computed(() => [
|
||||||
|
{ label: t('logs.filterSourceAll'), value: 'all' as const },
|
||||||
|
{ label: t('logs.sourceWeb'), value: 'web' as const },
|
||||||
|
{ label: t('logs.sourceApi'), value: 'api' as const }
|
||||||
|
])
|
||||||
|
|
||||||
|
const userItems = computed(() => {
|
||||||
|
const items: Array<{ label: string, value: 'all' | number }> = [
|
||||||
|
{ label: t('logs.filterUserAll'), value: 'all' }
|
||||||
|
]
|
||||||
|
for (const user of listData.value?.users ?? []) {
|
||||||
|
items.push({ label: user.username, value: user.id })
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
})
|
||||||
|
|
||||||
|
function formatTime(value: string) {
|
||||||
|
try {
|
||||||
|
return new Date(value).toLocaleString(locale.value, { hour12: false })
|
||||||
|
} catch {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTimeShort(value: string) {
|
||||||
|
try {
|
||||||
|
return new Date(value).toLocaleString(locale.value, {
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actionBadgeClass(action: LogAction) {
|
||||||
|
const base = 'inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium whitespace-nowrap'
|
||||||
|
return action === 'upload'
|
||||||
|
? `${base} bg-success/10 text-success`
|
||||||
|
: `${base} bg-error/10 text-error`
|
||||||
|
}
|
||||||
|
|
||||||
|
function actionIcon(action: LogAction) {
|
||||||
|
return action === 'upload' ? 'i-lucide-upload' : 'i-lucide-trash-2'
|
||||||
|
}
|
||||||
|
|
||||||
|
function sourceLabel(source: LogSource) {
|
||||||
|
switch (source) {
|
||||||
|
case 'web':
|
||||||
|
return t('logs.sourceWeb')
|
||||||
|
case 'api':
|
||||||
|
return t('logs.sourceApi')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function storageIcon(storage: ActivityLogStorage | null) {
|
||||||
|
return storage?.type === 'local' ? 'i-lucide-hard-drive' : 'i-lucide-cloud'
|
||||||
|
}
|
||||||
|
|
||||||
|
function publicPathFromKey(key: string) {
|
||||||
|
if (hideFolderInUrl.value) {
|
||||||
|
const slash = key.lastIndexOf('/')
|
||||||
|
return slash >= 0 ? key.slice(slash + 1) : key
|
||||||
|
}
|
||||||
|
const prefix = 'images/'
|
||||||
|
return key.startsWith(prefix) ? key.slice(prefix.length) : key
|
||||||
|
}
|
||||||
|
|
||||||
|
function imageUrl(key: string) {
|
||||||
|
const base = imageLinkBase.value.replace(/\/$/, '')
|
||||||
|
const path = publicPathFromKey(key)
|
||||||
|
if (!base) return `/${path}`
|
||||||
|
return `${base}/${path}`
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadImageLinkBase() {
|
||||||
|
try {
|
||||||
|
if (isAdmin.value) {
|
||||||
|
const data = await $fetch<{ effectiveImageBaseUrl: string, hideFolderInUrl: boolean }>('/api/settings', {
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
imageLinkBase.value = data.effectiveImageBaseUrl
|
||||||
|
hideFolderInUrl.value = data.hideFolderInUrl
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const data = await $fetch<{ env: { imageBaseUrl: string, hideFolderInUrl: boolean } }>('/api/user/api-token', {
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
imageLinkBase.value = data.env.imageBaseUrl
|
||||||
|
hideFolderInUrl.value = data.env.hideFolderInUrl
|
||||||
|
} catch {
|
||||||
|
if (import.meta.client) {
|
||||||
|
imageLinkBase.value = window.location.origin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadLogs() {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const query: Record<string, string | number> = {
|
||||||
|
page: page.value,
|
||||||
|
limit: pageSize
|
||||||
|
}
|
||||||
|
if (actionFilter.value !== 'all') {
|
||||||
|
query.action = actionFilter.value
|
||||||
|
}
|
||||||
|
if (sourceFilter.value !== 'all') {
|
||||||
|
query.source = sourceFilter.value
|
||||||
|
}
|
||||||
|
if (isAdmin.value && userFilter.value !== 'all') {
|
||||||
|
query.userId = userFilter.value
|
||||||
|
}
|
||||||
|
if (activeSearch.value) {
|
||||||
|
query.q = activeSearch.value
|
||||||
|
}
|
||||||
|
|
||||||
|
listData.value = await $fetch<ActivityLogListResponse>('/api/logs', {
|
||||||
|
credentials: 'include',
|
||||||
|
query
|
||||||
|
})
|
||||||
|
page.value = listData.value.page
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleAuthError(error)
|
||||||
|
if (isAuthenticated.value) {
|
||||||
|
toast.add({ title: t('logs.loadFailed'), color: 'error' })
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyFilters() {
|
||||||
|
page.value = 1
|
||||||
|
void loadLogs()
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitSearch() {
|
||||||
|
activeSearch.value = searchQuery.value.trim()
|
||||||
|
applyFilters()
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSearch() {
|
||||||
|
searchQuery.value = ''
|
||||||
|
activeSearch.value = ''
|
||||||
|
applyFilters()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePageChange(target: number) {
|
||||||
|
page.value = target
|
||||||
|
void loadLogs()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await loadImageLinkBase()
|
||||||
|
await loadLogs()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<div class="flex flex-wrap items-start justify-between gap-3 border-b border-default px-5 py-4 sm:px-6">
|
||||||
|
<div>
|
||||||
|
<h2 class="text-sm font-semibold">
|
||||||
|
{{ t('logs.pageTitle') }}
|
||||||
|
</h2>
|
||||||
|
<p class="mt-0.5 text-xs text-muted">
|
||||||
|
{{ isAdmin ? t('logs.pageSubtitleAdmin') : t('logs.pageSubtitle') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<UButton
|
||||||
|
icon="i-lucide-refresh-cw"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
size="sm"
|
||||||
|
:label="t('common.refresh')"
|
||||||
|
:loading="loading"
|
||||||
|
@click="loadLogs"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form
|
||||||
|
class="border-b border-default px-5 py-3 sm:px-6"
|
||||||
|
@submit.prevent="submitSearch"
|
||||||
|
>
|
||||||
|
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<p
|
||||||
|
v-if="summaryLabel"
|
||||||
|
class="text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ summaryLabel }}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
v-else
|
||||||
|
class="text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ t('stats.counting') }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 flex-wrap items-center gap-2 sm:justify-end">
|
||||||
|
<USelect
|
||||||
|
v-if="isAdmin"
|
||||||
|
v-model="userFilter"
|
||||||
|
:items="userItems"
|
||||||
|
value-key="value"
|
||||||
|
class="min-w-0 w-full sm:w-36"
|
||||||
|
size="sm"
|
||||||
|
@update:model-value="applyFilters"
|
||||||
|
/>
|
||||||
|
<USelect
|
||||||
|
v-model="actionFilter"
|
||||||
|
:items="actionItems"
|
||||||
|
value-key="value"
|
||||||
|
class="min-w-0 w-[calc(50%-0.25rem)] sm:w-32"
|
||||||
|
size="sm"
|
||||||
|
@update:model-value="applyFilters"
|
||||||
|
/>
|
||||||
|
<USelect
|
||||||
|
v-model="sourceFilter"
|
||||||
|
:items="sourceItems"
|
||||||
|
value-key="value"
|
||||||
|
class="min-w-0 w-[calc(50%-0.25rem)] sm:w-36"
|
||||||
|
size="sm"
|
||||||
|
@update:model-value="applyFilters"
|
||||||
|
/>
|
||||||
|
<div class="flex min-w-0 w-full items-center gap-2 sm:w-auto">
|
||||||
|
<UInput
|
||||||
|
v-model="searchQuery"
|
||||||
|
icon="i-lucide-search"
|
||||||
|
:placeholder="t('logs.searchPlaceholder')"
|
||||||
|
class="min-w-0 flex-1 sm:w-40 sm:flex-none"
|
||||||
|
size="sm"
|
||||||
|
:disabled="loading"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
type="submit"
|
||||||
|
icon="i-lucide-search"
|
||||||
|
size="sm"
|
||||||
|
class="shrink-0"
|
||||||
|
:aria-label="t('common.search')"
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
<span class="hidden sm:inline">{{ t('common.search') }}</span>
|
||||||
|
</UButton>
|
||||||
|
<UButton
|
||||||
|
v-if="activeSearch"
|
||||||
|
type="button"
|
||||||
|
icon="i-lucide-x"
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
color="neutral"
|
||||||
|
class="shrink-0"
|
||||||
|
:aria-label="t('stats.clear')"
|
||||||
|
@click="clearSearch"
|
||||||
|
>
|
||||||
|
<span class="hidden sm:inline">{{ t('stats.clear') }}</span>
|
||||||
|
</UButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="loading"
|
||||||
|
class="p-4 sm:p-6"
|
||||||
|
>
|
||||||
|
<div class="space-y-3 sm:hidden">
|
||||||
|
<USkeleton
|
||||||
|
v-for="n in 6"
|
||||||
|
:key="`mobile-${n}`"
|
||||||
|
class="h-24 rounded-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="hidden space-y-2 sm:block">
|
||||||
|
<USkeleton
|
||||||
|
v-for="n in 8"
|
||||||
|
:key="`desktop-${n}`"
|
||||||
|
class="h-12 rounded-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else-if="listData && listData.items.length">
|
||||||
|
<div class="min-w-0 sm:hidden">
|
||||||
|
<div class="divide-y divide-default">
|
||||||
|
<article
|
||||||
|
v-for="row in listData.items"
|
||||||
|
:key="row.id"
|
||||||
|
class="min-w-0 px-4 py-3.5"
|
||||||
|
>
|
||||||
|
<div class="flex items-start justify-between gap-3">
|
||||||
|
<time class="text-xs text-muted">
|
||||||
|
{{ formatTimeShort(row.createdAt) }}
|
||||||
|
</time>
|
||||||
|
<span class="shrink-0 text-xs tabular-nums text-muted">
|
||||||
|
{{ formatFileSize(row.size) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-2 flex min-w-0 max-w-full flex-wrap items-center gap-1.5">
|
||||||
|
<span :class="actionBadgeClass(row.action)">
|
||||||
|
<UIcon
|
||||||
|
:name="actionIcon(row.action)"
|
||||||
|
class="size-3 shrink-0"
|
||||||
|
/>
|
||||||
|
{{ row.action === 'upload' ? t('logs.actionUpload') : t('logs.actionDelete') }}
|
||||||
|
</span>
|
||||||
|
<span class="inline-flex items-center rounded-md bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary whitespace-nowrap">
|
||||||
|
{{ sourceLabel(row.source) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="isAdmin"
|
||||||
|
class="text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ row.username ?? '—' }}
|
||||||
|
</span>
|
||||||
|
<UBadge
|
||||||
|
v-if="row.storage"
|
||||||
|
color="neutral"
|
||||||
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
class="max-w-full truncate"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="storageIcon(row.storage)"
|
||||||
|
class="mr-1 size-3"
|
||||||
|
/>
|
||||||
|
{{ row.storage.name }}
|
||||||
|
</UBadge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p
|
||||||
|
class="mt-2 truncate text-sm"
|
||||||
|
:title="row.originalName"
|
||||||
|
>
|
||||||
|
{{ row.originalName }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="mt-2 flex min-w-0 items-center gap-1">
|
||||||
|
<a
|
||||||
|
v-if="row.action === 'upload'"
|
||||||
|
:href="imageUrl(row.key)"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="min-w-0 flex-1 truncate font-mono text-xs text-primary hover:underline"
|
||||||
|
:title="row.key"
|
||||||
|
>
|
||||||
|
{{ row.key }}
|
||||||
|
</a>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="min-w-0 flex-1 truncate font-mono text-xs text-dimmed"
|
||||||
|
:title="row.key"
|
||||||
|
>
|
||||||
|
{{ row.key }}
|
||||||
|
</span>
|
||||||
|
<CopyButton
|
||||||
|
icon="i-lucide-copy"
|
||||||
|
icon-only
|
||||||
|
class="shrink-0"
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:value="row.key"
|
||||||
|
:success-title="t('copy.copiedUrl')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hidden min-w-0 sm:block">
|
||||||
|
<table class="w-full table-fixed text-left text-sm">
|
||||||
|
<thead class="border-b border-default bg-muted/30 text-xs text-muted">
|
||||||
|
<tr>
|
||||||
|
<th class="w-36 px-4 py-3 font-medium sm:px-6">
|
||||||
|
{{ t('logs.colTime') }}
|
||||||
|
</th>
|
||||||
|
<th
|
||||||
|
v-if="isAdmin"
|
||||||
|
class="w-20 px-4 py-3 font-medium"
|
||||||
|
>
|
||||||
|
{{ t('logs.colUser') }}
|
||||||
|
</th>
|
||||||
|
<th class="w-20 whitespace-nowrap px-4 py-3 font-medium">
|
||||||
|
{{ t('logs.colAction') }}
|
||||||
|
</th>
|
||||||
|
<th class="w-16 whitespace-nowrap px-4 py-3 font-medium">
|
||||||
|
{{ t('logs.colSource') }}
|
||||||
|
</th>
|
||||||
|
<th class="w-24 px-4 py-3 font-medium">
|
||||||
|
{{ t('logs.colStorage') }}
|
||||||
|
</th>
|
||||||
|
<th class="hidden px-4 py-3 font-medium md:table-cell">
|
||||||
|
{{ t('logs.colFile') }}
|
||||||
|
</th>
|
||||||
|
<th class="w-20 px-4 py-3 font-medium">
|
||||||
|
{{ t('logs.colSize') }}
|
||||||
|
</th>
|
||||||
|
<th class="hidden px-4 py-3 font-medium xl:table-cell">
|
||||||
|
{{ t('logs.colKey') }}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-default">
|
||||||
|
<tr
|
||||||
|
v-for="row in listData.items"
|
||||||
|
:key="row.id"
|
||||||
|
class="hover:bg-muted/20"
|
||||||
|
>
|
||||||
|
<td class="px-4 py-3 text-xs text-muted sm:px-6">
|
||||||
|
<span class="block truncate">{{ formatTime(row.createdAt) }}</span>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
v-if="isAdmin"
|
||||||
|
class="px-4 py-3 text-xs"
|
||||||
|
>
|
||||||
|
<span class="block truncate">{{ row.username ?? '—' }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="whitespace-nowrap px-4 py-3">
|
||||||
|
<span :class="actionBadgeClass(row.action)">
|
||||||
|
<UIcon
|
||||||
|
:name="actionIcon(row.action)"
|
||||||
|
class="size-3 shrink-0"
|
||||||
|
/>
|
||||||
|
{{ row.action === 'upload' ? t('logs.actionUpload') : t('logs.actionDelete') }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td class="whitespace-nowrap px-4 py-3">
|
||||||
|
<span class="inline-flex items-center rounded-md bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary">
|
||||||
|
{{ sourceLabel(row.source) }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3 text-xs">
|
||||||
|
<span
|
||||||
|
v-if="row.storage"
|
||||||
|
class="flex min-w-0 items-center gap-1"
|
||||||
|
:title="row.storage.name"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="storageIcon(row.storage)"
|
||||||
|
class="size-3.5 shrink-0 opacity-70"
|
||||||
|
/>
|
||||||
|
<span class="truncate">{{ row.storage.name }}</span>
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="text-muted"
|
||||||
|
>—</span>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
class="hidden max-w-0 truncate px-4 py-3 md:table-cell"
|
||||||
|
:title="row.originalName"
|
||||||
|
>
|
||||||
|
{{ row.originalName }}
|
||||||
|
</td>
|
||||||
|
<td class="whitespace-nowrap px-4 py-3 tabular-nums text-muted">
|
||||||
|
{{ formatFileSize(row.size) }}
|
||||||
|
</td>
|
||||||
|
<td class="hidden max-w-0 px-4 py-3 xl:table-cell">
|
||||||
|
<div class="flex min-w-0 items-center gap-1">
|
||||||
|
<a
|
||||||
|
v-if="row.action === 'upload'"
|
||||||
|
:href="imageUrl(row.key)"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="min-w-0 truncate font-mono text-xs text-primary hover:underline"
|
||||||
|
:title="row.key"
|
||||||
|
>
|
||||||
|
{{ row.key }}
|
||||||
|
</a>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="min-w-0 truncate font-mono text-xs text-dimmed"
|
||||||
|
:title="row.key"
|
||||||
|
>
|
||||||
|
{{ row.key }}
|
||||||
|
</span>
|
||||||
|
<CopyButton
|
||||||
|
icon="i-lucide-copy"
|
||||||
|
icon-only
|
||||||
|
class="shrink-0"
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:value="row.key"
|
||||||
|
:success-title="t('copy.copiedUrl')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="px-4 py-16 text-center text-sm text-muted sm:px-6"
|
||||||
|
>
|
||||||
|
{{ t('logs.empty') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="listData && listData.total > 0"
|
||||||
|
class="border-t border-default px-4 py-4 sm:px-6"
|
||||||
|
>
|
||||||
|
<PaginationBar
|
||||||
|
:page="listData.page"
|
||||||
|
:total-pages="listData.totalPages"
|
||||||
|
:total="listData.total"
|
||||||
|
:unit="t('logs.entriesUnit')"
|
||||||
|
:loading="loading"
|
||||||
|
@update:page="handlePageChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<div class="overflow-hidden rounded-xl border border-default bg-default p-5 sm:p-6">
|
||||||
|
<div class="space-y-8">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
title: string
|
||||||
|
hint?: string
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="space-y-4">
|
||||||
|
<div class="flex items-start justify-between gap-4">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="h-4 w-1 shrink-0 rounded-full bg-primary"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<h2 class="text-sm font-semibold text-highlighted">
|
||||||
|
{{ title }}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-if="hint"
|
||||||
|
class="mt-1.5 pl-3 text-xs leading-relaxed text-muted"
|
||||||
|
>
|
||||||
|
{{ hint }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="$slots.action"
|
||||||
|
class="shrink-0"
|
||||||
|
>
|
||||||
|
<slot name="action" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<slot />
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
hasChanges: boolean
|
||||||
|
saving: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
save: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="border-t border-default bg-default px-4 py-4 sm:px-6">
|
||||||
|
<div class="flex items-center justify-end gap-3">
|
||||||
|
<p
|
||||||
|
v-if="hasChanges"
|
||||||
|
class="mr-auto text-xs text-warning"
|
||||||
|
>
|
||||||
|
{{ t('settings.unsavedChanges') }}
|
||||||
|
</p>
|
||||||
|
<UButton
|
||||||
|
:label="t('settings.saveSettings')"
|
||||||
|
icon="i-lucide-save"
|
||||||
|
color="primary"
|
||||||
|
:loading="saving"
|
||||||
|
:disabled="!hasChanges"
|
||||||
|
@click="emit('save')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { SettingsTab } from '~/types/settings'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
modelValue: SettingsTab
|
||||||
|
items: Array<{ id: SettingsTab, label: string, icon: string }>
|
||||||
|
title: string
|
||||||
|
subtitle: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [SettingsTab]
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<aside class="flex w-full shrink-0 flex-col border-b border-default bg-neutral-50 dark:bg-neutral-900/30 lg:w-56 lg:border-b-0 lg:border-r xl:w-60">
|
||||||
|
<div class="border-b border-default px-4 py-5 sm:px-5">
|
||||||
|
<h1 class="text-lg font-semibold tracking-tight text-highlighted">
|
||||||
|
{{ title }}
|
||||||
|
</h1>
|
||||||
|
<p class="mt-1 text-xs leading-relaxed text-muted">
|
||||||
|
{{ subtitle }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav class="flex-1 space-y-0.5 p-3">
|
||||||
|
<button
|
||||||
|
v-for="item in items"
|
||||||
|
:key="item.id"
|
||||||
|
type="button"
|
||||||
|
class="flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left text-sm transition-colors"
|
||||||
|
:class="modelValue === item.id
|
||||||
|
? 'bg-primary/10 font-medium text-primary'
|
||||||
|
: 'text-muted hover:bg-muted/50 hover:text-highlighted'"
|
||||||
|
@click="emit('update:modelValue', item.id)"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="item.icon"
|
||||||
|
class="size-4 shrink-0"
|
||||||
|
:class="modelValue === item.id ? 'text-primary' : 'opacity-70'"
|
||||||
|
/>
|
||||||
|
<span>{{ item.label }}</span>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
appVersion: string
|
||||||
|
updateAvailable: boolean
|
||||||
|
latestVersion: string | null
|
||||||
|
releaseUrl: string | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="pl-3">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.systemVersion') }}
|
||||||
|
</span>
|
||||||
|
<UBadge
|
||||||
|
color="neutral"
|
||||||
|
variant="subtle"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
v{{ appVersion }}
|
||||||
|
</UBadge>
|
||||||
|
<a
|
||||||
|
v-if="updateAvailable && latestVersion"
|
||||||
|
:href="releaseUrl || 'https://github.com/O96u/PicHost/releases'"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="text-xs text-warning hover:underline"
|
||||||
|
>
|
||||||
|
{{ t('settings.updateAvailable', { version: `v${latestVersion}` }) }}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
title?: string
|
||||||
|
hint?: string
|
||||||
|
disabled?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const model = defineModel<boolean>({ required: true })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex items-start justify-between gap-4 px-4 py-4 sm:px-5">
|
||||||
|
<div class="min-w-0 flex-1 pr-2">
|
||||||
|
<p class="text-sm font-medium text-highlighted">
|
||||||
|
<slot name="title">
|
||||||
|
{{ title }}
|
||||||
|
</slot>
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
v-if="hint || $slots.hint"
|
||||||
|
class="mt-1 text-xs leading-relaxed text-muted"
|
||||||
|
>
|
||||||
|
<slot name="hint">
|
||||||
|
{{ hint }}
|
||||||
|
</slot>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<USwitch
|
||||||
|
v-model="model"
|
||||||
|
:disabled="disabled"
|
||||||
|
class="mt-0.5 shrink-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const {
|
||||||
|
compressEnabled,
|
||||||
|
autoCopyMarkdown,
|
||||||
|
copyFormat,
|
||||||
|
clientWebpQuality,
|
||||||
|
loadPreferences
|
||||||
|
} = useUploadPreferences()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const {
|
||||||
|
userSettings,
|
||||||
|
enabled: userAutoDeleteEnabled,
|
||||||
|
daysDraft: userAutoDeleteDaysDraft,
|
||||||
|
load: loadUserSettings
|
||||||
|
} = useUserAutoDeleteSettings()
|
||||||
|
|
||||||
|
const copyFormatItems = computed(() => [
|
||||||
|
{ label: t('copy.url'), value: 'url' as const },
|
||||||
|
{ label: t('copy.markdown'), value: 'markdown' as const },
|
||||||
|
{ label: t('copy.html'), value: 'html' as const }
|
||||||
|
])
|
||||||
|
|
||||||
|
const clientQualityLevel = computed(() => {
|
||||||
|
if (clientWebpQuality.value >= 85) return t('preferences.qualityHigh')
|
||||||
|
if (clientWebpQuality.value >= 60) return t('preferences.qualityMedium')
|
||||||
|
return t('preferences.qualityLow')
|
||||||
|
})
|
||||||
|
|
||||||
|
function setCopyFormat(value: 'url' | 'markdown' | 'html') {
|
||||||
|
copyFormat.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClientQualityInput(event: Event) {
|
||||||
|
const value = Number((event.target as HTMLInputElement).value)
|
||||||
|
clientWebpQuality.value = Number.isFinite(value) ? value : 80
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadPreferences()
|
||||||
|
void loadUserSettings()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SettingsSection :title="t('preferences.processing')">
|
||||||
|
<SettingsGroup>
|
||||||
|
<SettingsToggleRow
|
||||||
|
v-model="compressEnabled"
|
||||||
|
:title="t('preferences.clientCompress')"
|
||||||
|
:hint="t('preferences.clientCompressHint')"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="userSettings"
|
||||||
|
class="flex items-start justify-between gap-4 px-4 py-4 sm:px-5"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 flex-1 pr-2">
|
||||||
|
<p class="flex flex-wrap items-center gap-x-1.5 gap-y-1 text-sm font-medium text-highlighted">
|
||||||
|
<span>{{ t('preferences.autoDeletePrefix') }}</span>
|
||||||
|
<UInput
|
||||||
|
v-model.number="userAutoDeleteDaysDraft"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="3650"
|
||||||
|
size="xs"
|
||||||
|
class="w-14 tabular-nums"
|
||||||
|
:class="userAutoDeleteEnabled ? '' : 'pointer-events-none opacity-40'"
|
||||||
|
/>
|
||||||
|
<span>{{ t('preferences.autoDeleteSuffix') }}</span>
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-xs leading-relaxed text-muted">
|
||||||
|
{{ t('preferences.autoDeleteHint') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<USwitch
|
||||||
|
v-model="userAutoDeleteEnabled"
|
||||||
|
class="mt-0.5 shrink-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex justify-center py-4"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-loader-circle"
|
||||||
|
class="size-5 animate-spin text-muted"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-4 sm:px-5">
|
||||||
|
<div class="flex items-start justify-between gap-4">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<p class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('preferences.webpQuality') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-xs leading-relaxed text-muted">
|
||||||
|
{{ t('preferences.webpQualityHint') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="shrink-0 text-right text-xs text-muted">
|
||||||
|
<p>{{ t('preferences.current', { n: clientWebpQuality }) }}</p>
|
||||||
|
<p class="mt-0.5">
|
||||||
|
{{ clientQualityLevel }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="1"
|
||||||
|
max="100"
|
||||||
|
:value="clientWebpQuality"
|
||||||
|
class="mt-3 h-1.5 w-full cursor-pointer appearance-none rounded-full bg-muted accent-primary"
|
||||||
|
@input="onClientQualityInput"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</SettingsGroup>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<SettingsSection :title="t('settings.uploadConvenience')">
|
||||||
|
<SettingsGroup>
|
||||||
|
<SettingsToggleRow
|
||||||
|
v-model="autoCopyMarkdown"
|
||||||
|
:title="t('preferences.autoCopy')"
|
||||||
|
:hint="t('preferences.autoCopyHint')"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-col gap-3 px-4 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-5">
|
||||||
|
<p class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.defaultCopyFormat') }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
class="flex w-full max-w-xs gap-1 rounded-lg border border-default p-0.5 sm:w-auto"
|
||||||
|
:class="autoCopyMarkdown ? '' : 'pointer-events-none opacity-40'"
|
||||||
|
>
|
||||||
|
<UButton
|
||||||
|
v-for="item in copyFormatItems"
|
||||||
|
:key="item.value"
|
||||||
|
size="xs"
|
||||||
|
class="flex-1 justify-center sm:min-w-[4.5rem]"
|
||||||
|
:variant="copyFormat === item.value ? 'solid' : 'ghost'"
|
||||||
|
:color="copyFormat === item.value ? 'primary' : 'neutral'"
|
||||||
|
:label="item.label"
|
||||||
|
@click="setCopyFormat(item.value)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SettingsGroup>
|
||||||
|
</SettingsSection>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,444 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { BackendSyncPreview, SyncDraft } from '~/types/backup'
|
||||||
|
import type { StorageBackendItem } from '~/types/storage'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
backends: StorageBackendItem[]
|
||||||
|
syncDraft: SyncDraft | null
|
||||||
|
highlighted?: boolean
|
||||||
|
busy: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
activeJob?: { progress: number, total: number, message: string } | null
|
||||||
|
previewSync: (body: { fromBackendId: string, toBackendId: string }) => Promise<BackendSyncPreview>
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
sync: [body: {
|
||||||
|
fromBackendId: string
|
||||||
|
toBackendId: string
|
||||||
|
deleteSource: boolean
|
||||||
|
setDefault: boolean
|
||||||
|
}]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t, locale } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
|
const fromBackendId = ref('')
|
||||||
|
const toBackendId = ref('')
|
||||||
|
const deleteSource = ref(false)
|
||||||
|
const setDefault = ref(false)
|
||||||
|
const preview = ref<BackendSyncPreview | null>(null)
|
||||||
|
const previewLoading = ref(false)
|
||||||
|
const statsLoading = ref(false)
|
||||||
|
const confirmOpen = ref(false)
|
||||||
|
const userTouched = ref(false)
|
||||||
|
|
||||||
|
let statsTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
|
const backendOptions = computed(() =>
|
||||||
|
props.backends.map(backend => ({
|
||||||
|
label: backend.name,
|
||||||
|
value: backend.id
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
|
const backendNameById = computed(() =>
|
||||||
|
new Map(props.backends.map(backend => [backend.id, backend.name]))
|
||||||
|
)
|
||||||
|
|
||||||
|
const needsMoreBackends = computed(() => props.backends.length < 2)
|
||||||
|
|
||||||
|
const syncDisabled = computed(() =>
|
||||||
|
props.disabled || props.busy || needsMoreBackends.value
|
||||||
|
)
|
||||||
|
|
||||||
|
function formatCount(value: number) {
|
||||||
|
return value.toLocaleString(locale.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDefaultSelection() {
|
||||||
|
if (userTouched.value || props.syncDraft) return
|
||||||
|
const defaultBackend = props.backends.find(backend => backend.isDefault)
|
||||||
|
const target = props.backends.find(backend => !backend.isDefault && backend.enabled)
|
||||||
|
if (defaultBackend && target) {
|
||||||
|
fromBackendId.value = defaultBackend.id
|
||||||
|
toBackendId.value = target.id
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (props.backends.length >= 2) {
|
||||||
|
fromBackendId.value = props.backends[0]!.id
|
||||||
|
toBackendId.value = props.backends[1]!.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function canLoadStats(): boolean {
|
||||||
|
return !needsMoreBackends.value
|
||||||
|
&& Boolean(fromBackendId.value)
|
||||||
|
&& Boolean(toBackendId.value)
|
||||||
|
&& fromBackendId.value !== toBackendId.value
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshStats(immediate = false) {
|
||||||
|
if (!canLoadStats()) {
|
||||||
|
preview.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (immediate) {
|
||||||
|
if (statsTimer) clearTimeout(statsTimer)
|
||||||
|
await loadStats()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
scheduleStatsLoad()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadStats() {
|
||||||
|
if (needsMoreBackends.value || !fromBackendId.value || !toBackendId.value) {
|
||||||
|
preview.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (fromBackendId.value === toBackendId.value) {
|
||||||
|
preview.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
statsLoading.value = true
|
||||||
|
try {
|
||||||
|
preview.value = await props.previewSync({
|
||||||
|
fromBackendId: fromBackendId.value,
|
||||||
|
toBackendId: toBackendId.value
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
preview.value = null
|
||||||
|
} finally {
|
||||||
|
statsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleStatsLoad() {
|
||||||
|
if (statsTimer) clearTimeout(statsTimer)
|
||||||
|
statsTimer = setTimeout(() => {
|
||||||
|
void loadStats()
|
||||||
|
}, 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.backends,
|
||||||
|
async () => {
|
||||||
|
initDefaultSelection()
|
||||||
|
await nextTick()
|
||||||
|
await refreshStats(true)
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.syncDraft,
|
||||||
|
async (draft) => {
|
||||||
|
if (!draft) return
|
||||||
|
fromBackendId.value = draft.fromBackendId
|
||||||
|
toBackendId.value = draft.toBackendId
|
||||||
|
userTouched.value = true
|
||||||
|
await refreshStats(true)
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
watch([fromBackendId, toBackendId], () => {
|
||||||
|
void refreshStats()
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (statsTimer) clearTimeout(statsTimer)
|
||||||
|
})
|
||||||
|
|
||||||
|
function applyDraft(draft: SyncDraft) {
|
||||||
|
fromBackendId.value = draft.fromBackendId
|
||||||
|
toBackendId.value = draft.toBackendId
|
||||||
|
userTouched.value = true
|
||||||
|
void refreshStats(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ applyDraft })
|
||||||
|
|
||||||
|
function backendName(id: string) {
|
||||||
|
return backendNameById.value.get(id) ?? id
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateSelection(): boolean {
|
||||||
|
if (needsMoreBackends.value) {
|
||||||
|
toast.add({ title: t('storage.backup.syncNeedTwoBackends'), color: 'warning' })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (!fromBackendId.value || !toBackendId.value) {
|
||||||
|
toast.add({ title: t('storage.backup.syncSelectRequired'), color: 'warning' })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (fromBackendId.value === toBackendId.value) {
|
||||||
|
toast.add({ title: t('storage.backup.syncSameBackend'), color: 'warning' })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!validateSelection()) return
|
||||||
|
previewLoading.value = true
|
||||||
|
try {
|
||||||
|
preview.value = await props.previewSync({
|
||||||
|
fromBackendId: fromBackendId.value,
|
||||||
|
toBackendId: toBackendId.value
|
||||||
|
})
|
||||||
|
confirmOpen.value = true
|
||||||
|
} catch {
|
||||||
|
toast.add({ title: t('storage.backup.previewFailed'), color: 'error' })
|
||||||
|
} finally {
|
||||||
|
previewLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmSync() {
|
||||||
|
emit('sync', {
|
||||||
|
fromBackendId: fromBackendId.value,
|
||||||
|
toBackendId: toBackendId.value,
|
||||||
|
deleteSource: deleteSource.value,
|
||||||
|
setDefault: setDefault.value
|
||||||
|
})
|
||||||
|
confirmOpen.value = false
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<article
|
||||||
|
class="flex h-full flex-col rounded-xl border bg-elevated p-4 transition-colors sm:p-5"
|
||||||
|
:class="highlighted ? 'border-primary ring-2 ring-primary/25' : 'border-default'"
|
||||||
|
>
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-info/10 text-info">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-arrow-left-right"
|
||||||
|
class="size-5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<h3 class="text-base font-semibold">
|
||||||
|
{{ t('storage.backup.syncTitle') }}
|
||||||
|
</h3>
|
||||||
|
<p class="mt-0.5 text-sm text-muted">
|
||||||
|
{{ t('storage.backup.syncSubtitle') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex flex-1 flex-col">
|
||||||
|
<UAlert
|
||||||
|
v-if="needsMoreBackends"
|
||||||
|
color="warning"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-triangle-alert"
|
||||||
|
:description="t('storage.backup.syncNeedTwoBackends')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex flex-1 flex-col space-y-3"
|
||||||
|
>
|
||||||
|
<div class="grid gap-3 sm:grid-cols-[1fr_auto_1fr] sm:items-end">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label class="text-xs text-muted">{{ t('storage.backup.syncFrom') }}</label>
|
||||||
|
<USelect
|
||||||
|
v-model="fromBackendId"
|
||||||
|
:items="backendOptions"
|
||||||
|
size="sm"
|
||||||
|
class="w-full"
|
||||||
|
:disabled="syncDisabled"
|
||||||
|
@update:model-value="userTouched = true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-arrow-right"
|
||||||
|
class="hidden size-4 shrink-0 text-muted sm:mb-2.5 sm:block"
|
||||||
|
/>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label class="text-xs text-muted">{{ t('storage.backup.syncTo') }}</label>
|
||||||
|
<USelect
|
||||||
|
v-model="toBackendId"
|
||||||
|
:items="backendOptions"
|
||||||
|
size="sm"
|
||||||
|
class="w-full"
|
||||||
|
:disabled="syncDisabled"
|
||||||
|
@update:model-value="userTouched = true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl class="space-y-1.5 rounded-lg bg-muted/25 px-3 py-2.5 text-sm">
|
||||||
|
<div class="flex items-baseline justify-between gap-2">
|
||||||
|
<dt class="text-muted">
|
||||||
|
{{ t('storage.backup.syncPendingImages') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="font-medium tabular-nums">
|
||||||
|
<template v-if="statsLoading">
|
||||||
|
…
|
||||||
|
</template>
|
||||||
|
<template v-else-if="preview">
|
||||||
|
{{ formatCount(preview.imageCount) }}
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
—
|
||||||
|
</template>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-baseline justify-between gap-2">
|
||||||
|
<dt class="text-muted">
|
||||||
|
{{ t('storage.backup.syncPendingSize') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="font-medium tabular-nums">
|
||||||
|
<template v-if="statsLoading">
|
||||||
|
…
|
||||||
|
</template>
|
||||||
|
<template v-else-if="preview">
|
||||||
|
{{ formatFileSize(preview.imageBytes) }}
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
—
|
||||||
|
</template>
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<div class="space-y-2 text-xs">
|
||||||
|
<label class="flex cursor-pointer items-center gap-2">
|
||||||
|
<UCheckbox
|
||||||
|
v-model="deleteSource"
|
||||||
|
:disabled="syncDisabled"
|
||||||
|
/>
|
||||||
|
<span class="text-muted">{{ t('storage.backup.syncDeleteSource') }}</span>
|
||||||
|
</label>
|
||||||
|
<label class="flex cursor-pointer items-center gap-2">
|
||||||
|
<UCheckbox
|
||||||
|
v-model="setDefault"
|
||||||
|
:disabled="syncDisabled"
|
||||||
|
/>
|
||||||
|
<span class="text-muted">{{ t('storage.backup.syncSetDefault') }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-auto rounded-lg bg-muted/15 px-3 py-2.5">
|
||||||
|
<p class="text-xs font-medium text-default">
|
||||||
|
{{ t('storage.backup.syncIncludesTitle') }}
|
||||||
|
</p>
|
||||||
|
<ul class="mt-2 space-y-1.5 text-xs leading-relaxed text-muted">
|
||||||
|
<li class="flex items-start gap-2">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-check"
|
||||||
|
class="mt-0.5 size-3.5 shrink-0 text-info"
|
||||||
|
/>
|
||||||
|
<span>{{ t('storage.backup.syncIncludesCopy') }}</span>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-start gap-2">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-check"
|
||||||
|
class="mt-0.5 size-3.5 shrink-0 text-info"
|
||||||
|
/>
|
||||||
|
<span>{{ t('storage.backup.syncIncludesIndex') }}</span>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-start gap-2">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-minus"
|
||||||
|
class="mt-0.5 size-3.5 shrink-0 text-muted"
|
||||||
|
/>
|
||||||
|
<span>{{ t('storage.backup.syncIncludesConfig') }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<StorageBackupJobProgress
|
||||||
|
v-if="busy && activeJob"
|
||||||
|
class="mt-auto"
|
||||||
|
:message="activeJob.message"
|
||||||
|
:progress="activeJob.progress"
|
||||||
|
:total="activeJob.total"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="!needsMoreBackends"
|
||||||
|
class="mt-auto border-t border-default pt-4"
|
||||||
|
>
|
||||||
|
<UButton
|
||||||
|
:label="t('storage.backup.syncPreview')"
|
||||||
|
icon="i-lucide-play"
|
||||||
|
size="sm"
|
||||||
|
:loading="previewLoading || busy"
|
||||||
|
:disabled="syncDisabled"
|
||||||
|
@click="submit"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UModal
|
||||||
|
v-model:open="confirmOpen"
|
||||||
|
:ui="{ content: 'max-w-md' }"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="p-5 sm:p-6">
|
||||||
|
<h2 class="text-base font-semibold">
|
||||||
|
{{ t('storage.backup.syncConfirmTitle') }}
|
||||||
|
</h2>
|
||||||
|
<p class="mt-2 text-sm text-muted">
|
||||||
|
{{ backendName(fromBackendId) }} → {{ backendName(toBackendId) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<dl
|
||||||
|
v-if="preview"
|
||||||
|
class="mt-4 grid grid-cols-2 gap-3 text-sm"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<dt class="text-xs text-muted">
|
||||||
|
{{ t('storage.backup.previewImages') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-0.5 font-semibold tabular-nums">
|
||||||
|
{{ formatCount(preview.imageCount) }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt class="text-xs text-muted">
|
||||||
|
{{ t('storage.backup.previewSize') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-0.5 font-semibold tabular-nums">
|
||||||
|
{{ formatFileSize(preview.imageBytes) }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<UAlert
|
||||||
|
v-if="deleteSource"
|
||||||
|
class="mt-4"
|
||||||
|
color="warning"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-triangle-alert"
|
||||||
|
:description="t('storage.backup.syncDeleteWarning')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="mt-5 flex justify-end gap-2">
|
||||||
|
<UButton
|
||||||
|
:label="t('common.cancel')"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
@click="() => { confirmOpen = false }"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('storage.backup.syncConfirm')"
|
||||||
|
size="sm"
|
||||||
|
icon="i-lucide-play"
|
||||||
|
:loading="busy"
|
||||||
|
@click="confirmSync"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { BackupEstimate } from '~/types/backup'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
estimate: BackupEstimate | null
|
||||||
|
loading: boolean
|
||||||
|
busy: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
activeJob?: { progress: number, total: number, message: string } | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
export: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<article class="flex h-full flex-col rounded-xl border border-default bg-elevated p-4 sm:p-5">
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-archive"
|
||||||
|
class="size-5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<h3 class="text-base font-semibold">
|
||||||
|
{{ t('storage.backup.exportTitle') }}
|
||||||
|
</h3>
|
||||||
|
<p class="mt-0.5 text-sm text-muted">
|
||||||
|
{{ t('storage.backup.exportSubtitle') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex flex-1 flex-col space-y-2">
|
||||||
|
<div
|
||||||
|
v-if="loading"
|
||||||
|
class="flex items-center gap-2 text-sm text-muted"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-loader-circle"
|
||||||
|
class="size-4 animate-spin"
|
||||||
|
/>
|
||||||
|
{{ t('storage.backup.estimateLoading') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl
|
||||||
|
v-else-if="estimate"
|
||||||
|
class="space-y-1.5 rounded-lg bg-muted/25 px-3 py-2.5 text-sm"
|
||||||
|
>
|
||||||
|
<div class="flex items-baseline justify-between gap-2">
|
||||||
|
<dt class="text-muted">
|
||||||
|
{{ t('storage.backup.estimateImageCountLabel') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="font-medium tabular-nums">
|
||||||
|
{{ estimate.imageCount }} · {{ formatFileSize(estimate.imageBytes) }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-baseline justify-between gap-2">
|
||||||
|
<dt class="text-muted">
|
||||||
|
{{ t('storage.backup.estimateDatabaseSnapshotLabel') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="font-medium tabular-nums">
|
||||||
|
{{ formatFileSize(estimate.databaseBytes) }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-baseline justify-between gap-2 border-t border-default/40 pt-1.5">
|
||||||
|
<dt class="font-medium text-default">
|
||||||
|
{{ t('storage.backup.estimatePackageSizeLabel') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="font-semibold tabular-nums">
|
||||||
|
{{ formatFileSize(estimate.totalBytes) }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-baseline justify-between gap-2 border-t border-default/40 pt-1.5">
|
||||||
|
<dt class="text-muted">
|
||||||
|
{{ t('storage.backup.estimateStoragePathLabel') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="truncate font-mono text-xs font-medium">
|
||||||
|
{{ t('storage.backup.estimateStoragePathValue') }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="estimate && !loading"
|
||||||
|
class="mt-auto rounded-lg bg-muted/15 px-3 py-2.5"
|
||||||
|
>
|
||||||
|
<p class="text-xs font-medium text-default">
|
||||||
|
{{ t('storage.backup.exportIncludesTitle') }}
|
||||||
|
</p>
|
||||||
|
<ul class="mt-2 space-y-1.5 text-xs leading-relaxed text-muted">
|
||||||
|
<li class="flex items-start gap-2">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-check"
|
||||||
|
class="mt-0.5 size-3.5 shrink-0 text-primary"
|
||||||
|
/>
|
||||||
|
<span>{{ t('storage.backup.exportIncludesDb') }}</span>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-start gap-2">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-check"
|
||||||
|
class="mt-0.5 size-3.5 shrink-0 text-primary"
|
||||||
|
/>
|
||||||
|
<span>{{ t('storage.backup.exportIncludesImages', { count: estimate.imageCount }) }}</span>
|
||||||
|
</li>
|
||||||
|
<li class="flex items-start gap-2">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-minus"
|
||||||
|
class="mt-0.5 size-3.5 shrink-0 text-muted"
|
||||||
|
/>
|
||||||
|
<span>{{ t('storage.backup.exportExcludesSecrets') }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<StorageBackupJobProgress
|
||||||
|
v-if="busy && activeJob"
|
||||||
|
class="mt-2"
|
||||||
|
:message="activeJob.message"
|
||||||
|
:progress="activeJob.progress"
|
||||||
|
:total="activeJob.total"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-auto border-t border-default pt-4">
|
||||||
|
<UButton
|
||||||
|
:label="t('storage.backup.exportAction')"
|
||||||
|
icon="i-lucide-download"
|
||||||
|
size="sm"
|
||||||
|
:loading="busy"
|
||||||
|
:disabled="disabled || busy"
|
||||||
|
@click="emit('export')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
message: string
|
||||||
|
progress: number
|
||||||
|
total: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const percent = computed(() => {
|
||||||
|
if (!props.total) return 0
|
||||||
|
return Math.min(100, Math.round((props.progress / props.total) * 100))
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<div class="flex items-center justify-between gap-2 text-xs text-muted">
|
||||||
|
<span class="truncate">{{ message }}</span>
|
||||||
|
<span
|
||||||
|
v-if="total > 0"
|
||||||
|
class="shrink-0 tabular-nums"
|
||||||
|
>
|
||||||
|
{{ progress }} / {{ total }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="h-1 overflow-hidden rounded-full bg-muted">
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full bg-primary transition-all duration-300"
|
||||||
|
:style="{ width: `${percent}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,257 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { BackupJobItem } from '~/types/backup'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
jobs: BackupJobItem[]
|
||||||
|
polling: boolean
|
||||||
|
page: number
|
||||||
|
totalPages: number
|
||||||
|
total: number
|
||||||
|
pageSize: number
|
||||||
|
loading?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'retry': [jobId: string]
|
||||||
|
'download': [jobId: string]
|
||||||
|
'cancel': [jobId: string]
|
||||||
|
'view': [job: BackupJobItem]
|
||||||
|
'update:page': [page: number]
|
||||||
|
'update:pageSize': [pageSize: number]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t, locale } = useI18n()
|
||||||
|
|
||||||
|
function typeLabel(type: BackupJobItem['type']): string {
|
||||||
|
const map: Record<BackupJobItem['type'], string> = {
|
||||||
|
full_export: t('storage.backup.jobTypeExport'),
|
||||||
|
full_restore: t('storage.backup.jobTypeRestore'),
|
||||||
|
backend_sync: t('storage.backup.jobTypeSync')
|
||||||
|
}
|
||||||
|
return map[type]
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusColor(status: BackupJobItem['status']): 'success' | 'error' | 'warning' | 'neutral' {
|
||||||
|
if (status === 'done') return 'success'
|
||||||
|
if (status === 'failed') return 'error'
|
||||||
|
if (status === 'running') return 'warning'
|
||||||
|
return 'neutral'
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusLabel(status: BackupJobItem['status']): string {
|
||||||
|
const map: Record<BackupJobItem['status'], string> = {
|
||||||
|
pending: t('storage.backup.statusPending'),
|
||||||
|
running: t('storage.backup.statusRunning'),
|
||||||
|
done: t('storage.backup.statusDone'),
|
||||||
|
failed: t('storage.backup.statusFailed')
|
||||||
|
}
|
||||||
|
return map[status]
|
||||||
|
}
|
||||||
|
|
||||||
|
function progressPercent(job: BackupJobItem): number {
|
||||||
|
if (!job.total) return job.status === 'done' ? 100 : 0
|
||||||
|
return Math.min(100, Math.round((job.progress / job.total) * 100))
|
||||||
|
}
|
||||||
|
|
||||||
|
function jobMessage(job: BackupJobItem): string {
|
||||||
|
if (job.status === 'failed') {
|
||||||
|
return job.error || job.message || t('storage.backup.jobFailedUnknown')
|
||||||
|
}
|
||||||
|
if (job.status === 'running' || job.status === 'pending') {
|
||||||
|
return job.message
|
||||||
|
}
|
||||||
|
if (job.status === 'done' && job.message) {
|
||||||
|
return job.message
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function canRetry(job: BackupJobItem): boolean {
|
||||||
|
return job.type === 'backend_sync' && job.status === 'failed'
|
||||||
|
}
|
||||||
|
|
||||||
|
function canCancel(job: BackupJobItem): boolean {
|
||||||
|
return job.status === 'running' || job.status === 'pending'
|
||||||
|
}
|
||||||
|
|
||||||
|
function canView(job: BackupJobItem): boolean {
|
||||||
|
return job.type === 'full_restore' && job.status === 'done' && Boolean(job.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(value: string) {
|
||||||
|
if (!value) return '—'
|
||||||
|
return new Date(value).toLocaleString(locale.value, { hour12: false })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="overflow-hidden rounded-xl border border-default bg-elevated">
|
||||||
|
<header class="flex items-center justify-between gap-3 border-b border-default/50 px-4 py-4 sm:px-5">
|
||||||
|
<div>
|
||||||
|
<h3 class="text-sm font-semibold">
|
||||||
|
{{ t('storage.backup.jobsTitle') }}
|
||||||
|
</h3>
|
||||||
|
<p class="mt-0.5 text-xs text-muted">
|
||||||
|
{{ t('storage.backup.jobsSubtitle') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<UIcon
|
||||||
|
v-if="polling"
|
||||||
|
name="i-lucide-loader-circle"
|
||||||
|
class="size-4 shrink-0 animate-spin text-muted"
|
||||||
|
/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="!jobs.length && !loading"
|
||||||
|
class="flex flex-col items-center gap-2 px-4 py-12 text-center sm:px-5"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-clipboard-list"
|
||||||
|
class="size-7 text-muted"
|
||||||
|
/>
|
||||||
|
<p class="text-sm text-muted">
|
||||||
|
{{ t('storage.backup.jobsEmpty') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="overflow-x-auto"
|
||||||
|
>
|
||||||
|
<table class="w-full min-w-[800px] text-left text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr class="border-b border-default/50 text-xs text-muted">
|
||||||
|
<th class="px-4 py-3 font-medium sm:px-5">
|
||||||
|
{{ t('storage.backup.colTask') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-3 font-medium sm:px-5">
|
||||||
|
{{ t('storage.backup.colStatus') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-3 font-medium sm:px-5">
|
||||||
|
{{ t('storage.backup.colMessage') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-3 font-medium sm:px-5">
|
||||||
|
{{ t('storage.backup.colProgress') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-3 font-medium sm:px-5">
|
||||||
|
{{ t('storage.backup.colCreated') }}
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-3 font-medium sm:px-5">
|
||||||
|
{{ t('storage.backup.colActions') }}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr
|
||||||
|
v-for="job in jobs"
|
||||||
|
:key="job.id"
|
||||||
|
class="border-b border-default/40 last:border-0"
|
||||||
|
>
|
||||||
|
<td class="px-4 py-3.5 whitespace-nowrap font-medium sm:px-5">
|
||||||
|
{{ typeLabel(job.type) }}
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3.5 sm:px-5">
|
||||||
|
<UBadge
|
||||||
|
:color="statusColor(job.status)"
|
||||||
|
variant="subtle"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
{{ statusLabel(job.status) }}
|
||||||
|
</UBadge>
|
||||||
|
</td>
|
||||||
|
<td class="max-w-xs px-4 py-3.5 sm:px-5">
|
||||||
|
<p
|
||||||
|
v-if="jobMessage(job)"
|
||||||
|
class="line-clamp-2 text-xs leading-relaxed"
|
||||||
|
:class="job.status === 'failed' ? 'text-error' : 'text-muted'"
|
||||||
|
:title="jobMessage(job)"
|
||||||
|
>
|
||||||
|
{{ jobMessage(job) }}
|
||||||
|
</p>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="text-xs text-dimmed"
|
||||||
|
>—</span>
|
||||||
|
</td>
|
||||||
|
<td class="min-w-32 px-4 py-3.5 sm:px-5">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="h-1 min-w-0 flex-1 overflow-hidden rounded-full bg-muted">
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full bg-primary transition-all"
|
||||||
|
:class="{ 'animate-pulse': job.status === 'running' }"
|
||||||
|
:style="{ width: `${progressPercent(job)}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span class="shrink-0 text-xs tabular-nums text-muted">
|
||||||
|
<template v-if="job.total">{{ job.progress }}/{{ job.total }}</template>
|
||||||
|
<template v-else-if="job.status === 'done'">100%</template>
|
||||||
|
<template v-else>—</template>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3.5 whitespace-nowrap text-xs text-muted sm:px-5">
|
||||||
|
{{ formatTime(job.createdAt) }}
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3.5 sm:px-5">
|
||||||
|
<div class="flex flex-wrap gap-1.5">
|
||||||
|
<UButton
|
||||||
|
v-if="job.downloadable"
|
||||||
|
:label="t('storage.backup.download')"
|
||||||
|
icon="i-lucide-download"
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
@click="emit('download', job.id)"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="canView(job)"
|
||||||
|
:label="t('storage.backup.jobView')"
|
||||||
|
icon="i-lucide-eye"
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
@click="emit('view', job)"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="canCancel(job)"
|
||||||
|
:label="t('storage.backup.cancel')"
|
||||||
|
icon="i-lucide-x"
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
color="warning"
|
||||||
|
@click="emit('cancel', job.id)"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="canRetry(job)"
|
||||||
|
:label="t('storage.backup.retry')"
|
||||||
|
icon="i-lucide-rotate-ccw"
|
||||||
|
size="xs"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
@click="emit('retry', job.id)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="total > 0"
|
||||||
|
class="border-t border-default/50 px-4 py-4 sm:px-5"
|
||||||
|
>
|
||||||
|
<PaginationBar
|
||||||
|
:page="page"
|
||||||
|
:total-pages="totalPages"
|
||||||
|
:total="total"
|
||||||
|
:page-size="pageSize"
|
||||||
|
:loading="loading"
|
||||||
|
:unit="t('storage.backup.jobsUnit')"
|
||||||
|
@update:page="emit('update:page', $event)"
|
||||||
|
@update:page-size="emit('update:pageSize', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { BackupPackageItem, BackupRestorePreview } from '~/types/backup'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
packages: BackupPackageItem[]
|
||||||
|
busy: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
restoreBusy?: boolean
|
||||||
|
activeJob?: { progress: number, total: number, message: string } | null
|
||||||
|
previewRestore: (input: { file?: File, archiveName?: string }) => Promise<BackupRestorePreview>
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
restore: [input: { file?: File, archiveName?: string, conflictMode: 'skip' | 'overwrite' }]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t, locale } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
|
const fileInput = ref<HTMLInputElement | null>(null)
|
||||||
|
const selectedFile = ref<File | null>(null)
|
||||||
|
const selectedPackage = ref<string>('')
|
||||||
|
const conflictMode = ref<'skip' | 'overwrite'>('skip')
|
||||||
|
const preview = ref<BackupRestorePreview | null>(null)
|
||||||
|
const previewLoading = ref(false)
|
||||||
|
const confirmOpen = ref(false)
|
||||||
|
|
||||||
|
const conflictItems = computed(() => [
|
||||||
|
{ label: t('storage.backup.conflictSkip'), value: 'skip' },
|
||||||
|
{ label: t('storage.backup.conflictOverwrite'), value: 'overwrite' }
|
||||||
|
])
|
||||||
|
|
||||||
|
const selectMenuUi = {
|
||||||
|
content: 'min-w-[var(--reka-select-trigger-width)] w-max max-w-[min(100vw-2rem,24rem)]',
|
||||||
|
item: 'whitespace-normal',
|
||||||
|
itemLabel: 'whitespace-normal'
|
||||||
|
}
|
||||||
|
|
||||||
|
const packageOptions = computed(() =>
|
||||||
|
props.packages.map(pkg => ({
|
||||||
|
label: `${shortenName(pkg.name)} (${formatFileSize(pkg.bytes)})`,
|
||||||
|
value: pkg.name
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
|
||||||
|
function shortenName(name: string) {
|
||||||
|
if (name.length <= 36) return name
|
||||||
|
return `${name.slice(0, 22)}…${name.slice(-10)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(value: string) {
|
||||||
|
if (!value) return '—'
|
||||||
|
return new Date(value).toLocaleString(locale.value, { hour12: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickFile() {
|
||||||
|
fileInput.value?.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFileChange(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
const file = input.files?.[0] ?? null
|
||||||
|
if (!file) return
|
||||||
|
selectedFile.value = file
|
||||||
|
selectedPackage.value = ''
|
||||||
|
preview.value = null
|
||||||
|
if (input) input.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectPackage(name: string | null) {
|
||||||
|
if (!name) {
|
||||||
|
selectedPackage.value = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
selectedPackage.value = name
|
||||||
|
selectedFile.value = null
|
||||||
|
preview.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!selectedFile.value && !selectedPackage.value) {
|
||||||
|
toast.add({ title: t('storage.backup.restoreSelectRequired'), color: 'warning' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previewLoading.value = true
|
||||||
|
try {
|
||||||
|
preview.value = await props.previewRestore({
|
||||||
|
file: selectedFile.value ?? undefined,
|
||||||
|
archiveName: selectedPackage.value || undefined
|
||||||
|
})
|
||||||
|
confirmOpen.value = true
|
||||||
|
} catch {
|
||||||
|
toast.add({ title: t('storage.backup.previewFailed'), color: 'error' })
|
||||||
|
} finally {
|
||||||
|
previewLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmRestore() {
|
||||||
|
emit('restore', {
|
||||||
|
file: selectedFile.value ?? undefined,
|
||||||
|
archiveName: selectedPackage.value || undefined,
|
||||||
|
conflictMode: conflictMode.value
|
||||||
|
})
|
||||||
|
confirmOpen.value = false
|
||||||
|
selectedFile.value = null
|
||||||
|
selectedPackage.value = ''
|
||||||
|
preview.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceLabel = computed(() => selectedFile.value?.name || selectedPackage.value || '')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<article class="flex h-full flex-col rounded-xl border border-default bg-elevated p-4 sm:p-5">
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-warning/10 text-warning">
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-upload"
|
||||||
|
class="size-5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<h3 class="text-base font-semibold">
|
||||||
|
{{ t('storage.backup.restoreTitle') }}
|
||||||
|
</h3>
|
||||||
|
<p class="mt-0.5 text-sm text-muted">
|
||||||
|
{{ t('storage.backup.restoreSubtitle') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex flex-1 flex-col space-y-3">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label class="text-xs text-muted">{{ t('storage.backup.restoreUploadLabel') }}</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full flex-col items-center gap-1.5 rounded-lg border-2 border-dashed px-3 py-2.5 text-center transition-colors disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
:class="selectedFile
|
||||||
|
? 'border-primary/50 bg-primary/5'
|
||||||
|
: 'border-warning/40 bg-warning/5 hover:border-warning/60 hover:bg-warning/10'"
|
||||||
|
:disabled="disabled || busy"
|
||||||
|
@click="pickFile"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex size-8 items-center justify-center rounded-full"
|
||||||
|
:class="selectedFile ? 'bg-primary/15 text-primary' : 'bg-warning/15 text-warning'"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="selectedFile ? 'i-lucide-check' : 'i-lucide-upload'"
|
||||||
|
class="size-4.5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span class="max-w-full truncate text-sm font-medium text-default">
|
||||||
|
{{ selectedFile?.name ?? t('storage.backup.restoreUpload') }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="!selectedFile"
|
||||||
|
class="text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ t('storage.backup.restoreUploadHint') }}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="packages.length"
|
||||||
|
class="space-y-1.5"
|
||||||
|
>
|
||||||
|
<label class="text-xs text-muted">{{ t('storage.backup.restoreServerPackages') }}</label>
|
||||||
|
<USelect
|
||||||
|
:model-value="selectedPackage || undefined"
|
||||||
|
:items="packageOptions"
|
||||||
|
size="sm"
|
||||||
|
class="w-full"
|
||||||
|
:ui="selectMenuUi"
|
||||||
|
:placeholder="t('storage.backup.restoreServerSelectPlaceholder')"
|
||||||
|
:disabled="disabled || busy"
|
||||||
|
@update:model-value="selectPackage"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-xs text-muted">{{ t('storage.backup.conflictMode') }}</label>
|
||||||
|
<URadioGroup
|
||||||
|
v-model="conflictMode"
|
||||||
|
:items="conflictItems"
|
||||||
|
:disabled="disabled || busy"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<StorageBackupJobProgress
|
||||||
|
v-if="restoreBusy && activeJob"
|
||||||
|
class="mt-auto"
|
||||||
|
:message="activeJob.message"
|
||||||
|
:progress="activeJob.progress"
|
||||||
|
:total="activeJob.total"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-auto border-t border-default pt-4">
|
||||||
|
<UButton
|
||||||
|
:label="t('storage.backup.restorePreviewConfirm')"
|
||||||
|
icon="i-lucide-search"
|
||||||
|
size="sm"
|
||||||
|
:loading="previewLoading || restoreBusy"
|
||||||
|
:disabled="disabled || busy"
|
||||||
|
@click="submit"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input
|
||||||
|
ref="fileInput"
|
||||||
|
type="file"
|
||||||
|
accept=".phost.tar.gz,.tar.gz"
|
||||||
|
class="hidden"
|
||||||
|
@change="onFileChange"
|
||||||
|
>
|
||||||
|
|
||||||
|
<UModal
|
||||||
|
v-model:open="confirmOpen"
|
||||||
|
:ui="{ content: 'max-w-md' }"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="p-5 sm:p-6">
|
||||||
|
<h2 class="text-base font-semibold">
|
||||||
|
{{ t('storage.backup.restoreConfirmTitle') }}
|
||||||
|
</h2>
|
||||||
|
<p
|
||||||
|
v-if="sourceLabel"
|
||||||
|
class="mt-2 truncate font-mono text-xs text-muted"
|
||||||
|
:title="sourceLabel"
|
||||||
|
>
|
||||||
|
{{ sourceLabel }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<dl
|
||||||
|
v-if="preview"
|
||||||
|
class="mt-4 grid grid-cols-2 gap-3 text-sm"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<dt class="text-xs text-muted">
|
||||||
|
{{ t('storage.backup.previewImages') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-0.5 font-semibold tabular-nums">
|
||||||
|
{{ preview.imageCount }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt class="text-xs text-muted">
|
||||||
|
{{ t('storage.backup.previewNew') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-0.5 font-semibold tabular-nums">
|
||||||
|
{{ preview.newImages }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt class="text-xs text-muted">
|
||||||
|
{{ t('storage.backup.previewConflicts') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-0.5 font-semibold tabular-nums">
|
||||||
|
{{ preview.conflictingImages }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt class="text-xs text-muted">
|
||||||
|
{{ t('storage.backup.previewCreated') }}
|
||||||
|
</dt>
|
||||||
|
<dd class="mt-0.5 text-xs">
|
||||||
|
{{ formatTime(preview.createdAt) }}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<UAlert
|
||||||
|
v-if="conflictMode === 'overwrite'"
|
||||||
|
class="mt-4"
|
||||||
|
color="warning"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-triangle-alert"
|
||||||
|
:description="t('storage.backup.restoreOverwriteWarning')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="mt-5 flex justify-end gap-2">
|
||||||
|
<UButton
|
||||||
|
:label="t('common.cancel')"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
@click="() => { confirmOpen = false }"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('storage.backup.restoreConfirm')"
|
||||||
|
size="sm"
|
||||||
|
color="warning"
|
||||||
|
:loading="restoreBusy"
|
||||||
|
@click="confirmRestore"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
@@ -1,20 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { StorageBackendItem } from '~/types/storage'
|
import type { StorageBackendItem } from '~/types/storage'
|
||||||
|
|
||||||
type CardAction = {
|
|
||||||
key: string
|
|
||||||
icon: string
|
|
||||||
label: string
|
|
||||||
shortLabel: string
|
|
||||||
danger?: boolean
|
|
||||||
disabled?: boolean
|
|
||||||
onClick: () => void
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
backend: StorageBackendItem
|
backend: StorageBackendItem
|
||||||
envOverride?: boolean
|
envOverride?: boolean
|
||||||
busy?: boolean
|
busy?: boolean
|
||||||
|
showMigrateIn?: boolean
|
||||||
|
showMigrateOut?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -23,6 +15,8 @@ const emit = defineEmits<{
|
|||||||
test: []
|
test: []
|
||||||
toggleEnabled: []
|
toggleEnabled: []
|
||||||
delete: []
|
delete: []
|
||||||
|
migrateIn: []
|
||||||
|
migrateOut: []
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -35,181 +29,172 @@ const typeLabel = computed(() =>
|
|||||||
props.backend.type === 'local' ? t('storage.backendLocal') : t('storage.backendCloud')
|
props.backend.type === 'local' ? t('storage.backendLocal') : t('storage.backendCloud')
|
||||||
)
|
)
|
||||||
|
|
||||||
const servingLabel = computed(() =>
|
|
||||||
props.backend.servingMode === 'public'
|
|
||||||
? t('storage.servingPublic')
|
|
||||||
: t('storage.servingProxy')
|
|
||||||
)
|
|
||||||
|
|
||||||
const bucketLine = computed(() => {
|
|
||||||
if (props.backend.type !== 's3') return null
|
|
||||||
return props.backend.config.bucket || t('storage.notConfigured')
|
|
||||||
})
|
|
||||||
|
|
||||||
const actionsDisabled = computed(() => props.envOverride || props.busy)
|
const actionsDisabled = computed(() => props.envOverride || props.busy)
|
||||||
|
|
||||||
const actions = computed<CardAction[]>(() => {
|
const isLocal = computed(() => props.backend.type === 'local')
|
||||||
const isLocal = props.backend.type === 'local'
|
|
||||||
const items: CardAction[] = []
|
|
||||||
|
|
||||||
if (!props.backend.isDefault && props.backend.enabled) {
|
function canSetDefault() {
|
||||||
items.push({
|
return !props.backend.isDefault && props.backend.enabled
|
||||||
key: 'default',
|
|
||||||
icon: 'i-lucide-star',
|
|
||||||
label: t('storage.setDefault'),
|
|
||||||
shortLabel: isLocal ? t('storage.setDefault') : t('storage.actionSetDefault'),
|
|
||||||
onClick: () => emit('setDefault')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.backend.type === 's3') {
|
function canEdit() {
|
||||||
items.push({
|
return props.backend.type === 's3'
|
||||||
key: 'edit',
|
|
||||||
icon: 'i-lucide-pencil',
|
|
||||||
label: t('common.edit'),
|
|
||||||
shortLabel: t('common.edit'),
|
|
||||||
onClick: () => emit('edit')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
function canToggle() {
|
||||||
key: 'test',
|
return props.backend.type !== 'local'
|
||||||
icon: 'i-lucide-plug-zap',
|
|
||||||
label: t('storage.testConnection'),
|
|
||||||
shortLabel: isLocal ? t('storage.testConnection') : t('storage.actionTest'),
|
|
||||||
onClick: () => emit('test')
|
|
||||||
})
|
|
||||||
|
|
||||||
if (props.backend.type !== 'local') {
|
|
||||||
items.push({
|
|
||||||
key: 'toggle',
|
|
||||||
icon: props.backend.enabled ? 'i-lucide-pause' : 'i-lucide-play',
|
|
||||||
label: props.backend.enabled ? t('storage.disable') : t('storage.enable'),
|
|
||||||
shortLabel: props.backend.enabled ? t('storage.disable') : t('storage.enable'),
|
|
||||||
disabled: props.backend.isDefault && props.backend.enabled,
|
|
||||||
onClick: () => emit('toggleEnabled')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.backend.type !== 'local' && !props.backend.isDefault) {
|
function canDelete() {
|
||||||
items.push({
|
return props.backend.type !== 'local' && !props.backend.isDefault
|
||||||
key: 'delete',
|
|
||||||
icon: 'i-lucide-trash-2',
|
|
||||||
label: t('common.delete'),
|
|
||||||
shortLabel: t('common.delete'),
|
|
||||||
danger: true,
|
|
||||||
onClick: () => emit('delete')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return items
|
|
||||||
})
|
|
||||||
|
|
||||||
const actionGridClass = computed(() => {
|
|
||||||
switch (actions.value.length) {
|
|
||||||
case 1: return 'grid-cols-1'
|
|
||||||
case 2: return 'grid-cols-2'
|
|
||||||
case 3: return 'grid-cols-3'
|
|
||||||
case 4: return 'grid-cols-4'
|
|
||||||
default: return 'grid-cols-5'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<article
|
<article
|
||||||
class="flex h-full flex-col rounded-2xl border border-default bg-elevated p-4 shadow-sm"
|
class="flex h-full flex-col rounded-xl border border-default bg-elevated p-4 sm:p-5"
|
||||||
:class="{
|
:class="{ 'opacity-75': !backend.enabled }"
|
||||||
'ring-2 ring-primary/30': backend.isDefault,
|
|
||||||
'opacity-75': !backend.enabled
|
|
||||||
}"
|
|
||||||
>
|
|
||||||
<div class="mb-3 flex items-start justify-between gap-2">
|
|
||||||
<div class="flex min-w-0 items-start gap-2.5">
|
|
||||||
<div
|
|
||||||
class="flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary"
|
|
||||||
>
|
>
|
||||||
|
<div class="flex items-start justify-between gap-3">
|
||||||
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
|
<div class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary">
|
||||||
<UIcon
|
<UIcon
|
||||||
:name="typeIcon"
|
:name="typeIcon"
|
||||||
class="size-4.5"
|
class="size-5"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="min-w-0">
|
<h3 class="truncate text-base font-semibold">
|
||||||
<h3 class="truncate text-sm font-semibold">
|
|
||||||
{{ backend.name }}
|
{{ backend.name }}
|
||||||
</h3>
|
</h3>
|
||||||
<p class="mt-0.5 text-xs text-muted">
|
|
||||||
{{ typeLabel }}
|
|
||||||
<template v-if="bucketLine">
|
|
||||||
· {{ bucketLine }}
|
|
||||||
</template>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="flex shrink-0 flex-wrap justify-end gap-1.5">
|
||||||
<div class="flex shrink-0 flex-wrap justify-end gap-1">
|
<span
|
||||||
<UBadge
|
v-if="backend.isDefault"
|
||||||
v-if="backend.enabled"
|
class="inline-flex rounded-md bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary"
|
||||||
color="success"
|
>
|
||||||
variant="subtle"
|
{{ t('storage.badgeDefaultStorage') }}
|
||||||
size="xs"
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="isLocal"
|
||||||
|
class="inline-flex rounded-md border border-default bg-default px-2 py-0.5 text-xs font-medium text-muted"
|
||||||
|
>
|
||||||
|
{{ t('storage.badgeLocal') }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else-if="backend.enabled"
|
||||||
|
class="inline-flex rounded-md border border-default bg-default px-2 py-0.5 text-xs font-medium text-muted"
|
||||||
>
|
>
|
||||||
{{ t('storage.badgeEnabled') }}
|
{{ t('storage.badgeEnabled') }}
|
||||||
</UBadge>
|
</span>
|
||||||
<UBadge
|
<span
|
||||||
v-if="backend.isDefault"
|
v-else
|
||||||
color="primary"
|
class="inline-flex rounded-md bg-muted px-2 py-0.5 text-xs font-medium text-muted"
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
{{ t('storage.badgeDefault') }}
|
|
||||||
</UBadge>
|
|
||||||
<UBadge
|
|
||||||
v-if="!backend.enabled"
|
|
||||||
color="warning"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
>
|
||||||
{{ t('storage.badgeDisabled') }}
|
{{ t('storage.badgeDisabled') }}
|
||||||
</UBadge>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
<StorageUsageBar
|
<StorageUsageBar
|
||||||
:capacity="backend.capacity"
|
:capacity="backend.capacity"
|
||||||
:index-bytes="backend.usage.bytes"
|
:index-bytes="backend.usage.bytes"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p class="mt-3 text-xs text-muted">
|
|
||||||
{{ t('storage.servingMode') }}: {{ servingLabel }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="mt-4 border-t border-default pt-4">
|
|
||||||
<div
|
|
||||||
class="grid gap-1.5"
|
|
||||||
:class="actionGridClass"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
v-for="action in actions"
|
|
||||||
:key="action.key"
|
|
||||||
type="button"
|
|
||||||
class="flex flex-col items-center justify-center gap-1 rounded-lg border px-1 py-2 transition disabled:cursor-not-allowed disabled:opacity-40"
|
|
||||||
:class="action.danger
|
|
||||||
? 'border-error/30 text-error hover:bg-error/5'
|
|
||||||
: 'border-default text-muted hover:bg-muted/40 hover:text-highlighted'"
|
|
||||||
:title="action.label"
|
|
||||||
:aria-label="action.label"
|
|
||||||
:disabled="actionsDisabled || action.disabled"
|
|
||||||
@click="action.onClick"
|
|
||||||
>
|
|
||||||
<UIcon
|
|
||||||
:name="action.icon"
|
|
||||||
class="size-4 shrink-0"
|
|
||||||
/>
|
|
||||||
<span class="w-full truncate text-center text-[11px] leading-none">
|
|
||||||
{{ action.shortLabel }}
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted">
|
||||||
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
|
<span class="shrink-0">{{ t('storage.storageId') }}:</span>
|
||||||
|
<code class="min-w-0 truncate font-mono text-dimmed">{{ backend.id }}</code>
|
||||||
|
<CopyButton
|
||||||
|
icon="i-lucide-copy"
|
||||||
|
icon-only
|
||||||
|
variant="ghost"
|
||||||
|
color="primary"
|
||||||
|
class="shrink-0"
|
||||||
|
:label="t('common.copy')"
|
||||||
|
:value="backend.id"
|
||||||
|
:success-title="t('copy.copied')"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span>
|
||||||
|
{{ t('storage.storageType') }}: {{ typeLabel }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4 flex flex-wrap gap-2 border-t border-default pt-4">
|
||||||
|
<UButton
|
||||||
|
v-if="canSetDefault()"
|
||||||
|
:label="t('storage.setDefault')"
|
||||||
|
icon="i-lucide-star"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:disabled="actionsDisabled"
|
||||||
|
@click="emit('setDefault')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="showMigrateIn"
|
||||||
|
:label="t('storage.backup.migrateIn')"
|
||||||
|
:title="t('storage.backup.migrateInHint')"
|
||||||
|
icon="i-lucide-import"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:disabled="actionsDisabled"
|
||||||
|
@click="emit('migrateIn')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="showMigrateOut"
|
||||||
|
:label="t('storage.backup.migrateOut')"
|
||||||
|
:title="t('storage.backup.migrateOutHint')"
|
||||||
|
icon="i-lucide-arrow-up-from-line"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:disabled="actionsDisabled"
|
||||||
|
@click="emit('migrateOut')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="canEdit()"
|
||||||
|
:label="t('common.edit')"
|
||||||
|
icon="i-lucide-pencil"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:disabled="actionsDisabled"
|
||||||
|
@click="emit('edit')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('storage.testConnection')"
|
||||||
|
:icon="isLocal ? 'i-lucide-wand-sparkles' : 'i-lucide-activity'"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:loading="busy"
|
||||||
|
:disabled="actionsDisabled"
|
||||||
|
@click="emit('test')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="canToggle()"
|
||||||
|
:label="backend.enabled ? t('storage.disable') : t('storage.enable')"
|
||||||
|
:icon="backend.enabled ? 'i-lucide-pause' : 'i-lucide-play'"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
:disabled="actionsDisabled || (backend.isDefault && backend.enabled)"
|
||||||
|
@click="emit('toggleEnabled')"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
v-if="canDelete()"
|
||||||
|
:label="t('common.delete')"
|
||||||
|
icon="i-lucide-trash-2"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
color="error"
|
||||||
|
:disabled="actionsDisabled"
|
||||||
|
@click="emit('delete')"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</template>
|
</template>
|
||||||
@@ -6,6 +6,7 @@ type StorageProvider = 'r2' | 'cos' | 'oss' | 'aws' | 'custom'
|
|||||||
|
|
||||||
export interface StorageFormPayload {
|
export interface StorageFormPayload {
|
||||||
name: string
|
name: string
|
||||||
|
provider: StorageProvider
|
||||||
config: {
|
config: {
|
||||||
endpoint: string
|
endpoint: string
|
||||||
region: string
|
region: string
|
||||||
@@ -158,6 +159,7 @@ watch(provider, (value) => {
|
|||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
emit('submit', {
|
emit('submit', {
|
||||||
name: name.value.trim() || providerLabel(provider.value),
|
name: name.value.trim() || providerLabel(provider.value),
|
||||||
|
provider: provider.value,
|
||||||
config: {
|
config: {
|
||||||
endpoint: endpoint.value.trim(),
|
endpoint: endpoint.value.trim(),
|
||||||
region: region.value.trim() || 'auto',
|
region: region.value.trim() || 'auto',
|
||||||
|
|||||||
@@ -0,0 +1,178 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { BackupJobItem, SyncDraft } from '~/types/backup'
|
||||||
|
import type { StorageBackendItem } from '~/types/storage'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
backends: StorageBackendItem[]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const toast = useToast()
|
||||||
|
const {
|
||||||
|
jobs,
|
||||||
|
jobsPage,
|
||||||
|
jobsPageSize,
|
||||||
|
jobsTotal,
|
||||||
|
jobsTotalPages,
|
||||||
|
jobsLoading,
|
||||||
|
estimate,
|
||||||
|
packages,
|
||||||
|
loadingEstimate,
|
||||||
|
polling,
|
||||||
|
hasActiveJob,
|
||||||
|
getActiveJob,
|
||||||
|
loadJobs,
|
||||||
|
setJobsPage,
|
||||||
|
setJobsPageSize,
|
||||||
|
loadEstimate,
|
||||||
|
startPolling,
|
||||||
|
createExport,
|
||||||
|
previewRestore,
|
||||||
|
confirmRestore,
|
||||||
|
previewSync,
|
||||||
|
startSync,
|
||||||
|
retryJob,
|
||||||
|
cancelJob,
|
||||||
|
downloadUrl
|
||||||
|
} = useBackup()
|
||||||
|
|
||||||
|
const syncDraft = ref<SyncDraft | null>(null)
|
||||||
|
const syncCardRef = ref<{ applyDraft: (draft: SyncDraft) => void } | null>(null)
|
||||||
|
const panelRef = ref<HTMLElement | null>(null)
|
||||||
|
const syncHighlighted = ref(false)
|
||||||
|
|
||||||
|
const activeJob = computed(() => getActiveJob())
|
||||||
|
const exportBusy = computed(() => activeJob.value?.type === 'full_export')
|
||||||
|
const restoreBusy = computed(() => activeJob.value?.type === 'full_restore')
|
||||||
|
const syncBusy = computed(() => activeJob.value?.type === 'backend_sync')
|
||||||
|
const anyJobBusy = computed(() => Boolean(activeJob.value))
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await Promise.all([loadJobs(), loadEstimate()])
|
||||||
|
if (hasActiveJob()) {
|
||||||
|
startPolling()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function applySyncDraft(draft: SyncDraft) {
|
||||||
|
syncDraft.value = draft
|
||||||
|
syncCardRef.value?.applyDraft(draft)
|
||||||
|
syncHighlighted.value = true
|
||||||
|
window.setTimeout(() => {
|
||||||
|
syncHighlighted.value = false
|
||||||
|
}, 2500)
|
||||||
|
nextTick(() => {
|
||||||
|
panelRef.value?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
|
})
|
||||||
|
toast.add({ title: t('storage.backup.syncDraftApplied'), color: 'info' })
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ applySyncDraft })
|
||||||
|
|
||||||
|
async function onExport() {
|
||||||
|
await createExport()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onRestore(input: {
|
||||||
|
file?: File
|
||||||
|
archiveName?: string
|
||||||
|
conflictMode: 'skip' | 'overwrite'
|
||||||
|
}) {
|
||||||
|
await confirmRestore(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onCancel(jobId: string) {
|
||||||
|
await cancelJob(jobId)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onSync(body: {
|
||||||
|
fromBackendId: string
|
||||||
|
toBackendId: string
|
||||||
|
deleteSource: boolean
|
||||||
|
setDefault: boolean
|
||||||
|
}) {
|
||||||
|
await startSync(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDownload(jobId: string) {
|
||||||
|
window.open(downloadUrl(jobId), '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onRetry(jobId: string) {
|
||||||
|
await retryJob(jobId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onViewJob(job: BackupJobItem) {
|
||||||
|
toast.add({
|
||||||
|
title: t('storage.backup.jobTypeRestore'),
|
||||||
|
description: job.message,
|
||||||
|
color: 'info'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section
|
||||||
|
ref="panelRef"
|
||||||
|
class="scroll-mt-20 space-y-4 border-t border-default pt-5"
|
||||||
|
>
|
||||||
|
<header>
|
||||||
|
<h2 class="text-base font-semibold">
|
||||||
|
{{ t('storage.backup.sectionTitle') }}
|
||||||
|
</h2>
|
||||||
|
<p class="mt-1 text-sm text-muted">
|
||||||
|
{{ t('storage.backup.sectionSubtitle') }}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 items-stretch gap-4 xl:grid-cols-3">
|
||||||
|
<StorageBackupExportCard
|
||||||
|
class="h-full"
|
||||||
|
:estimate="estimate"
|
||||||
|
:loading="loadingEstimate"
|
||||||
|
:busy="exportBusy"
|
||||||
|
:active-job="exportBusy ? activeJob : null"
|
||||||
|
:disabled="anyJobBusy && !exportBusy"
|
||||||
|
@export="onExport"
|
||||||
|
/>
|
||||||
|
<StorageBackupRestoreCard
|
||||||
|
class="h-full"
|
||||||
|
:packages="packages"
|
||||||
|
:busy="anyJobBusy"
|
||||||
|
:restore-busy="restoreBusy"
|
||||||
|
:active-job="restoreBusy ? activeJob : null"
|
||||||
|
:disabled="anyJobBusy && !restoreBusy"
|
||||||
|
:preview-restore="previewRestore"
|
||||||
|
@restore="onRestore"
|
||||||
|
/>
|
||||||
|
<StorageBackendSyncCard
|
||||||
|
ref="syncCardRef"
|
||||||
|
class="h-full"
|
||||||
|
:backends="props.backends"
|
||||||
|
:sync-draft="syncDraft"
|
||||||
|
:highlighted="syncHighlighted"
|
||||||
|
:busy="syncBusy"
|
||||||
|
:active-job="syncBusy ? activeJob : null"
|
||||||
|
:disabled="anyJobBusy && !syncBusy"
|
||||||
|
:preview-sync="previewSync"
|
||||||
|
@sync="onSync"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<StorageBackupJobTable
|
||||||
|
:jobs="jobs"
|
||||||
|
:polling="polling"
|
||||||
|
:page="jobsPage"
|
||||||
|
:total-pages="jobsTotalPages"
|
||||||
|
:total="jobsTotal"
|
||||||
|
:page-size="jobsPageSize"
|
||||||
|
:loading="jobsLoading"
|
||||||
|
@update:page="setJobsPage"
|
||||||
|
@update:page-size="setJobsPageSize"
|
||||||
|
@download="onDownload"
|
||||||
|
@retry="onRetry"
|
||||||
|
@cancel="onCancel"
|
||||||
|
@view="onViewJob"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { StorageBackendItem } from '~/types/storage'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
backends: StorageBackendItem[]
|
||||||
|
loading?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const { formatFileSize } = useFileSize()
|
||||||
|
|
||||||
|
const CHART_COLORS = [
|
||||||
|
'var(--ui-primary)',
|
||||||
|
'#3b82f6',
|
||||||
|
'#6366f1',
|
||||||
|
'#f59e0b',
|
||||||
|
'#ec4899',
|
||||||
|
'#8b5cf6'
|
||||||
|
] as const
|
||||||
|
|
||||||
|
function backendUsedBytes(backend: StorageBackendItem) {
|
||||||
|
return backend.capacity.source === 'disk'
|
||||||
|
? backend.capacity.usedBytes
|
||||||
|
: backend.usage.bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalCapacityBytes = computed(() => {
|
||||||
|
let total = 0
|
||||||
|
let hasTotal = false
|
||||||
|
for (const backend of props.backends) {
|
||||||
|
if (backend.capacity.totalBytes != null && backend.capacity.totalBytes > 0) {
|
||||||
|
total += backend.capacity.totalBytes
|
||||||
|
hasTotal = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasTotal ? total : null
|
||||||
|
})
|
||||||
|
|
||||||
|
const totalUsedBytes = computed(() =>
|
||||||
|
props.backends.reduce((sum, backend) => sum + backendUsedBytes(backend), 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
const totalFreeBytes = computed(() => {
|
||||||
|
if (!totalCapacityBytes.value) return null
|
||||||
|
return Math.max(0, totalCapacityBytes.value - totalUsedBytes.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const usagePercent = computed(() => {
|
||||||
|
if (!totalCapacityBytes.value) return null
|
||||||
|
return Math.min(Math.round((totalUsedBytes.value / totalCapacityBytes.value) * 1000) / 10, 100)
|
||||||
|
})
|
||||||
|
|
||||||
|
const usageBarWidth = computed(() => {
|
||||||
|
if (usagePercent.value == null) return 0
|
||||||
|
return Math.max(usagePercent.value, totalUsedBytes.value > 0 ? 4 : 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
const distributionItems = computed(() => {
|
||||||
|
if (!totalCapacityBytes.value) return []
|
||||||
|
|
||||||
|
return props.backends
|
||||||
|
.filter(backend => backend.capacity.totalBytes != null && backend.capacity.totalBytes > 0)
|
||||||
|
.map((backend, index) => ({
|
||||||
|
id: backend.id,
|
||||||
|
name: backend.name,
|
||||||
|
color: CHART_COLORS[index % CHART_COLORS.length]!,
|
||||||
|
percent: Math.round((backend.capacity.totalBytes! / totalCapacityBytes.value!) * 1000) / 10
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
const donutStyle = computed(() => {
|
||||||
|
const items = distributionItems.value
|
||||||
|
if (!items.length) return { background: 'var(--ui-bg-muted)' }
|
||||||
|
|
||||||
|
let cursor = 0
|
||||||
|
const segments = items.map((item) => {
|
||||||
|
const start = cursor
|
||||||
|
cursor += item.percent
|
||||||
|
return `${item.color} ${start}% ${cursor}%`
|
||||||
|
})
|
||||||
|
|
||||||
|
return { background: `conic-gradient(${segments.join(', ')})` }
|
||||||
|
})
|
||||||
|
|
||||||
|
function displaySize(bytes: number | null) {
|
||||||
|
if (props.loading) return '—'
|
||||||
|
if (bytes == null) return '—'
|
||||||
|
return formatFileSize(bytes)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="rounded-xl border border-default bg-elevated p-4 sm:p-5">
|
||||||
|
<h2 class="text-sm font-semibold">
|
||||||
|
{{ t('storage.overviewTitle') }}
|
||||||
|
</h2>
|
||||||
|
<p class="mt-0.5 text-xs text-muted">
|
||||||
|
{{ t('storage.overviewSubtitle') }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="mt-4 grid gap-5 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-center">
|
||||||
|
<div>
|
||||||
|
<div class="grid grid-cols-2 gap-4 sm:grid-cols-4">
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('storage.overviewTotal') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-lg font-semibold tabular-nums">
|
||||||
|
{{ displaySize(totalCapacityBytes) }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-if="totalCapacityBytes"
|
||||||
|
class="mt-2 h-1 overflow-hidden rounded-full bg-muted/50"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full bg-primary transition-all"
|
||||||
|
:style="{ width: `${usageBarWidth}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('storage.overviewUsed') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-lg font-semibold tabular-nums">
|
||||||
|
{{ displaySize(totalUsedBytes) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('storage.overviewFree') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-lg font-semibold tabular-nums">
|
||||||
|
{{ displaySize(totalFreeBytes) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ t('storage.overviewUsageRate') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-lg font-semibold tabular-nums">
|
||||||
|
{{ usagePercent != null ? `${usagePercent}%` : '—' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<div
|
||||||
|
class="relative size-24 shrink-0 rounded-full p-2"
|
||||||
|
:style="donutStyle"
|
||||||
|
>
|
||||||
|
<div class="flex size-full items-center justify-center rounded-full bg-elevated px-2 text-center">
|
||||||
|
<p class="text-[10px] leading-tight text-muted">
|
||||||
|
{{ t('storage.capacityDistribution') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul
|
||||||
|
v-if="distributionItems.length"
|
||||||
|
class="min-w-[8rem] space-y-2"
|
||||||
|
>
|
||||||
|
<li
|
||||||
|
v-for="item in distributionItems"
|
||||||
|
:key="item.id"
|
||||||
|
class="flex items-center justify-between gap-3 text-xs"
|
||||||
|
>
|
||||||
|
<span class="flex min-w-0 items-center gap-1.5">
|
||||||
|
<span
|
||||||
|
class="size-2 shrink-0 rounded-full"
|
||||||
|
:style="{ background: item.color }"
|
||||||
|
/>
|
||||||
|
<span class="truncate">{{ item.name }}</span>
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 tabular-nums text-muted">
|
||||||
|
{{ item.percent }}%
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const items = computed(() => [
|
||||||
|
{
|
||||||
|
icon: 'i-lucide-hard-drive',
|
||||||
|
iconClass: 'text-primary',
|
||||||
|
boxClass: 'border-primary/20 bg-primary/5',
|
||||||
|
title: t('storage.backendLocal'),
|
||||||
|
desc: t('storage.supportedLocalDesc')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'i-lucide-cloud',
|
||||||
|
iconClass: 'text-orange-500',
|
||||||
|
boxClass: 'border-orange-500/20 bg-orange-500/5',
|
||||||
|
title: 'Cloudflare R2',
|
||||||
|
desc: t('storage.supportedR2Desc')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'i-lucide-server',
|
||||||
|
iconClass: 'text-blue-500',
|
||||||
|
boxClass: 'border-blue-500/20 bg-blue-500/5',
|
||||||
|
title: t('storage.supportedS3Title'),
|
||||||
|
desc: t('storage.supportedS3Desc')
|
||||||
|
}
|
||||||
|
])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="rounded-xl border border-default bg-elevated p-4 sm:p-5">
|
||||||
|
<h2 class="text-sm font-semibold">
|
||||||
|
{{ t('storage.supportedTitle') }}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="mt-4 grid grid-cols-1 gap-3 lg:grid-cols-3">
|
||||||
|
<div
|
||||||
|
v-for="item in items"
|
||||||
|
:key="item.title"
|
||||||
|
class="flex items-start gap-3 rounded-lg border border-default bg-muted/30 px-4 py-3"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex size-10 shrink-0 items-center justify-center rounded-lg border"
|
||||||
|
:class="item.boxClass"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="item.icon"
|
||||||
|
class="size-5"
|
||||||
|
:class="item.iconClass"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 pt-0.5">
|
||||||
|
<p class="text-sm font-semibold">
|
||||||
|
{{ item.title }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-0.5 text-xs leading-relaxed text-muted">
|
||||||
|
{{ item.desc }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
@@ -36,56 +36,53 @@ function formatOptional(bytes: number | null): string {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="space-y-3">
|
<div class="space-y-3">
|
||||||
<div class="grid grid-cols-3 gap-2 text-center text-xs">
|
<div class="grid grid-cols-2 gap-3 sm:grid-cols-4">
|
||||||
<div class="rounded-lg bg-muted/30 px-2 py-2">
|
<div>
|
||||||
<p class="text-muted">
|
<p class="text-xs text-muted">
|
||||||
{{ $t('storage.statTotal') }}
|
|
||||||
</p>
|
|
||||||
<p class="mt-1 font-medium tabular-nums text-highlighted">
|
|
||||||
{{ formatOptional(capacity.totalBytes) }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="rounded-lg bg-muted/30 px-2 py-2">
|
|
||||||
<p class="text-muted">
|
|
||||||
{{ $t('storage.statUsed') }}
|
{{ $t('storage.statUsed') }}
|
||||||
</p>
|
</p>
|
||||||
<p class="mt-1 font-medium tabular-nums text-highlighted">
|
<p class="mt-1 text-sm font-semibold tabular-nums">
|
||||||
{{ formatFileSize(displayUsedBytes) }}
|
{{ formatFileSize(displayUsedBytes) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="rounded-lg bg-muted/30 px-2 py-2">
|
<div>
|
||||||
<p class="text-muted">
|
<p class="text-xs text-muted">
|
||||||
|
{{ $t('storage.statTotal') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-sm font-semibold tabular-nums">
|
||||||
|
{{ formatOptional(capacity.totalBytes) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
{{ $t('storage.statFree') }}
|
{{ $t('storage.statFree') }}
|
||||||
</p>
|
</p>
|
||||||
<p
|
<p
|
||||||
class="mt-1 font-medium tabular-nums"
|
class="mt-1 text-sm font-semibold tabular-nums"
|
||||||
:class="overQuota ? 'text-error' : 'text-highlighted'"
|
:class="overQuota ? 'text-error' : ''"
|
||||||
>
|
>
|
||||||
{{ formatOptional(capacity.freeBytes) }}
|
{{ formatOptional(capacity.freeBytes) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs text-muted">
|
||||||
|
{{ $t('storage.usageRate') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-sm font-semibold tabular-nums">
|
||||||
|
{{ hasBar ? `${displayPercent}%` : '—' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="hasBar"
|
v-if="hasBar"
|
||||||
class="space-y-1"
|
class="h-1 overflow-hidden rounded-full bg-muted/50"
|
||||||
>
|
>
|
||||||
<div class="flex items-center justify-between text-xs">
|
|
||||||
<span class="text-muted">{{ $t('storage.usageRate') }}</span>
|
|
||||||
<span
|
|
||||||
class="tabular-nums font-medium"
|
|
||||||
:class="overQuota ? 'text-error' : ''"
|
|
||||||
>
|
|
||||||
{{ displayPercent }}%
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="h-1.5 overflow-hidden rounded-full bg-muted/50">
|
|
||||||
<div
|
<div
|
||||||
class="h-full rounded-full transition-all"
|
class="h-full rounded-full transition-all"
|
||||||
:class="overQuota ? 'bg-error/80' : 'bg-primary/70'"
|
:class="overQuota ? 'bg-error/80' : 'bg-primary'"
|
||||||
:style="{ width: `${barWidth}%` }"
|
:style="{ width: `${barWidth}%` }"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,323 @@
|
|||||||
|
export type ApiDocMethod = 'GET' | 'POST' | 'DELETE'
|
||||||
|
export type ApiDocCategory = 'image' | 'extension' | 'system'
|
||||||
|
export type ApiParamLocation = 'form-data' | 'query' | 'header' | 'body'
|
||||||
|
|
||||||
|
export interface ApiDocParam {
|
||||||
|
name: string
|
||||||
|
type: string
|
||||||
|
location: ApiParamLocation
|
||||||
|
required: boolean
|
||||||
|
descriptionKey: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ApiDocEndpoint {
|
||||||
|
id: string
|
||||||
|
category: ApiDocCategory
|
||||||
|
method: ApiDocMethod
|
||||||
|
path: string
|
||||||
|
titleKey: string
|
||||||
|
descKey: string
|
||||||
|
params: ApiDocParam[]
|
||||||
|
requiresAuth: boolean
|
||||||
|
curl: string
|
||||||
|
responseExample: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ApiDocsContext {
|
||||||
|
baseUrl: string
|
||||||
|
authHeader: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function authFlag(authHeader: string) {
|
||||||
|
return `-H 'Auth-Token: ${authHeader}'`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildApiDocs(ctx: ApiDocsContext): ApiDocEndpoint[] {
|
||||||
|
const { baseUrl, authHeader } = ctx
|
||||||
|
const auth = authFlag(authHeader)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 'upload',
|
||||||
|
category: 'image',
|
||||||
|
method: 'POST',
|
||||||
|
path: '/api/images/upload',
|
||||||
|
titleKey: 'api.docs.upload.title',
|
||||||
|
descKey: 'api.docs.upload.desc',
|
||||||
|
requiresAuth: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'image',
|
||||||
|
type: 'file',
|
||||||
|
location: 'form-data',
|
||||||
|
required: true,
|
||||||
|
descriptionKey: 'api.params.upload.image'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'file',
|
||||||
|
type: 'file',
|
||||||
|
location: 'form-data',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.upload.file'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'files',
|
||||||
|
type: 'file',
|
||||||
|
location: 'form-data',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.upload.files'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'token',
|
||||||
|
type: 'string',
|
||||||
|
location: 'form-data',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.upload.token'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl -X POST "${baseUrl}/api/images/upload" \\
|
||||||
|
${auth} \\
|
||||||
|
-F "image=@./demo.png"`,
|
||||||
|
responseExample: `{
|
||||||
|
"success": true,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"key": "images/2026/08/abc123.webp",
|
||||||
|
"url": "https://pic.example.com/abc123.webp",
|
||||||
|
"originalName": "demo.png",
|
||||||
|
"contentType": "image/webp",
|
||||||
|
"size": 12345,
|
||||||
|
"uploadedAt": "2026-08-01T12:00:00.000Z",
|
||||||
|
"markdown": "",
|
||||||
|
"html": "<img src=\\"https://pic.example.com/abc123.webp\\" alt=\\"demo.png\\">"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"errors": []
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'list',
|
||||||
|
category: 'image',
|
||||||
|
method: 'GET',
|
||||||
|
path: '/api/images',
|
||||||
|
titleKey: 'api.docs.list.title',
|
||||||
|
descKey: 'api.docs.list.desc',
|
||||||
|
requiresAuth: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.list.limit'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'page',
|
||||||
|
type: 'number',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.list.page'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'backendId',
|
||||||
|
type: 'string',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.backendId'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl "${baseUrl}/api/images?limit=20&page=1" \\
|
||||||
|
${auth}`,
|
||||||
|
responseExample: `{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"key": "images/2026/08/abc123.webp",
|
||||||
|
"url": "https://pic.example.com/abc123.webp",
|
||||||
|
"originalName": "demo.png",
|
||||||
|
"contentType": "image/webp",
|
||||||
|
"size": 12345,
|
||||||
|
"uploadedAt": "2026-08-01T12:00:00.000Z",
|
||||||
|
"markdown": "",
|
||||||
|
"html": "<img src=\\"https://pic.example.com/abc123.webp\\" alt=\\"demo.png\\">"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"total": 1,
|
||||||
|
"page": 1,
|
||||||
|
"pageSize": 20,
|
||||||
|
"totalPages": 1
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'search',
|
||||||
|
category: 'image',
|
||||||
|
method: 'GET',
|
||||||
|
path: '/api/images/search',
|
||||||
|
titleKey: 'api.docs.search.title',
|
||||||
|
descKey: 'api.docs.search.desc',
|
||||||
|
requiresAuth: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'q',
|
||||||
|
type: 'string',
|
||||||
|
location: 'query',
|
||||||
|
required: true,
|
||||||
|
descriptionKey: 'api.params.search.q'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.list.limit'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'page',
|
||||||
|
type: 'number',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.list.page'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'backendId',
|
||||||
|
type: 'string',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.backendId'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl "${baseUrl}/api/images/search?q=demo&limit=20&page=1" \\
|
||||||
|
${auth}`,
|
||||||
|
responseExample: `{
|
||||||
|
"items": [],
|
||||||
|
"total": 0,
|
||||||
|
"page": 1,
|
||||||
|
"pageSize": 20,
|
||||||
|
"totalPages": 0
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'delete',
|
||||||
|
category: 'image',
|
||||||
|
method: 'DELETE',
|
||||||
|
path: '/api/images',
|
||||||
|
titleKey: 'api.docs.delete.title',
|
||||||
|
descKey: 'api.docs.delete.desc',
|
||||||
|
requiresAuth: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
type: 'string',
|
||||||
|
location: 'query',
|
||||||
|
required: true,
|
||||||
|
descriptionKey: 'api.params.delete.key'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl -X DELETE "${baseUrl}/api/images?key=images/2026/08/xxxx.webp" \\
|
||||||
|
${auth}`,
|
||||||
|
responseExample: `{
|
||||||
|
"success": true
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'batchDelete',
|
||||||
|
category: 'image',
|
||||||
|
method: 'POST',
|
||||||
|
path: '/api/images/batch-delete',
|
||||||
|
titleKey: 'api.docs.batchDelete.title',
|
||||||
|
descKey: 'api.docs.batchDelete.desc',
|
||||||
|
requiresAuth: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'keys',
|
||||||
|
type: 'string[]',
|
||||||
|
location: 'body',
|
||||||
|
required: true,
|
||||||
|
descriptionKey: 'api.params.batchDelete.keys'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl -X POST "${baseUrl}/api/images/batch-delete" \\
|
||||||
|
${auth} \\
|
||||||
|
-H "Content-Type: application/json" \\
|
||||||
|
-d '{"keys":["images/2026/08/a.webp","images/2026/08/b.webp"]}'`,
|
||||||
|
responseExample: `{
|
||||||
|
"success": true,
|
||||||
|
"deleted": ["images/2026/08/a.webp"],
|
||||||
|
"failed": []
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'twikoo',
|
||||||
|
category: 'extension',
|
||||||
|
method: 'POST',
|
||||||
|
path: '/api/index.php',
|
||||||
|
titleKey: 'api.docs.twikoo.title',
|
||||||
|
descKey: 'api.docs.twikoo.desc',
|
||||||
|
requiresAuth: false,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'image',
|
||||||
|
type: 'file',
|
||||||
|
location: 'form-data',
|
||||||
|
required: true,
|
||||||
|
descriptionKey: 'api.params.twikoo.image'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'token',
|
||||||
|
type: 'string',
|
||||||
|
location: 'form-data',
|
||||||
|
required: true,
|
||||||
|
descriptionKey: 'api.params.twikoo.token'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl -X POST "${baseUrl}/api/index.php" \\
|
||||||
|
-F "token=${authHeader}" \\
|
||||||
|
-F "image=@./demo.png"`,
|
||||||
|
responseExample: `{
|
||||||
|
"result": "success",
|
||||||
|
"code": 200,
|
||||||
|
"url": "https://pic.example.com/abc123.webp"
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'config',
|
||||||
|
category: 'system',
|
||||||
|
method: 'GET',
|
||||||
|
path: '/api/auth/config',
|
||||||
|
titleKey: 'api.docs.config.title',
|
||||||
|
descKey: 'api.docs.config.desc',
|
||||||
|
requiresAuth: false,
|
||||||
|
params: [],
|
||||||
|
curl: `curl "${baseUrl}/api/auth/config"`,
|
||||||
|
responseExample: `{
|
||||||
|
"initialized": true,
|
||||||
|
"allowRegistration": false,
|
||||||
|
"legacyMode": false,
|
||||||
|
"adminSecretConfigured": false,
|
||||||
|
"apiUploadTokenConfigured": true
|
||||||
|
}`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'count',
|
||||||
|
category: 'system',
|
||||||
|
method: 'GET',
|
||||||
|
path: '/api/images/count',
|
||||||
|
titleKey: 'api.docs.count.title',
|
||||||
|
descKey: 'api.docs.count.desc',
|
||||||
|
requiresAuth: true,
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'backendId',
|
||||||
|
type: 'string',
|
||||||
|
location: 'query',
|
||||||
|
required: false,
|
||||||
|
descriptionKey: 'api.params.backendId'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
curl: `curl "${baseUrl}/api/images/count" \\
|
||||||
|
${auth}`,
|
||||||
|
responseExample: `{
|
||||||
|
"total": 42
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { LoginVerificationPayload } from '~/types/auth'
|
||||||
|
|
||||||
export type AuthStatus = 'checking' | 'authenticated' | 'unauthenticated'
|
export type AuthStatus = 'checking' | 'authenticated' | 'unauthenticated'
|
||||||
|
|
||||||
export type UserRole = 'admin' | 'user'
|
export type UserRole = 'admin' | 'user'
|
||||||
@@ -8,11 +10,18 @@ export interface AuthUser {
|
|||||||
role: UserRole
|
role: UserRole
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LoginVerificationPublicConfig {
|
||||||
|
method: 'slider' | 'turnstile' | 'cap'
|
||||||
|
turnstileSiteKey?: string
|
||||||
|
capApiEndpoint?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface AuthStatusResponse {
|
export interface AuthStatusResponse {
|
||||||
initialized: boolean
|
initialized: boolean
|
||||||
allowRegistration: boolean
|
allowRegistration: boolean
|
||||||
legacyMode: boolean
|
legacyMode: boolean
|
||||||
needsMigration: boolean
|
needsMigration: boolean
|
||||||
|
loginVerification: LoginVerificationPublicConfig
|
||||||
user: AuthUser | null
|
user: AuthUser | null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,9 +75,19 @@ export function getFetchErrorMessage(error: unknown, fallback: string): string {
|
|||||||
|
|
||||||
export type AuthActionResult = { ok: true } | { ok: false, error: string }
|
export type AuthActionResult = { ok: true } | { ok: false, error: string }
|
||||||
|
|
||||||
export interface LoginCaptchaPayload {
|
export type { LoginVerificationPayload }
|
||||||
captchaId: string
|
|
||||||
captchaPosition: number
|
function buildVerificationBody(verification: LoginVerificationPayload): Record<string, unknown> {
|
||||||
|
if (verification.method === 'slider') {
|
||||||
|
return {
|
||||||
|
captchaId: verification.captchaId,
|
||||||
|
captchaPosition: verification.captchaPosition
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (verification.method === 'turnstile') {
|
||||||
|
return { turnstileToken: verification.turnstileToken }
|
||||||
|
}
|
||||||
|
return { capToken: verification.capToken }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAuth() {
|
export function useAuth() {
|
||||||
@@ -123,7 +142,7 @@ export function useAuth() {
|
|||||||
async function login(
|
async function login(
|
||||||
credentials: { username: string, password: string }
|
credentials: { username: string, password: string }
|
||||||
| { secret: string },
|
| { secret: string },
|
||||||
captcha: LoginCaptchaPayload
|
verification: LoginVerificationPayload
|
||||||
): Promise<{ ok: boolean, needsMigration?: boolean, error?: string }> {
|
): Promise<{ ok: boolean, needsMigration?: boolean, error?: string }> {
|
||||||
try {
|
try {
|
||||||
const result = await $fetch<{
|
const result = await $fetch<{
|
||||||
@@ -135,8 +154,7 @@ export function useAuth() {
|
|||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: {
|
body: {
|
||||||
...credentials,
|
...credentials,
|
||||||
captchaId: captcha.captchaId,
|
...buildVerificationBody(verification)
|
||||||
captchaPosition: captcha.captchaPosition
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (result.needsMigration) {
|
if (result.needsMigration) {
|
||||||
@@ -159,7 +177,8 @@ export function useAuth() {
|
|||||||
|
|
||||||
async function register(
|
async function register(
|
||||||
username: string,
|
username: string,
|
||||||
password: string
|
password: string,
|
||||||
|
verification: LoginVerificationPayload
|
||||||
): Promise<AuthActionResult> {
|
): Promise<AuthActionResult> {
|
||||||
const validationError = validateAuthInput(username, password)
|
const validationError = validateAuthInput(username, password)
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
@@ -172,7 +191,11 @@ export function useAuth() {
|
|||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: { username: username.trim(), password }
|
body: {
|
||||||
|
username: username.trim(),
|
||||||
|
password,
|
||||||
|
...buildVerificationBody(verification)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
user.value = result.user
|
user.value = result.user
|
||||||
@@ -291,15 +314,19 @@ export function useAuth() {
|
|||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
try {
|
try {
|
||||||
await $fetch('/api/auth/logout', { method: 'POST' })
|
await $fetch('/api/auth/logout', { method: 'POST', credentials: 'include' })
|
||||||
} catch {
|
} catch {
|
||||||
// 忽略登出失败
|
// 忽略登出失败
|
||||||
} finally {
|
} finally {
|
||||||
status.value = 'unauthenticated'
|
status.value = 'unauthenticated'
|
||||||
user.value = null
|
user.value = null
|
||||||
authStatus.value = null
|
|
||||||
hasValidatedOnce.value = true
|
hasValidatedOnce.value = true
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
await fetchStatus()
|
||||||
|
} catch {
|
||||||
|
// 保留既有公开配置(loginVerification 等)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAuthError(error: unknown) {
|
function handleAuthError(error: unknown) {
|
||||||
|
|||||||
@@ -0,0 +1,319 @@
|
|||||||
|
import type {
|
||||||
|
BackupEstimate,
|
||||||
|
BackupJobItem,
|
||||||
|
BackupPackageItem,
|
||||||
|
BackupRestorePreview,
|
||||||
|
BackendSyncPreview
|
||||||
|
} from '~/types/backup'
|
||||||
|
|
||||||
|
const jobs = ref<BackupJobItem[]>([])
|
||||||
|
const jobsPage = ref(1)
|
||||||
|
const jobsPageSize = ref(10)
|
||||||
|
const jobsTotal = ref(0)
|
||||||
|
const jobsTotalPages = ref(1)
|
||||||
|
const jobsLoading = ref(false)
|
||||||
|
const activeJobState = ref<BackupJobItem | null>(null)
|
||||||
|
const estimate = ref<BackupEstimate | null>(null)
|
||||||
|
const packages = ref<BackupPackageItem[]>([])
|
||||||
|
const loadingEstimate = ref(false)
|
||||||
|
const polling = ref(false)
|
||||||
|
let pollTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
export function useBackup() {
|
||||||
|
const toast = useToast()
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
function stopPolling() {
|
||||||
|
if (pollTimer) {
|
||||||
|
clearInterval(pollTimer)
|
||||||
|
pollTimer = null
|
||||||
|
}
|
||||||
|
polling.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasActiveJob(): boolean {
|
||||||
|
return activeJobState.value !== null
|
||||||
|
}
|
||||||
|
|
||||||
|
function getActiveJob(): BackupJobItem | null {
|
||||||
|
return activeJobState.value
|
||||||
|
}
|
||||||
|
|
||||||
|
async function cancelJob(jobId: string) {
|
||||||
|
try {
|
||||||
|
await $fetch(`/api/admin/backup/jobs/${jobId}/cancel`, {
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
await loadJobs()
|
||||||
|
toast.add({ title: t('storage.backup.cancelDone'), color: 'success' })
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleError(error, t('storage.backup.cancelFailed'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadJobs(options?: { page?: number, pageSize?: number }) {
|
||||||
|
if (options?.page !== undefined) jobsPage.value = options.page
|
||||||
|
if (options?.pageSize !== undefined) jobsPageSize.value = options.pageSize
|
||||||
|
jobsLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await $fetch<{
|
||||||
|
jobs: BackupJobItem[]
|
||||||
|
total: number
|
||||||
|
page: number
|
||||||
|
pageSize: number
|
||||||
|
totalPages: number
|
||||||
|
activeJob: BackupJobItem | null
|
||||||
|
}>('/api/admin/backup/jobs', {
|
||||||
|
credentials: 'include',
|
||||||
|
query: {
|
||||||
|
pageNum: jobsPage.value,
|
||||||
|
pageSize: jobsPageSize.value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
jobs.value = data.jobs
|
||||||
|
jobsTotal.value = data.total
|
||||||
|
jobsPage.value = data.page
|
||||||
|
jobsPageSize.value = data.pageSize
|
||||||
|
jobsTotalPages.value = data.totalPages
|
||||||
|
activeJobState.value = data.activeJob
|
||||||
|
if (!data.activeJob) {
|
||||||
|
stopPolling()
|
||||||
|
void loadEstimate().catch(() => {})
|
||||||
|
}
|
||||||
|
return data.jobs
|
||||||
|
} finally {
|
||||||
|
jobsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setJobsPage(page: number) {
|
||||||
|
jobsPage.value = page
|
||||||
|
return loadJobs()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setJobsPageSize(pageSize: number) {
|
||||||
|
jobsPageSize.value = pageSize
|
||||||
|
jobsPage.value = 1
|
||||||
|
return loadJobs()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshJobsFirstPage() {
|
||||||
|
jobsPage.value = 1
|
||||||
|
return loadJobs()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadEstimate() {
|
||||||
|
loadingEstimate.value = true
|
||||||
|
try {
|
||||||
|
const data = await $fetch<{
|
||||||
|
estimate: BackupEstimate
|
||||||
|
packages: BackupPackageItem[]
|
||||||
|
backupsDir: string
|
||||||
|
}>('/api/admin/backup/estimate', { credentials: 'include' })
|
||||||
|
estimate.value = data.estimate
|
||||||
|
packages.value = data.packages
|
||||||
|
return data
|
||||||
|
} finally {
|
||||||
|
loadingEstimate.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startPolling() {
|
||||||
|
if (pollTimer) return
|
||||||
|
polling.value = true
|
||||||
|
pollTimer = setInterval(() => {
|
||||||
|
void loadJobs().catch(() => {})
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createExport() {
|
||||||
|
try {
|
||||||
|
const data = await $fetch<{ job: BackupJobItem, estimate: BackupEstimate }>(
|
||||||
|
'/api/admin/backup/export',
|
||||||
|
{ method: 'POST', credentials: 'include' }
|
||||||
|
)
|
||||||
|
estimate.value = data.estimate
|
||||||
|
await refreshJobsFirstPage()
|
||||||
|
startPolling()
|
||||||
|
toast.add({ title: t('storage.backup.exportStarted'), color: 'success' })
|
||||||
|
return data.job
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleError(error, t('storage.backup.exportFailed'))
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function previewRestore(input: {
|
||||||
|
file?: File
|
||||||
|
archiveName?: string
|
||||||
|
}): Promise<BackupRestorePreview> {
|
||||||
|
if (input.file) {
|
||||||
|
const form = new FormData()
|
||||||
|
form.append('file', input.file)
|
||||||
|
form.append('dryRun', 'true')
|
||||||
|
const data = await $fetch<{ preview: BackupRestorePreview }>(
|
||||||
|
'/api/admin/backup/restore',
|
||||||
|
{ method: 'POST', credentials: 'include', body: form }
|
||||||
|
)
|
||||||
|
return data.preview
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await $fetch<{ preview: BackupRestorePreview }>(
|
||||||
|
'/api/admin/backup/restore',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
|
body: {
|
||||||
|
archiveName: input.archiveName,
|
||||||
|
dryRun: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return data.preview
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmRestore(input: {
|
||||||
|
file?: File
|
||||||
|
archiveName?: string
|
||||||
|
conflictMode: 'skip' | 'overwrite'
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
if (input.file) {
|
||||||
|
const form = new FormData()
|
||||||
|
form.append('file', input.file)
|
||||||
|
form.append('conflictMode', input.conflictMode)
|
||||||
|
const data = await $fetch<{ job: BackupJobItem }>(
|
||||||
|
'/api/admin/backup/restore',
|
||||||
|
{ method: 'POST', credentials: 'include', body: form }
|
||||||
|
)
|
||||||
|
await refreshJobsFirstPage()
|
||||||
|
startPolling()
|
||||||
|
toast.add({ title: t('storage.backup.restoreStarted'), color: 'success' })
|
||||||
|
return data.job
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await $fetch<{ job: BackupJobItem }>(
|
||||||
|
'/api/admin/backup/restore',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
|
body: {
|
||||||
|
archiveName: input.archiveName,
|
||||||
|
conflictMode: input.conflictMode,
|
||||||
|
dryRun: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
await refreshJobsFirstPage()
|
||||||
|
startPolling()
|
||||||
|
toast.add({ title: t('storage.backup.restoreStarted'), color: 'success' })
|
||||||
|
return data.job
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleError(error, t('storage.backup.restoreFailed'))
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function previewSync(body: {
|
||||||
|
fromBackendId: string
|
||||||
|
toBackendId: string
|
||||||
|
}): Promise<BackendSyncPreview> {
|
||||||
|
const data = await $fetch<{ preview: BackendSyncPreview }>(
|
||||||
|
'/api/admin/storage/sync',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
|
body: { ...body, dryRun: true }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return data.preview
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startSync(body: {
|
||||||
|
fromBackendId: string
|
||||||
|
toBackendId: string
|
||||||
|
deleteSource?: boolean
|
||||||
|
setDefault?: boolean
|
||||||
|
}) {
|
||||||
|
try {
|
||||||
|
const data = await $fetch<{ job: BackupJobItem }>(
|
||||||
|
'/api/admin/storage/sync',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
|
body
|
||||||
|
}
|
||||||
|
)
|
||||||
|
await refreshJobsFirstPage()
|
||||||
|
startPolling()
|
||||||
|
toast.add({ title: t('storage.backup.syncStarted'), color: 'success' })
|
||||||
|
return data.job
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleError(error, t('storage.backup.syncFailed'))
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function retryJob(jobId: string) {
|
||||||
|
try {
|
||||||
|
await $fetch(`/api/admin/backup/jobs/${jobId}/retry`, {
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include'
|
||||||
|
})
|
||||||
|
await refreshJobsFirstPage()
|
||||||
|
startPolling()
|
||||||
|
toast.add({ title: t('storage.backup.retryStarted'), color: 'success' })
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleError(error, t('storage.backup.retryFailed'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadUrl(jobId: string): string {
|
||||||
|
return `/api/admin/backup/jobs/${jobId}/download`
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleError(error: unknown, fallback: string) {
|
||||||
|
const status = typeof error === 'object' && error !== null && 'statusCode' in error
|
||||||
|
? (error as { statusCode: number }).statusCode
|
||||||
|
: 0
|
||||||
|
if (status === 409) {
|
||||||
|
toast.add({ title: t('storage.backup.jobRunning'), color: 'warning' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toast.add({ title: fallback, color: 'error' })
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
stopPolling()
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
jobs,
|
||||||
|
jobsPage,
|
||||||
|
jobsPageSize,
|
||||||
|
jobsTotal,
|
||||||
|
jobsTotalPages,
|
||||||
|
jobsLoading,
|
||||||
|
estimate,
|
||||||
|
packages,
|
||||||
|
loadingEstimate,
|
||||||
|
polling,
|
||||||
|
hasActiveJob,
|
||||||
|
getActiveJob,
|
||||||
|
loadJobs,
|
||||||
|
setJobsPage,
|
||||||
|
setJobsPageSize,
|
||||||
|
loadEstimate,
|
||||||
|
startPolling,
|
||||||
|
stopPolling,
|
||||||
|
createExport,
|
||||||
|
previewRestore,
|
||||||
|
confirmRestore,
|
||||||
|
previewSync,
|
||||||
|
startSync,
|
||||||
|
retryJob,
|
||||||
|
cancelJob,
|
||||||
|
downloadUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,13 @@ import type {
|
|||||||
ImageListResponse
|
ImageListResponse
|
||||||
} from '~/types/image'
|
} from '~/types/image'
|
||||||
|
|
||||||
const PAGE_SIZE = 12
|
const PAGE_SIZE_DEFAULT = 10
|
||||||
|
|
||||||
export function useImageList() {
|
export function useImageList() {
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const items = ref<ImageItem[]>([])
|
const items = ref<ImageItem[]>([])
|
||||||
const page = ref(1)
|
const page = ref(1)
|
||||||
|
const pageSize = ref(PAGE_SIZE_DEFAULT)
|
||||||
const totalPages = ref(1)
|
const totalPages = ref(1)
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -17,6 +18,8 @@ export function useImageList() {
|
|||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
const activeSearch = ref('')
|
const activeSearch = ref('')
|
||||||
const activeStorageBackend = ref('all')
|
const activeStorageBackend = ref('all')
|
||||||
|
const activeContentType = ref('all')
|
||||||
|
const activeUploadSource = ref('all')
|
||||||
const storageBackendOptions = ref<Array<{ id: string, name: string }>>([])
|
const storageBackendOptions = ref<Array<{ id: string, name: string }>>([])
|
||||||
|
|
||||||
function storageQueryParams(): Record<string, string> {
|
function storageQueryParams(): Record<string, string> {
|
||||||
@@ -25,8 +28,21 @@ export function useImageList() {
|
|||||||
return { backendId }
|
return { backendId }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterQueryParams(): Record<string, string> {
|
||||||
|
const params: Record<string, string> = { ...storageQueryParams() }
|
||||||
|
const contentType = activeContentType.value.trim()
|
||||||
|
if (contentType && contentType !== 'all') {
|
||||||
|
params.contentType = contentType
|
||||||
|
}
|
||||||
|
const uploadSource = activeUploadSource.value.trim()
|
||||||
|
if (uploadSource && uploadSource !== 'all') {
|
||||||
|
params.uploadSource = uploadSource
|
||||||
|
}
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
function listQueryParams(): Record<string, string> {
|
function listQueryParams(): Record<string, string> {
|
||||||
return storageQueryParams()
|
return filterQueryParams()
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchesActiveStorage(item: ImageItem) {
|
function matchesActiveStorage(item: ImageItem) {
|
||||||
@@ -72,7 +88,7 @@ export function useImageList() {
|
|||||||
const response = await $fetch<ImageListResponse>('/api/images', {
|
const response = await $fetch<ImageListResponse>('/api/images', {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
query: {
|
query: {
|
||||||
limit: PAGE_SIZE,
|
limit: pageSize.value,
|
||||||
page: targetPage,
|
page: targetPage,
|
||||||
...listQueryParams()
|
...listQueryParams()
|
||||||
}
|
}
|
||||||
@@ -100,7 +116,7 @@ export function useImageList() {
|
|||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
query: {
|
query: {
|
||||||
q,
|
q,
|
||||||
limit: PAGE_SIZE,
|
limit: pageSize.value,
|
||||||
page: targetPage,
|
page: targetPage,
|
||||||
...listQueryParams()
|
...listQueryParams()
|
||||||
}
|
}
|
||||||
@@ -141,6 +157,40 @@ export function useImageList() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setActiveContentType(contentType: string) {
|
||||||
|
const next = contentType.trim() || 'all'
|
||||||
|
if (next === activeContentType.value) return
|
||||||
|
activeContentType.value = next
|
||||||
|
page.value = 1
|
||||||
|
if (activeSearch.value) {
|
||||||
|
await Promise.all([fetchSearch(1), fetchTotal()])
|
||||||
|
} else {
|
||||||
|
await Promise.all([fetchList(1), fetchTotal()])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setActiveUploadSource(uploadSource: string) {
|
||||||
|
const next = uploadSource.trim() || 'all'
|
||||||
|
if (next === activeUploadSource.value) return
|
||||||
|
activeUploadSource.value = next
|
||||||
|
page.value = 1
|
||||||
|
if (activeSearch.value) {
|
||||||
|
await Promise.all([fetchSearch(1), fetchTotal()])
|
||||||
|
} else {
|
||||||
|
await Promise.all([fetchList(1), fetchTotal()])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetFilters() {
|
||||||
|
searchQuery.value = ''
|
||||||
|
activeSearch.value = ''
|
||||||
|
activeStorageBackend.value = 'all'
|
||||||
|
activeContentType.value = 'all'
|
||||||
|
activeUploadSource.value = 'all'
|
||||||
|
page.value = 1
|
||||||
|
await Promise.all([fetchList(1), fetchTotal()])
|
||||||
|
}
|
||||||
|
|
||||||
async function submitSearch() {
|
async function submitSearch() {
|
||||||
const q = searchQuery.value.trim()
|
const q = searchQuery.value.trim()
|
||||||
activeSearch.value = q
|
activeSearch.value = q
|
||||||
@@ -161,6 +211,17 @@ export function useImageList() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setPageSize(size: number) {
|
||||||
|
if (!Number.isFinite(size) || size <= 0 || size === pageSize.value) return
|
||||||
|
pageSize.value = size
|
||||||
|
page.value = 1
|
||||||
|
if (activeSearch.value) {
|
||||||
|
await Promise.all([fetchSearch(1), fetchTotal()])
|
||||||
|
} else {
|
||||||
|
await Promise.all([fetchList(1), fetchTotal()])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function prependItems(newItems: ImageItem[]) {
|
function prependItems(newItems: ImageItem[]) {
|
||||||
const matched = newItems.filter(item => matchesActiveStorage(item))
|
const matched = newItems.filter(item => matchesActiveStorage(item))
|
||||||
if (!matched.length || page.value !== 1) return
|
if (!matched.length || page.value !== 1) return
|
||||||
@@ -220,10 +281,13 @@ export function useImageList() {
|
|||||||
return {
|
return {
|
||||||
items,
|
items,
|
||||||
page,
|
page,
|
||||||
|
pageSize,
|
||||||
totalPages,
|
totalPages,
|
||||||
total,
|
total,
|
||||||
loading,
|
loading,
|
||||||
activeStorageBackend,
|
activeStorageBackend,
|
||||||
|
activeContentType,
|
||||||
|
activeUploadSource,
|
||||||
storageBackendOptions,
|
storageBackendOptions,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
activeSearch,
|
activeSearch,
|
||||||
@@ -234,9 +298,13 @@ export function useImageList() {
|
|||||||
refreshList,
|
refreshList,
|
||||||
initializeList,
|
initializeList,
|
||||||
setActiveStorageBackend,
|
setActiveStorageBackend,
|
||||||
|
setActiveContentType,
|
||||||
|
setActiveUploadSource,
|
||||||
|
resetFilters,
|
||||||
loadStorageBackendOptions,
|
loadStorageBackendOptions,
|
||||||
submitSearch,
|
submitSearch,
|
||||||
goToPage,
|
goToPage,
|
||||||
|
setPageSize,
|
||||||
prependItems,
|
prependItems,
|
||||||
removeItems
|
removeItems
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,15 +12,6 @@ interface SettingsResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ApiDocItem {
|
|
||||||
index: number
|
|
||||||
method: 'GET' | 'POST' | 'DELETE'
|
|
||||||
path: string
|
|
||||||
title: string
|
|
||||||
description: string
|
|
||||||
curl: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus, isAdmin } = useAuth()
|
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus, isAdmin } = useAuth()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
@@ -31,6 +22,7 @@ const regenerating = ref(false)
|
|||||||
const confirmRegenerateOpen = ref(false)
|
const confirmRegenerateOpen = ref(false)
|
||||||
const regenerateResultOpen = ref(false)
|
const regenerateResultOpen = ref(false)
|
||||||
const newToken = ref('')
|
const newToken = ref('')
|
||||||
|
const activeEndpointId = ref('upload')
|
||||||
|
|
||||||
const baseUrl = computed(() => {
|
const baseUrl = computed(() => {
|
||||||
const configured = settings.value?.env.siteBaseUrl
|
const configured = settings.value?.env.siteBaseUrl
|
||||||
@@ -43,106 +35,24 @@ const baseUrl = computed(() => {
|
|||||||
|
|
||||||
const tokenDisplay = computed(() => settings.value?.apiUploadToken ?? '')
|
const tokenDisplay = computed(() => settings.value?.apiUploadToken ?? '')
|
||||||
const hasToken = computed(() => tokenDisplay.value.length > 0)
|
const hasToken = computed(() => tokenDisplay.value.length > 0)
|
||||||
const canRegenerate = computed(() => !settings.value?.envTokenOverride && !loading.value)
|
const canRegenerate = computed(() =>
|
||||||
|
!settings.value?.envTokenOverride && !loading.value
|
||||||
|
)
|
||||||
|
|
||||||
const authHeader = computed(() =>
|
const authHeader = computed(() =>
|
||||||
hasToken.value ? tokenDisplay.value : 'YOUR-TOKEN'
|
hasToken.value ? tokenDisplay.value : 'YOUR-TOKEN'
|
||||||
)
|
)
|
||||||
|
|
||||||
const authHeaderFlag = computed(() => `-H 'Auth-Token: ${authHeader.value}'`)
|
const apiDocs = computed(() =>
|
||||||
|
buildApiDocs({
|
||||||
const apiDocs = computed<ApiDocItem[]>(() => {
|
baseUrl: baseUrl.value,
|
||||||
const uploadDescription = t('api.docs.upload.desc')
|
authHeader: authHeader.value
|
||||||
const uploadCurl = `curl -X POST "${baseUrl.value}/api/images/upload" \\
|
|
||||||
${authHeaderFlag.value} \\
|
|
||||||
-F "image=@./demo.png"`
|
|
||||||
|
|
||||||
const listDescription = t('api.docs.list.desc')
|
|
||||||
const listCurl = `curl "${baseUrl.value}/api/images?limit=20&page=1" \\
|
|
||||||
${authHeaderFlag.value}`
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
index: 1,
|
|
||||||
method: 'POST',
|
|
||||||
path: '/api/images/upload',
|
|
||||||
title: t('api.docs.upload.title'),
|
|
||||||
description: uploadDescription,
|
|
||||||
curl: uploadCurl
|
|
||||||
},
|
|
||||||
{
|
|
||||||
index: 2,
|
|
||||||
method: 'GET',
|
|
||||||
path: '/api/images',
|
|
||||||
title: t('api.docs.list.title'),
|
|
||||||
description: listDescription,
|
|
||||||
curl: listCurl
|
|
||||||
},
|
|
||||||
{
|
|
||||||
index: 3,
|
|
||||||
method: 'GET',
|
|
||||||
path: '/api/images/search',
|
|
||||||
title: t('api.docs.search.title'),
|
|
||||||
description: t('api.docs.search.desc'),
|
|
||||||
curl: `curl "${baseUrl.value}/api/images/search?q=demo&limit=20&page=1" \\
|
|
||||||
${authHeaderFlag.value}`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
index: 4,
|
|
||||||
method: 'DELETE',
|
|
||||||
path: '/api/images',
|
|
||||||
title: t('api.docs.delete.title'),
|
|
||||||
description: t('api.docs.delete.desc'),
|
|
||||||
curl: `curl -X DELETE "${baseUrl.value}/api/images?key=images/2026/08/xxxx.webp" \\
|
|
||||||
${authHeaderFlag.value}`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
index: 5,
|
|
||||||
method: 'POST',
|
|
||||||
path: '/api/images/batch-delete',
|
|
||||||
title: t('api.docs.batchDelete.title'),
|
|
||||||
description: t('api.docs.batchDelete.desc'),
|
|
||||||
curl: `curl -X POST "${baseUrl.value}/api/images/batch-delete" \\
|
|
||||||
${authHeaderFlag.value} \\
|
|
||||||
-H "Content-Type: application/json" \\
|
|
||||||
-d '{"keys":["images/2026/08/a.webp","images/2026/08/b.webp"]}'`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const twikooDoc = computed(() => ({
|
const activeEndpoint = computed(() =>
|
||||||
method: 'POST' as const,
|
apiDocs.value.find(endpoint => endpoint.id === activeEndpointId.value) ?? apiDocs.value[0]
|
||||||
path: '/api/index.php',
|
)
|
||||||
title: t('api.docs.twikoo.title'),
|
|
||||||
description: t('api.docs.twikoo.desc'),
|
|
||||||
curl: `curl -X POST "${baseUrl.value}/api/index.php" \\
|
|
||||||
-F "token=${authHeader.value}" \\
|
|
||||||
-F "image=@./demo.png"`
|
|
||||||
}))
|
|
||||||
|
|
||||||
function tokenSourceLabel(source: SettingsResponse['tokenSource']) {
|
|
||||||
switch (source) {
|
|
||||||
case 'env':
|
|
||||||
return t('api.tokenSourceEnv')
|
|
||||||
case 'db':
|
|
||||||
return t('api.tokenSourceDb')
|
|
||||||
default:
|
|
||||||
return t('api.tokenSourceNone')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function methodBadgeColor(method: ApiDocItem['method']) {
|
|
||||||
switch (method) {
|
|
||||||
case 'GET':
|
|
||||||
return 'info' as const
|
|
||||||
case 'POST':
|
|
||||||
return 'warning' as const
|
|
||||||
case 'DELETE':
|
|
||||||
return 'error' as const
|
|
||||||
default:
|
|
||||||
return 'neutral' as const
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadSettings() {
|
async function loadSettings() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
@@ -251,175 +161,36 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
|
|
||||||
<AppShell v-else>
|
<AppShell v-else>
|
||||||
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
||||||
<div class="flex items-center gap-2 border-b border-default px-5 py-4 sm:px-6">
|
<div class="flex flex-col lg:flex-row lg:items-stretch">
|
||||||
<UIcon
|
<ApiSidebar
|
||||||
name="i-lucide-key-round"
|
:endpoints="apiDocs"
|
||||||
class="size-5 text-primary"
|
:active-id="activeEndpointId"
|
||||||
/>
|
@select="activeEndpointId = $event"
|
||||||
<h2 class="text-base font-semibold">
|
|
||||||
{{ t('api.tokenTitle') }}
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-4 p-5 sm:p-6">
|
|
||||||
<UAlert
|
|
||||||
v-if="settings?.envTokenOverride"
|
|
||||||
color="warning"
|
|
||||||
variant="subtle"
|
|
||||||
icon="i-lucide-triangle-alert"
|
|
||||||
:title="t('api.envOverrideTitle')"
|
|
||||||
:description="t('api.envOverrideDesc')"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<UAlert
|
<div class="flex min-w-0 flex-1 flex-col bg-default lg:border-r lg:border-default">
|
||||||
v-else-if="!isAdmin"
|
<ApiTokenCard
|
||||||
color="info"
|
:token="tokenDisplay"
|
||||||
variant="subtle"
|
|
||||||
icon="i-lucide-info"
|
|
||||||
:title="t('api.personalTitle')"
|
|
||||||
:description="t('api.personalDesc')"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<UAlert
|
|
||||||
v-else-if="settings && !hasToken"
|
|
||||||
color="info"
|
|
||||||
variant="subtle"
|
|
||||||
icon="i-lucide-info"
|
|
||||||
:title="t('api.notConfiguredTitle')"
|
|
||||||
:description="t('api.notConfiguredDesc')"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="flex flex-col gap-2 sm:flex-row sm:items-stretch">
|
|
||||||
<UInput
|
|
||||||
:model-value="hasToken ? tokenDisplay : t('common.notConfigured')"
|
|
||||||
readonly
|
|
||||||
class="min-w-0 flex-1 font-mono text-xs sm:text-sm"
|
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
:regenerating="regenerating"
|
||||||
|
:can-regenerate="canRegenerate"
|
||||||
|
:token-source="settings?.tokenSource"
|
||||||
|
:env-token-override="settings?.envTokenOverride"
|
||||||
|
:is-admin="isAdmin"
|
||||||
|
@regenerate="requestRegenerate"
|
||||||
/>
|
/>
|
||||||
<div class="flex gap-2">
|
|
||||||
<CopyButton
|
<ApiDocView
|
||||||
:label="t('common.copy')"
|
v-if="activeEndpoint"
|
||||||
:value="tokenDisplay"
|
:endpoint="activeEndpoint"
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
icon="i-lucide-refresh-cw"
|
|
||||||
:label="t('api.regenerate')"
|
|
||||||
color="warning"
|
|
||||||
variant="soft"
|
|
||||||
:loading="regenerating"
|
|
||||||
:disabled="!canRegenerate"
|
|
||||||
@click="requestRegenerate"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<p
|
<ApiDebugger
|
||||||
v-if="settings"
|
v-if="activeEndpoint"
|
||||||
class="text-xs text-muted"
|
:endpoint="activeEndpoint"
|
||||||
>
|
:token="tokenDisplay"
|
||||||
{{ tokenSourceLabel(settings.tokenSource) }}
|
|
||||||
· {{ t('api.tokenHeader') }}
|
|
||||||
<code class="font-mono">Auth-Token: <token></code>
|
|
||||||
<template v-if="hasToken && !settings.envTokenOverride">
|
|
||||||
· {{ t('api.tokenInvalidate') }}
|
|
||||||
</template>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
|
||||||
<div class="flex items-center gap-2 border-b border-default px-5 py-4 sm:px-6">
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-book-open"
|
|
||||||
class="size-5 text-primary"
|
|
||||||
/>
|
/>
|
||||||
<h2 class="text-base font-semibold">
|
|
||||||
{{ t('api.docsTitle') }}
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="divide-y divide-default">
|
|
||||||
<article
|
|
||||||
v-for="doc in apiDocs"
|
|
||||||
:key="doc.index"
|
|
||||||
class="space-y-4 p-5 sm:p-6"
|
|
||||||
>
|
|
||||||
<div class="flex gap-3">
|
|
||||||
<span
|
|
||||||
class="flex size-7 shrink-0 items-center justify-center rounded-full bg-primary/10 text-sm font-semibold text-primary"
|
|
||||||
>
|
|
||||||
{{ doc.index }}
|
|
||||||
</span>
|
|
||||||
<div class="min-w-0 space-y-2">
|
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
|
||||||
<UBadge
|
|
||||||
:color="methodBadgeColor(doc.method)"
|
|
||||||
variant="subtle"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{{ doc.method }}
|
|
||||||
</UBadge>
|
|
||||||
<code class="rounded-md border border-primary/20 bg-primary/10 px-2 py-0.5 font-mono text-sm font-medium text-primary">
|
|
||||||
{{ doc.path }}
|
|
||||||
</code>
|
|
||||||
<span class="text-sm font-medium">
|
|
||||||
{{ doc.title }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="text-sm leading-relaxed text-muted">
|
|
||||||
{{ doc.description }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<p class="mb-2 text-xs font-medium text-muted">
|
|
||||||
{{ t('api.curlExample') }}
|
|
||||||
</p>
|
|
||||||
<ApiCurlBlock :code="doc.curl" />
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="overflow-hidden rounded-2xl border border-dashed border-default bg-muted/20">
|
|
||||||
<div class="space-y-4 p-5 sm:p-6">
|
|
||||||
<div class="flex gap-3">
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-message-square"
|
|
||||||
class="mt-0.5 size-5 shrink-0 text-muted"
|
|
||||||
/>
|
|
||||||
<div class="min-w-0 space-y-2">
|
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
|
||||||
<UBadge
|
|
||||||
:color="methodBadgeColor(twikooDoc.method)"
|
|
||||||
variant="subtle"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{{ twikooDoc.method }}
|
|
||||||
</UBadge>
|
|
||||||
<code class="rounded-md border border-primary/20 bg-primary/10 px-2 py-0.5 font-mono text-sm font-medium text-primary">
|
|
||||||
{{ twikooDoc.path }}
|
|
||||||
</code>
|
|
||||||
<span class="text-sm font-medium">
|
|
||||||
{{ twikooDoc.title }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="text-sm leading-relaxed text-muted">
|
|
||||||
{{ twikooDoc.description }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<p class="mb-2 text-xs font-medium text-muted">
|
|
||||||
{{ t('api.curlExample') }}
|
|
||||||
</p>
|
|
||||||
<ApiCurlBlock
|
|
||||||
:code="twikooDoc.curl"
|
|
||||||
:scrollable="false"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</AppShell>
|
</AppShell>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { ImageItem } from '~/types/image'
|
||||||
|
|
||||||
interface StatsResponse {
|
interface StatsResponse {
|
||||||
uploadToday: number
|
uploadToday: number
|
||||||
|
uploadYesterday: number
|
||||||
uploadMonth: number
|
uploadMonth: number
|
||||||
|
uploadLastMonth: number
|
||||||
deleteToday: number
|
deleteToday: number
|
||||||
deleteMonth: number
|
deleteMonth: number
|
||||||
uploadTotal: number
|
uploadTotal: number
|
||||||
@@ -13,32 +17,39 @@ interface StatsResponse {
|
|||||||
web: number
|
web: number
|
||||||
api: number
|
api: number
|
||||||
}
|
}
|
||||||
|
storageUsage: {
|
||||||
|
usedBytes: number
|
||||||
|
totalBytes: number | null
|
||||||
|
percent: number | null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
items,
|
items,
|
||||||
page: galleryPage,
|
page: galleryPage,
|
||||||
|
pageSize: galleryPageSize,
|
||||||
totalPages: galleryTotalPages,
|
totalPages: galleryTotalPages,
|
||||||
total: galleryTotal,
|
total: galleryTotal,
|
||||||
loading: galleryLoading,
|
loading: galleryLoading,
|
||||||
searchQuery,
|
searchQuery,
|
||||||
activeSearch,
|
activeSearch,
|
||||||
listSummary,
|
|
||||||
refreshList,
|
|
||||||
fetchList,
|
fetchList,
|
||||||
fetchSearch,
|
fetchSearch,
|
||||||
fetchTotal,
|
fetchTotal,
|
||||||
submitSearch,
|
submitSearch,
|
||||||
goToPage,
|
goToPage,
|
||||||
|
setPageSize,
|
||||||
removeItems,
|
removeItems,
|
||||||
activeStorageBackend,
|
activeStorageBackend,
|
||||||
storageBackendOptions,
|
|
||||||
setActiveStorageBackend,
|
setActiveStorageBackend,
|
||||||
|
storageBackendOptions,
|
||||||
|
activeUploadSource,
|
||||||
|
setActiveUploadSource,
|
||||||
|
resetFilters,
|
||||||
loadStorageBackendOptions
|
loadStorageBackendOptions
|
||||||
} = useImageList()
|
} = useImageList()
|
||||||
|
|
||||||
const { formatFileSize } = useFileSize()
|
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus } = useAuth()
|
||||||
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus, isAdmin } = useAuth()
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
@@ -52,9 +63,20 @@ const deleteModalOpen = ref(false)
|
|||||||
const deleteTargetKeys = ref<string[]>([])
|
const deleteTargetKeys = ref<string[]>([])
|
||||||
const batchDeleting = ref(false)
|
const batchDeleting = ref(false)
|
||||||
const showScrollTop = ref(false)
|
const showScrollTop = ref(false)
|
||||||
const currentStorage = ref('all')
|
const previewOpen = ref(false)
|
||||||
|
const previewImage = ref<ImageItem | null>(null)
|
||||||
|
const viewMode = ref<'grid' | 'list'>('grid')
|
||||||
|
|
||||||
const storageSelectItems = computed(() => [
|
const currentUploadSource = ref('all')
|
||||||
|
const currentStorageBackend = ref('all')
|
||||||
|
|
||||||
|
const uploadSourceItems = computed(() => [
|
||||||
|
{ label: t('stats.filterSourceAll'), value: 'all' },
|
||||||
|
{ label: t('stats.sourceWeb'), value: 'web' },
|
||||||
|
{ label: t('stats.sourceApi'), value: 'api' }
|
||||||
|
])
|
||||||
|
|
||||||
|
const storageBackendItems = computed(() => [
|
||||||
{ label: t('stats.filterStorageAll'), value: 'all' },
|
{ label: t('stats.filterStorageAll'), value: 'all' },
|
||||||
...storageBackendOptions.value.map(backend => ({
|
...storageBackendOptions.value.map(backend => ({
|
||||||
label: backend.name,
|
label: backend.name,
|
||||||
@@ -64,47 +86,6 @@ const storageSelectItems = computed(() => [
|
|||||||
|
|
||||||
const selectedCount = computed(() => selectedKeys.value.size)
|
const selectedCount = computed(() => selectedKeys.value.size)
|
||||||
|
|
||||||
const SOURCE_CHART_COLORS = [
|
|
||||||
'var(--ui-primary)',
|
|
||||||
'#10b981'
|
|
||||||
]
|
|
||||||
|
|
||||||
const sourceUploadItems = computed(() => {
|
|
||||||
const bySource = stats.value?.bySource
|
|
||||||
if (!bySource) return []
|
|
||||||
return [
|
|
||||||
{ key: 'web', label: t('stats.sourceWeb'), count: bySource.web, color: SOURCE_CHART_COLORS[0]! },
|
|
||||||
{ key: 'api', label: t('stats.sourceApi'), count: bySource.api, color: SOURCE_CHART_COLORS[1]! }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
const sourceUploadTotal = computed(() =>
|
|
||||||
sourceUploadItems.value.reduce((sum, item) => sum + item.count, 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
function sourcePercent(count: number) {
|
|
||||||
const total = sourceUploadTotal.value
|
|
||||||
if (!total) return 0
|
|
||||||
return Math.round((count / total) * 100)
|
|
||||||
}
|
|
||||||
|
|
||||||
const statCards = computed(() => {
|
|
||||||
const s = stats.value
|
|
||||||
const base = [
|
|
||||||
{ label: t('stats.uploadToday'), value: s?.uploadToday ?? '—' },
|
|
||||||
{ label: t('stats.uploadMonth'), value: s?.uploadMonth ?? '—' },
|
|
||||||
{ label: t('stats.uploadTotal'), value: s?.uploadTotal ?? '—' },
|
|
||||||
{ label: t('stats.storedCount'), value: s?.storedCount ?? '—' },
|
|
||||||
{ label: t('stats.deleteToday'), value: s?.deleteToday ?? '—' },
|
|
||||||
{ label: t('stats.deleteMonth'), value: s?.deleteMonth ?? '—' },
|
|
||||||
isAdmin.value
|
|
||||||
? { label: t('stats.userCount'), value: s?.userCount ?? '—' }
|
|
||||||
: { label: t('stats.deleteTotal'), value: s?.deleteTotal ?? '—' },
|
|
||||||
{ label: t('stats.uploadBytes'), value: s ? formatFileSize(s.uploadBytesTotal) : '—' }
|
|
||||||
]
|
|
||||||
return base
|
|
||||||
})
|
|
||||||
|
|
||||||
function onWindowScroll() {
|
function onWindowScroll() {
|
||||||
showScrollTop.value = window.scrollY > 400
|
showScrollTop.value = window.scrollY > 400
|
||||||
}
|
}
|
||||||
@@ -133,17 +114,6 @@ async function refreshStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshGallery() {
|
|
||||||
if (!isAuthenticated.value) return
|
|
||||||
selectedKeys.value = new Set()
|
|
||||||
try {
|
|
||||||
await Promise.all([refreshList(), loadStorageBackendOptions()])
|
|
||||||
currentStorage.value = activeStorageBackend.value
|
|
||||||
} catch (error: unknown) {
|
|
||||||
handleAuthError(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function reloadGallery() {
|
async function reloadGallery() {
|
||||||
if (activeSearch.value) {
|
if (activeSearch.value) {
|
||||||
await fetchSearch(galleryPage.value)
|
await fetchSearch(galleryPage.value)
|
||||||
@@ -163,7 +133,8 @@ async function refreshAll() {
|
|||||||
reloadGallery(),
|
reloadGallery(),
|
||||||
loadStorageBackendOptions()
|
loadStorageBackendOptions()
|
||||||
])
|
])
|
||||||
currentStorage.value = activeStorageBackend.value
|
currentUploadSource.value = activeUploadSource.value
|
||||||
|
currentStorageBackend.value = activeStorageBackend.value
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
handleAuthError(error)
|
handleAuthError(error)
|
||||||
if (isAuthenticated.value) {
|
if (isAuthenticated.value) {
|
||||||
@@ -174,9 +145,9 @@ async function refreshAll() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleStorageChange(backendId: string) {
|
async function handleStorageBackendChange(backendId: string) {
|
||||||
if (!isAuthenticated.value) return
|
if (!isAuthenticated.value) return
|
||||||
currentStorage.value = backendId
|
currentStorageBackend.value = backendId
|
||||||
selectedKeys.value = new Set()
|
selectedKeys.value = new Set()
|
||||||
try {
|
try {
|
||||||
await setActiveStorageBackend(backendId)
|
await setActiveStorageBackend(backendId)
|
||||||
@@ -185,6 +156,33 @@ async function handleStorageChange(backendId: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleUploadSourceChange(uploadSource: string) {
|
||||||
|
if (!isAuthenticated.value) return
|
||||||
|
currentUploadSource.value = uploadSource
|
||||||
|
selectedKeys.value = new Set()
|
||||||
|
try {
|
||||||
|
await setActiveUploadSource(uploadSource)
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleAuthError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleResetFilters() {
|
||||||
|
if (!isAuthenticated.value) return
|
||||||
|
selectedKeys.value = new Set()
|
||||||
|
currentUploadSource.value = 'all'
|
||||||
|
currentStorageBackend.value = 'all'
|
||||||
|
try {
|
||||||
|
await resetFilters()
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleAuthError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSelectedKeys(keys: Set<string>) {
|
||||||
|
selectedKeys.value = keys
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSearch() {
|
async function handleSearch() {
|
||||||
if (!isAuthenticated.value) return
|
if (!isAuthenticated.value) return
|
||||||
selectedKeys.value = new Set()
|
selectedKeys.value = new Set()
|
||||||
@@ -195,14 +193,10 @@ async function handleSearch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clearSearch() {
|
|
||||||
searchQuery.value = ''
|
|
||||||
if (!activeSearch.value) return
|
|
||||||
await refreshGallery()
|
|
||||||
}
|
|
||||||
|
|
||||||
function requestDelete(key: string) {
|
function requestDelete(key: string) {
|
||||||
if (!isAuthenticated.value) return
|
if (!isAuthenticated.value) return
|
||||||
|
previewOpen.value = false
|
||||||
|
previewImage.value = null
|
||||||
deleteTargetKeys.value = [key]
|
deleteTargetKeys.value = [key]
|
||||||
deleteModalOpen.value = true
|
deleteModalOpen.value = true
|
||||||
}
|
}
|
||||||
@@ -217,6 +211,10 @@ function requestBatchDelete() {
|
|||||||
deleteModalOpen.value = true
|
deleteModalOpen.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearSelection() {
|
||||||
|
selectedKeys.value = new Set()
|
||||||
|
}
|
||||||
|
|
||||||
async function confirmDelete() {
|
async function confirmDelete() {
|
||||||
const keys = [...deleteTargetKeys.value]
|
const keys = [...deleteTargetKeys.value]
|
||||||
if (!keys.length || !isAuthenticated.value) return
|
if (!keys.length || !isAuthenticated.value) return
|
||||||
@@ -279,6 +277,8 @@ async function confirmDelete() {
|
|||||||
|
|
||||||
async function handleGalleryPageChange(targetPage: number) {
|
async function handleGalleryPageChange(targetPage: number) {
|
||||||
selectedKeys.value = new Set()
|
selectedKeys.value = new Set()
|
||||||
|
previewOpen.value = false
|
||||||
|
previewImage.value = null
|
||||||
try {
|
try {
|
||||||
await goToPage(targetPage)
|
await goToPage(targetPage)
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -286,6 +286,27 @@ async function handleGalleryPageChange(targetPage: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleGalleryPageSizeChange(size: number) {
|
||||||
|
selectedKeys.value = new Set()
|
||||||
|
previewOpen.value = false
|
||||||
|
previewImage.value = null
|
||||||
|
try {
|
||||||
|
await setPageSize(size)
|
||||||
|
} catch (error: unknown) {
|
||||||
|
handleAuthError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPreview(image: ImageItem) {
|
||||||
|
previewImage.value = image
|
||||||
|
previewOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestPreviewDelete() {
|
||||||
|
if (!previewImage.value) return
|
||||||
|
requestDelete(previewImage.value.key)
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
window.addEventListener('scroll', onWindowScroll, { passive: true })
|
window.addEventListener('scroll', onWindowScroll, { passive: true })
|
||||||
const status = await fetchStatus()
|
const status = await fetchStatus()
|
||||||
@@ -357,168 +378,85 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="grid gap-3 lg:grid-cols-3 lg:items-stretch">
|
<GalleryStatsOverview
|
||||||
<div class="grid grid-cols-2 gap-3 lg:col-span-2 lg:grid-cols-4">
|
:stats="stats"
|
||||||
<div
|
:loading="statsLoading"
|
||||||
v-for="item in statCards"
|
/>
|
||||||
:key="item.label"
|
|
||||||
class="rounded-xl border border-default bg-elevated p-4"
|
|
||||||
>
|
|
||||||
<p class="text-xs text-muted">
|
|
||||||
{{ item.label }}
|
|
||||||
</p>
|
|
||||||
<p class="mt-1 text-2xl font-semibold tabular-nums">
|
|
||||||
{{ item.value }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex h-full min-h-0 flex-col rounded-xl border border-default bg-elevated p-4 lg:col-span-1">
|
<section class="space-y-3">
|
||||||
<h2 class="shrink-0 text-sm font-medium text-muted">
|
<div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-2">
|
||||||
{{ t('stats.sourceDistribution') }}
|
<GallerySelectionBar
|
||||||
</h2>
|
:items="items"
|
||||||
<div
|
:selected-keys="selectedKeys"
|
||||||
v-if="!sourceUploadTotal"
|
@update:selected-keys="updateSelectedKeys"
|
||||||
class="flex flex-1 items-center justify-center text-center text-xs text-muted"
|
@clear="clearSelection"
|
||||||
>
|
|
||||||
{{ t('stats.noData') }}
|
|
||||||
</div>
|
|
||||||
<ul
|
|
||||||
v-else
|
|
||||||
class="mt-4 flex min-h-0 flex-1 flex-col"
|
|
||||||
>
|
|
||||||
<li
|
|
||||||
v-for="item in sourceUploadItems"
|
|
||||||
:key="item.key"
|
|
||||||
class="flex flex-1 flex-col justify-center gap-2 py-1"
|
|
||||||
>
|
|
||||||
<div class="flex items-center justify-between gap-2 text-xs">
|
|
||||||
<span class="flex min-w-0 items-center gap-1.5">
|
|
||||||
<span
|
|
||||||
class="size-2 shrink-0 rounded-full"
|
|
||||||
:style="{ background: item.color }"
|
|
||||||
/>
|
/>
|
||||||
<span class="truncate">{{ item.label }}</span>
|
|
||||||
</span>
|
|
||||||
<span class="shrink-0 tabular-nums text-muted">
|
|
||||||
{{ item.count }} ({{ sourcePercent(item.count) }}%)
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="h-2 rounded-full bg-muted/40">
|
|
||||||
<div
|
|
||||||
class="h-full rounded-full transition-[width]"
|
|
||||||
:style="{
|
|
||||||
width: `${sourcePercent(item.count)}%`,
|
|
||||||
backgroundColor: item.color
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="space-y-4">
|
<GalleryFilterBar
|
||||||
<div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-3">
|
v-model:search-query="searchQuery"
|
||||||
<div class="min-w-0">
|
:storage-backend="currentStorageBackend"
|
||||||
<h2 class="text-lg font-medium">
|
:storage-backend-items="storageBackendItems"
|
||||||
{{ t('stats.gallery') }}
|
:upload-source="currentUploadSource"
|
||||||
</h2>
|
:upload-source-items="uploadSourceItems"
|
||||||
<p
|
:view-mode="viewMode"
|
||||||
v-if="!galleryLoading"
|
:selected-count="selectedCount"
|
||||||
class="mt-0.5 text-sm text-muted"
|
|
||||||
>
|
|
||||||
{{ listSummary }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form
|
|
||||||
class="flex flex-wrap items-center justify-end gap-2"
|
|
||||||
@submit.prevent="handleSearch"
|
|
||||||
>
|
|
||||||
<UBadge
|
|
||||||
v-if="selectedCount"
|
|
||||||
color="primary"
|
|
||||||
variant="subtle"
|
|
||||||
class="shrink-0"
|
|
||||||
>
|
|
||||||
{{ t('stats.selected', { n: selectedCount }) }}
|
|
||||||
</UBadge>
|
|
||||||
<USelect
|
|
||||||
v-model="currentStorage"
|
|
||||||
:items="storageSelectItems"
|
|
||||||
class="w-[6.5rem] shrink-0 sm:w-36"
|
|
||||||
size="sm"
|
|
||||||
:aria-label="t('stats.storage')"
|
|
||||||
@update:model-value="handleStorageChange"
|
|
||||||
/>
|
|
||||||
<UInput
|
|
||||||
v-model="searchQuery"
|
|
||||||
icon="i-lucide-search"
|
|
||||||
:placeholder="t('stats.searchPlaceholder')"
|
|
||||||
class="w-36 shrink-0 sm:w-44"
|
|
||||||
size="sm"
|
|
||||||
:disabled="galleryLoading"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
type="submit"
|
|
||||||
icon="i-lucide-search"
|
|
||||||
size="sm"
|
|
||||||
class="shrink-0"
|
|
||||||
:aria-label="t('common.search')"
|
|
||||||
:loading="galleryLoading"
|
:loading="galleryLoading"
|
||||||
>
|
:show-batch-delete="true"
|
||||||
<span class="hidden sm:inline">{{ t('common.search') }}</span>
|
@update:storage-backend="handleStorageBackendChange"
|
||||||
</UButton>
|
@update:upload-source="handleUploadSourceChange"
|
||||||
<UButton
|
@update:view-mode="viewMode = $event"
|
||||||
v-if="activeSearch"
|
@search="handleSearch"
|
||||||
type="button"
|
@reset="handleResetFilters"
|
||||||
icon="i-lucide-x"
|
@batch-delete="requestBatchDelete"
|
||||||
size="sm"
|
/>
|
||||||
variant="ghost"
|
|
||||||
color="neutral"
|
|
||||||
class="shrink-0"
|
|
||||||
:aria-label="t('stats.clear')"
|
|
||||||
@click="clearSearch"
|
|
||||||
>
|
|
||||||
<span class="hidden sm:inline">{{ t('stats.clear') }}</span>
|
|
||||||
</UButton>
|
|
||||||
<UButton
|
|
||||||
type="button"
|
|
||||||
icon="i-lucide-trash-2"
|
|
||||||
color="error"
|
|
||||||
variant="soft"
|
|
||||||
size="sm"
|
|
||||||
class="shrink-0"
|
|
||||||
:aria-label="t('stats.batchDelete')"
|
|
||||||
:disabled="!selectedCount"
|
|
||||||
@click="requestBatchDelete"
|
|
||||||
>
|
|
||||||
<span class="hidden sm:inline">{{ t('stats.batchDelete') }}</span>
|
|
||||||
</UButton>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="galleryLoading"
|
v-if="galleryLoading"
|
||||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
|
:class="viewMode === 'grid'
|
||||||
|
? 'grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5'
|
||||||
|
: 'space-y-2'"
|
||||||
>
|
>
|
||||||
<USkeleton
|
<USkeleton
|
||||||
v-for="n in 12"
|
v-for="n in 10"
|
||||||
:key="n"
|
:key="n"
|
||||||
class="aspect-square rounded-lg"
|
:class="viewMode === 'grid' ? 'aspect-[4/3] rounded-lg' : 'h-16 rounded-lg'"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ImageGrid
|
<ImageGrid
|
||||||
v-else
|
v-else-if="viewMode === 'grid'"
|
||||||
|
gallery
|
||||||
:show-key="false"
|
:show-key="false"
|
||||||
show-storage
|
show-storage
|
||||||
:items="items"
|
:items="items"
|
||||||
:selected-keys="selectedKeys"
|
:selected-keys="selectedKeys"
|
||||||
:deleting-keys="deletingKeys"
|
:selectable="true"
|
||||||
@update:selected-keys="selectedKeys = $event"
|
:allow-delete="true"
|
||||||
@delete="requestDelete"
|
@update:selected-keys="updateSelectedKeys"
|
||||||
|
@preview="openPreview"
|
||||||
|
@delete="(image) => requestDelete(image.key)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<GalleryImageList
|
||||||
|
v-else
|
||||||
|
show-storage
|
||||||
|
:items="items"
|
||||||
|
:selected-keys="selectedKeys"
|
||||||
|
:selectable="true"
|
||||||
|
:show-delete="true"
|
||||||
|
@update:selected-keys="updateSelectedKeys"
|
||||||
|
@preview="openPreview"
|
||||||
|
@delete="(image) => requestDelete(image.key)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ImagePreviewModal
|
||||||
|
v-model:open="previewOpen"
|
||||||
|
:image="previewImage"
|
||||||
|
show-storage
|
||||||
|
:deleting="previewImage ? deletingKeys.has(previewImage.key) : false"
|
||||||
|
:allow-delete="true"
|
||||||
|
@delete="requestPreviewDelete"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PaginationBar
|
<PaginationBar
|
||||||
@@ -526,9 +464,11 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
:page="galleryPage"
|
:page="galleryPage"
|
||||||
:total-pages="galleryTotalPages"
|
:total-pages="galleryTotalPages"
|
||||||
:total="galleryTotal"
|
:total="galleryTotal"
|
||||||
|
:page-size="galleryPageSize"
|
||||||
:unit="t('common.imagesUnit')"
|
:unit="t('common.imagesUnit')"
|
||||||
:loading="galleryLoading"
|
:loading="galleryLoading"
|
||||||
@update:page="handleGalleryPageChange"
|
@update:page="handleGalleryPageChange"
|
||||||
|
@update:page-size="handleGalleryPageSizeChange"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -15,6 +15,8 @@ const { t } = useI18n()
|
|||||||
const sessionItems = ref<ImageItem[]>([])
|
const sessionItems = ref<ImageItem[]>([])
|
||||||
const deletingKeys = ref<Set<string>>(new Set())
|
const deletingKeys = ref<Set<string>>(new Set())
|
||||||
const emptySelection = ref(new Set<string>())
|
const emptySelection = ref(new Set<string>())
|
||||||
|
const previewOpen = ref(false)
|
||||||
|
const previewImage = ref<ImageItem | null>(null)
|
||||||
|
|
||||||
const showProgress = computed(
|
const showProgress = computed(
|
||||||
() =>
|
() =>
|
||||||
@@ -123,6 +125,10 @@ async function handleDelete(key: string) {
|
|||||||
query: { key }
|
query: { key }
|
||||||
})
|
})
|
||||||
sessionItems.value = sessionItems.value.filter(item => item.key !== key)
|
sessionItems.value = sessionItems.value.filter(item => item.key !== key)
|
||||||
|
if (previewImage.value?.key === key) {
|
||||||
|
previewOpen.value = false
|
||||||
|
previewImage.value = null
|
||||||
|
}
|
||||||
toast.add({ title: t('stats.deletedSingle'), color: 'success' })
|
toast.add({ title: t('stats.deletedSingle'), color: 'success' })
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
handleAuthError(error)
|
handleAuthError(error)
|
||||||
@@ -132,6 +138,16 @@ async function handleDelete(key: string) {
|
|||||||
deletingKeys.value = new Set(deletingKeys.value)
|
deletingKeys.value = new Set(deletingKeys.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openPreview(image: ImageItem) {
|
||||||
|
previewImage.value = image
|
||||||
|
previewOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestPreviewDelete() {
|
||||||
|
if (!previewImage.value) return
|
||||||
|
void handleDelete(previewImage.value.key)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -178,14 +194,21 @@ async function handleDelete(key: string) {
|
|||||||
<ImageGrid
|
<ImageGrid
|
||||||
:items="sessionItems"
|
:items="sessionItems"
|
||||||
:selected-keys="emptySelection"
|
:selected-keys="emptySelection"
|
||||||
:deleting-keys="deletingKeys"
|
|
||||||
:selectable="false"
|
:selectable="false"
|
||||||
:show-key="false"
|
:show-key="false"
|
||||||
:empty-text="t('upload.sessionEmpty')"
|
:empty-text="t('upload.sessionEmpty')"
|
||||||
@update:selected-keys="() => {}"
|
@update:selected-keys="() => {}"
|
||||||
@delete="handleDelete"
|
@preview="openPreview"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<ImagePreviewModal
|
||||||
|
v-model:open="previewOpen"
|
||||||
|
:image="previewImage"
|
||||||
|
:deleting="previewImage ? deletingKeys.has(previewImage.key) : false"
|
||||||
|
:allow-delete="true"
|
||||||
|
@delete="requestPreviewDelete"
|
||||||
|
/>
|
||||||
</AppShell>
|
</AppShell>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,621 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { ActivityLogListResponse, ActivityLogStorage, LogAction, LogSource } from '~/types/logs'
|
await navigateTo({ path: '/settings', query: { tab: 'logs' } }, { replace: true })
|
||||||
|
|
||||||
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus, isAdmin } = useAuth()
|
|
||||||
const toast = useToast()
|
|
||||||
const { t, locale } = useI18n()
|
|
||||||
const { formatFileSize } = useFileSize()
|
|
||||||
|
|
||||||
const loading = ref(true)
|
|
||||||
const page = ref(1)
|
|
||||||
const actionFilter = ref<'all' | LogAction>('all')
|
|
||||||
const sourceFilter = ref<'all' | LogSource>('all')
|
|
||||||
const userFilter = ref<'all' | number>('all')
|
|
||||||
const searchQuery = ref('')
|
|
||||||
const activeSearch = ref('')
|
|
||||||
const listData = ref<ActivityLogListResponse | null>(null)
|
|
||||||
const imageLinkBase = ref('')
|
|
||||||
const hideFolderInUrl = ref(false)
|
|
||||||
|
|
||||||
const pageSize = 10
|
|
||||||
|
|
||||||
const summaryLabel = computed(() => {
|
|
||||||
const summary = listData.value?.summary
|
|
||||||
if (!summary) return ''
|
|
||||||
return t('logs.summaryAll', {
|
|
||||||
total: summary.total,
|
|
||||||
upload: summary.upload,
|
|
||||||
delete: summary.delete
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const actionItems = computed(() => [
|
|
||||||
{ label: t('logs.filterActionAll'), value: 'all' as const },
|
|
||||||
{ label: t('logs.actionUpload'), value: 'upload' as const },
|
|
||||||
{ label: t('logs.actionDelete'), value: 'delete' as const }
|
|
||||||
])
|
|
||||||
|
|
||||||
const sourceItems = computed(() => [
|
|
||||||
{ label: t('logs.filterSourceAll'), value: 'all' as const },
|
|
||||||
{ label: t('logs.sourceWeb'), value: 'web' as const },
|
|
||||||
{ label: t('logs.sourceApi'), value: 'api' as const }
|
|
||||||
])
|
|
||||||
|
|
||||||
const userItems = computed(() => {
|
|
||||||
const items: Array<{ label: string, value: 'all' | number }> = [
|
|
||||||
{ label: t('logs.filterUserAll'), value: 'all' }
|
|
||||||
]
|
|
||||||
for (const user of listData.value?.users ?? []) {
|
|
||||||
items.push({ label: user.username, value: user.id })
|
|
||||||
}
|
|
||||||
return items
|
|
||||||
})
|
|
||||||
|
|
||||||
function formatTime(value: string) {
|
|
||||||
try {
|
|
||||||
return new Date(value).toLocaleString(locale.value, { hour12: false })
|
|
||||||
} catch {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTimeShort(value: string) {
|
|
||||||
try {
|
|
||||||
return new Date(value).toLocaleString(locale.value, {
|
|
||||||
month: 'numeric',
|
|
||||||
day: 'numeric',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false
|
|
||||||
})
|
|
||||||
} catch {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function folderFromKey(key: string) {
|
|
||||||
const slash = key.indexOf('/')
|
|
||||||
return slash > 0 ? key.slice(0, slash) : '(root)'
|
|
||||||
}
|
|
||||||
|
|
||||||
function actionColor(action: LogAction) {
|
|
||||||
return action === 'upload' ? 'success' : 'error'
|
|
||||||
}
|
|
||||||
|
|
||||||
function actionIcon(action: LogAction) {
|
|
||||||
return action === 'upload' ? 'i-lucide-upload' : 'i-lucide-trash-2'
|
|
||||||
}
|
|
||||||
|
|
||||||
function sourceLabel(source: LogSource) {
|
|
||||||
switch (source) {
|
|
||||||
case 'web':
|
|
||||||
return t('logs.sourceWeb')
|
|
||||||
case 'api':
|
|
||||||
return t('logs.sourceApi')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function storageIcon(storage: ActivityLogStorage | null) {
|
|
||||||
return storage?.type === 'local' ? 'i-lucide-hard-drive' : 'i-lucide-cloud'
|
|
||||||
}
|
|
||||||
|
|
||||||
function publicPathFromKey(key: string) {
|
|
||||||
if (hideFolderInUrl.value) {
|
|
||||||
const slash = key.lastIndexOf('/')
|
|
||||||
return slash >= 0 ? key.slice(slash + 1) : key
|
|
||||||
}
|
|
||||||
const prefix = 'images/'
|
|
||||||
return key.startsWith(prefix) ? key.slice(prefix.length) : key
|
|
||||||
}
|
|
||||||
|
|
||||||
function imageUrl(key: string) {
|
|
||||||
const base = imageLinkBase.value.replace(/\/$/, '')
|
|
||||||
const path = publicPathFromKey(key)
|
|
||||||
if (!base) return `/${path}`
|
|
||||||
return `${base}/${path}`
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadImageLinkBase() {
|
|
||||||
try {
|
|
||||||
if (isAdmin.value) {
|
|
||||||
const data = await $fetch<{ effectiveImageBaseUrl: string, hideFolderInUrl: boolean }>('/api/settings', {
|
|
||||||
credentials: 'include'
|
|
||||||
})
|
|
||||||
imageLinkBase.value = data.effectiveImageBaseUrl
|
|
||||||
hideFolderInUrl.value = data.hideFolderInUrl
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const data = await $fetch<{ env: { imageBaseUrl: string, hideFolderInUrl: boolean } }>('/api/user/api-token', {
|
|
||||||
credentials: 'include'
|
|
||||||
})
|
|
||||||
imageLinkBase.value = data.env.imageBaseUrl
|
|
||||||
hideFolderInUrl.value = data.env.hideFolderInUrl
|
|
||||||
} catch {
|
|
||||||
if (import.meta.client) {
|
|
||||||
imageLinkBase.value = window.location.origin
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadLogs() {
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const query: Record<string, string | number> = {
|
|
||||||
page: page.value,
|
|
||||||
limit: pageSize
|
|
||||||
}
|
|
||||||
if (actionFilter.value !== 'all') {
|
|
||||||
query.action = actionFilter.value
|
|
||||||
}
|
|
||||||
if (sourceFilter.value !== 'all') {
|
|
||||||
query.source = sourceFilter.value
|
|
||||||
}
|
|
||||||
if (isAdmin.value && userFilter.value !== 'all') {
|
|
||||||
query.userId = userFilter.value
|
|
||||||
}
|
|
||||||
if (activeSearch.value) {
|
|
||||||
query.q = activeSearch.value
|
|
||||||
}
|
|
||||||
|
|
||||||
listData.value = await $fetch<ActivityLogListResponse>('/api/logs', {
|
|
||||||
credentials: 'include',
|
|
||||||
query
|
|
||||||
})
|
|
||||||
page.value = listData.value.page
|
|
||||||
} catch (error: unknown) {
|
|
||||||
handleAuthError(error)
|
|
||||||
if (isAuthenticated.value) {
|
|
||||||
toast.add({ title: t('logs.loadFailed'), color: 'error' })
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyFilters() {
|
|
||||||
page.value = 1
|
|
||||||
void loadLogs()
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitSearch() {
|
|
||||||
activeSearch.value = searchQuery.value.trim()
|
|
||||||
applyFilters()
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearSearch() {
|
|
||||||
searchQuery.value = ''
|
|
||||||
activeSearch.value = ''
|
|
||||||
applyFilters()
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePageChange(target: number) {
|
|
||||||
page.value = target
|
|
||||||
void loadLogs()
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
const status = await fetchStatus()
|
|
||||||
if (!status.initialized && !status.legacyMode) {
|
|
||||||
await navigateTo('/setup')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await checkSession()
|
|
||||||
if (!isAuthenticated.value) {
|
|
||||||
await navigateTo('/')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await loadImageLinkBase()
|
|
||||||
await loadLogs()
|
|
||||||
})
|
|
||||||
|
|
||||||
watch(isAuthenticated, async (authed, prev) => {
|
|
||||||
if (authed && prev === false) {
|
|
||||||
await loadImageLinkBase()
|
|
||||||
await loadLogs()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="min-h-screen">
|
<div />
|
||||||
<div
|
|
||||||
v-if="isChecking"
|
|
||||||
class="flex min-h-screen items-center justify-center"
|
|
||||||
>
|
|
||||||
<div class="flex flex-col items-center gap-3 text-muted">
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-loader-circle"
|
|
||||||
class="size-8 animate-spin"
|
|
||||||
/>
|
|
||||||
<p class="text-sm">
|
|
||||||
{{ t('common.loadingSession') }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<AdminLoginGate v-else-if="!isAuthenticated" />
|
|
||||||
|
|
||||||
<AppShell v-else>
|
|
||||||
<section class="min-w-0 overflow-x-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
|
||||||
<div class="flex flex-wrap items-start justify-between gap-3 border-b border-default px-4 py-4 sm:px-6">
|
|
||||||
<div class="flex items-start gap-2">
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-scroll-text"
|
|
||||||
class="mt-0.5 size-5 shrink-0 text-primary"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<h1 class="text-base font-semibold">
|
|
||||||
{{ t('logs.pageTitle') }}
|
|
||||||
</h1>
|
|
||||||
<p class="mt-0.5 text-xs text-muted">
|
|
||||||
{{ isAdmin ? t('logs.pageSubtitleAdmin') : t('logs.pageSubtitle') }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<UButton
|
|
||||||
icon="i-lucide-refresh-cw"
|
|
||||||
variant="ghost"
|
|
||||||
color="neutral"
|
|
||||||
size="sm"
|
|
||||||
:aria-label="t('common.refresh')"
|
|
||||||
:loading="loading"
|
|
||||||
@click="loadLogs"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form
|
|
||||||
class="border-b border-default px-4 py-3 sm:px-6"
|
|
||||||
@submit.prevent="submitSearch"
|
|
||||||
>
|
|
||||||
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
|
||||||
<p
|
|
||||||
v-if="summaryLabel"
|
|
||||||
class="text-xs text-muted"
|
|
||||||
>
|
|
||||||
{{ summaryLabel }}
|
|
||||||
</p>
|
|
||||||
<p
|
|
||||||
v-else
|
|
||||||
class="text-xs text-muted"
|
|
||||||
>
|
|
||||||
{{ t('stats.counting') }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="flex min-w-0 flex-wrap items-center gap-2 sm:justify-end">
|
|
||||||
<USelect
|
|
||||||
v-if="isAdmin"
|
|
||||||
v-model="userFilter"
|
|
||||||
:items="userItems"
|
|
||||||
value-key="value"
|
|
||||||
class="min-w-0 w-full sm:w-36"
|
|
||||||
size="sm"
|
|
||||||
@update:model-value="applyFilters"
|
|
||||||
/>
|
|
||||||
<USelect
|
|
||||||
v-model="actionFilter"
|
|
||||||
:items="actionItems"
|
|
||||||
value-key="value"
|
|
||||||
class="min-w-0 w-[calc(50%-0.25rem)] sm:w-32"
|
|
||||||
size="sm"
|
|
||||||
@update:model-value="applyFilters"
|
|
||||||
/>
|
|
||||||
<USelect
|
|
||||||
v-model="sourceFilter"
|
|
||||||
:items="sourceItems"
|
|
||||||
value-key="value"
|
|
||||||
class="min-w-0 w-[calc(50%-0.25rem)] sm:w-36"
|
|
||||||
size="sm"
|
|
||||||
@update:model-value="applyFilters"
|
|
||||||
/>
|
|
||||||
<div class="flex min-w-0 w-full items-center gap-2 sm:w-auto">
|
|
||||||
<UInput
|
|
||||||
v-model="searchQuery"
|
|
||||||
icon="i-lucide-search"
|
|
||||||
:placeholder="t('logs.searchPlaceholder')"
|
|
||||||
class="min-w-0 flex-1 sm:w-40 sm:flex-none"
|
|
||||||
size="sm"
|
|
||||||
:disabled="loading"
|
|
||||||
/>
|
|
||||||
<UButton
|
|
||||||
type="submit"
|
|
||||||
icon="i-lucide-search"
|
|
||||||
size="sm"
|
|
||||||
class="shrink-0"
|
|
||||||
:aria-label="t('common.search')"
|
|
||||||
:loading="loading"
|
|
||||||
>
|
|
||||||
<span class="hidden sm:inline">{{ t('common.search') }}</span>
|
|
||||||
</UButton>
|
|
||||||
<UButton
|
|
||||||
v-if="activeSearch"
|
|
||||||
type="button"
|
|
||||||
icon="i-lucide-x"
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
color="neutral"
|
|
||||||
class="shrink-0"
|
|
||||||
:aria-label="t('stats.clear')"
|
|
||||||
@click="clearSearch"
|
|
||||||
>
|
|
||||||
<span class="hidden sm:inline">{{ t('stats.clear') }}</span>
|
|
||||||
</UButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div
|
|
||||||
v-if="loading"
|
|
||||||
class="p-4 sm:p-6"
|
|
||||||
>
|
|
||||||
<div class="space-y-3 sm:hidden">
|
|
||||||
<USkeleton
|
|
||||||
v-for="n in 6"
|
|
||||||
:key="`mobile-${n}`"
|
|
||||||
class="h-24 rounded-lg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="hidden space-y-2 sm:block">
|
|
||||||
<USkeleton
|
|
||||||
v-for="n in 8"
|
|
||||||
:key="`desktop-${n}`"
|
|
||||||
class="h-12 rounded-lg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template v-else-if="listData && listData.items.length">
|
|
||||||
<div class="min-w-0 sm:hidden">
|
|
||||||
<div class="divide-y divide-default">
|
|
||||||
<article
|
|
||||||
v-for="row in listData.items"
|
|
||||||
:key="row.id"
|
|
||||||
class="min-w-0 px-4 py-3.5"
|
|
||||||
>
|
|
||||||
<div class="flex items-start justify-between gap-3">
|
|
||||||
<time class="text-xs text-muted">
|
|
||||||
{{ formatTimeShort(row.createdAt) }}
|
|
||||||
</time>
|
|
||||||
<span class="shrink-0 text-xs tabular-nums text-muted">
|
|
||||||
{{ formatFileSize(row.size) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-2 flex min-w-0 max-w-full flex-wrap items-center gap-1.5">
|
|
||||||
<UBadge
|
|
||||||
:color="actionColor(row.action)"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
<UIcon
|
|
||||||
:name="actionIcon(row.action)"
|
|
||||||
class="mr-1 size-3"
|
|
||||||
/>
|
|
||||||
{{ row.action === 'upload' ? t('logs.actionUpload') : t('logs.actionDelete') }}
|
|
||||||
</UBadge>
|
|
||||||
<UBadge
|
|
||||||
color="neutral"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
{{ sourceLabel(row.source) }}
|
|
||||||
</UBadge>
|
|
||||||
<span
|
|
||||||
v-if="isAdmin"
|
|
||||||
class="text-xs text-muted"
|
|
||||||
>
|
|
||||||
{{ row.username ?? '—' }}
|
|
||||||
</span>
|
|
||||||
<UBadge
|
|
||||||
v-if="row.storage"
|
|
||||||
color="neutral"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
class="max-w-full truncate"
|
|
||||||
>
|
|
||||||
<UIcon
|
|
||||||
:name="storageIcon(row.storage)"
|
|
||||||
class="mr-1 size-3"
|
|
||||||
/>
|
|
||||||
{{ row.storage.name }}
|
|
||||||
</UBadge>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p
|
|
||||||
class="mt-2 truncate text-sm"
|
|
||||||
:title="row.originalName"
|
|
||||||
>
|
|
||||||
{{ row.originalName }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="mt-2 flex min-w-0 items-center gap-1">
|
|
||||||
<a
|
|
||||||
v-if="row.action === 'upload'"
|
|
||||||
:href="imageUrl(row.key)"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="min-w-0 flex-1 truncate font-mono text-xs text-primary hover:underline"
|
|
||||||
:title="row.key"
|
|
||||||
>
|
|
||||||
{{ row.key }}
|
|
||||||
</a>
|
|
||||||
<span
|
|
||||||
v-else
|
|
||||||
class="min-w-0 flex-1 truncate font-mono text-xs text-dimmed"
|
|
||||||
:title="row.key"
|
|
||||||
>
|
|
||||||
{{ row.key }}
|
|
||||||
</span>
|
|
||||||
<CopyButton
|
|
||||||
icon="i-lucide-copy"
|
|
||||||
icon-only
|
|
||||||
class="shrink-0"
|
|
||||||
:label="t('common.copy')"
|
|
||||||
:value="row.key"
|
|
||||||
:success-title="t('copy.copiedUrl')"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="hidden overflow-x-auto sm:block">
|
|
||||||
<table class="min-w-full text-left text-sm">
|
|
||||||
<thead class="border-b border-default bg-muted/30 text-xs text-muted">
|
|
||||||
<tr>
|
|
||||||
<th class="px-4 py-3 font-medium sm:px-6">
|
|
||||||
{{ t('logs.colTime') }}
|
|
||||||
</th>
|
|
||||||
<th
|
|
||||||
v-if="isAdmin"
|
|
||||||
class="px-4 py-3 font-medium"
|
|
||||||
>
|
|
||||||
{{ t('logs.colUser') }}
|
|
||||||
</th>
|
|
||||||
<th class="px-4 py-3 font-medium">
|
|
||||||
{{ t('logs.colAction') }}
|
|
||||||
</th>
|
|
||||||
<th class="px-4 py-3 font-medium">
|
|
||||||
{{ t('logs.colSource') }}
|
|
||||||
</th>
|
|
||||||
<th class="px-4 py-3 font-medium">
|
|
||||||
{{ t('logs.colStorage') }}
|
|
||||||
</th>
|
|
||||||
<th class="hidden px-4 py-3 font-medium md:table-cell">
|
|
||||||
{{ t('logs.colFile') }}
|
|
||||||
</th>
|
|
||||||
<th class="hidden px-4 py-3 font-medium lg:table-cell">
|
|
||||||
{{ t('logs.colFolder') }}
|
|
||||||
</th>
|
|
||||||
<th class="px-4 py-3 font-medium">
|
|
||||||
{{ t('logs.colSize') }}
|
|
||||||
</th>
|
|
||||||
<th class="hidden px-4 py-3 font-medium xl:table-cell">
|
|
||||||
{{ t('logs.colKey') }}
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody class="divide-y divide-default">
|
|
||||||
<tr
|
|
||||||
v-for="row in listData.items"
|
|
||||||
:key="row.id"
|
|
||||||
class="hover:bg-muted/20"
|
|
||||||
>
|
|
||||||
<td class="whitespace-nowrap px-4 py-3 text-xs text-muted sm:px-6">
|
|
||||||
{{ formatTime(row.createdAt) }}
|
|
||||||
</td>
|
|
||||||
<td
|
|
||||||
v-if="isAdmin"
|
|
||||||
class="px-4 py-3 text-xs"
|
|
||||||
>
|
|
||||||
{{ row.username ?? '—' }}
|
|
||||||
</td>
|
|
||||||
<td class="px-4 py-3">
|
|
||||||
<UBadge
|
|
||||||
:color="actionColor(row.action)"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
<UIcon
|
|
||||||
:name="actionIcon(row.action)"
|
|
||||||
class="mr-1 size-3"
|
|
||||||
/>
|
|
||||||
{{ row.action === 'upload' ? t('logs.actionUpload') : t('logs.actionDelete') }}
|
|
||||||
</UBadge>
|
|
||||||
</td>
|
|
||||||
<td class="px-4 py-3">
|
|
||||||
<UBadge
|
|
||||||
color="neutral"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
{{ sourceLabel(row.source) }}
|
|
||||||
</UBadge>
|
|
||||||
</td>
|
|
||||||
<td class="px-4 py-3 text-xs">
|
|
||||||
<span
|
|
||||||
v-if="row.storage"
|
|
||||||
class="inline-flex max-w-[8rem] items-center gap-1 truncate"
|
|
||||||
:title="row.storage.name"
|
|
||||||
>
|
|
||||||
<UIcon
|
|
||||||
:name="storageIcon(row.storage)"
|
|
||||||
class="size-3.5 shrink-0 opacity-70"
|
|
||||||
/>
|
|
||||||
<span class="truncate">{{ row.storage.name }}</span>
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
v-else
|
|
||||||
class="text-muted"
|
|
||||||
>—</span>
|
|
||||||
</td>
|
|
||||||
<td
|
|
||||||
class="hidden max-w-[12rem] truncate px-4 py-3 md:table-cell"
|
|
||||||
:title="row.originalName"
|
|
||||||
>
|
|
||||||
{{ row.originalName }}
|
|
||||||
</td>
|
|
||||||
<td class="hidden px-4 py-3 font-mono text-xs text-muted lg:table-cell">
|
|
||||||
{{ folderFromKey(row.key) }}
|
|
||||||
</td>
|
|
||||||
<td class="whitespace-nowrap px-4 py-3 tabular-nums text-muted">
|
|
||||||
{{ formatFileSize(row.size) }}
|
|
||||||
</td>
|
|
||||||
<td class="hidden px-4 py-3 xl:table-cell">
|
|
||||||
<div class="flex max-w-[16rem] items-center gap-1">
|
|
||||||
<a
|
|
||||||
v-if="row.action === 'upload'"
|
|
||||||
:href="imageUrl(row.key)"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="truncate font-mono text-xs text-primary hover:underline"
|
|
||||||
:title="row.key"
|
|
||||||
>
|
|
||||||
{{ row.key }}
|
|
||||||
</a>
|
|
||||||
<span
|
|
||||||
v-else
|
|
||||||
class="truncate font-mono text-xs text-dimmed"
|
|
||||||
:title="row.key"
|
|
||||||
>
|
|
||||||
{{ row.key }}
|
|
||||||
</span>
|
|
||||||
<CopyButton
|
|
||||||
icon="i-lucide-copy"
|
|
||||||
icon-only
|
|
||||||
:label="t('common.copy')"
|
|
||||||
:value="row.key"
|
|
||||||
:success-title="t('copy.copiedUrl')"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
class="px-4 py-16 text-center text-sm text-muted sm:px-6"
|
|
||||||
>
|
|
||||||
{{ t('logs.empty') }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
v-if="listData && listData.total > 0"
|
|
||||||
class="border-t border-default px-4 py-4 sm:px-6"
|
|
||||||
>
|
|
||||||
<PaginationBar
|
|
||||||
:page="listData.page"
|
|
||||||
:total-pages="listData.totalPages"
|
|
||||||
:total="listData.total"
|
|
||||||
:unit="t('logs.entriesUnit')"
|
|
||||||
:loading="loading"
|
|
||||||
@update:page="handlePageChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</AppShell>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
@@ -2,9 +2,10 @@
|
|||||||
import logoLight from '~/assets/image/logo-light.png'
|
import logoLight from '~/assets/image/logo-light.png'
|
||||||
import logoDark from '~/assets/image/logo-dark.png'
|
import logoDark from '~/assets/image/logo-dark.png'
|
||||||
import { isPasswordValid } from '~/utils/password-strength'
|
import { isPasswordValid } from '~/utils/password-strength'
|
||||||
|
import type { LoginVerificationPayload } from '~/types/auth'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { register, fetchStatus } = useAuth()
|
const { register, fetchStatus, authStatus } = useAuth()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
@@ -12,14 +13,34 @@ const username = ref('')
|
|||||||
const password = ref('')
|
const password = ref('')
|
||||||
const confirmPassword = ref('')
|
const confirmPassword = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const verificationRef = ref<{ reset: () => Promise<void> } | null>(null)
|
||||||
|
const verificationPayload = ref<LoginVerificationPayload | null>(null)
|
||||||
|
|
||||||
|
const loginVerification = computed(() =>
|
||||||
|
authStatus.value?.loginVerification ?? { method: 'slider' as const }
|
||||||
|
)
|
||||||
|
|
||||||
const canSubmit = computed(() =>
|
const canSubmit = computed(() =>
|
||||||
Boolean(username.value && password.value && confirmPassword.value)
|
Boolean(verificationPayload.value)
|
||||||
|
&& Boolean(username.value && password.value && confirmPassword.value)
|
||||||
&& password.value === confirmPassword.value
|
&& password.value === confirmPassword.value
|
||||||
&& isPasswordValid(password.value)
|
&& isPasswordValid(password.value)
|
||||||
&& AUTH_USERNAME_PATTERN.test(username.value.trim())
|
&& AUTH_USERNAME_PATTERN.test(username.value.trim())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function onVerificationVerified(payload: LoginVerificationPayload) {
|
||||||
|
verificationPayload.value = payload
|
||||||
|
}
|
||||||
|
|
||||||
|
function onVerificationCleared() {
|
||||||
|
verificationPayload.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resetVerification() {
|
||||||
|
verificationPayload.value = null
|
||||||
|
await verificationRef.value?.reset()
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const status = await fetchStatus()
|
const status = await fetchStatus()
|
||||||
if (!status.initialized && !status.legacyMode) {
|
if (!status.initialized && !status.legacyMode) {
|
||||||
@@ -32,7 +53,7 @@ onMounted(async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
if (!canSubmit.value || loading.value) return
|
if (!canSubmit.value || loading.value || !verificationPayload.value) return
|
||||||
|
|
||||||
if (password.value !== confirmPassword.value) {
|
if (password.value !== confirmPassword.value) {
|
||||||
toast.add({ title: t('auth.passwordMismatch'), color: 'error' })
|
toast.add({ title: t('auth.passwordMismatch'), color: 'error' })
|
||||||
@@ -41,11 +62,16 @@ async function submit() {
|
|||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const result = await register(username.value.trim(), password.value)
|
const result = await register(
|
||||||
|
username.value.trim(),
|
||||||
|
password.value,
|
||||||
|
verificationPayload.value
|
||||||
|
)
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
toast.add({ title: t('auth.registerSuccess'), color: 'success' })
|
toast.add({ title: t('auth.registerSuccess'), color: 'success' })
|
||||||
await router.replace('/')
|
await router.replace('/')
|
||||||
} else {
|
} else {
|
||||||
|
await resetVerification()
|
||||||
toast.add({ title: result.error, color: 'error' })
|
toast.add({ title: result.error, color: 'error' })
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -142,6 +168,15 @@ async function submit() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<LoginVerification
|
||||||
|
ref="verificationRef"
|
||||||
|
:method="loginVerification.method"
|
||||||
|
:turnstile-site-key="loginVerification.turnstileSiteKey"
|
||||||
|
:cap-api-endpoint="loginVerification.capApiEndpoint"
|
||||||
|
@verified="onVerificationVerified"
|
||||||
|
@cleared="onVerificationCleared"
|
||||||
|
/>
|
||||||
|
|
||||||
<UButton
|
<UButton
|
||||||
type="submit"
|
type="submit"
|
||||||
:label="t('auth.register')"
|
:label="t('auth.register')"
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { SettingsTab } from '~/types/settings'
|
||||||
|
import { ADMIN_SETTINGS_TABS, USER_SETTINGS_TABS } from '~/types/settings'
|
||||||
|
import { willActivateDomainSeparation } from '~/utils/domain-separation'
|
||||||
|
|
||||||
type SettingSource = 'env' | 'db' | 'none'
|
type SettingSource = 'env' | 'db' | 'none'
|
||||||
type WebpQualitySource = 'env' | 'db' | 'default'
|
type WebpQualitySource = 'env' | 'db' | 'default'
|
||||||
|
type LoginVerificationMethod = 'slider' | 'turnstile' | 'cap'
|
||||||
|
|
||||||
interface SettingsResponse {
|
interface SettingsResponse {
|
||||||
apiUploadToken: string
|
apiUploadToken: string
|
||||||
@@ -30,12 +35,60 @@ interface SettingsResponse {
|
|||||||
storageUseDatePath: boolean
|
storageUseDatePath: boolean
|
||||||
storageUseDatePathSource: SettingSource
|
storageUseDatePathSource: SettingSource
|
||||||
allowRegistration: boolean
|
allowRegistration: boolean
|
||||||
|
loginVerificationMethod: LoginVerificationMethod
|
||||||
|
turnstileSiteKey: string
|
||||||
|
turnstileSecretKey: string
|
||||||
|
capApiEndpoint: string
|
||||||
|
capSecret: string
|
||||||
appVersion: string
|
appVersion: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus, isAdmin } = useAuth()
|
const { isChecking, isAuthenticated, checkSession, handleAuthError, fetchStatus, isAdmin } = useAuth()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const allowedTabs = computed(() => (isAdmin.value ? ADMIN_SETTINGS_TABS : USER_SETTINGS_TABS))
|
||||||
|
|
||||||
|
const defaultTab = computed<SettingsTab>(() => (isAdmin.value ? 'basic' : 'logs'))
|
||||||
|
|
||||||
|
function parseTab(value: unknown): SettingsTab | null {
|
||||||
|
if (typeof value !== 'string') return null
|
||||||
|
return allowedTabs.value.includes(value as SettingsTab) ? value as SettingsTab : null
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeTab = computed<SettingsTab>({
|
||||||
|
get() {
|
||||||
|
return parseTab(route.query.tab) ?? defaultTab.value
|
||||||
|
},
|
||||||
|
set(tab) {
|
||||||
|
void router.replace({ query: { tab } })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const sidebarItems = computed(() => {
|
||||||
|
const labels: Record<SettingsTab, { label: string, icon: string }> = {
|
||||||
|
basic: { label: t('settings.navBasic'), icon: 'i-lucide-sliders-horizontal' },
|
||||||
|
domains: { label: t('settings.navDomains'), icon: 'i-lucide-globe' },
|
||||||
|
access: { label: t('settings.navAccess'), icon: 'i-lucide-shield' },
|
||||||
|
logs: { label: t('settings.navLogs'), icon: 'i-lucide-scroll-text' }
|
||||||
|
}
|
||||||
|
return allowedTabs.value.map(id => ({ id, ...labels[id] }))
|
||||||
|
})
|
||||||
|
|
||||||
|
const showSaveBar = computed(() =>
|
||||||
|
isAdmin.value && ['basic', 'domains', 'access'].includes(activeTab.value)
|
||||||
|
)
|
||||||
|
|
||||||
|
const pageSubtitle = computed(() => {
|
||||||
|
if (activeTab.value === 'basic') {
|
||||||
|
return t('settings.pageSubtitleBasic')
|
||||||
|
}
|
||||||
|
return t('settings.pageSubtitle')
|
||||||
|
})
|
||||||
|
|
||||||
|
const checkingRelease = ref(false)
|
||||||
|
|
||||||
const domainSeparationDocUrl = computed(() =>
|
const domainSeparationDocUrl = computed(() =>
|
||||||
locale.value === 'en'
|
locale.value === 'en'
|
||||||
@@ -52,9 +105,15 @@ const imageBaseUrlDraft = ref('')
|
|||||||
const hideFolderInUrlDraft = ref(false)
|
const hideFolderInUrlDraft = ref(false)
|
||||||
const storageUseDatePathDraft = ref(true)
|
const storageUseDatePathDraft = ref(true)
|
||||||
const allowRegistrationDraft = ref(false)
|
const allowRegistrationDraft = ref(false)
|
||||||
|
const loginVerificationMethodDraft = ref<LoginVerificationMethod>('slider')
|
||||||
|
const turnstileSiteKeyDraft = ref('')
|
||||||
|
const turnstileSecretKeyDraft = ref('')
|
||||||
|
const capApiEndpointDraft = ref('')
|
||||||
|
const capSecretDraft = ref('')
|
||||||
const domainSeparationDraft = ref(false)
|
const domainSeparationDraft = ref(false)
|
||||||
const disableDomainSeparationOpen = ref(false)
|
const disableDomainSeparationOpen = ref(false)
|
||||||
const pendingDomainSeparationDisable = ref(false)
|
const pendingDomainSeparationDisable = ref(false)
|
||||||
|
const domainSeparationSaveConfirmOpen = ref(false)
|
||||||
|
|
||||||
interface ReleaseCheckResponse {
|
interface ReleaseCheckResponse {
|
||||||
currentVersion: string
|
currentVersion: string
|
||||||
@@ -74,8 +133,32 @@ const hasServerChanges = computed(() => {
|
|||||||
|| hideFolderInUrlDraft.value !== settings.value.hideFolderInUrl
|
|| hideFolderInUrlDraft.value !== settings.value.hideFolderInUrl
|
||||||
|| storageUseDatePathDraft.value !== settings.value.storageUseDatePath
|
|| storageUseDatePathDraft.value !== settings.value.storageUseDatePath
|
||||||
|| allowRegistrationDraft.value !== settings.value.allowRegistration
|
|| allowRegistrationDraft.value !== settings.value.allowRegistration
|
||||||
|
|| loginVerificationMethodDraft.value !== settings.value.loginVerificationMethod
|
||||||
|
|| turnstileSiteKeyDraft.value !== settings.value.turnstileSiteKey
|
||||||
|
|| turnstileSecretKeyDraft.value !== settings.value.turnstileSecretKey
|
||||||
|
|| capApiEndpointDraft.value !== settings.value.capApiEndpoint
|
||||||
|
|| capSecretDraft.value !== settings.value.capSecret
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const domainSeparationWouldActivate = computed(() =>
|
||||||
|
willActivateDomainSeparation(
|
||||||
|
domainSeparationDraft.value,
|
||||||
|
siteBaseUrlDraft.value,
|
||||||
|
imageBaseUrlDraft.value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const domainSeparationFieldsChanged = computed(() => {
|
||||||
|
if (!settings.value) return false
|
||||||
|
return domainSeparationDraft.value !== settings.value.domainSeparation
|
||||||
|
|| siteBaseUrlDraft.value !== (settings.value.domainSeparation ? settings.value.siteBaseUrl : '')
|
||||||
|
|| imageBaseUrlDraft.value !== settings.value.imageBaseUrl
|
||||||
|
})
|
||||||
|
|
||||||
|
const needsDomainSeparationSaveConfirm = computed(() =>
|
||||||
|
domainSeparationWouldActivate.value && domainSeparationFieldsChanged.value
|
||||||
|
)
|
||||||
|
|
||||||
function sourceBadge(source: SettingSource | WebpQualitySource) {
|
function sourceBadge(source: SettingSource | WebpQualitySource) {
|
||||||
switch (source) {
|
switch (source) {
|
||||||
case 'env':
|
case 'env':
|
||||||
@@ -89,17 +172,6 @@ function sourceBadge(source: SettingSource | WebpQualitySource) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tokenSourceText(source: SettingSource) {
|
|
||||||
switch (source) {
|
|
||||||
case 'env':
|
|
||||||
return t('settings.tokenEnv')
|
|
||||||
case 'db':
|
|
||||||
return t('settings.tokenDb')
|
|
||||||
default:
|
|
||||||
return t('settings.tokenNone')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function errorStatus(error: unknown): number {
|
function errorStatus(error: unknown): number {
|
||||||
if (typeof error === 'object' && error !== null && 'statusCode' in error) {
|
if (typeof error === 'object' && error !== null && 'statusCode' in error) {
|
||||||
return (error as { statusCode: number }).statusCode
|
return (error as { statusCode: number }).statusCode
|
||||||
@@ -115,6 +187,11 @@ function applySettings(data: SettingsResponse) {
|
|||||||
hideFolderInUrlDraft.value = data.hideFolderInUrl
|
hideFolderInUrlDraft.value = data.hideFolderInUrl
|
||||||
storageUseDatePathDraft.value = data.storageUseDatePath
|
storageUseDatePathDraft.value = data.storageUseDatePath
|
||||||
allowRegistrationDraft.value = data.allowRegistration
|
allowRegistrationDraft.value = data.allowRegistration
|
||||||
|
loginVerificationMethodDraft.value = data.loginVerificationMethod
|
||||||
|
turnstileSiteKeyDraft.value = data.turnstileSiteKey
|
||||||
|
turnstileSecretKeyDraft.value = data.turnstileSecretKey
|
||||||
|
capApiEndpointDraft.value = data.capApiEndpoint
|
||||||
|
capSecretDraft.value = data.capSecret
|
||||||
domainSeparationDraft.value = data.domainSeparation
|
domainSeparationDraft.value = data.domainSeparation
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +254,18 @@ async function saveServerSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needsDomainSeparationSaveConfirm.value) {
|
||||||
|
domainSeparationSaveConfirmOpen.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await performSaveServerSettings()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function performSaveServerSettings() {
|
||||||
|
domainSeparationSaveConfirmOpen.value = false
|
||||||
|
if (!isAuthenticated.value || !hasServerChanges.value) return
|
||||||
|
|
||||||
savingServer.value = true
|
savingServer.value = true
|
||||||
try {
|
try {
|
||||||
await patchSettings({
|
await patchSettings({
|
||||||
@@ -186,7 +275,12 @@ async function saveServerSettings() {
|
|||||||
imageBaseUrl: imageBaseUrlDraft.value,
|
imageBaseUrl: imageBaseUrlDraft.value,
|
||||||
hideFolderInUrl: hideFolderInUrlDraft.value,
|
hideFolderInUrl: hideFolderInUrlDraft.value,
|
||||||
storageUseDatePath: storageUseDatePathDraft.value,
|
storageUseDatePath: storageUseDatePathDraft.value,
|
||||||
allowRegistration: allowRegistrationDraft.value
|
allowRegistration: allowRegistrationDraft.value,
|
||||||
|
loginVerificationMethod: loginVerificationMethodDraft.value,
|
||||||
|
turnstileSiteKey: turnstileSiteKeyDraft.value,
|
||||||
|
turnstileSecretKey: turnstileSecretKeyDraft.value,
|
||||||
|
capApiEndpoint: capApiEndpointDraft.value,
|
||||||
|
capSecret: capSecretDraft.value
|
||||||
})
|
})
|
||||||
toast.add({ title: t('settings.saved'), color: 'success' })
|
toast.add({ title: t('settings.saved'), color: 'success' })
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -210,22 +304,68 @@ async function loadSettings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkLatestRelease() {
|
async function checkLatestRelease(options: { notify?: boolean, refresh?: boolean } = {}) {
|
||||||
|
const { notify = false, refresh = false } = options
|
||||||
|
checkingRelease.value = true
|
||||||
try {
|
try {
|
||||||
releaseCheck.value = await $fetch<ReleaseCheckResponse>('/api/version/latest', {
|
releaseCheck.value = await $fetch<ReleaseCheckResponse>('/api/version/latest', {
|
||||||
credentials: 'include'
|
credentials: 'include',
|
||||||
|
query: refresh ? { refresh: '1' } : undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!notify) return
|
||||||
|
|
||||||
|
const result = releaseCheck.value
|
||||||
|
if (!result?.latestVersion) {
|
||||||
|
toast.add({ title: t('settings.checkUpdateFailed'), color: 'error' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (result.updateAvailable) {
|
||||||
|
toast.add({
|
||||||
|
title: t('settings.updateAvailable', { version: `v${result.latestVersion}` }),
|
||||||
|
color: 'warning'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toast.add({ title: t('settings.upToDate'), color: 'success' })
|
||||||
} catch {
|
} catch {
|
||||||
releaseCheck.value = null
|
releaseCheck.value = null
|
||||||
|
if (notify) {
|
||||||
|
toast.add({ title: t('settings.checkUpdateFailed'), color: 'error' })
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
checkingRelease.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPage() {
|
const loginVerificationOptions = computed(() => [
|
||||||
if (!isAdmin.value) {
|
{ value: 'slider' as const, label: t('settings.loginVerificationSlider') },
|
||||||
await navigateTo('/')
|
{ value: 'turnstile' as const, label: t('settings.loginVerificationTurnstile') },
|
||||||
return
|
{ value: 'cap' as const, label: t('settings.loginVerificationCap') }
|
||||||
|
])
|
||||||
|
|
||||||
|
const loginVerificationHint = computed(() => {
|
||||||
|
switch (loginVerificationMethodDraft.value) {
|
||||||
|
case 'turnstile':
|
||||||
|
return t('settings.loginVerificationTurnstileHint')
|
||||||
|
case 'cap':
|
||||||
|
return t('settings.loginVerificationCapHint')
|
||||||
|
default:
|
||||||
|
return t('settings.loginVerificationSliderHint')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function loadPage() {
|
||||||
|
if (isAdmin.value) {
|
||||||
|
await loadSettings()
|
||||||
|
await checkLatestRelease()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureValidTab() {
|
||||||
|
if (route.query.tab && !parseTab(route.query.tab)) {
|
||||||
|
void router.replace({ query: { tab: defaultTab.value } })
|
||||||
}
|
}
|
||||||
await Promise.all([loadSettings(), checkLatestRelease()])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@@ -235,28 +375,31 @@ onMounted(async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
await checkSession()
|
await checkSession()
|
||||||
if (isAuthenticated.value && !isAdmin.value) {
|
if (!isAuthenticated.value) {
|
||||||
await navigateTo('/')
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (isAuthenticated.value && isAdmin.value) {
|
ensureValidTab()
|
||||||
await loadPage()
|
await loadPage()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(isAuthenticated, async (authed, prev) => {
|
watch(isAuthenticated, async (authed, prev) => {
|
||||||
if (authed && prev === false) {
|
if (authed && prev === false) {
|
||||||
if (!isAdmin.value) {
|
ensureValidTab()
|
||||||
await navigateTo('/')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await nextTick()
|
await nextTick()
|
||||||
await loadPage()
|
await loadPage()
|
||||||
} else {
|
} else if (!authed) {
|
||||||
settings.value = null
|
settings.value = null
|
||||||
releaseCheck.value = null
|
releaseCheck.value = null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(() => route.query.tab, () => {
|
||||||
|
ensureValidTab()
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(isAdmin, () => {
|
||||||
|
ensureValidTab()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -278,124 +421,102 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
|
|
||||||
<AdminLoginGate v-else-if="!isAuthenticated" />
|
<AdminLoginGate v-else-if="!isAuthenticated" />
|
||||||
|
|
||||||
<AppShell v-else-if="isAdmin">
|
<AppShell v-else>
|
||||||
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
||||||
<UploadPreferencesPanel embedded />
|
<div class="flex min-h-[36rem] flex-col lg:flex-row lg:items-stretch">
|
||||||
</section>
|
<SettingsSidebar
|
||||||
|
v-model="activeTab"
|
||||||
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
:items="sidebarItems"
|
||||||
<div class="flex items-start gap-2 border-b border-default px-5 py-4 sm:px-6">
|
:title="t('settings.pageTitle')"
|
||||||
<UIcon
|
:subtitle="pageSubtitle"
|
||||||
name="i-lucide-server"
|
/>
|
||||||
class="mt-0.5 size-5 shrink-0 text-primary"
|
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col bg-default">
|
||||||
|
<div
|
||||||
|
class="flex-1"
|
||||||
|
:class="activeTab === 'logs' ? '' : 'p-4 sm:p-5'"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-if="activeTab === 'basic' && isAdmin"
|
||||||
|
>
|
||||||
|
<SettingsPanel v-if="settings">
|
||||||
|
<SettingsSection
|
||||||
|
:title="t('settings.featureToggles')"
|
||||||
|
:hint="t('settings.featureTogglesHint')"
|
||||||
|
>
|
||||||
|
<SettingsGroup>
|
||||||
|
<SettingsToggleRow
|
||||||
|
v-model="allowRegistrationDraft"
|
||||||
|
:title="t('settings.allowRegistration')"
|
||||||
|
:hint="t('settings.allowRegistrationHint')"
|
||||||
|
/>
|
||||||
|
</SettingsGroup>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<SettingsUserPreferencesFields />
|
||||||
|
|
||||||
|
<SettingsSection
|
||||||
|
:title="t('settings.systemInfo')"
|
||||||
|
:hint="t('settings.systemInfoHint')"
|
||||||
|
>
|
||||||
|
<template
|
||||||
|
v-if="isAdmin"
|
||||||
|
#action
|
||||||
|
>
|
||||||
|
<UButton
|
||||||
|
:label="t('settings.checkUpdate')"
|
||||||
|
icon="i-lucide-refresh-cw"
|
||||||
|
variant="outline"
|
||||||
|
color="neutral"
|
||||||
|
size="sm"
|
||||||
|
class="shrink-0"
|
||||||
|
:loading="checkingRelease"
|
||||||
|
@click="checkLatestRelease({ notify: true, refresh: true })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<SettingsSystemInfo
|
||||||
|
:app-version="settings.appVersion"
|
||||||
|
:update-available="!!releaseCheck?.updateAvailable"
|
||||||
|
:latest-version="releaseCheck?.latestVersion ?? null"
|
||||||
|
:release-url="releaseCheck?.releaseUrl ?? null"
|
||||||
|
/>
|
||||||
|
</SettingsSection>
|
||||||
|
</SettingsPanel>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex justify-center py-16"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-loader-circle"
|
||||||
|
class="size-6 animate-spin text-muted"
|
||||||
/>
|
/>
|
||||||
<div class="min-w-0">
|
|
||||||
<h1 class="text-base font-semibold">
|
|
||||||
{{ t('settings.title') }}
|
|
||||||
</h1>
|
|
||||||
<p class="mt-0.5 text-xs text-muted">
|
|
||||||
{{ t('settings.subtitle') }}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="settings"
|
v-else-if="activeTab === 'domains' && isAdmin"
|
||||||
class="p-5 sm:p-6"
|
|
||||||
>
|
>
|
||||||
<div class="space-y-5">
|
<SettingsPanel v-if="settings">
|
||||||
<div class="grid min-w-0 gap-5 lg:grid-cols-2 lg:items-stretch">
|
<SettingsSection :title="t('settings.domainSettings')">
|
||||||
<div class="flex h-full min-w-0 flex-col space-y-3 rounded-xl border border-default/60 bg-muted/10 p-4 sm:p-5">
|
<p
|
||||||
<h3 class="text-sm font-semibold">
|
v-if="settings.runtime.currentOrigin"
|
||||||
{{ t('settings.featureToggles') }}
|
class="mb-3 pl-3 text-xs text-primary"
|
||||||
</h3>
|
|
||||||
|
|
||||||
<label class="flex cursor-pointer items-start gap-2.5 rounded-lg border border-default/50 bg-default/40 p-3">
|
|
||||||
<UCheckbox
|
|
||||||
v-model="allowRegistrationDraft"
|
|
||||||
class="mt-0.5 shrink-0"
|
|
||||||
/>
|
|
||||||
<span class="min-w-0">
|
|
||||||
<span class="block text-sm font-medium">{{ t('settings.allowRegistration') }}</span>
|
|
||||||
<span class="mt-1 block text-xs leading-relaxed text-muted">
|
|
||||||
{{ t('settings.allowRegistrationHint') }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label class="flex cursor-pointer items-start gap-2.5 rounded-lg border border-default/50 bg-default/40 p-3">
|
|
||||||
<UCheckbox
|
|
||||||
:model-value="storageUseDatePathDraft"
|
|
||||||
class="mt-0.5 shrink-0"
|
|
||||||
:disabled="settings.storageUseDatePathSource === 'env'"
|
|
||||||
@update:model-value="(v) => storageUseDatePathDraft = v === true"
|
|
||||||
/>
|
|
||||||
<span class="min-w-0">
|
|
||||||
<span class="flex flex-wrap items-center gap-2 text-sm font-medium">
|
|
||||||
{{ t('settings.storageUseDatePath') }}
|
|
||||||
<UBadge
|
|
||||||
v-if="settings.storageUseDatePathSource === 'env'"
|
|
||||||
:color="sourceBadge(settings.storageUseDatePathSource).color"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
>
|
||||||
{{ sourceBadge(settings.storageUseDatePathSource).label }}
|
{{ t('settings.runtimeDetected', { url: settings.runtime.currentOrigin }) }}
|
||||||
</UBadge>
|
</p>
|
||||||
</span>
|
<SettingsGroup>
|
||||||
<span class="mt-1 block text-xs leading-relaxed text-muted">
|
<SettingsToggleRow
|
||||||
{{ t('settings.storageUseDatePathHint') }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label class="flex cursor-pointer items-start gap-2.5 rounded-lg border border-default/50 bg-default/40 p-3">
|
|
||||||
<UCheckbox
|
|
||||||
:model-value="hideFolderInUrlDraft"
|
|
||||||
class="mt-0.5 shrink-0"
|
|
||||||
:disabled="settings.hideFolderInUrlSource === 'env'"
|
|
||||||
@update:model-value="(v) => hideFolderInUrlDraft = v === true"
|
|
||||||
/>
|
|
||||||
<span class="min-w-0">
|
|
||||||
<span class="flex flex-wrap items-center gap-2 text-sm font-medium">
|
|
||||||
{{ t('settings.hideFolderInUrl') }}
|
|
||||||
<UBadge
|
|
||||||
v-if="settings.hideFolderInUrlSource === 'env'"
|
|
||||||
:color="sourceBadge(settings.hideFolderInUrlSource).color"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
{{ sourceBadge(settings.hideFolderInUrlSource).label }}
|
|
||||||
</UBadge>
|
|
||||||
</span>
|
|
||||||
<span class="mt-1 block text-xs leading-relaxed text-muted">
|
|
||||||
{{ t('settings.hideFolderInUrlHint') }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex h-full min-w-0 flex-col space-y-4 rounded-xl border border-default/60 bg-muted/10 p-4 sm:p-5">
|
|
||||||
<h3 class="text-sm font-semibold">
|
|
||||||
{{ t('settings.domainSettings') }}
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<label class="flex cursor-pointer items-start gap-2.5 rounded-lg border border-default/50 bg-default/40 p-3">
|
|
||||||
<UCheckbox
|
|
||||||
:model-value="domainSeparationDraft"
|
:model-value="domainSeparationDraft"
|
||||||
class="mt-0.5 shrink-0"
|
:title="t('setup.domainSeparation')"
|
||||||
|
:hint="t('setup.domainSeparationHint')"
|
||||||
@update:model-value="onDomainSeparationDraftChange"
|
@update:model-value="onDomainSeparationDraftChange"
|
||||||
/>
|
/>
|
||||||
<span class="min-w-0">
|
</SettingsGroup>
|
||||||
<span class="block text-sm font-medium">{{ t('setup.domainSeparation') }}</span>
|
</SettingsSection>
|
||||||
<span class="mt-1 block text-xs leading-relaxed text-muted">
|
|
||||||
{{ t('setup.domainSeparationHint') }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<p
|
<p
|
||||||
v-if="domainSeparationDraft"
|
v-if="domainSeparationDraft"
|
||||||
class="rounded-lg border border-warning/25 bg-warning/5 px-3 py-2.5 text-xs leading-relaxed text-warning"
|
class="rounded-xl border border-warning/25 bg-warning/5 px-4 py-3 text-xs leading-relaxed text-warning"
|
||||||
>
|
>
|
||||||
{{ t('setup.domainSeparationProxyHint') }}
|
{{ t('setup.domainSeparationProxyHint') }}
|
||||||
<a
|
<a
|
||||||
@@ -408,27 +529,78 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p
|
<UAlert
|
||||||
v-if="settings.runtime.currentOrigin"
|
|
||||||
class="text-xs text-muted"
|
|
||||||
>
|
|
||||||
{{ t('settings.runtimeDetected', { url: settings.runtime.currentOrigin }) }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p
|
|
||||||
v-if="domainSeparationDraft && settings.runtime.hostRole === 'unknown'"
|
v-if="domainSeparationDraft && settings.runtime.hostRole === 'unknown'"
|
||||||
class="rounded-lg border border-error/25 bg-error/5 px-3 py-2.5 text-xs leading-relaxed text-error"
|
color="warning"
|
||||||
>
|
variant="subtle"
|
||||||
{{ t('settings.hostRoleUnknown') }}
|
icon="i-lucide-triangle-alert"
|
||||||
</p>
|
:title="t('settings.hostRoleUnknown')"
|
||||||
|
class="mb-4"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SettingsSection
|
||||||
|
:title="t('settings.pathAndLink')"
|
||||||
|
:hint="t('settings.pathAndLinkHint')"
|
||||||
|
>
|
||||||
|
<SettingsGroup>
|
||||||
|
<SettingsToggleRow
|
||||||
|
:model-value="hideFolderInUrlDraft"
|
||||||
|
:disabled="settings.hideFolderInUrlSource === 'env'"
|
||||||
|
@update:model-value="(v) => hideFolderInUrlDraft = v"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<span class="inline-flex flex-wrap items-center gap-2">
|
||||||
|
{{ t('settings.hideFolderInUrl') }}
|
||||||
|
<UBadge
|
||||||
|
v-if="settings.hideFolderInUrlSource === 'env'"
|
||||||
|
:color="sourceBadge(settings.hideFolderInUrlSource).color"
|
||||||
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{{ sourceBadge(settings.hideFolderInUrlSource).label }}
|
||||||
|
</UBadge>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #hint>
|
||||||
|
{{ t('settings.hideFolderInUrlHint') }}
|
||||||
|
</template>
|
||||||
|
</SettingsToggleRow>
|
||||||
|
<SettingsToggleRow
|
||||||
|
:model-value="storageUseDatePathDraft"
|
||||||
|
:disabled="settings.storageUseDatePathSource === 'env'"
|
||||||
|
@update:model-value="(v) => storageUseDatePathDraft = v"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<span class="inline-flex flex-wrap items-center gap-2">
|
||||||
|
{{ t('settings.storageUseDatePath') }}
|
||||||
|
<UBadge
|
||||||
|
v-if="settings.storageUseDatePathSource === 'env'"
|
||||||
|
:color="sourceBadge(settings.storageUseDatePathSource).color"
|
||||||
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{{ sourceBadge(settings.storageUseDatePathSource).label }}
|
||||||
|
</UBadge>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #hint>
|
||||||
|
{{ t('settings.storageUseDatePathHint') }}
|
||||||
|
</template>
|
||||||
|
</SettingsToggleRow>
|
||||||
|
</SettingsGroup>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<SettingsSection :title="t('settings.imageBaseUrl')">
|
||||||
<div
|
<div
|
||||||
v-if="domainSeparationDraft"
|
v-if="domainSeparationDraft"
|
||||||
class="grid gap-4 sm:grid-cols-2"
|
class="grid gap-4 sm:grid-cols-2"
|
||||||
>
|
>
|
||||||
<div class="space-y-1.5">
|
<SettingsGroup>
|
||||||
|
<div class="space-y-3 px-4 py-4 sm:px-5">
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<label class="text-sm font-medium">{{ t('settings.siteBaseUrl') }}</label>
|
<p class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.siteBaseUrl') }}
|
||||||
|
</p>
|
||||||
<UBadge
|
<UBadge
|
||||||
:color="sourceBadge(settings.siteBaseUrlSource).color"
|
:color="sourceBadge(settings.siteBaseUrlSource).color"
|
||||||
variant="subtle"
|
variant="subtle"
|
||||||
@@ -464,10 +636,14 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
{{ t('settings.siteBaseUrlActive', { url: settings.effectiveSiteBaseUrl }) }}
|
{{ t('settings.siteBaseUrlActive', { url: settings.effectiveSiteBaseUrl }) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
</SettingsGroup>
|
||||||
|
|
||||||
<div class="space-y-1.5">
|
<SettingsGroup>
|
||||||
|
<div class="space-y-3 px-4 py-4 sm:px-5">
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<label class="text-sm font-medium">{{ t('settings.imageBaseUrl') }}</label>
|
<p class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.imageBaseUrl') }}
|
||||||
|
</p>
|
||||||
<UBadge
|
<UBadge
|
||||||
:color="sourceBadge(settings.imageBaseUrlSource).color"
|
:color="sourceBadge(settings.imageBaseUrlSource).color"
|
||||||
variant="subtle"
|
variant="subtle"
|
||||||
@@ -492,15 +668,24 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
{{ t('settings.imageBaseUrlActive', { url: settings.effectiveImageBaseUrl }) }}
|
{{ t('settings.imageBaseUrlActive', { url: settings.effectiveImageBaseUrl }) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
</SettingsGroup>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<SettingsGroup v-else>
|
||||||
v-else
|
<div class="space-y-3 px-4 py-4 sm:px-5">
|
||||||
class="space-y-1.5"
|
|
||||||
>
|
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<label class="text-sm font-medium">{{ t('settings.imageBaseUrl') }}</label>
|
<p class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.imageBaseUrl') }}
|
||||||
|
</p>
|
||||||
<UBadge
|
<UBadge
|
||||||
|
color="success"
|
||||||
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{{ t('settings.badgeOptional') }}
|
||||||
|
</UBadge>
|
||||||
|
<UBadge
|
||||||
|
v-if="settings.imageBaseUrlSource === 'env'"
|
||||||
:color="sourceBadge(settings.imageBaseUrlSource).color"
|
:color="sourceBadge(settings.imageBaseUrlSource).color"
|
||||||
variant="subtle"
|
variant="subtle"
|
||||||
size="xs"
|
size="xs"
|
||||||
@@ -524,105 +709,180 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
{{ t('settings.imageBaseUrlActive', { url: settings.effectiveImageBaseUrl }) }}
|
{{ t('settings.imageBaseUrlActive', { url: settings.effectiveImageBaseUrl }) }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</SettingsGroup>
|
||||||
</div>
|
</SettingsSection>
|
||||||
|
</SettingsPanel>
|
||||||
<div class="settings-referer-section space-y-1.5 rounded-xl border border-default/60 bg-muted/10 p-4 sm:p-5">
|
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
|
||||||
<h3 class="text-sm font-semibold">
|
|
||||||
{{ t('settings.accessControl') }}
|
|
||||||
</h3>
|
|
||||||
<UBadge
|
|
||||||
:color="sourceBadge(settings.refererSource).color"
|
|
||||||
variant="subtle"
|
|
||||||
size="xs"
|
|
||||||
>
|
|
||||||
{{ sourceBadge(settings.refererSource).label }}
|
|
||||||
</UBadge>
|
|
||||||
</div>
|
|
||||||
<p class="text-xs leading-relaxed text-muted">
|
|
||||||
{{ t('settings.refererHint') }}
|
|
||||||
</p>
|
|
||||||
<UTextarea
|
|
||||||
v-model="refererDraft"
|
|
||||||
:placeholder="t('settings.refererPlaceholder')"
|
|
||||||
:rows="4"
|
|
||||||
:autoresize="false"
|
|
||||||
class="settings-referer-field w-full font-mono text-sm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
class="flex justify-center py-12"
|
class="flex justify-center py-16"
|
||||||
>
|
>
|
||||||
<UIcon
|
<UIcon
|
||||||
name="i-lucide-loader-circle"
|
name="i-lucide-loader-circle"
|
||||||
class="size-6 animate-spin text-muted"
|
class="size-6 animate-spin text-muted"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="settings"
|
v-else-if="activeTab === 'access' && isAdmin"
|
||||||
class="flex flex-col gap-3 border-t border-default px-5 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-6"
|
class="settings-referer-section"
|
||||||
>
|
>
|
||||||
<div class="flex min-w-0 items-center gap-2 text-xs text-muted">
|
<SettingsPanel v-if="settings">
|
||||||
|
<div class="flex items-start gap-3">
|
||||||
|
<div class="flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary/10">
|
||||||
<UIcon
|
<UIcon
|
||||||
name="i-lucide-key-round"
|
name="i-lucide-shield"
|
||||||
class="size-3.5 shrink-0"
|
class="size-4 text-primary"
|
||||||
/>
|
/>
|
||||||
<span class="min-w-0">
|
|
||||||
{{ t('settings.apiTokenLine', { source: tokenSourceText(settings.tokenSource) }) }}
|
|
||||||
<a
|
|
||||||
:href="releaseCheck?.updateAvailable && releaseCheck.releaseUrl
|
|
||||||
? releaseCheck.releaseUrl
|
|
||||||
: 'https://github.com/O96u/PicHost/releases'"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="inline-flex items-center gap-0.5 underline-offset-2 hover:underline"
|
|
||||||
:class="releaseCheck?.updateAvailable ? 'text-warning' : 'text-primary'"
|
|
||||||
:title="t('settings.viewReleases')"
|
|
||||||
>
|
|
||||||
v{{ settings.appVersion }}
|
|
||||||
<UIcon
|
|
||||||
name="i-lucide-external-link"
|
|
||||||
class="size-3 opacity-70"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
<template v-if="releaseCheck?.updateAvailable && releaseCheck.latestVersion">
|
|
||||||
·
|
|
||||||
<a
|
|
||||||
:href="releaseCheck.releaseUrl || 'https://github.com/O96u/PicHost/releases'"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="text-warning hover:underline"
|
|
||||||
>
|
|
||||||
{{ t('settings.updateAvailable', { version: `v${releaseCheck.latestVersion}` }) }}
|
|
||||||
</a>
|
|
||||||
</template>
|
|
||||||
<template v-if="hasServerChanges">
|
|
||||||
· <span class="text-warning">{{ t('settings.unsavedChanges') }}</span>
|
|
||||||
</template>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap items-center justify-end gap-2">
|
<div class="min-w-0 flex-1">
|
||||||
<UButton
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
:label="t('settings.manageToken')"
|
<h2 class="text-sm font-semibold text-highlighted">
|
||||||
icon="i-lucide-external-link"
|
{{ t('settings.accessControl') }}
|
||||||
variant="outline"
|
</h2>
|
||||||
color="neutral"
|
<UBadge
|
||||||
size="sm"
|
:color="refererDraft.trim() ? 'success' : 'neutral'"
|
||||||
to="/api"
|
variant="subtle"
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{{ refererDraft.trim() ? t('settings.refererEnabled') : t('settings.refererUnrestricted') }}
|
||||||
|
</UBadge>
|
||||||
|
</div>
|
||||||
|
<p class="mt-1 text-xs leading-relaxed text-muted">
|
||||||
|
{{ t('settings.refererHint') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-5 grid gap-5 lg:grid-cols-[minmax(0,1fr)_12rem] xl:grid-cols-[minmax(0,1fr)_14rem]">
|
||||||
|
<div class="min-w-0 space-y-2">
|
||||||
|
<label class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.refererDomainsLabel') }}
|
||||||
|
</label>
|
||||||
|
<UTextarea
|
||||||
|
v-model="refererDraft"
|
||||||
|
:placeholder="t('settings.refererPlaceholder')"
|
||||||
|
:rows="7"
|
||||||
|
:autoresize="false"
|
||||||
|
class="settings-referer-field w-full font-mono text-sm"
|
||||||
/>
|
/>
|
||||||
<UButton
|
<div class="flex gap-2 rounded-lg border border-info/20 bg-info/5 px-3 py-2.5 text-xs leading-relaxed text-muted">
|
||||||
:label="t('common.save')"
|
<UIcon
|
||||||
icon="i-lucide-save"
|
name="i-lucide-info"
|
||||||
size="sm"
|
class="mt-0.5 size-3.5 shrink-0 text-info"
|
||||||
:loading="savingServer"
|
/>
|
||||||
:disabled="!hasServerChanges"
|
<span>{{ t('settings.refererTip') }}</span>
|
||||||
@click="saveServerSettings"
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="space-y-3 border-l border-default pl-4">
|
||||||
|
<div>
|
||||||
|
<p class="text-xs font-medium text-highlighted">
|
||||||
|
{{ t('settings.refererExamplesTitle') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 font-mono text-xs text-muted">
|
||||||
|
{{ t('settings.refererExamplesSample') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-xs font-medium text-highlighted">
|
||||||
|
{{ t('settings.refererScenarioTitle') }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-xs leading-relaxed text-muted">
|
||||||
|
{{ t('settings.refererScenarioDesc') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SettingsSection
|
||||||
|
:title="t('settings.loginVerification')"
|
||||||
|
:hint="t('settings.loginVerificationHint')"
|
||||||
|
>
|
||||||
|
<SettingsGroup>
|
||||||
|
<div class="space-y-4 px-4 py-4 sm:px-5">
|
||||||
|
<URadioGroup
|
||||||
|
v-model="loginVerificationMethodDraft"
|
||||||
|
:items="loginVerificationOptions"
|
||||||
|
/>
|
||||||
|
<p class="text-xs leading-relaxed text-muted">
|
||||||
|
{{ loginVerificationHint }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-if="loginVerificationMethodDraft === 'turnstile'"
|
||||||
|
class="space-y-3 rounded-xl border border-default bg-muted/20 p-4"
|
||||||
|
>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.turnstileSiteKey') }}
|
||||||
|
</label>
|
||||||
|
<UInput
|
||||||
|
v-model="turnstileSiteKeyDraft"
|
||||||
|
:placeholder="t('settings.turnstileSiteKeyPlaceholder')"
|
||||||
|
class="w-full font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.turnstileSecretKey') }}
|
||||||
|
</label>
|
||||||
|
<UInput
|
||||||
|
v-model="turnstileSecretKeyDraft"
|
||||||
|
type="password"
|
||||||
|
:placeholder="t('settings.turnstileSecretKeyPlaceholder')"
|
||||||
|
class="w-full font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="loginVerificationMethodDraft === 'cap'"
|
||||||
|
class="space-y-3 rounded-xl border border-default bg-muted/20 p-4"
|
||||||
|
>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.capApiEndpoint') }}
|
||||||
|
</label>
|
||||||
|
<UInput
|
||||||
|
v-model="capApiEndpointDraft"
|
||||||
|
:placeholder="t('settings.capApiEndpointPlaceholder')"
|
||||||
|
class="w-full font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2">
|
||||||
|
<label class="text-sm font-medium text-highlighted">
|
||||||
|
{{ t('settings.capSecretKey') }}
|
||||||
|
</label>
|
||||||
|
<UInput
|
||||||
|
v-model="capSecretDraft"
|
||||||
|
type="password"
|
||||||
|
:placeholder="t('settings.capSecretKeyPlaceholder')"
|
||||||
|
class="w-full font-mono text-sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SettingsGroup>
|
||||||
|
</SettingsSection>
|
||||||
|
</SettingsPanel>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex justify-center py-16"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
name="i-lucide-loader-circle"
|
||||||
|
class="size-6 animate-spin text-muted"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SettingsLogsPanel v-else-if="activeTab === 'logs'" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SettingsServerFooter
|
||||||
|
v-if="showSaveBar && settings"
|
||||||
|
:has-changes="hasServerChanges"
|
||||||
|
:saving="savingServer"
|
||||||
|
@save="saveServerSettings"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -651,6 +911,30 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</UModal>
|
</UModal>
|
||||||
|
|
||||||
|
<UModal
|
||||||
|
:open="domainSeparationSaveConfirmOpen"
|
||||||
|
:title="t('domainSeparationConfirm.title')"
|
||||||
|
:description="t('domainSeparationConfirm.description')"
|
||||||
|
@update:open="(v) => { if (!v) domainSeparationSaveConfirmOpen = false }"
|
||||||
|
>
|
||||||
|
<template #footer>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<UButton
|
||||||
|
:label="t('common.cancel')"
|
||||||
|
color="neutral"
|
||||||
|
variant="outline"
|
||||||
|
@click="() => { domainSeparationSaveConfirmOpen = false }"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('domainSeparationConfirm.confirm')"
|
||||||
|
color="warning"
|
||||||
|
:loading="savingServer"
|
||||||
|
@click="performSaveServerSettings"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import logoLight from '~/assets/image/logo-light.png'
|
import logoLight from '~/assets/image/logo-light.png'
|
||||||
import logoDark from '~/assets/image/logo-dark.png'
|
import logoDark from '~/assets/image/logo-dark.png'
|
||||||
import { isPasswordValid } from '~/utils/password-strength'
|
import { isPasswordValid } from '~/utils/password-strength'
|
||||||
|
import { willActivateDomainSeparation } from '~/utils/domain-separation'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -26,6 +27,102 @@ const domainSeparation = ref(false)
|
|||||||
const siteBaseUrl = ref('')
|
const siteBaseUrl = ref('')
|
||||||
const imageBaseUrl = ref('')
|
const imageBaseUrl = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const domainSeparationConfirmOpen = ref(false)
|
||||||
|
|
||||||
|
const setupMode = ref<'init' | 'restore'>('init')
|
||||||
|
const restoreFile = ref<File | null>(null)
|
||||||
|
const restoreFileInput = ref<HTMLInputElement | null>(null)
|
||||||
|
const restoreLoading = ref(false)
|
||||||
|
const restoreJobId = ref<string | null>(null)
|
||||||
|
const restoreProgress = ref({ progress: 0, total: 0, message: '' })
|
||||||
|
let restorePollTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
function stopRestorePolling() {
|
||||||
|
if (restorePollTimer) {
|
||||||
|
clearInterval(restorePollTimer)
|
||||||
|
restorePollTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickRestoreFile() {
|
||||||
|
restoreFileInput.value?.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRestoreFileChange(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
restoreFile.value = input.files?.[0] ?? null
|
||||||
|
if (input) input.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pollRestoreJob(jobId: string) {
|
||||||
|
try {
|
||||||
|
const data = await $fetch<{ job: { status: string, progress: number, total: number, message: string, error: string | null } }>(
|
||||||
|
`/api/setup/restore/${jobId}`
|
||||||
|
)
|
||||||
|
restoreProgress.value = {
|
||||||
|
progress: data.job.progress,
|
||||||
|
total: data.job.total,
|
||||||
|
message: data.job.message
|
||||||
|
}
|
||||||
|
if (data.job.status === 'done') {
|
||||||
|
stopRestorePolling()
|
||||||
|
restoreLoading.value = false
|
||||||
|
toast.add({
|
||||||
|
title: t('setup.restoreSuccess'),
|
||||||
|
description: t('setup.restoreSecretsHint'),
|
||||||
|
color: 'success'
|
||||||
|
})
|
||||||
|
await router.replace('/')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (data.job.status === 'failed') {
|
||||||
|
stopRestorePolling()
|
||||||
|
restoreLoading.value = false
|
||||||
|
toast.add({
|
||||||
|
title: t('setup.restoreFailed'),
|
||||||
|
description: data.job.error ?? data.job.message,
|
||||||
|
color: 'error'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
stopRestorePolling()
|
||||||
|
restoreLoading.value = false
|
||||||
|
toast.add({ title: t('setup.restoreFailed'), color: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitRestore() {
|
||||||
|
if (!restoreFile.value || restoreLoading.value) return
|
||||||
|
restoreLoading.value = true
|
||||||
|
try {
|
||||||
|
const form = new FormData()
|
||||||
|
form.append('file', restoreFile.value)
|
||||||
|
const data = await $fetch<{ job: { id: string } }>('/api/setup/restore', {
|
||||||
|
method: 'POST',
|
||||||
|
body: form
|
||||||
|
})
|
||||||
|
restoreJobId.value = data.job.id
|
||||||
|
restorePollTimer = setInterval(() => {
|
||||||
|
void pollRestoreJob(data.job.id)
|
||||||
|
}, 1500)
|
||||||
|
await pollRestoreJob(data.job.id)
|
||||||
|
} catch {
|
||||||
|
restoreLoading.value = false
|
||||||
|
toast.add({ title: t('setup.restoreFailed'), color: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
stopRestorePolling()
|
||||||
|
})
|
||||||
|
|
||||||
|
const domainSeparationWouldActivate = computed(() =>
|
||||||
|
willActivateDomainSeparation(
|
||||||
|
domainSeparation.value,
|
||||||
|
siteBaseUrl.value,
|
||||||
|
imageBaseUrl.value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
const canSubmit = computed(() => {
|
const canSubmit = computed(() => {
|
||||||
if (!username.value || !password.value || !confirmPassword.value) return false
|
if (!username.value || !password.value || !confirmPassword.value) return false
|
||||||
@@ -33,7 +130,7 @@ const canSubmit = computed(() => {
|
|||||||
if (!isPasswordValid(password.value)) return false
|
if (!isPasswordValid(password.value)) return false
|
||||||
if (!AUTH_USERNAME_PATTERN.test(username.value.trim())) return false
|
if (!AUTH_USERNAME_PATTERN.test(username.value.trim())) return false
|
||||||
if (domainSeparation.value) {
|
if (domainSeparation.value) {
|
||||||
return Boolean(siteBaseUrl.value.trim() && imageBaseUrl.value.trim())
|
if (!siteBaseUrl.value.trim() || !imageBaseUrl.value.trim()) return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@@ -63,6 +160,18 @@ async function submit() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (domainSeparationWouldActivate.value) {
|
||||||
|
domainSeparationConfirmOpen.value = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
await performSubmit()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function performSubmit() {
|
||||||
|
domainSeparationConfirmOpen.value = false
|
||||||
|
if (!canSubmit.value || loading.value) return
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
@@ -127,7 +236,28 @@ async function submit() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-6 flex rounded-lg border border-default p-1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors"
|
||||||
|
:class="setupMode === 'init' ? 'bg-primary text-inverted' : 'text-muted hover:text-default'"
|
||||||
|
@click="setupMode = 'init'"
|
||||||
|
>
|
||||||
|
{{ t('setup.modeInit') }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="!isMigrate"
|
||||||
|
type="button"
|
||||||
|
class="flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors"
|
||||||
|
:class="setupMode === 'restore' ? 'bg-primary text-inverted' : 'text-muted hover:text-default'"
|
||||||
|
@click="setupMode = 'restore'"
|
||||||
|
>
|
||||||
|
{{ t('setup.modeRestore') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
|
v-if="setupMode === 'init'"
|
||||||
class="flex w-full flex-col gap-5"
|
class="flex w-full flex-col gap-5"
|
||||||
@submit.prevent="submit"
|
@submit.prevent="submit"
|
||||||
>
|
>
|
||||||
@@ -247,6 +377,97 @@ async function submit() {
|
|||||||
:disabled="!canSubmit"
|
:disabled="!canSubmit"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex w-full flex-col gap-5"
|
||||||
|
>
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<label class="text-xs text-muted">{{ t('storage.backup.restoreUploadLabel') }}</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-full flex-col items-center gap-1.5 rounded-lg border-2 border-dashed px-3 py-4 text-center transition-colors disabled:cursor-not-allowed disabled:opacity-60"
|
||||||
|
:class="restoreFile
|
||||||
|
? 'border-primary/50 bg-primary/5'
|
||||||
|
: 'border-warning/40 bg-warning/5 hover:border-warning/60 hover:bg-warning/10'"
|
||||||
|
:disabled="restoreLoading"
|
||||||
|
@click="pickRestoreFile"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex size-8 items-center justify-center rounded-full"
|
||||||
|
:class="restoreFile ? 'bg-primary/15 text-primary' : 'bg-warning/15 text-warning'"
|
||||||
|
>
|
||||||
|
<UIcon
|
||||||
|
:name="restoreFile ? 'i-lucide-check' : 'i-lucide-upload'"
|
||||||
|
class="size-4.5"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<span class="max-w-full truncate text-sm font-medium text-default">
|
||||||
|
{{ restoreFile?.name ?? t('storage.backup.restoreUpload') }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="!restoreFile"
|
||||||
|
class="text-xs text-muted"
|
||||||
|
>
|
||||||
|
{{ t('storage.backup.restoreUploadHint') }}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="rounded-lg bg-muted/15 px-3 py-2.5 text-xs leading-relaxed text-muted">
|
||||||
|
{{ t('setup.restoreHint') }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<StorageBackupJobProgress
|
||||||
|
v-if="restoreLoading"
|
||||||
|
:message="restoreProgress.message || t('setup.restoreSubmit')"
|
||||||
|
:progress="restoreProgress.progress"
|
||||||
|
:total="restoreProgress.total"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UButton
|
||||||
|
:label="t('setup.restoreSubmit')"
|
||||||
|
icon="i-lucide-upload"
|
||||||
|
size="lg"
|
||||||
|
block
|
||||||
|
class="w-full"
|
||||||
|
:loading="restoreLoading"
|
||||||
|
:disabled="!restoreFile"
|
||||||
|
@click="submitRestore"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<input
|
||||||
|
ref="restoreFileInput"
|
||||||
|
type="file"
|
||||||
|
accept=".phost.tar.gz,.tar.gz"
|
||||||
|
class="hidden"
|
||||||
|
@change="onRestoreFileChange"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UModal
|
||||||
|
:open="domainSeparationConfirmOpen"
|
||||||
|
:title="t('domainSeparationConfirm.title')"
|
||||||
|
:description="t('domainSeparationConfirm.description')"
|
||||||
|
@update:open="(v) => { if (!v) domainSeparationConfirmOpen = false }"
|
||||||
|
>
|
||||||
|
<template #footer>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<UButton
|
||||||
|
:label="t('common.cancel')"
|
||||||
|
color="neutral"
|
||||||
|
variant="outline"
|
||||||
|
@click="() => { domainSeparationConfirmOpen = false }"
|
||||||
|
/>
|
||||||
|
<UButton
|
||||||
|
:label="t('domainSeparationConfirm.confirm')"
|
||||||
|
color="warning"
|
||||||
|
:loading="loading"
|
||||||
|
@click="performSubmit"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</UModal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -21,6 +21,58 @@ const deleteTarget = ref<StorageBackendItem | null>(null)
|
|||||||
const deleteConfirmName = ref('')
|
const deleteConfirmName = ref('')
|
||||||
const deleting = ref(false)
|
const deleting = ref(false)
|
||||||
|
|
||||||
|
const backupPanelRef = ref<{ applySyncDraft: (draft: { fromBackendId: string, toBackendId: string }) => void } | null>(null)
|
||||||
|
|
||||||
|
function onMigrateIn(backend: StorageBackendItem) {
|
||||||
|
const defaultBackend = storageData.value?.backends.find(item => item.isDefault)
|
||||||
|
if (!defaultBackend || defaultBackend.id === backend.id) return
|
||||||
|
backupPanelRef.value?.applySyncDraft({
|
||||||
|
fromBackendId: defaultBackend.id,
|
||||||
|
toBackendId: backend.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMigrateOut(backend: StorageBackendItem) {
|
||||||
|
const backends = storageData.value?.backends ?? []
|
||||||
|
if (backend.isDefault) {
|
||||||
|
const target = backends.find(item => !item.isDefault && item.enabled)
|
||||||
|
if (!target) return
|
||||||
|
backupPanelRef.value?.applySyncDraft({
|
||||||
|
fromBackendId: backend.id,
|
||||||
|
toBackendId: target.id
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultBackend = backends.find(item => item.isDefault)
|
||||||
|
if (!defaultBackend) return
|
||||||
|
backupPanelRef.value?.applySyncDraft({
|
||||||
|
fromBackendId: backend.id,
|
||||||
|
toBackendId: defaultBackend.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMigrateIn(backend: StorageBackendItem): boolean {
|
||||||
|
const backends = storageData.value?.backends ?? []
|
||||||
|
return !backend.isDefault
|
||||||
|
&& backend.enabled
|
||||||
|
&& backends.some(item => item.isDefault)
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMigrateOut(backend: StorageBackendItem): boolean {
|
||||||
|
const backends = storageData.value?.backends ?? []
|
||||||
|
if (backend.usage.count === 0) return false
|
||||||
|
if (backend.isDefault) {
|
||||||
|
return backends.some(item => !item.isDefault && item.enabled)
|
||||||
|
}
|
||||||
|
return backends.some(item => item.isDefault)
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultBackendName = computed(() => {
|
||||||
|
const backend = storageData.value?.backends.find(item => item.isDefault)
|
||||||
|
return backend?.name ?? t('storage.backendLocal')
|
||||||
|
})
|
||||||
|
|
||||||
async function loadStorage() {
|
async function loadStorage() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -43,6 +95,7 @@ function buildPatchBody(payload: StorageFormPayload) {
|
|||||||
const quotaBytes = quotaToBytes(payload.quotaValue, payload.quotaUnit)
|
const quotaBytes = quotaToBytes(payload.quotaValue, payload.quotaUnit)
|
||||||
const body: Record<string, unknown> = {
|
const body: Record<string, unknown> = {
|
||||||
name: payload.name,
|
name: payload.name,
|
||||||
|
provider: payload.provider,
|
||||||
servingMode: payload.servingMode,
|
servingMode: payload.servingMode,
|
||||||
publicUrl: payload.publicUrl,
|
publicUrl: payload.publicUrl,
|
||||||
quotaBytes,
|
quotaBytes,
|
||||||
@@ -232,22 +285,16 @@ watch(isAuthenticated, async (authed) => {
|
|||||||
<AdminLoginGate v-else-if="!isAuthenticated" />
|
<AdminLoginGate v-else-if="!isAuthenticated" />
|
||||||
|
|
||||||
<AppShell v-else-if="isAdmin">
|
<AppShell v-else-if="isAdmin">
|
||||||
<section class="overflow-hidden rounded-2xl border border-default bg-elevated shadow-sm">
|
<div class="flex items-start justify-between gap-3">
|
||||||
<div class="flex flex-wrap items-start justify-between gap-3 border-b border-default px-5 py-4 sm:px-6">
|
<div class="min-w-0">
|
||||||
<div class="flex items-start gap-2">
|
<h1 class="text-2xl font-semibold tracking-tight">
|
||||||
<UIcon
|
|
||||||
name="i-lucide-hard-drive"
|
|
||||||
class="mt-0.5 size-5 shrink-0 text-primary"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<h1 class="text-base font-semibold">
|
|
||||||
{{ t('storage.pageTitle') }}
|
{{ t('storage.pageTitle') }}
|
||||||
</h1>
|
</h1>
|
||||||
<p class="mt-0.5 text-xs text-muted">
|
<p class="text-sm text-muted">
|
||||||
{{ t('storage.pageSubtitle') }}
|
{{ t('storage.pageSubtitle') }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<UButton
|
<UButton
|
||||||
:label="t('storage.addBackend')"
|
:label="t('storage.addBackend')"
|
||||||
icon="i-lucide-plus"
|
icon="i-lucide-plus"
|
||||||
@@ -257,20 +304,15 @@ watch(isAuthenticated, async (authed) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="p-5 sm:p-6">
|
<section class="mt-5 space-y-5">
|
||||||
<UAlert
|
<UAlert
|
||||||
v-if="storageData?.envOverride"
|
v-if="storageData?.envOverride"
|
||||||
color="warning"
|
color="warning"
|
||||||
variant="subtle"
|
variant="subtle"
|
||||||
class="mb-5"
|
|
||||||
:title="t('storage.envOverride')"
|
:title="t('storage.envOverride')"
|
||||||
icon="i-lucide-triangle-alert"
|
icon="i-lucide-triangle-alert"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<p class="mb-5 text-xs text-muted">
|
|
||||||
{{ t('storage.switchHint') }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="loading"
|
v-if="loading"
|
||||||
class="flex justify-center py-16"
|
class="flex justify-center py-16"
|
||||||
@@ -281,28 +323,54 @@ watch(isAuthenticated, async (authed) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<template v-else-if="storageData">
|
||||||
v-else-if="storageData"
|
<StorageOverview
|
||||||
class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3"
|
:backends="storageData.backends"
|
||||||
>
|
:loading="loading"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UAlert
|
||||||
|
v-if="!storageData.envOverride"
|
||||||
|
color="success"
|
||||||
|
variant="subtle"
|
||||||
|
icon="i-lucide-info"
|
||||||
|
:description="t('storage.defaultStorageTip', { name: defaultBackendName })"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 gap-4 xl:grid-cols-2">
|
||||||
<StorageBackendCard
|
<StorageBackendCard
|
||||||
v-for="backend in storageData.backends"
|
v-for="backend in storageData.backends"
|
||||||
:key="backend.id"
|
:key="backend.id"
|
||||||
:backend="backend"
|
:backend="backend"
|
||||||
:env-override="storageData.envOverride"
|
:env-override="storageData.envOverride"
|
||||||
:busy="busyId === backend.id"
|
:busy="busyId === backend.id"
|
||||||
|
:show-migrate-in="showMigrateIn(backend)"
|
||||||
|
:show-migrate-out="showMigrateOut(backend)"
|
||||||
@set-default="setDefault(backend)"
|
@set-default="setDefault(backend)"
|
||||||
@edit="openEdit(backend)"
|
@edit="openEdit(backend)"
|
||||||
@test="testBackend(backend)"
|
@test="testBackend(backend)"
|
||||||
@toggle-enabled="toggleEnabled(backend)"
|
@toggle-enabled="toggleEnabled(backend)"
|
||||||
@delete="confirmDelete(backend)"
|
@delete="confirmDelete(backend)"
|
||||||
|
@migrate-in="onMigrateIn(backend)"
|
||||||
|
@migrate-out="onMigrateOut(backend)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<StorageBackupPanel
|
||||||
|
v-if="!storageData.envOverride"
|
||||||
|
ref="backupPanelRef"
|
||||||
|
:backends="storageData.backends"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StorageSupportedBackends />
|
||||||
|
</template>
|
||||||
</section>
|
</section>
|
||||||
</AppShell>
|
</AppShell>
|
||||||
|
|
||||||
<UModal v-model:open="formOpen">
|
<UModal
|
||||||
|
v-model:open="formOpen"
|
||||||
|
:ui="{ content: 'max-w-2xl sm:max-w-3xl' }"
|
||||||
|
>
|
||||||
<template #content>
|
<template #content>
|
||||||
<div class="p-5 sm:p-6">
|
<div class="p-5 sm:p-6">
|
||||||
<h2 class="mb-4 text-base font-semibold">
|
<h2 class="mb-4 text-base font-semibold">
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
export type LoginVerificationMethod = 'slider' | 'turnstile' | 'cap'
|
||||||
|
|
||||||
|
export interface LoginVerificationPublicConfig {
|
||||||
|
method: LoginVerificationMethod
|
||||||
|
turnstileSiteKey?: string
|
||||||
|
capApiEndpoint?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LoginVerificationPayload = {
|
||||||
|
method: 'slider'
|
||||||
|
captchaId: string
|
||||||
|
captchaPosition: number
|
||||||
|
} | {
|
||||||
|
method: 'turnstile'
|
||||||
|
turnstileToken: string
|
||||||
|
} | {
|
||||||
|
method: 'cap'
|
||||||
|
capToken: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
export type BackupJobType = 'full_export' | 'full_restore' | 'backend_sync'
|
||||||
|
export type BackupJobStatus = 'pending' | 'running' | 'done' | 'failed'
|
||||||
|
|
||||||
|
export interface BackupJobItem {
|
||||||
|
id: string
|
||||||
|
type: BackupJobType
|
||||||
|
status: BackupJobStatus
|
||||||
|
progress: number
|
||||||
|
total: number
|
||||||
|
message: string
|
||||||
|
payload: Record<string, unknown>
|
||||||
|
outputPath: string | null
|
||||||
|
archiveName: string | null
|
||||||
|
downloadable: boolean
|
||||||
|
error: string | null
|
||||||
|
createdAt: string
|
||||||
|
finishedAt: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackupEstimate {
|
||||||
|
imageCount: number
|
||||||
|
imageBytes: number
|
||||||
|
databaseBytes: number
|
||||||
|
totalBytes: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackupPackageItem {
|
||||||
|
name: string
|
||||||
|
bytes: number
|
||||||
|
modifiedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackupRestorePreview {
|
||||||
|
imageCount: number
|
||||||
|
imageBytes: number
|
||||||
|
newImages: number
|
||||||
|
conflictingImages: number
|
||||||
|
formatVersion: number
|
||||||
|
appVersion: string
|
||||||
|
createdAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackendSyncPreview {
|
||||||
|
imageCount: number
|
||||||
|
imageBytes: number
|
||||||
|
fromBackendId: string
|
||||||
|
toBackendId: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SyncDraft {
|
||||||
|
fromBackendId: string
|
||||||
|
toBackendId: string
|
||||||
|
}
|
||||||
@@ -42,6 +42,8 @@ export interface ImageItem {
|
|||||||
name: string
|
name: string
|
||||||
type: 'local' | 's3'
|
type: 'local' | 's3'
|
||||||
}
|
}
|
||||||
|
/** 上传来源:网页或 API(来自活动日志) */
|
||||||
|
uploadSource?: 'web' | 'api'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploadErrorItem {
|
export interface UploadErrorItem {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export type SettingsTab = 'basic' | 'domains' | 'access' | 'logs'
|
||||||
|
|
||||||
|
export const ADMIN_SETTINGS_TABS: SettingsTab[] = ['basic', 'domains', 'access', 'logs']
|
||||||
|
|
||||||
|
export const USER_SETTINGS_TABS: SettingsTab[] = ['logs']
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export function hostnameFromBaseUrl(value: string): string | null {
|
||||||
|
const trimmed = value.trim()
|
||||||
|
if (!trimmed) return null
|
||||||
|
try {
|
||||||
|
return new URL(trimmed).hostname.toLowerCase()
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 勾选分离且网站域、图片域主机名不同 → 保存后将启用双域名中间件隔离 */
|
||||||
|
export function willActivateDomainSeparation(
|
||||||
|
enabled: boolean,
|
||||||
|
siteBaseUrl: string,
|
||||||
|
imageBaseUrl: string
|
||||||
|
): boolean {
|
||||||
|
if (!enabled) return false
|
||||||
|
const site = siteBaseUrl.trim()
|
||||||
|
const image = imageBaseUrl.trim()
|
||||||
|
if (!site || !image) return false
|
||||||
|
const siteHost = hostnameFromBaseUrl(site)
|
||||||
|
const imageHost = hostnameFromBaseUrl(image)
|
||||||
|
return Boolean(siteHost && imageHost && siteHost !== imageHost)
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export function getFileExtension(filename: string): string {
|
||||||
|
const base = filename.split(/[/\\]/).pop() ?? filename
|
||||||
|
const dot = base.lastIndexOf('.')
|
||||||
|
if (dot <= 0 || dot === base.length - 1) return '—'
|
||||||
|
return base.slice(dot + 1).toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUrlPathname(url: string): string {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(new URL(url).pathname.replace(/^\/+/, ''))
|
||||||
|
} catch {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getStorageKeyTail(key: string): string {
|
||||||
|
const prefix = 'images/'
|
||||||
|
return key.startsWith(prefix) ? key.slice(prefix.length) : key
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatImageDimensions(width: number | null, height: number | null): string | null {
|
||||||
|
if (!width || !height) return null
|
||||||
|
return `${width} × ${height} px`
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ services:
|
|||||||
- "6892:6892"
|
- "6892:6892"
|
||||||
# 首次访问 Web 引导创建管理员,无需预先配置环境变量
|
# 首次访问 Web 引导创建管理员,无需预先配置环境变量
|
||||||
# 可选:environment 中设置 API_UPLOAD_TOKEN、ALLOWED_REFERER_HOSTS 等
|
# 可选:environment 中设置 API_UPLOAD_TOKEN、ALLOWED_REFERER_HOSTS 等
|
||||||
# 运维:docker exec pichost reset-password | migrate [--apply]
|
# 运维:docker exec pichost reset-password | slider | clear-domains | backup-export | backup-restore | storage-sync
|
||||||
volumes:
|
volumes:
|
||||||
# 冒号左边改成 NAS 上的实际存图目录(飞牛示例:/vol1/1000/pichost-data)
|
# 冒号左边改成 NAS 上的实际存图目录(飞牛示例:/vol1/1000/pichost-data)
|
||||||
- ./data:/data
|
- ./data:/data
|
||||||
@@ -5,8 +5,24 @@ if [ "$1" = "reset-password" ]; then
|
|||||||
exec node /app/server/cli/reset-password.mjs "${@:2}"
|
exec node /app/server/cli/reset-password.mjs "${@:2}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "migrate" ]; then
|
if [ "$1" = "slider" ]; then
|
||||||
exec node /app/server/cli/migrate-to-single-images.mjs "${@:2}"
|
exec node /app/server/cli/slider.mjs "${@:2}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "clear-domains" ]; then
|
||||||
|
exec node /app/server/cli/clear-domains.mjs "${@:2}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "backup-export" ]; then
|
||||||
|
exec node /app/server/cli/backup-export.mjs "${@:2}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "backup-restore" ]; then
|
||||||
|
exec node /app/server/cli/backup-restore.mjs "${@:2}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "storage-sync" ]; then
|
||||||
|
exec node /app/server/cli/storage-sync.mjs "${@:2}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec node /app/.output/server/index.mjs "$@"
|
exec node /app/.output/server/index.mjs "$@"
|
||||||
@@ -34,7 +34,6 @@ const zhSidebar = [
|
|||||||
text: '升级',
|
text: '升级',
|
||||||
items: [
|
items: [
|
||||||
{ text: '更新日志', link: '/guide/changelog' },
|
{ text: '更新日志', link: '/guide/changelog' },
|
||||||
{ text: 'v1.2 迁移', link: '/guide/migration' },
|
|
||||||
{ text: '常见问题', link: '/guide/faq' }
|
{ text: '常见问题', link: '/guide/faq' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -71,7 +70,6 @@ const enSidebar = [
|
|||||||
text: 'Upgrade',
|
text: 'Upgrade',
|
||||||
items: [
|
items: [
|
||||||
{ text: 'Changelog', link: '/en/guide/changelog' },
|
{ text: 'Changelog', link: '/en/guide/changelog' },
|
||||||
{ text: 'v1.2 migration', link: '/en/guide/migration' },
|
|
||||||
{ text: 'FAQ', link: '/en/guide/faq' }
|
{ text: 'FAQ', link: '/en/guide/faq' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# API
|
# API
|
||||||
|
|
||||||
PicHost exposes REST endpoints and a Twikoo-compatible upload. After deployment, open the in-app **API** page for your token and copyable cURL snippets.
|
PicHost exposes REST endpoints and a Twikoo-compatible upload. After sign-in, open **API** in the nav: a sidebar lists endpoints and token controls, the center shows parameters and copyable cURL, and the right panel supports **live debugging**.
|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,61 @@ Version history and notable changes. The full log is also in the repo root [CHAN
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.2.8] — 2026-09-04
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
|
||||||
|
- **Dual-domain**: confirm dialog on save/setup with lockout risks and `clear-domains` recovery; no longer blocks save based on current Host
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Ops CLI**: `clear-domains` clears site/image URL settings from DB (`docker exec pichost clear-domains`)
|
||||||
|
|
||||||
|
### Docs
|
||||||
|
|
||||||
|
- FAQ and dual-domain / reverse-proxy guides updated with recovery steps
|
||||||
|
|
||||||
|
## [1.2.7] — 2026-09-03
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Login verification**: slider, Cloudflare Turnstile, or Cap on login/register; configure under Settings → Access
|
||||||
|
- **Ops CLI**: `slider` resets verification to the local slider (`docker exec pichost slider`)
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
|
||||||
|
- Login captcha reloads correctly after logout
|
||||||
|
|
||||||
|
## [1.2.6] — 2026-09-01
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Admin UI**: redesigned Settings, API, Gallery, and Storage pages; API page includes live debugging
|
||||||
|
- **Gallery filter**: filter by storage backend
|
||||||
|
- **Storage IDs**: new R2 / COS / OSS / S3 backends get `r2-*`, `cos-*`, `oss-*`, or `s3-*` prefixes
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
|
||||||
|
- Activity log table styling and path truncation
|
||||||
|
- Storage backend card metadata layout
|
||||||
|
- Docs site and README screenshots updated
|
||||||
|
|
||||||
|
## [1.2.5] — 2026-08-31
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Gallery page**: nav “Stats” renamed to “Gallery” (`/gallery`); click a thumbnail for a detail modal (full image, dimensions, upload source, storage path, link copy)
|
||||||
|
- **List actions**: select all / invert selection; single-image delete moved into the detail modal
|
||||||
|
- **Upload source**: gallery API returns web / API upload source (from activity logs)
|
||||||
|
|
||||||
|
### Improved
|
||||||
|
|
||||||
|
- README tech stack section
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- `/stats` route (no compatibility redirect)
|
||||||
|
|
||||||
## [1.2.4] — 2026-08-31
|
## [1.2.4] — 2026-08-31
|
||||||
|
|
||||||
### Fix
|
### Fix
|
||||||
@@ -104,15 +159,12 @@ Version history and notable changes. The full log is also in the repo root [CHAN
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- All images under `data/images/`; legacy `blog/` / `twikoo/` need migration
|
- All images under `data/images/`; parallel top-level folders beside `images` are no longer used
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- CLI: `docker exec pichost migrate` / `migrate --apply`
|
|
||||||
- Startup index sync (disk scan, legacy key normalization, orphan cleanup)
|
- Startup index sync (disk scan, legacy key normalization, orphan cleanup)
|
||||||
|
|
||||||
See [v1.2 migration](./migration.md).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## [1.1.x] summary
|
## [1.1.x] summary
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Environment variables
|
# Environment variables
|
||||||
|
|
||||||
Configure PicHost via environment variables (Docker / `.env`) or the in-app **Settings** page. Most values prefer **SQLite** when saved; some env vars override or lock UI editing.
|
Configure PicHost via environment variables (Docker / `.env`) or the in-app **Settings** page. Admins use **Settings** (`/settings`) with sidebar sections **Basic**, **Domains & paths**, **Access control**, and **Activity log**. Most values prefer **SQLite** when saved; some env vars override or lock UI editing.
|
||||||
|
|
||||||
## Priority overview
|
## Priority overview
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ Configure PicHost via environment variables (Docker / `.env`) or the in-app **Se
|
|||||||
| Short image links | SQLite → env → default false | No |
|
| Short image links | SQLite → env → default false | No |
|
||||||
| Date-based paths | SQLite → env → default true | No |
|
| Date-based paths | SQLite → env → default true | No |
|
||||||
| Global auto-delete days | SQLite → env → default 0 | No |
|
| Global auto-delete days | SQLite → env → default 0 | No |
|
||||||
|
| Login verification | SQLite (Settings → Access control) | No |
|
||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
@@ -64,6 +65,18 @@ Delete images older than N days globally; `0` disables. Affects **new uploads af
|
|||||||
|
|
||||||
Local dev only: `true` bypasses login. Never use in production.
|
Local dev only: `true` bypasses login. Never use in production.
|
||||||
|
|
||||||
|
### Login verification (Settings only)
|
||||||
|
|
||||||
|
Configure under **Settings → Access control** (stored in SQLite; no env vars):
|
||||||
|
|
||||||
|
| Method | Notes |
|
||||||
|
| ------ | ----- |
|
||||||
|
| **Local slider** (default) | No third-party service |
|
||||||
|
| **Cloudflare Turnstile** | Site key + secret key |
|
||||||
|
| **Cap** | API endpoint + secret |
|
||||||
|
|
||||||
|
Login and registration share the same method. If misconfigured: `docker exec pichost slider` (or `npm run slider`) resets to the slider.
|
||||||
|
|
||||||
### Storage backends (optional)
|
### Storage backends (optional)
|
||||||
|
|
||||||
Admins usually add backends in **Storage** UI; env vars such as `STORAGE_BACKEND=s3` and `S3_*` are also supported. See [Storage](./storage.md).
|
Admins usually add backends in **Storage** UI; env vars such as `STORAGE_BACKEND=s3` and `S3_*` are also supported. See [Storage](./storage.md).
|
||||||
@@ -99,5 +112,6 @@ Restart the container after changing env vars.
|
|||||||
| Date-based paths | `STORAGE_USE_DATE_PATH` / `STORAGE_LAYOUT` |
|
| Date-based paths | `STORAGE_USE_DATE_PATH` / `STORAGE_LAYOUT` |
|
||||||
| WebP quality | `WEBP_QUALITY` |
|
| WebP quality | `WEBP_QUALITY` |
|
||||||
| Auto-delete | `AUTO_DELETE_DAYS` |
|
| Auto-delete | `AUTO_DELETE_DAYS` |
|
||||||
|
| Login verification | (Settings → Access control only) |
|
||||||
|
|
||||||
Template: [`.env.example`](https://github.com/O96u/PicHost/blob/main/.env.example) in the repo root.
|
Template: [`.env.example`](https://github.com/O96u/PicHost/blob/main/.env.example) in the repo root.
|
||||||
@@ -69,10 +69,21 @@ This is independent of hyphenated or long domain names. Older versions did not b
|
|||||||
|
|
||||||
1. Configure `server_name` only for the site and image hosts; add a **default server** to reject other Host values and bare IP access (see Nginx example above; complements app-layer blocking)
|
1. Configure `server_name` only for the site and image hosts; add a **default server** to reject other Host values and bare IP access (see Nginx example above; complements app-layer blocking)
|
||||||
2. With Cloudflare **orange-cloud** DNS, restrict the origin firewall to **[Cloudflare IP ranges](https://www.cloudflare.com/ips/)** so traffic cannot bypass the CDN
|
2. With Cloudflare **orange-cloud** DNS, restrict the origin firewall to **[Cloudflare IP ranges](https://www.cloudflare.com/ips/)** so traffic cannot bypass the CDN
|
||||||
3. Sign in only on the **site hostname** from Settings; do not mix `localhost`, IP, or unlisted domains
|
3. **Before saving**, read the risk confirmation in Settings / setup; saving via IP, LAN, or a proxy that does not forward Host correctly may lock you out — see **Recovery when locked out** below
|
||||||
4. Do **not** put Cloudflare Pages / Workers in front of PicHost as a **full-site reverse proxy** (`IMAGE_BASE_URL` may point at a CDN URL, but the app itself should run on Docker/VPS)
|
4. Sign in only on the **site hostname** from Settings; do not mix `localhost`, IP, or unlisted domains
|
||||||
5. If you must proxy at the edge, preserve the client **`Host` or `X-Forwarded-Host`** or host isolation will fail
|
5. Do **not** put Cloudflare Pages / Workers in front of PicHost as a **full-site reverse proxy** (`IMAGE_BASE_URL` may point at a CDN URL, but the app itself should run on Docker/VPS)
|
||||||
6. PicHost **cannot** run as-is on Pages/Workers (needs `node-server`, SQLite, `sharp`, local `data/`). Keep Docker/VPS; use orange-cloud DNS and optional R2 storage on CF
|
6. If you must proxy at the edge, preserve the client **`Host` or `X-Forwarded-Host`** (Lucky/NPM “force hostname” must match PicHost settings) or isolation fails or you get locked out after save
|
||||||
|
7. PicHost **cannot** run as-is on Pages/Workers (needs `node-server`, SQLite, `sharp`, local `data/`). Keep Docker/VPS; use orange-cloud DNS and optional R2 storage on CF
|
||||||
|
|
||||||
|
### Recovery when locked out
|
||||||
|
|
||||||
|
If IP / LAN access returns 404 after a bad save:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost clear-domains
|
||||||
|
```
|
||||||
|
|
||||||
|
Local: `npm run clear-domains`. Then reconfigure using the site hostname and verify proxy `Host` headers.
|
||||||
|
|
||||||
### Cloudflare orange cloud (incl. preferred edge IPs)
|
### Cloudflare orange cloud (incl. preferred edge IPs)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,24 @@ Local: `npm run reset-password`. See [Quick start](./getting-started.md#forgot-p
|
|||||||
|
|
||||||
Check the **Referer whitelist** (`ALLOWED_REFERER_HOSTS` or Settings). Referring sites must be listed; PicHost’s own hosts and dual-domain pair are allowed automatically.
|
Check the **Referer whitelist** (`ALLOWED_REFERER_HOSTS` or Settings). Referring sites must be listed; PicHost’s own hosts and dual-domain pair are allowed automatically.
|
||||||
|
|
||||||
|
## Admin 404 / locked out after dual-domain setup?
|
||||||
|
|
||||||
|
**Cause:** With dual-domain enabled, PicHost returns **404 for every request** whose Host is not the configured site or image hostname. Common triggers:
|
||||||
|
|
||||||
|
1. Saving dual-domain URLs while browsing via IP or an internal address
|
||||||
|
2. Reverse proxy “force hostname” or wrong `Host` header so PicHost sees a different host than configured
|
||||||
|
|
||||||
|
**Recovery (when locked out):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost clear-domains
|
||||||
|
# Site URL only: docker exec pichost clear-domains --site
|
||||||
|
```
|
||||||
|
|
||||||
|
Local dev: `npm run clear-domains`. Then reopen admin via your previous IP/internal URL and reconfigure using the [dual-domain guide](./domain-separation.md#middleware-isolation-and-third-hosts).
|
||||||
|
|
||||||
|
**Prevention:** Read the risk confirmation when saving dual-domain settings; proxy must send `Host $host` and `X-Forwarded-Proto`. See [Dual-domain separation](./domain-separation.md#middleware-isolation-and-third-hosts).
|
||||||
|
|
||||||
## Why can admin load on pages.dev / workers.dev / IP with dual-domain?
|
## Why can admin load on pages.dev / workers.dev / IP with dual-domain?
|
||||||
|
|
||||||
**From v1.2.2:** when dual-domain is on, PicHost returns **404** for Host values **other than** the configured site and image hostnames (`localhost` / `127.0.0.1` exempt in development). See [Changelog](./changelog.md#1-2-2-2026-08-30).
|
**From v1.2.2:** when dual-domain is on, PicHost returns **404** for Host values **other than** the configured site and image hostnames (`localhost` / `127.0.0.1` exempt in development). See [Changelog](./changelog.md#1-2-2-2026-08-30).
|
||||||
@@ -43,21 +61,21 @@ Recommended: run PicHost on origin; use **proxied DNS** (and optional **R2** sto
|
|||||||
- Always open admin on the **site hostname**, not mixed with `localhost`
|
- Always open admin on the **site hostname**, not mixed with `localhost`
|
||||||
- See [Dual-domain separation](./domain-separation.md)
|
- See [Dual-domain separation](./domain-separation.md)
|
||||||
|
|
||||||
## Undeletable gallery items after v1.2 upgrade?
|
## Undeletable gallery items?
|
||||||
|
|
||||||
Likely **orphan index** rows (no file on disk). Startup sync removes them on restart. See [v1.2 migration](./migration.md#step-2-startup-index-sync-automatic).
|
Likely **orphan index** rows (no file on disk). Startup sync removes them on restart; you can also delete them from the gallery.
|
||||||
|
|
||||||
## Do I still need `data/blog/` after migration?
|
## How do I back up or migrate the full site?
|
||||||
|
|
||||||
After `migrate --apply`, files live under `data/images/blog/`. Remove leftover empty dirs after backup if you like; dirs with non-image files are kept by the CLI.
|
From v1.3.0, use **Storage → Backup & migration**, or CLI:
|
||||||
|
|
||||||
## Object storage only — run migrate?
|
```bash
|
||||||
|
docker exec pichost backup-export
|
||||||
|
docker exec pichost backup-restore /data/backups/pichost-xxx.phost.tar.gz
|
||||||
|
docker exec pichost storage-sync --from local --to s3-xxx --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
No. Skip the CLI; startup sync focuses on local `data/images/` scanning.
|
Packages include the database and all images but **not** cloud storage secrets — re-enter them on the Storage page after restore. See [Storage → Backup & migration](./storage.md#backup--migration-v130).
|
||||||
|
|
||||||
## Replace old image URLs in posts?
|
|
||||||
|
|
||||||
Use `data/mapping.json` from `migrate` preview. Keys are **storage paths**, not full legacy URLs. See [Migration](./migration.md#urls).
|
|
||||||
|
|
||||||
## Skip login during development?
|
## Skip login during development?
|
||||||
|
|
||||||
|
|||||||
@@ -33,17 +33,37 @@ See `docker-compose.yml` in the repository.
|
|||||||
## First-time setup
|
## First-time setup
|
||||||
|
|
||||||
1. Open your instance URL (Docker default `http://<host>:6892`).
|
1. Open your instance URL (Docker default `http://<host>:6892`).
|
||||||
2. Complete `/setup` with admin username and password.
|
2. On `/setup`, choose **Create admin** or **Restore backup**:
|
||||||
|
- **Create admin** — username, password, optional registration and dual-domain options.
|
||||||
|
- **Restore backup** — upload a `.phost.tar.gz` full-site package (replaces current data; re-enter cloud storage secrets after restore).
|
||||||
3. (Optional) Configure site URL, image URL, Referer rules — see [Environment variables](./configuration.md) and [Dual-domain separation](./domain-separation.md).
|
3. (Optional) Configure site URL, image URL, Referer rules — see [Environment variables](./configuration.md) and [Dual-domain separation](./domain-separation.md).
|
||||||
4. Upload from the home page; admins can open **Storage**, **Settings**, and **API**.
|
4. Upload from the home page; use the top nav for **Gallery**, **Storage** (admin), **Settings**, and **API**.
|
||||||
|
|
||||||
|
| Create admin | Restore from backup |
|
||||||
|
| :----------: | :-----------------: |
|
||||||
|
|  |  |
|
||||||
|
|
||||||
|
For an already-initialized instance, use [Storage → Backup & migration](./storage.md#backup--migration-v130) instead of `/setup`.
|
||||||
|
|
||||||
## Sign in
|
## Sign in
|
||||||
|
|
||||||
Management pages (upload, stats, settings, etc.) require login. Enter username and password, **drag the slider to align with the gap**, then click **Sign in**.
|
Management pages (upload, gallery, settings, etc.) require login. Enter username and password, complete the verification challenge, then click **Sign in**.
|
||||||
|
|
||||||
|
The default is a **local slider** (align the thumb with the gap). Admins can switch to **Cloudflare Turnstile** or **Cap** under **Settings → Access control**, with the matching site key / secret or API endpoint.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
If registration is enabled, create an account from the register page. Legacy deployments may still use a secret key (see the on-screen hint).
|
If registration is enabled, create an account from the register page (same verification). Legacy deployments may still use a secret key (see the on-screen hint).
|
||||||
|
|
||||||
|
### Locked out of verification
|
||||||
|
|
||||||
|
If Turnstile / Cap is misconfigured and you cannot sign in, reset to the local slider on the server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost slider
|
||||||
|
```
|
||||||
|
|
||||||
|
Local dev: `npm run slider`
|
||||||
|
|
||||||
## Forgot password
|
## Forgot password
|
||||||
|
|
||||||
@@ -58,11 +78,15 @@ A random password is printed. Change it after login.
|
|||||||
|
|
||||||
Local dev: `npm run reset-password` or `npm run reset-password -- <username>`
|
Local dev: `npm run reset-password` or `npm run reset-password -- <username>`
|
||||||
|
|
||||||
## Upgrading to v1.2.0
|
## Dual-domain lockout
|
||||||
|
|
||||||
If `data/` has legacy top-level folders next to `images` (e.g. `blog/`, `twikoo/`), read the [v1.2 migration guide](./migration.md) first.
|
If dual-domain is enabled and IP / LAN access returns 404:
|
||||||
|
|
||||||
Object-storage-only or files already under `data/images/` — pull the new image and restart.
|
```bash
|
||||||
|
docker exec pichost clear-domains
|
||||||
|
```
|
||||||
|
|
||||||
|
Local: `npm run clear-domains`. See [FAQ — Admin 404 after dual-domain setup](./faq.md#admin-404--locked-out-after-dual-domain-setup).
|
||||||
|
|
||||||
## Next steps
|
## Next steps
|
||||||
|
|
||||||
|
|||||||
@@ -12,20 +12,20 @@ Welcome to the PicHost user guide. This site is the single source of truth; the
|
|||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
**main** has no public demo. Below are v1.2.0 product screenshots.
|
**main** has no public demo. Below are current product screenshots (v1.3.0+).
|
||||||
|
|
||||||
| First-time setup | Login |
|
| API | Gallery (detail) |
|
||||||
| :--------------: | :---: |
|
| :-: | :--------------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| API | Stats & gallery |
|
|
||||||
| :-: | :-------------: |
|
|
||||||
|  |  |
|
|
||||||
|
|
||||||
| Storage | Settings |
|
| Storage | Settings |
|
||||||
| :-----: | :------: |
|
| :-----: | :-------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
|
| First-time setup | Restore from backup |
|
||||||
|
| :--------------: | :-----------------: |
|
||||||
|
|  |  |
|
||||||
|
|
||||||
| Activity log |
|
| Activity log |
|
||||||
| :----------: |
|
| :----------: |
|
||||||
|  |
|
|  |
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ Open `http://localhost:3000/setup` to create the admin account. Data directory d
|
|||||||
| `npm run typecheck` | Type check |
|
| `npm run typecheck` | Type check |
|
||||||
| `npm test` | Unit tests |
|
| `npm test` | Unit tests |
|
||||||
| `npm run reset-password` | Reset password (optional username) |
|
| `npm run reset-password` | Reset password (optional username) |
|
||||||
| `npm run migrate` | Preview legacy dir migration (`-- --apply` to run) |
|
| `npm run slider` | Reset login verification to local slider |
|
||||||
|
| `npm run clear-domains` | Clear site/image URL settings from DB (recover from dual-domain lockout) |
|
||||||
|
|
||||||
## Dev-only variables
|
## Dev-only variables
|
||||||
|
|
||||||
@@ -51,4 +52,4 @@ npm run docs:build
|
|||||||
npm run docs:preview
|
npm run docs:preview
|
||||||
```
|
```
|
||||||
|
|
||||||
Sources live in `docs-site/`; screenshot sources are in `docs/screenshots/` (including `login.png`), copied to `docs-site/public/screenshots/` before build. Live docs: <https://o96u.github.io/PicHost/>
|
Sources live in `docs-site/`; screenshot sources are in `docs/screenshots/` (including `login.png`, `setup.png`, `setup-restore.png`, etc.), copied to `docs-site/public/screenshots/` before build. Live docs: <https://o96u.github.io/PicHost/>
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
# v1.2.0 local disk migration guide
|
|
||||||
|
|
||||||
From v1.2.0, **all local image files** live under `data/images/`; SQLite `keys` also start with `images/`. Legacy top-level folders next to `images` (e.g. `data/blog/`, `data/twikoo/`) are no longer used.
|
|
||||||
|
|
||||||
Migration is **two steps**: run the **CLI** to move files on disk, then let **startup sync** align the SQLite index.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Migrating from other image hosts (EasyImage, Lsky, Chevereto, …)
|
|
||||||
|
|
||||||
There is **no** dedicated “pull from URLs” or “import via vendor API” tool. Moving from **legacy PicHost** or **another self-hosted** install uses the same **local file** workflow:
|
|
||||||
|
|
||||||
1. Locate the **image files** on the old server (copy the tree, not just the database).
|
|
||||||
2. Place them under PicHost `data/` as a **top-level folder** next to `images` (any name — it becomes `images/{name}/...`).
|
|
||||||
3. Run `migrate` / `migrate --apply`, then restart PicHost.
|
|
||||||
|
|
||||||
| Source | Typical path on old server | After copy into PicHost |
|
|
||||||
| ------ | -------------------------- | ----------------------- |
|
|
||||||
| PicHost v1.1.x | `data/blog/`, `data/twikoo/` | Already under `data/` → run `migrate` |
|
|
||||||
| EasyImage(s) | `i/` or `upload/` | e.g. `data/easyimage/` → `migrate` |
|
|
||||||
| Lsky | `public/uploads/` etc. | e.g. `data/lsky/` → `migrate` |
|
|
||||||
| Chevereto etc. | `images/` or `content/` | e.g. `data/chevereto/` → `migrate` |
|
|
||||||
| Custom | your folder name | `data/your-folder/` → `migrate` |
|
|
||||||
|
|
||||||
The CLI scans **every top-level directory under `data/` except `images`**, not only `blog` / `twikoo`.
|
|
||||||
|
|
||||||
**Limits:** files only — accounts, tokens, and old public URLs are not imported. `mapping.json` maps old **storage keys**, not full old-site URLs. For S3/R2-only legacy hosts, sync blobs to `data/…` or attach the bucket in PicHost **Storage** settings.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Layout before and after
|
|
||||||
|
|
||||||
### Before (typical v1.1.x)
|
|
||||||
|
|
||||||
```
|
|
||||||
/data
|
|
||||||
├── pichost.db
|
|
||||||
├── blog/
|
|
||||||
│ └── 2026/08/TeKJ2fD6cB6j.webp
|
|
||||||
├── twikoo/
|
|
||||||
└── images/
|
|
||||||
```
|
|
||||||
|
|
||||||
Index keys might look like `blog/2026/08/TeKJ2fD6cB6j.webp`.
|
|
||||||
|
|
||||||
### After (v1.2.0)
|
|
||||||
|
|
||||||
```
|
|
||||||
/data
|
|
||||||
├── pichost.db
|
|
||||||
├── mapping.json
|
|
||||||
└── images/
|
|
||||||
├── blog/
|
|
||||||
│ └── 2026/08/TeKJ2fD6cB6j.webp
|
|
||||||
└── twikoo/
|
|
||||||
```
|
|
||||||
|
|
||||||
Index key: `images/blog/2026/08/TeKJ2fD6cB6j.webp`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 1: CLI file migration
|
|
||||||
|
|
||||||
Run **before or after** upgrading the image; backup `data/` first.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker exec pichost migrate # preview + mapping.json
|
|
||||||
docker exec pichost migrate --apply # move files
|
|
||||||
```
|
|
||||||
|
|
||||||
Local: `npm run migrate` / `npm run migrate -- --apply`.
|
|
||||||
|
|
||||||
| Item | Behavior |
|
|
||||||
| ---- | -------- |
|
|
||||||
| Scan | Every top-level directory under `data/` **except `images`** |
|
|
||||||
| Target | `data/images/{original-top-dir}/{relative-path}` |
|
|
||||||
| Extensions | jpg, jpeg, png, webp, gif, svg, ico |
|
|
||||||
| Sidecar | `.meta.json` next to an image is moved if present |
|
|
||||||
| Other files | Not moved; parent directory kept if anything remains |
|
|
||||||
| Mapping | `data/mapping.json` — old key → new key |
|
|
||||||
|
|
||||||
Script: `server/cli/migrate-to-single-images.mjs`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Step 2: Startup index sync (automatic)
|
|
||||||
|
|
||||||
Runs on every start (`npm run dev`, Docker). No manual command.
|
|
||||||
|
|
||||||
```text
|
|
||||||
[INFO] 开始同步图片索引:扫描本地磁盘 ...
|
|
||||||
[INFO] 磁盘扫描完成:...
|
|
||||||
[INFO] 开始归一化遗留图片路径 ...
|
|
||||||
[INFO] 开始校验索引与磁盘一致性,清理无文件的孤儿记录
|
|
||||||
[INFO] 图片索引同步结束
|
|
||||||
```
|
|
||||||
|
|
||||||
| Step | Purpose |
|
|
||||||
| ---- | ------- |
|
|
||||||
| Scan `data/images/` | Insert missing index rows for files on disk |
|
|
||||||
| Normalize legacy keys | `blog/...` → `images/blog/...` when files are in place |
|
|
||||||
| Purge orphans | Remove index rows with no file on disk |
|
|
||||||
| Repair Content-Type | Fix `application/octet-stream` entries |
|
|
||||||
|
|
||||||
The CLI only **moves files**. Index alignment runs at startup — **restart** after `migrate --apply`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Recommended upgrade flow
|
|
||||||
|
|
||||||
1. Backup `data/`.
|
|
||||||
2. `docker exec pichost migrate` — review output and `mapping.json`.
|
|
||||||
3. `docker exec pichost migrate --apply`.
|
|
||||||
4. Deploy v1.2.0 and restart.
|
|
||||||
5. Check logs for successful index sync.
|
|
||||||
6. Use `mapping.json` to update external URLs if needed.
|
|
||||||
|
|
||||||
Skip step 1 if you only use object storage or everything is already under `data/images/`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## URLs
|
|
||||||
|
|
||||||
| Old key | `blog/TeKJ2fD6cB6j.webp` |
|
|
||||||
| New key | `images/blog/TeKJ2fD6cB6j.webp` |
|
|
||||||
|
|
||||||
With “hide folder” mode, short URLs like `/TeKJ2fD6cB6j.webp` may still resolve by filename. Use `mapping.json` for bulk replacements.
|
|
||||||
|
|
||||||
Chinese version: [v1.2 迁移指南](/guide/migration)
|
|
||||||
@@ -57,12 +57,14 @@ See [Cloudflare deployment](./cloudflare-deployment.md).
|
|||||||
|
|
||||||
## Origin hardening (dual-domain)
|
## Origin hardening (dual-domain)
|
||||||
|
|
||||||
PicHost middleware does **not** reject unlisted Host values. Complement with:
|
Complement PicHost middleware with:
|
||||||
|
|
||||||
1. **`server_name` allowlist** — site + image hosts only; `default_server` blocks bare IP and unknown Host
|
1. **`server_name` allowlist** — site + image hosts only; `default_server` blocks bare IP and unknown Host
|
||||||
2. **Do not expose 6892 on the public Internet** — only local reverse proxy; public 80/443 only
|
2. **Do not expose 6892 on the public Internet** — only local reverse proxy; public 80/443 only
|
||||||
3. **Orange cloud** — origin firewall limited to Cloudflare IP ranges
|
3. **Orange cloud** — origin firewall limited to Cloudflare IP ranges
|
||||||
|
|
||||||
|
**From v1.2.2**, when dual-domain is active PicHost also returns **404 at the app layer** for Host values other than the configured site and image names (complementing, not replacing, a default server block). If misconfiguration locks you out, run `docker exec pichost clear-domains` — see [FAQ](./faq.md#admin-404--locked-out-after-dual-domain-setup).
|
||||||
|
|
||||||
## Caddy
|
## Caddy
|
||||||
|
|
||||||
```caddy
|
```caddy
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Storage
|
# Storage
|
||||||
|
|
||||||
PicHost supports **local disk** and **S3-compatible object storage** (Cloudflare R2, Tencent COS, Alibaba OSS, AWS S3, etc.). Admins manage backends at **Storage** (`/storage`); new uploads go to the **default** backend.
|
PicHost supports **local disk** and **S3-compatible object storage** (Cloudflare R2, Tencent COS, Alibaba OSS, AWS S3, etc.). Admins manage backends at **Storage** (`/storage`); new uploads go to the **default** backend. The page shows a **storage overview** (total, used, remaining, usage rate, capacity chart) plus per-backend cards and supported backend types.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -25,6 +25,8 @@ All **keys** start with `images/`. The upload API does **not** accept a `folder`
|
|||||||
3. Enter connection details (bucket, endpoint, keys).
|
3. Enter connection details (bucket, endpoint, keys).
|
||||||
4. **Set as default** so new uploads use it.
|
4. **Set as default** so new uploads use it.
|
||||||
|
|
||||||
|
New object-storage backends get an auto-generated **storage ID** prefix: `local` for disk; `r2-*` for R2; `cos-*` for COS; `oss-*` for OSS; `s3-*` for AWS S3 and custom S3-compatible endpoints (immutable after creation; the image index references this ID).
|
||||||
|
|
||||||
### Cloudflare R2
|
### Cloudflare R2
|
||||||
|
|
||||||
| Field | Value |
|
| Field | Value |
|
||||||
@@ -52,13 +54,48 @@ Copied links use **IMAGE_BASE_URL**. “Hide folder prefix” may shorten URLs;
|
|||||||
## Usage & gallery filter
|
## Usage & gallery filter
|
||||||
|
|
||||||
- Per-backend usage on the Storage page
|
- Per-backend usage on the Storage page
|
||||||
- Gallery filter by backend (admin)
|
- Gallery filters by **storage backend** and **upload source**; grid/list view toggle; click a thumbnail for the detail modal (dimensions, storage path, link formats)
|
||||||
|
|
||||||
## Backup
|
## Backup & migration (v1.3.0+)
|
||||||
|
|
||||||
Back up `data/images/`, `data/pichost.db`, and bucket objects.
|
The **Backup & migration** panel has three action cards and a paginated **Recent jobs** table below:
|
||||||
|
|
||||||
Upgrading from v1.1.x with parallel folders: [v1.2 migration](./migration.md).
|
| Feature | Description |
|
||||||
|
| ------- | ------------- |
|
||||||
|
| **Create site backup** | Export `.phost.tar.gz` with `pichost.db` and all images (including objects on cloud backends); shows estimated size and package contents |
|
||||||
|
| **Restore from backup** | Upload locally or pick an existing package under `data/backups/`, preview, then confirm; skip or overwrite conflicting images |
|
||||||
|
| **Cross-backend sync** | Copy images between configured backends and update the index; shows pending count/size, dry-run, optional delete-source and set-default |
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Exports are saved under `data/backups/`; only one backup/migration job may run at a time
|
||||||
|
- Job list supports pagination; download exports, view restore summaries, retry failed sync jobs
|
||||||
|
- Packages **do not** include cloud storage secrets — re-enter them on the Storage page after restore
|
||||||
|
- Uninitialized instances can use the **Restore backup** tab on `/setup` (always overwrite mode)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### CLI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost backup-export
|
||||||
|
docker exec pichost backup-restore /data/backups/pichost-xxx.phost.tar.gz
|
||||||
|
docker exec pichost backup-restore /data/backups/pichost-xxx.phost.tar.gz --overwrite
|
||||||
|
docker exec pichost storage-sync --from local --to s3-xxx --dry-run
|
||||||
|
docker exec pichost storage-sync --from local --to s3-xxx --set-default
|
||||||
|
```
|
||||||
|
|
||||||
|
Local development (project root):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run backup-export
|
||||||
|
npm run backup-restore -- data/backups/pichost-xxx.phost.tar.gz
|
||||||
|
npm run storage-sync -- --from local --to s3-xxx --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual backup
|
||||||
|
|
||||||
|
You can still back up `data/images/`, `data/pichost.db`, and bucket objects directly; prefer the full-site export above.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ PicHost uses role-based access control (RBAC): **admin** and **user**. Enforceme
|
|||||||
| Storage management (`/storage`) | ✓ | — |
|
| Storage management (`/storage`) | ✓ | — |
|
||||||
| System settings (`/settings`) | ✓ | — |
|
| System settings (`/settings`) | ✓ | — |
|
||||||
| Allow registration | ✓ | — |
|
| Allow registration | ✓ | — |
|
||||||
|
| Login verification (slider / Turnstile / Cap) | ✓ | — |
|
||||||
| Global API token | ✓ | — |
|
| Global API token | ✓ | — |
|
||||||
| Personal API token | ✓ | ✓ |
|
| Personal API token | ✓ | ✓ |
|
||||||
| Stats (incl. user count) | ✓ | partial |
|
| Gallery stats overview (incl. user count) | ✓ | partial |
|
||||||
| Activity log | ✓ | — |
|
| Activity log (Settings → Activity log) | ✓ | — |
|
||||||
|
|
||||||
Regular users see **API**, **Stats** in the nav; user menu: **Change password**, **Sign out**.
|
Regular users see **API**, **Gallery** in the nav; user menu: **Change password**, **Sign out**.
|
||||||
|
|
||||||
## Auth scenarios
|
## Auth scenarios
|
||||||
|
|
||||||
@@ -34,12 +35,13 @@ Regular users see **API**, **Stats** in the nav; user menu: **Change password**,
|
|||||||
|
|
||||||
- By default only admins create users; **allow registration** is an admin setting
|
- By default only admins create users; **allow registration** is an admin setting
|
||||||
- Passwords hashed with scrypt
|
- Passwords hashed with scrypt
|
||||||
- Web login requires a slider captcha (align the thumb with the gap)
|
- Web login/register requires verification: local slider by default; admins can switch to Turnstile or Cap under **Settings → Access control**
|
||||||
|
- If verification is misconfigured: `docker exec pichost slider` resets to the local slider
|
||||||
- Login rate limiting
|
- Login rate limiting
|
||||||
|
|
||||||
## Upload preferences & auto-delete
|
## Upload preferences & auto-delete
|
||||||
|
|
||||||
- **Upload preferences** (home card flip): client compression, auto-copy links, per user
|
- **Upload preferences**: admins configure client compression and auto-copy in **Settings → Basic**; regular users can flip the home upload card for personal preferences
|
||||||
- **Auto-delete**: global (admin) and per-user policies; affects **new uploads after enable** only
|
- **Auto-delete**: global (admin) and per-user policies; affects **new uploads after enable** only
|
||||||
|
|
||||||
## API tokens
|
## API tokens
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# API
|
# API
|
||||||
|
|
||||||
PicHost 提供 REST 接口与 Twikoo 兼容端点。部署后登录 **API** 页可查看当前 Token 与可复制 cURL 示例。
|
PicHost 提供 REST 接口与 Twikoo 兼容端点。登录后打开顶栏 **API** 页:左侧为接口目录与 Token 管理,中间为参数说明与 cURL 示例,右侧可 **在线调试** 发送请求。
|
||||||
|
|
||||||
## 鉴权
|
## 鉴权
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,61 @@ PicHost 版本历史与重要变更说明。完整记录亦见仓库根目录 [C
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.2.8] — 2026-09-04
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- **双域名**:保存 / 初始化时弹出风险确认(含锁死说明与 `clear-domains` 恢复方式),不再强制校验当前 Host
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- **运维 CLI**:`clear-domains` 清除数据库域名配置(`docker exec pichost clear-domains`)
|
||||||
|
|
||||||
|
### 文档
|
||||||
|
|
||||||
|
- FAQ 与双域名、反代文档补充恢复步骤
|
||||||
|
|
||||||
|
## [1.2.7] — 2026-09-03
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- **登录验证**:登录/注册支持本地滑块、Cloudflare Turnstile、Cap;在「设置 → 访问控制」配置
|
||||||
|
- **运维 CLI**:`slider` 将验证方式重置为本地滑块(`docker exec pichost slider`)
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- 登出后登录页验证码可正常重新加载
|
||||||
|
|
||||||
|
## [1.2.6] — 2026-09-01
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- **管理界面**:设置、API、图库、存储页 UI 重构;API 页支持在线调试
|
||||||
|
- **图库筛选**:按存储后端筛选
|
||||||
|
- **存储标识**:新建 R2 / COS / OSS / S3 后端按类型生成 `r2-*`、`cos-*`、`oss-*`、`s3-*` 前缀
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- 操作日志表格样式与路径截断
|
||||||
|
- 存储后端卡片信息行布局
|
||||||
|
- 文档站与 README 截图更新
|
||||||
|
|
||||||
|
## [1.2.5] — 2026-08-31
|
||||||
|
|
||||||
|
### 新增
|
||||||
|
|
||||||
|
- **图库页**:导航「统计」改为「图库」(`/gallery`);点击图片打开详情弹层(大图、尺寸、上传方式、存储路径、链接复制)
|
||||||
|
- **列表操作**:全选 / 反选;单张删除移至详情弹层
|
||||||
|
- **上传来源**:图库 API 返回网页 / API 上传方式(来自活动日志)
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
|
||||||
|
- README 补充技术栈章节
|
||||||
|
|
||||||
|
### 移除
|
||||||
|
|
||||||
|
- `/stats` 路由(不再保留兼容跳转)
|
||||||
|
|
||||||
## [1.2.4] — 2026-08-31
|
## [1.2.4] — 2026-08-31
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
@@ -104,15 +159,12 @@ PicHost 版本历史与重要变更说明。完整记录亦见仓库根目录 [C
|
|||||||
|
|
||||||
### 变更
|
### 变更
|
||||||
|
|
||||||
- 图片统一存放在 `data/images/`;遗留 `blog/`、`twikoo/` 等并列目录需迁移
|
- 图片统一存放在 `data/images/`;不再使用与 `images` 并列的顶层目录
|
||||||
|
|
||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- CLI:`docker exec pichost migrate` / `migrate --apply`
|
|
||||||
- 启动时自动同步图片索引(扫描磁盘、归一化遗留 key、清理孤儿记录)
|
- 启动时自动同步图片索引(扫描磁盘、归一化遗留 key、清理孤儿记录)
|
||||||
|
|
||||||
详见 [v1.2 迁移](./migration.md)。
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## [1.1.x] 摘要
|
## [1.1.x] 摘要
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
# 环境变量
|
PicHost 支持通过环境变量(Docker / `.env`)与后台 **设置** 页配置。管理员在 **设置与偏好**(`/settings`)左侧切换 **基础设置**、**域名与路径**、**访问控制**、**操作日志**;多数项 **SQLite 优先**;部分项环境变量可覆盖或锁定后台编辑。
|
||||||
|
|
||||||
PicHost 支持通过环境变量(Docker / `.env`)与后台 **设置** 页配置。多数项 **SQLite 优先**;部分项环境变量可覆盖或锁定后台编辑。
|
|
||||||
|
|
||||||
## 优先级总览
|
## 优先级总览
|
||||||
|
|
||||||
@@ -13,6 +11,7 @@ PicHost 支持通过环境变量(Docker / `.env`)与后台 **设置** 页配
|
|||||||
| 简短图片链接 | SQLite → 环境变量 → 默认 false | 否 |
|
| 简短图片链接 | SQLite → 环境变量 → 默认 false | 否 |
|
||||||
| 按年/月分组存储 | SQLite → 环境变量 → 默认 true | 否 |
|
| 按年/月分组存储 | SQLite → 环境变量 → 默认 true | 否 |
|
||||||
| 全局自动删除天数 | SQLite → 环境变量 → 默认 0 | 否 |
|
| 全局自动删除天数 | SQLite → 环境变量 → 默认 0 | 否 |
|
||||||
|
| 登录人机验证 | SQLite(设置 → 访问控制) | 否 |
|
||||||
|
|
||||||
## 变量说明
|
## 变量说明
|
||||||
|
|
||||||
@@ -64,6 +63,18 @@ PicHost 支持通过环境变量(Docker / `.env`)与后台 **设置** 页配
|
|||||||
|
|
||||||
仅本地开发:`true` 绕过登录验证。生产环境勿用。
|
仅本地开发:`true` 绕过登录验证。生产环境勿用。
|
||||||
|
|
||||||
|
### 登录人机验证(仅后台设置)
|
||||||
|
|
||||||
|
在 **设置 → 访问控制** 配置,存入 SQLite,无对应环境变量:
|
||||||
|
|
||||||
|
| 方式 | 说明 |
|
||||||
|
| ---- | ---- |
|
||||||
|
| **本地滑块**(默认) | 无需第三方服务 |
|
||||||
|
| **Cloudflare Turnstile** | 填写 Site Key 与 Secret Key |
|
||||||
|
| **Cap** | 填写 API Endpoint 与 Secret |
|
||||||
|
|
||||||
|
登录与注册共用同一验证方式。若第三方配置错误导致无法登录,执行 `docker exec pichost slider`(或 `npm run slider`)恢复为本地滑块。
|
||||||
|
|
||||||
### 存储后端(可选)
|
### 存储后端(可选)
|
||||||
|
|
||||||
管理员通常在 **存储** 页添加后端;也可用环境变量引导(如 `STORAGE_BACKEND=s3` 与 `S3_*`)。详见 [存储](./storage.md)。
|
管理员通常在 **存储** 页添加后端;也可用环境变量引导(如 `STORAGE_BACKEND=s3` 与 `S3_*`)。详见 [存储](./storage.md)。
|
||||||
@@ -99,5 +110,6 @@ services:
|
|||||||
| 按年/月分组 | `STORAGE_USE_DATE_PATH` / `STORAGE_LAYOUT` |
|
| 按年/月分组 | `STORAGE_USE_DATE_PATH` / `STORAGE_LAYOUT` |
|
||||||
| WebP 质量 | `WEBP_QUALITY` |
|
| WebP 质量 | `WEBP_QUALITY` |
|
||||||
| 自动删除 | `AUTO_DELETE_DAYS` |
|
| 自动删除 | `AUTO_DELETE_DAYS` |
|
||||||
|
| 登录验证 | (仅后台 **设置 → 访问控制**) |
|
||||||
|
|
||||||
完整模板见仓库根目录 [`.env.example`](https://github.com/O96u/PicHost/blob/main/.env.example)。
|
完整模板见仓库根目录 [`.env.example`](https://github.com/O96u/PicHost/blob/main/.env.example)。
|
||||||
@@ -72,10 +72,21 @@ PicHost 根据请求 **Host**(反代会转发为 `X-Forwarded-Host`,应用
|
|||||||
|
|
||||||
1. 反代层仅为网站域、图片域配置 `server_name`,并增加 **default server** 拒绝其它 Host 与裸 IP(见上方 Nginx 示例,与应用层拦截互补)
|
1. 反代层仅为网站域、图片域配置 `server_name`,并增加 **default server** 拒绝其它 Host 与裸 IP(见上方 Nginx 示例,与应用层拦截互补)
|
||||||
2. 使用 Cloudflare **橙云** 时,源站防火墙 **仅放行 [Cloudflare IP 段](https://www.cloudflare.com/ips/)**,避免绕过 CDN 直连源站
|
2. 使用 Cloudflare **橙云** 时,源站防火墙 **仅放行 [Cloudflare IP 段](https://www.cloudflare.com/ips/)**,避免绕过 CDN 直连源站
|
||||||
3. **仅使用** 设置中的网站域名登录后台,不要用 `localhost`、IP 或未配置的域名混用
|
3. **保存前**阅读设置 / 初始化页的风险确认;若通过 IP、内网或未正确传递 Host 的反代保存,可能锁死后台;恢复见下方「已锁死时的恢复」
|
||||||
4. **不要** 用 Cloudflare Pages / Workers 对 PicHost **整站反代**(会多出 `pages.dev` / `workers.dev` 等第三入口;`IMAGE_BASE_URL` 可填 CDN 公网地址,但应用本体应 Docker/VPS 部署)
|
4. **仅使用** 设置中的网站域名登录后台,不要用 `localhost`、IP 或未配置的域名混用
|
||||||
5. 若必须在边缘做反代,须保留客户端 **`Host` 或 `X-Forwarded-Host`**,否则 Host 隔离会失效
|
5. **不要** 用 Cloudflare Pages / Workers 对 PicHost **整站反代**(会多出 `pages.dev` / `workers.dev` 等第三入口;`IMAGE_BASE_URL` 可填 CDN 公网地址,但应用本体应 Docker/VPS 部署)
|
||||||
6. PicHost **不能** 作为 Node 应用直接部署到 Pages/Workers(依赖 `node-server`、SQLite、`sharp` 与本地 `data/`);应用请继续 Docker/VPS 部署,CF 侧用橙云 DNS + 可选 R2 存储即可
|
6. 若必须在边缘做反代,须保留客户端 **`Host` 或 `X-Forwarded-Host`**(Lucky/NPM「强制域名」须与 PicHost 配置一致),否则 Host 隔离会失效或保存后被锁死
|
||||||
|
7. PicHost **不能** 作为 Node 应用直接部署到 Pages/Workers(依赖 `node-server`、SQLite、`sharp` 与本地 `data/`);应用请继续 Docker/VPS 部署,CF 侧用橙云 DNS + 可选 R2 存储即可
|
||||||
|
|
||||||
|
### 已锁死时的恢复
|
||||||
|
|
||||||
|
若已误保存导致 IP / 内网地址全站 404:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost clear-domains
|
||||||
|
```
|
||||||
|
|
||||||
|
本地:`npm run clear-domains`。清除后请用网站域名重新配置,并确认反代 `Host` 头正确。
|
||||||
|
|
||||||
### Cloudflare 橙云(含 DNS 优选)
|
### Cloudflare 橙云(含 DNS 优选)
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,24 @@ docker exec pichost reset-password 用户名
|
|||||||
|
|
||||||
检查 **防盗链白名单**(`ALLOWED_REFERER_HOSTS` 或设置页)。引用图片的站点域名需在白名单中;PicHost 自身域名与双域名场景下的网站域、图片域会自动放行。
|
检查 **防盗链白名单**(`ALLOWED_REFERER_HOSTS` 或设置页)。引用图片的站点域名需在白名单中;PicHost 自身域名与双域名场景下的网站域、图片域会自动放行。
|
||||||
|
|
||||||
|
## 双域名配置后后台 404 / 进不去?
|
||||||
|
|
||||||
|
**原因:** 启用双域名后,PicHost 会对**未配置的网站域、图片域之外**的 Host 全站返回 404。常见触发方式:
|
||||||
|
|
||||||
|
1. 通过 IP 或内网地址打开设置,保存了公网网站域 / 图片域
|
||||||
|
2. 反代「强制域名」或 Host 头配置错误,PicHost 收到的 Host 与设置中的网站域不一致
|
||||||
|
|
||||||
|
**恢复(已锁死时):**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost clear-domains
|
||||||
|
# 仅清除网站域:docker exec pichost clear-domains --site
|
||||||
|
```
|
||||||
|
|
||||||
|
本地开发:`npm run clear-domains`。执行后用原来的 IP / 内网地址刷新即可重新进入后台,再按文档正确配置双域名。
|
||||||
|
|
||||||
|
**预防:** 保存双域名时注意确认框中的风险提示;反代须 `proxy_set_header Host $host;` 并保留 `X-Forwarded-Proto`。详见 [双域名分离](./domain-separation.md#中间件隔离与第三-host)。
|
||||||
|
|
||||||
## 双域名下为什么用 pages.dev / workers.dev / IP 也能进后台?
|
## 双域名下为什么用 pages.dev / workers.dev / IP 也能进后台?
|
||||||
|
|
||||||
**v1.2.2 起:** 双域名开启时,PicHost 中间件会对**未配置的网站域、图片域之外**的 Host 返回 **404**(开发环境 `localhost` / `127.0.0.1` 例外)。详见 [更新日志](./changelog.md#1-2-2-2026-08-30)。
|
**v1.2.2 起:** 双域名开启时,PicHost 中间件会对**未配置的网站域、图片域之外**的 Host 返回 **404**(开发环境 `localhost` / `127.0.0.1` 例外)。详见 [更新日志](./changelog.md#1-2-2-2026-08-30)。
|
||||||
@@ -44,21 +62,21 @@ docker exec pichost reset-password 用户名
|
|||||||
- 后台请用 **网站域名** 打开,不要用 `localhost` 混用
|
- 后台请用 **网站域名** 打开,不要用 `localhost` 混用
|
||||||
- 见 [双域名分离](./domain-separation.md)
|
- 见 [双域名分离](./domain-separation.md)
|
||||||
|
|
||||||
## 升级 v1.2 后图库有删不掉的记录?
|
## 图库有删不掉的记录?
|
||||||
|
|
||||||
可能是 **孤儿索引**(有记录无文件)。重启后启动同步会自动清理;也可手动删除仅索引项。见 [v1.2 迁移](./migration.md#第二步启动时自动同步索引)。
|
可能是 **孤儿索引**(有记录无文件)。重启后启动同步会自动清理;也可在图库中手动删除。
|
||||||
|
|
||||||
## 遗留 `data/blog/` 目录还要吗?
|
## 如何备份与迁移整站?
|
||||||
|
|
||||||
执行 `migrate --apply` 后文件已迁入 `data/images/blog/`。若原目录只剩空壳或非图片文件,可自行备份后删除;迁移脚本不会删除仍含非图片文件的目录。
|
v1.3.0 起在 **存储** 页使用「备份与迁移」面板,或 CLI:
|
||||||
|
|
||||||
## 只用对象存储需要跑 migrate 吗?
|
```bash
|
||||||
|
docker exec pichost backup-export
|
||||||
|
docker exec pichost backup-restore /data/backups/pichost-xxx.phost.tar.gz
|
||||||
|
docker exec pichost storage-sync --from local --to s3-xxx --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
不需要。图片在桶内时跳过 CLI;启动同步主要面向本地 `data/images/` 磁盘扫描。
|
备份包含数据库与全部图片,**不含** 云存储密钥;恢复后请在存储页重新填写。详见 [存储 → 备份与迁移](./storage.md#备份与迁移v130)。
|
||||||
|
|
||||||
## 如何替换博客里的旧图片 URL?
|
|
||||||
|
|
||||||
使用 `data/mapping.json`(`migrate` 预览时生成)批量替换旧 key。注意映射的是 **存储 key**,不是完整旧站 URL。见 [迁移指南](./migration.md#外链与直链)。
|
|
||||||
|
|
||||||
## 开发时如何跳过登录?
|
## 开发时如何跳过登录?
|
||||||
|
|
||||||
|
|||||||
@@ -33,17 +33,37 @@ docker compose up -d
|
|||||||
## 首次设置
|
## 首次设置
|
||||||
|
|
||||||
1. 访问实例 URL(Docker 默认 `http://<主机>:6892`)。
|
1. 访问实例 URL(Docker 默认 `http://<主机>:6892`)。
|
||||||
2. 在 `/setup` 填写管理员用户名与密码。
|
2. 在 `/setup` 选择 **创建管理员** 或 **从备份恢复**:
|
||||||
|
- **创建管理员**:填写用户名与密码,可选开放注册、双域名等。
|
||||||
|
- **从备份恢复**:上传 `.phost.tar.gz` 整站备份包(覆盖当前数据;云存储密钥需恢复后重新填写)。
|
||||||
3. (可选)配置网站域名、图片域名、防盗链等 — 详见 [环境变量](./configuration.md) 与 [双域名分离](./domain-separation.md)。
|
3. (可选)配置网站域名、图片域名、防盗链等 — 详见 [环境变量](./configuration.md) 与 [双域名分离](./domain-separation.md)。
|
||||||
4. 登录后可在首页上传图片;管理员可进入 **存储**、**设置**、**API** 页。
|
4. 登录后可在首页上传图片;顶栏可进入 **图库**、**存储**(管理员)、**设置**、**API**。
|
||||||
|
|
||||||
|
| 创建管理员 | 从备份恢复 |
|
||||||
|
| :--------: | :--------: |
|
||||||
|
|  |  |
|
||||||
|
|
||||||
|
已初始化实例请使用 [存储 → 备份与迁移](./storage.md#备份与迁移v130) 恢复,而非 setup 页。
|
||||||
|
|
||||||
## 登录
|
## 登录
|
||||||
|
|
||||||
访问上传、统计、设置等管理页面前需登录。在登录卡片中填写用户名与密码,**拖动滑块对齐缺口**完成验证后点击 **登录**。
|
访问上传、图库、设置等管理页面前需登录。在登录卡片中填写用户名与密码,完成人机验证后点击 **登录**。
|
||||||
|
|
||||||
|
默认使用**本地滑块**(拖动滑块对齐缺口)。管理员可在 **设置 → 访问控制** 切换为 **Cloudflare Turnstile** 或 **Cap**,并填写对应 Site Key / Secret 或 API 端点。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
若管理员开启了开放注册,可前往注册页创建账号。遗留部署仍可能使用密钥登录(见界面提示)。
|
若管理员开启了开放注册,可前往注册页创建账号(同样需完成人机验证)。遗留部署仍可能使用密钥登录(见界面提示)。
|
||||||
|
|
||||||
|
### 验证方式被锁死时
|
||||||
|
|
||||||
|
若 Turnstile / Cap 配置错误导致无法登录,可在服务器上重置为本地滑块:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec pichost slider
|
||||||
|
```
|
||||||
|
|
||||||
|
本地开发:`npm run slider`
|
||||||
|
|
||||||
## 忘记密码
|
## 忘记密码
|
||||||
|
|
||||||
@@ -61,11 +81,15 @@ docker exec pichost reset-password 用户名
|
|||||||
|
|
||||||
本地开发:`npm run reset-password` 或 `npm run reset-password -- 用户名`
|
本地开发:`npm run reset-password` 或 `npm run reset-password -- 用户名`
|
||||||
|
|
||||||
## 升级到 v1.2.0
|
## 双域名配置锁死
|
||||||
|
|
||||||
若 `data/` 下存在与 `images` 并列的遗留目录(如 `blog/`、`twikoo/`),升级前请阅读 [v1.2 迁移指南](./migration.md)。
|
若启用双域名后通过 IP / 内网地址无法进入后台:
|
||||||
|
|
||||||
仅对象存储、或图片已在 `data/images/` 下时,拉取新镜像并重启即可。
|
```bash
|
||||||
|
docker exec pichost clear-domains
|
||||||
|
```
|
||||||
|
|
||||||
|
本地:`npm run clear-domains`。详见 [常见问题 — 双域名配置后后台 404](./faq.md#双域名配置后后台-404-进不去)。
|
||||||
|
|
||||||
## 下一步
|
## 下一步
|
||||||
|
|
||||||
|
|||||||
@@ -12,19 +12,19 @@
|
|||||||
|
|
||||||
## 截图预览
|
## 截图预览
|
||||||
|
|
||||||
**main** 分支暂无公网演示,以下为 v1.2.0 产品界面。
|
**main** 分支暂无公网演示,以下为当前产品界面(v1.3.0+)。
|
||||||
|
|
||||||
| 首次设置 | 登录 |
|
| API | 图库(详情) |
|
||||||
| :------: | :--: |
|
| :-: | :-: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| API | 统计与图库 |
|
| 存储管理 | 设置与偏好 |
|
||||||
| :-: | :--------: |
|
| :------: | :--------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| 存储管理 | 系统设置 |
|
| 首次设置 | 从备份恢复 |
|
||||||
| :------: | :------: |
|
| :------: | :--------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| 操作日志 |
|
| 操作日志 |
|
||||||
| :------: |
|
| :------: |
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ npm run dev
|
|||||||
| `npm run typecheck` | 类型检查 |
|
| `npm run typecheck` | 类型检查 |
|
||||||
| `npm test` | 单元测试 |
|
| `npm test` | 单元测试 |
|
||||||
| `npm run reset-password` | 重置密码(可选用户名) |
|
| `npm run reset-password` | 重置密码(可选用户名) |
|
||||||
| `npm run migrate` | 预览遗留目录迁移(加 `-- --apply` 执行) |
|
| `npm run slider` | 将登录验证重置为本地滑块 |
|
||||||
|
| `npm run clear-domains` | 清除数据库中的网站域 / 图片域配置(双域名锁死时恢复) |
|
||||||
|
|
||||||
## 开发专用环境变量
|
## 开发专用环境变量
|
||||||
|
|
||||||
@@ -51,4 +52,4 @@ npm run docs:build # 构建静态站点
|
|||||||
npm run docs:preview # 预览构建结果
|
npm run docs:preview # 预览构建结果
|
||||||
```
|
```
|
||||||
|
|
||||||
文档源码在 `docs-site/`;截图源文件在 `docs/screenshots/`(含 `login.png` 登录页),构建前会复制到 `docs-site/public/screenshots/`。在线文档:<https://o96u.github.io/PicHost/>
|
文档源码在 `docs-site/`;截图源文件在 `docs/screenshots/`(含 `login.png`、`setup.png`、`setup-restore.png` 等),构建前会复制到 `docs-site/public/screenshots/`。在线文档:<https://o96u.github.io/PicHost/>
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
# v1.2.0 本地磁盘迁移指南
|
|
||||||
|
|
||||||
v1.2.0 起,**所有本地图片文件**统一放在 `data/images/` 下;SQLite `images` 表中的 `key` 也以 `images/` 开头。旧版在 `data/blog/`、`data/twikoo/` 等与 `images` **并列的顶层目录**不再符合新模型。
|
|
||||||
|
|
||||||
迁移分 **两步**:先用手动 CLI **搬文件**,再由服务 **启动时自动同步索引**。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 从其它图床迁入(EasyImage / 兰空 / Chevereto 等)
|
|
||||||
|
|
||||||
**没有**单独的「一键从外链拉取」或「对接某某图床 API」工具。从 **PicHost 旧版** 或其它自托管图床迁入,走的是同一套 **本地文件迁移**:
|
|
||||||
|
|
||||||
1. 在旧图床服务器上找到图片**物理目录**(整目录拷贝,不要只拷数据库)。
|
|
||||||
2. 把该目录放到 PicHost 的 `data/` 下,作为与 `images` **并列的顶层文件夹**(文件夹名任意,会保留为 `images/{文件夹名}/...`)。
|
|
||||||
3. 执行 `migrate` / `migrate --apply`,再重启 PicHost。
|
|
||||||
|
|
||||||
### 常见来源示例
|
|
||||||
|
|
||||||
| 来源 | 典型图片目录(在旧服务器上) | 放入 PicHost 后示例 |
|
|
||||||
| ---- | ---------------------------- | ------------------- |
|
|
||||||
| PicHost v1.1.x | `data/blog/`、`data/twikoo/` | 已在 `data/` 下,直接 `migrate` |
|
|
||||||
| EasyImage / EasyImages | `i/` 或安装目录下的 `upload/` | 拷到 `data/easyimage/` 再 `migrate` |
|
|
||||||
| 兰空图床 (Lsky) | `public/uploads/` 等 | 拷到 `data/lsky/` 再 `migrate` |
|
|
||||||
| Chevereto 等 | `images/` 或 `content/` | 拷到 `data/chevereto/` 再 `migrate` |
|
|
||||||
| 任意自定义目录 | 你的顶层文件夹名 | 拷到 `data/你的目录名/` 再 `migrate` |
|
|
||||||
|
|
||||||
脚本会扫描 `data/` 下**除 `images` 外所有顶层目录**里的图片,不限于 `blog` / `twikoo`。子目录结构会原样保留在 `images/{顶层名}/` 下。
|
|
||||||
|
|
||||||
### 操作示例(Docker)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 在宿主机:把从旧图床打包的目录放进挂载卷(名称自定)
|
|
||||||
# 例如:./data/easyimage/2026/01/photo.jpg
|
|
||||||
|
|
||||||
docker exec pichost migrate # 预览
|
|
||||||
docker exec pichost migrate --apply
|
|
||||||
# 重启容器 → 启动日志会补全 SQLite 索引
|
|
||||||
```
|
|
||||||
|
|
||||||
### 说明与限制
|
|
||||||
|
|
||||||
- **只迁移文件**:旧图床的账号、Token、外链 URL **不会**自动导入;`mapping.json` 里的 key 是「旧磁盘相对 key → 新 key」,**不是**旧站完整 URL,替换外链需自行对照。
|
|
||||||
- **对象存储**:若旧图床图片在 S3/R2 桶里,请用桶工具同步到本地 `data/某目录/`,或直接在 PicHost **存储**页配置同一桶(不经过本 CLI)。
|
|
||||||
- **已直接在 `data/images/` 下**:无需 `migrate`,重启后启动同步会自动建索引。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 存储结构对比
|
|
||||||
|
|
||||||
### 迁移前(v1.1.x 常见)
|
|
||||||
|
|
||||||
```
|
|
||||||
/data
|
|
||||||
├── pichost.db
|
|
||||||
├── blog/
|
|
||||||
│ └── 2026/08/TeKJ2fD6cB6j.webp
|
|
||||||
├── twikoo/
|
|
||||||
│ └── xxx.webp
|
|
||||||
└── images/ # 可能已有部分新图
|
|
||||||
└── ...
|
|
||||||
```
|
|
||||||
|
|
||||||
SQLite 中 `key` 可能是 `blog/2026/08/TeKJ2fD6cB6j.webp`(与磁盘顶层目录一致)。
|
|
||||||
|
|
||||||
### 迁移后(v1.2.0)
|
|
||||||
|
|
||||||
```
|
|
||||||
/data
|
|
||||||
├── pichost.db
|
|
||||||
├── mapping.json # CLI 生成:旧 key → 新 key(供替换外链)
|
|
||||||
└── images/
|
|
||||||
├── blog/
|
|
||||||
│ └── 2026/08/TeKJ2fD6cB6j.webp
|
|
||||||
├── twikoo/
|
|
||||||
│ └── xxx.webp
|
|
||||||
└── ... # 新上传:images/随机ID.webp 或 images/年/月/随机ID.webp
|
|
||||||
```
|
|
||||||
|
|
||||||
对应 `key`:`images/blog/2026/08/TeKJ2fD6cB6j.webp`。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 第一步:CLI 迁移磁盘文件
|
|
||||||
|
|
||||||
在 **升级镜像之前或之后**均可执行;建议在升级前完成,并先备份整个 `data/` 目录。
|
|
||||||
|
|
||||||
### Docker
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 预览:列出待迁移文件,写入 data/mapping.json(旧 key → 新 key)
|
|
||||||
docker exec pichost migrate
|
|
||||||
|
|
||||||
# 确认无误后执行文件移动
|
|
||||||
docker exec pichost migrate --apply
|
|
||||||
```
|
|
||||||
|
|
||||||
### 本地开发
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run migrate # 预览
|
|
||||||
npm run migrate -- --apply # 执行
|
|
||||||
```
|
|
||||||
|
|
||||||
### 脚本行为
|
|
||||||
|
|
||||||
| 项目 | 说明 |
|
|
||||||
| ---- | ---- |
|
|
||||||
| 扫描范围 | `data/` 下**除 `images` 外所有顶层目录**(不限于 blog/twikoo) |
|
|
||||||
| 迁移目标 | `data/images/{原顶层目录名}/{相对路径}` |
|
|
||||||
| 图片类型 | `.jpg` `.jpeg` `.png` `.webp` `.gif` `.svg` `.ico` |
|
|
||||||
| 伴随文件 | 若存在同名的 `.meta.json` 会一并移动 |
|
|
||||||
| 非图片文件 | 不移动;若目录内仍有其它文件,**保留原目录**不删除 |
|
|
||||||
| 映射表 | `data/mapping.json`,例如 `"blog/foo.webp": "images/blog/foo.webp"` |
|
|
||||||
|
|
||||||
脚本路径:`server/cli/migrate-to-single-images.mjs`。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 第二步:启动时自动同步索引
|
|
||||||
|
|
||||||
每次 PicHost 启动(`npm run dev`、Docker 容器启动)会自动执行,**无需手动命令**。日志示例:
|
|
||||||
|
|
||||||
```text
|
|
||||||
[INFO] 开始同步图片索引:扫描本地磁盘 {"path":".../data/images/"}
|
|
||||||
[INFO] 磁盘扫描完成:已补全缺失索引 {"inserted":3}
|
|
||||||
[INFO] 开始归一化遗留图片路径(如 blog/ → images/blog/)
|
|
||||||
[INFO] 遗留路径归一化完成:无需调整
|
|
||||||
[INFO] 开始校验索引与磁盘一致性,清理无文件的孤儿记录
|
|
||||||
[INFO] 孤儿索引清理完成:未发现孤儿记录
|
|
||||||
[INFO] 开始修复存量 Content-Type 元数据
|
|
||||||
[INFO] Content-Type 修复完成:无需修复
|
|
||||||
[INFO] 图片索引同步结束
|
|
||||||
```
|
|
||||||
|
|
||||||
| 步骤 | 作用 |
|
|
||||||
| ---- | ---- |
|
|
||||||
| 扫描 `data/images/` | 磁盘上有、索引里没有 → **补全** `images` 表 |
|
|
||||||
| 归一化遗留 key | 将 `blog/...` 等旧 key 更新为 `images/blog/...`(文件已在正确路径时) |
|
|
||||||
| 清理孤儿索引 | 索引里有记录、磁盘无文件 → **删除**幽灵记录(避免图库出现删不掉的项) |
|
|
||||||
| 修复 Content-Type | 修正错误的 `application/octet-stream` |
|
|
||||||
|
|
||||||
CLI 只负责**搬文件**;索引对齐、遗留 key、孤儿记录由启动同步处理。执行 `migrate --apply` 后**重启一次**服务即可。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 推荐升级流程
|
|
||||||
|
|
||||||
1. **备份** `data/`(含 `pichost.db` 与各目录)。
|
|
||||||
2. `docker exec pichost migrate` 预览,检查输出与 `mapping.json`。
|
|
||||||
3. `docker exec pichost migrate --apply` 执行迁移。
|
|
||||||
4. 拉取 / 部署 **v1.2.0** 镜像并重启容器。
|
|
||||||
5. 查看启动日志,确认「图片索引同步结束」无报错。
|
|
||||||
6. 用 `mapping.json` 批量替换博客、Twikoo 等外链中的旧路径(若需要)。
|
|
||||||
|
|
||||||
仅使用对象存储、或图片早已全部在 `data/images/` 下时,**跳过第一步**;第二步仍会在启动时运行,通常几秒内完成且无变更日志。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 外链与直链
|
|
||||||
|
|
||||||
| 场景 | 说明 |
|
|
||||||
| ---- | ---- |
|
|
||||||
| 旧 key | `blog/TeKJ2fD6cB6j.webp` |
|
|
||||||
| 新 key | `images/blog/TeKJ2fD6cB6j.webp` |
|
|
||||||
| 隐藏目录模式 | 若开启「隐藏 images 前缀」,短链可能为 `/TeKJ2fD6cB6j.webp`;服务按文件名反查索引 |
|
|
||||||
| 替换建议 | 以 `mapping.json` 为准;或重新在图库复制新链接 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 相关命令
|
|
||||||
|
|
||||||
| 命令 | 说明 |
|
|
||||||
| ---- | ---- |
|
|
||||||
| `docker exec pichost migrate` | 预览磁盘迁移 |
|
|
||||||
| `docker exec pichost migrate --apply` | 执行磁盘迁移 |
|
|
||||||
| `docker exec pichost reset-password` | 重置密码(与迁移无关) |
|
|
||||||
@@ -63,7 +63,7 @@ IMAGE_BASE_URL=https://pic.example.com
|
|||||||
2. **禁止公网暴露 6892** — 仅本机或内网反代访问;公网只开 80/443
|
2. **禁止公网暴露 6892** — 仅本机或内网反代访问;公网只开 80/443
|
||||||
3. **橙云时限制源站来源 IP** — 仅 Cloudflare 回源 IP 段
|
3. **橙云时限制源站来源 IP** — 仅 Cloudflare 回源 IP 段
|
||||||
|
|
||||||
双域名场景下 PicHost **不会** 拒绝未配置的 Host;上述措施由运维层补齐。
|
**v1.2.2 起**,双域名开启时 PicHost 应用层也会对**未配置的网站域、图片域之外**的 Host 全站返回 404(与反代 default server 互补,而非替代)。误配置导致锁死时执行 `docker exec pichost clear-domains` 恢复,见 [常见问题](./faq.md#双域名配置后后台-404-进不去)。
|
||||||
|
|
||||||
## Caddy 示例
|
## Caddy 示例
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 存储
|
# 存储
|
||||||
|
|
||||||
PicHost 支持 **本地磁盘** 与 **S3 兼容对象存储**(Cloudflare R2、腾讯云 COS、阿里云 OSS、AWS S3 等)。管理员在 **存储**(`/storage`)页管理后端;新上传写入 **默认后端**。
|
PicHost 支持 **本地磁盘** 与 **S3 兼容对象存储**(Cloudflare R2、腾讯云 COS、阿里云 OSS、AWS S3 等)。管理员在 **存储**(`/storage`)页管理后端;新上传写入 **默认后端**。页面顶部展示 **存储总览**(总量、已用、剩余、使用率与容量分布),下方为各后端卡片与支持的后端类型说明。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -25,6 +25,8 @@ PicHost 支持 **本地磁盘** 与 **S3 兼容对象存储**(Cloudflare R2、
|
|||||||
3. 填写连接信息(桶名、Endpoint、Access Key 等)。
|
3. 填写连接信息(桶名、Endpoint、Access Key 等)。
|
||||||
4. 保存后可 **设默认**,新上传将写入该后端。
|
4. 保存后可 **设默认**,新上传将写入该后端。
|
||||||
|
|
||||||
|
新建对象存储后端的 **存储标识** 按类型自动生成前缀:本地为 `local`;R2 为 `r2-*`;COS 为 `cos-*`;OSS 为 `oss-*`;AWS S3 及自定义 S3 兼容为 `s3-*`(创建后不可修改,图片索引会引用该 ID)。
|
||||||
|
|
||||||
### Cloudflare R2 要点
|
### Cloudflare R2 要点
|
||||||
|
|
||||||
| 项 | 值 |
|
| 项 | 值 |
|
||||||
@@ -54,17 +56,53 @@ PicHost 支持 **本地磁盘** 与 **S3 兼容对象存储**(Cloudflare R2、
|
|||||||
## 用量与筛选
|
## 用量与筛选
|
||||||
|
|
||||||
- 存储页展示各后端用量(本地扫描目录,对象存储查询 API)
|
- 存储页展示各后端用量(本地扫描目录,对象存储查询 API)
|
||||||
- 图库可按存储后端筛选(管理员)
|
- 图库可按 **存储后端**、**上传来源** 筛选,支持网格/列表视图切换;点击图片打开详情弹窗(尺寸、存储路径、多格式链接复制)
|
||||||
|
|
||||||
## 备份
|
## 备份与迁移(v1.3.0+)
|
||||||
|
|
||||||
请同时备份:
|
存储页 **备份与迁移** 面板包含三张功能卡与下方 **最近任务** 列表:
|
||||||
|
|
||||||
- `data/images/`(本地后端)
|
| 能力 | 说明 |
|
||||||
- `data/pichost.db`
|
| ---- | ---- |
|
||||||
- 各云桶中的对象
|
| **创建站点备份** | 导出 `.phost.tar.gz`,含 `pichost.db` 与全部图片(含云存储中的对象);展示预计体积与备份包含项 |
|
||||||
|
| **从备份恢复** | 本地上传或选择 `data/backups/` 内已有包,预检后确认;可选跳过/覆盖冲突图片 |
|
||||||
|
| **跨后端同步** | 在已配置后端间拷贝图片并更新索引;展示待迁移数量与体积,支持预检、删源、设默认 |
|
||||||
|
|
||||||
从 v1.1.x 升级且存在 `data/blog/` 等并列目录时,见 [v1.2 迁移](./migration.md)。
|

|
||||||
|
|
||||||
|
- 导出文件保存在 `data/backups/`;后端同一时间仅允许一个进行中的备份/迁移任务
|
||||||
|
- 任务列表支持分页,可下载导出包、查看恢复结果、重试失败的同步任务
|
||||||
|
- 备份包 **不含** 云存储 Access Key / Secret Key,恢复后请在存储页重新填写
|
||||||
|
- 未初始化实例可在 **setup** 页 **从备份恢复** 标签上传整站包(始终覆盖模式)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### CLI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 导出整站备份
|
||||||
|
docker exec pichost backup-export
|
||||||
|
|
||||||
|
# 从备份恢复(默认跳过冲突图片)
|
||||||
|
docker exec pichost backup-restore /data/backups/pichost-xxx.phost.tar.gz
|
||||||
|
docker exec pichost backup-restore /data/backups/pichost-xxx.phost.tar.gz --overwrite
|
||||||
|
|
||||||
|
# 跨后端同步
|
||||||
|
docker exec pichost storage-sync --from local --to s3-xxx --dry-run
|
||||||
|
docker exec pichost storage-sync --from local --to s3-xxx --set-default
|
||||||
|
```
|
||||||
|
|
||||||
|
本地开发(项目根目录):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run backup-export
|
||||||
|
npm run backup-restore -- data/backups/pichost-xxx.phost.tar.gz
|
||||||
|
npm run storage-sync -- --from local --to s3-xxx --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
|
### 手动备份
|
||||||
|
|
||||||
|
仍可同时备份 `data/images/`(本地后端)、`data/pichost.db` 与各云桶中的对象;推荐使用上文整站导出。
|
||||||
|
|
||||||
## 相关
|
## 相关
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ PicHost 使用基于角色的访问控制(RBAC):**管理员(admin)**
|
|||||||
| 存储后端管理(`/storage`) | ✓ | — |
|
| 存储后端管理(`/storage`) | ✓ | — |
|
||||||
| 系统设置(`/settings`) | ✓ | — |
|
| 系统设置(`/settings`) | ✓ | — |
|
||||||
| 开放注册开关 | ✓ | — |
|
| 开放注册开关 | ✓ | — |
|
||||||
|
| 登录人机验证方式(滑块 / Turnstile / Cap) | ✓ | — |
|
||||||
| 全局 API Token 管理 | ✓ | — |
|
| 全局 API Token 管理 | ✓ | — |
|
||||||
| 个人 API Token | ✓ | ✓ |
|
| 个人 API Token | ✓ | ✓ |
|
||||||
| 统计页(含注册用户数) | ✓ | 部分 |
|
| 图库统计概览(含注册用户数) | ✓ | 部分 |
|
||||||
| 操作日志 | ✓ | — |
|
| 操作日志(设置 → 操作日志) | ✓ | — |
|
||||||
|
|
||||||
普通用户顶栏:**API**、**统计**;用户菜单:**修改密码**、**退出登录**。
|
普通用户顶栏:**API**、**图库**;用户菜单:**修改密码**、**退出登录**。
|
||||||
|
|
||||||
## 鉴权场景
|
## 鉴权场景
|
||||||
|
|
||||||
@@ -34,12 +35,13 @@ PicHost 使用基于角色的访问控制(RBAC):**管理员(admin)**
|
|||||||
|
|
||||||
- 默认仅管理员可创建用户;管理员可在设置中 **开放注册**
|
- 默认仅管理员可创建用户;管理员可在设置中 **开放注册**
|
||||||
- 密码使用 scrypt 哈希存储
|
- 密码使用 scrypt 哈希存储
|
||||||
- Web 登录需先完成滑动拼图验证(拖动滑块对齐缺口)
|
- Web 登录/注册需完成人机验证:默认本地滑块;管理员可在 **设置 → 访问控制** 切换 Turnstile 或 Cap
|
||||||
|
- 验证配置错误无法登录时:`docker exec pichost slider` 重置为本地滑块
|
||||||
- 登录失败有速率限制
|
- 登录失败有速率限制
|
||||||
|
|
||||||
## 上传偏好与自动删除
|
## 上传偏好与自动删除
|
||||||
|
|
||||||
- **上传偏好**(首页卡片翻转):客户端预压缩、自动复制链接等,按用户保存
|
- **上传偏好**:管理员在 **设置 → 基础设置** 配置客户端预压缩、自动复制链接等;普通用户可在首页上传卡片背面调整个人偏好
|
||||||
- **自动删除**:管理员可设全局策略;用户可设个人策略。启用后仅影响 **之后新上传** 的图片
|
- **自动删除**:管理员可设全局策略;用户可设个人策略。启用后仅影响 **之后新上传** 的图片
|
||||||
|
|
||||||
## API Token 说明
|
## API Token 说明
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 59 KiB |