Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8408d01197 | ||
|
|
ac65c1eb9d | ||
|
|
270af4e707 |
No files matched your search
@@ -4,6 +4,36 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [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
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
|
|||||||
@@ -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,36 @@
|
|||||||
|
|
||||||
**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 |
|
||||||
| :--: | :-----: |
|
| :--: | :-----: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| Stats | Settings |
|
| Storage | Settings |
|
||||||
| :---: | :-------: |
|
| :-----: | :-------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
## 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 captcha, 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
|
||||||
- **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,36 @@
|
|||||||
|
|
||||||
**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 防盗链
|
||||||
- **多用户**:账号密码登录(滑动验证)、可选开放注册;普通用户仅见自己的图片
|
- **多用户**:账号密码登录(滑动验证)、可选开放注册;普通用户仅见自己的图片
|
||||||
- **多后端存储**:本地磁盘 + S3 兼容(R2 / COS / OSS / AWS);混合直链 `proxy` / `public`
|
- **多后端存储**:本地磁盘 + S3 兼容(R2 / COS / OSS / AWS);混合直链 `proxy` / `public`
|
||||||
- **图库与统计**:浏览、搜索、批量删除;上传趋势与来源分布
|
- **图库**:浏览、搜索、按存储/来源筛选、网格/列表切换、批量删除;统计概览与来源分布
|
||||||
- **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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,28 @@ 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
|
||||||
}>(), {
|
}>(), {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
showKey: true,
|
showKey: true,
|
||||||
showStorage: false,
|
showStorage: false,
|
||||||
compact: false
|
compact: false,
|
||||||
|
gallery: false
|
||||||
})
|
})
|
||||||
|
|
||||||
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 +114,173 @@ 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
|
||||||
|
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 +292,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 +319,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,37 @@ 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
|
||||||
}>(), {
|
}>(), {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
showKey: true,
|
showKey: true,
|
||||||
showStorage: false,
|
showStorage: false,
|
||||||
dense: false,
|
dense: false,
|
||||||
compact: false
|
compact: false,
|
||||||
|
gallery: false
|
||||||
|
})
|
||||||
|
|
||||||
|
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 +52,22 @@ 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"
|
||||||
@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,423 @@
|
|||||||
|
<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
|
||||||
|
}>(), {
|
||||||
|
showStorage: false
|
||||||
|
})
|
||||||
|
|
||||||
|
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
|
||||||
|
: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>
|
||||||
@@ -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>
|
||||||
@@ -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,149 @@
|
|||||||
|
<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
|
||||||
|
}>(), {
|
||||||
|
selectedCount: 0,
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
|
||||||
|
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
|
||||||
|
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,221 @@
|
|||||||
|
<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
|
||||||
|
}>(), {
|
||||||
|
selectable: false,
|
||||||
|
showStorage: false
|
||||||
|
})
|
||||||
|
|
||||||
|
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
|
||||||
|
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>
|
||||||
@@ -1,16 +1,6 @@
|
|||||||
<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
|
||||||
@@ -35,181 +25,150 @@ 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="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,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
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -49,100 +41,16 @@ 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 +159,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,81 @@ 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"
|
||||||
>
|
@update:storage-backend="handleStorageBackendChange"
|
||||||
<span class="hidden sm:inline">{{ t('common.search') }}</span>
|
@update:upload-source="handleUploadSourceChange"
|
||||||
</UButton>
|
@update:view-mode="viewMode = $event"
|
||||||
<UButton
|
@search="handleSearch"
|
||||||
v-if="activeSearch"
|
@reset="handleResetFilters"
|
||||||
type="button"
|
@batch-delete="requestBatchDelete"
|
||||||
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>
|
|
||||||
<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
|
||||||
@update:selected-keys="selectedKeys = $event"
|
@update:selected-keys="updateSelectedKeys"
|
||||||
@delete="requestDelete"
|
@preview="openPreview"
|
||||||
|
@delete="(image) => requestDelete(image.key)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<GalleryImageList
|
||||||
|
v-else
|
||||||
|
show-storage
|
||||||
|
:items="items"
|
||||||
|
:selected-keys="selectedKeys"
|
||||||
|
:selectable="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"
|
||||||
|
@delete="requestPreviewDelete"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PaginationBar
|
<PaginationBar
|
||||||
@@ -526,9 +460,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,20 @@ 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"
|
||||||
|
@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>
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { SettingsTab } from '~/types/settings'
|
||||||
|
import { ADMIN_SETTINGS_TABS, USER_SETTINGS_TABS } from '~/types/settings'
|
||||||
|
|
||||||
type SettingSource = 'env' | 'db' | 'none'
|
type SettingSource = 'env' | 'db' | 'none'
|
||||||
type WebpQualitySource = 'env' | 'db' | 'default'
|
type WebpQualitySource = 'env' | 'db' | 'default'
|
||||||
|
|
||||||
@@ -36,6 +39,49 @@ interface SettingsResponse {
|
|||||||
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'
|
||||||
@@ -89,17 +135,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
|
||||||
@@ -210,23 +245,51 @@ 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() {
|
async function loadPage() {
|
||||||
if (!isAdmin.value) {
|
if (isAdmin.value) {
|
||||||
await navigateTo('/')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await Promise.all([loadSettings(), checkLatestRelease()])
|
await Promise.all([loadSettings(), checkLatestRelease()])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureValidTab() {
|
||||||
|
if (route.query.tab && !parseTab(route.query.tab)) {
|
||||||
|
void router.replace({ query: { tab: defaultTab.value } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const status = await fetchStatus()
|
const status = await fetchStatus()
|
||||||
@@ -235,28 +298,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 +344,99 @@ 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 #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 +449,76 @@ watch(isAuthenticated, async (authed, prev) => {
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p
|
|
||||||
v-if="settings.runtime.currentOrigin"
|
|
||||||
class="text-xs text-muted"
|
|
||||||
>
|
|
||||||
{{ t('settings.runtimeDetected', { url: settings.runtime.currentOrigin }) }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<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"
|
class="rounded-xl border border-error/25 bg-error/5 px-4 py-3 text-xs leading-relaxed text-error"
|
||||||
>
|
>
|
||||||
{{ t('settings.hostRoleUnknown') }}
|
{{ t('settings.hostRoleUnknown') }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<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 +554,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 +586,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 +627,111 @@ 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>
|
||||||
|
</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>
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ const deleteTarget = ref<StorageBackendItem | null>(null)
|
|||||||
const deleteConfirmName = ref('')
|
const deleteConfirmName = ref('')
|
||||||
const deleting = ref(false)
|
const deleting = ref(false)
|
||||||
|
|
||||||
|
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 +48,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 +238,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 +257,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,10 +276,21 @@ 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"
|
||||||
@@ -298,11 +304,16 @@ watch(isAuthenticated, async (authed) => {
|
|||||||
@delete="confirmDelete(backend)"
|
@delete="confirmDelete(backend)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
<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">
|
||||||
|
|||||||
@@ -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 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`
|
||||||
|
}
|
||||||
@@ -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,36 @@ Version history and notable changes. The full log is also in the repo root [CHAN
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ See `docker-compose.yml` in the repository.
|
|||||||
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. Complete `/setup` with admin username and password.
|
||||||
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**.
|
||||||
|
|
||||||
## 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, **drag the slider to align with the gap**, then click **Sign in**.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -12,18 +12,14 @@ 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.2.5+).
|
||||||
|
|
||||||
| First-time setup | Login |
|
| API | Gallery |
|
||||||
| :--------------: | :---: |
|
| :-: | :-----: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| API | Stats & gallery |
|
|
||||||
| :-: | :-------------: |
|
|
||||||
|  |  |
|
|
||||||
|
|
||||||
| Storage | Settings |
|
| Storage | Settings |
|
||||||
| :-----: | :------: |
|
| :-----: | :-------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| Activity log |
|
| Activity log |
|
||||||
|
|||||||
@@ -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,7 +54,7 @@ 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
|
||||||
|
|
||||||
## Backup
|
## Backup
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ PicHost uses role-based access control (RBAC): **admin** and **user**. Enforceme
|
|||||||
| Allow registration | ✓ | — |
|
| Allow registration | ✓ | — |
|
||||||
| 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
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ Regular users see **API**, **Stats** in the nav; user menu: **Change password**,
|
|||||||
|
|
||||||
## 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,36 @@ PicHost 版本历史与重要变更说明。完整记录亦见仓库根目录 [C
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [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
|
||||||
|
|
||||||
### 修复
|
### 修复
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
# 环境变量
|
PicHost 支持通过环境变量(Docker / `.env`)与后台 **设置** 页配置。管理员在 **设置与偏好**(`/settings`)左侧切换 **基础设置**、**域名与路径**、**访问控制**、**操作日志**;多数项 **SQLite 优先**;部分项环境变量可覆盖或锁定后台编辑。
|
||||||
|
|
||||||
PicHost 支持通过环境变量(Docker / `.env`)与后台 **设置** 页配置。多数项 **SQLite 优先**;部分项环境变量可覆盖或锁定后台编辑。
|
|
||||||
|
|
||||||
## 优先级总览
|
## 优先级总览
|
||||||
|
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ docker compose up -d
|
|||||||
1. 访问实例 URL(Docker 默认 `http://<主机>:6892`)。
|
1. 访问实例 URL(Docker 默认 `http://<主机>:6892`)。
|
||||||
2. 在 `/setup` 填写管理员用户名与密码。
|
2. 在 `/setup` 填写管理员用户名与密码。
|
||||||
3. (可选)配置网站域名、图片域名、防盗链等 — 详见 [环境变量](./configuration.md) 与 [双域名分离](./domain-separation.md)。
|
3. (可选)配置网站域名、图片域名、防盗链等 — 详见 [环境变量](./configuration.md) 与 [双域名分离](./domain-separation.md)。
|
||||||
4. 登录后可在首页上传图片;管理员可进入 **存储**、**设置**、**API** 页。
|
4. 登录后可在首页上传图片;顶栏可进入 **图库**、**存储**(管理员)、**设置**、**API**。
|
||||||
|
|
||||||
## 登录
|
## 登录
|
||||||
|
|
||||||
访问上传、统计、设置等管理页面前需登录。在登录卡片中填写用户名与密码,**拖动滑块对齐缺口**完成验证后点击 **登录**。
|
访问上传、图库、设置等管理页面前需登录。在登录卡片中填写用户名与密码,**拖动滑块对齐缺口**完成验证后点击 **登录**。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -12,19 +12,15 @@
|
|||||||
|
|
||||||
## 截图预览
|
## 截图预览
|
||||||
|
|
||||||
**main** 分支暂无公网演示,以下为 v1.2.0 产品界面。
|
**main** 分支暂无公网演示,以下为当前产品界面(v1.2.5+)。
|
||||||
|
|
||||||
| 首次设置 | 登录 |
|
| API | 图库 |
|
||||||
| :------: | :--: |
|
| :-: | :-: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| API | 统计与图库 |
|
| 存储管理 | 设置与偏好 |
|
||||||
| :-: | :--------: |
|
| :------: | :--------: |
|
||||||
|  |  |
|
|  |  |
|
||||||
|
|
||||||
| 存储管理 | 系统设置 |
|
|
||||||
| :------: | :------: |
|
|
||||||
|  |  |
|
|
||||||
|
|
||||||
| 操作日志 |
|
| 操作日志 |
|
||||||
| :------: |
|
| :------: |
|
||||||
|
|||||||
@@ -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,7 +56,7 @@ PicHost 支持 **本地磁盘** 与 **S3 兼容对象存储**(Cloudflare R2、
|
|||||||
## 用量与筛选
|
## 用量与筛选
|
||||||
|
|
||||||
- 存储页展示各后端用量(本地扫描目录,对象存储查询 API)
|
- 存储页展示各后端用量(本地扫描目录,对象存储查询 API)
|
||||||
- 图库可按存储后端筛选(管理员)
|
- 图库可按 **存储后端**、**上传来源** 筛选,支持网格/列表视图切换
|
||||||
|
|
||||||
## 备份
|
## 备份
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ PicHost 使用基于角色的访问控制(RBAC):**管理员(admin)**
|
|||||||
| 开放注册开关 | ✓ | — |
|
| 开放注册开关 | ✓ | — |
|
||||||
| 全局 API Token 管理 | ✓ | — |
|
| 全局 API Token 管理 | ✓ | — |
|
||||||
| 个人 API Token | ✓ | ✓ |
|
| 个人 API Token | ✓ | ✓ |
|
||||||
| 统计页(含注册用户数) | ✓ | 部分 |
|
| 图库统计概览(含注册用户数) | ✓ | 部分 |
|
||||||
| 操作日志 | ✓ | — |
|
| 操作日志(设置 → 操作日志) | ✓ | — |
|
||||||
|
|
||||||
普通用户顶栏:**API**、**统计**;用户菜单:**修改密码**、**退出登录**。
|
普通用户顶栏:**API**、**图库**;用户菜单:**修改密码**、**退出登录**。
|
||||||
|
|
||||||
## 鉴权场景
|
## 鉴权场景
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ PicHost 使用基于角色的访问控制(RBAC):**管理员(admin)**
|
|||||||
|
|
||||||
## 上传偏好与自动删除
|
## 上传偏好与自动删除
|
||||||
|
|
||||||
- **上传偏好**(首页卡片翻转):客户端预压缩、自动复制链接等,按用户保存
|
- **上传偏好**:管理员在 **设置 → 基础设置** 配置客户端预压缩、自动复制链接等;普通用户可在首页上传卡片背面调整个人偏好
|
||||||
- **自动删除**:管理员可设全局策略;用户可设个人策略。启用后仅影响 **之后新上传** 的图片
|
- **自动删除**:管理员可设全局策略;用户可设个人策略。启用后仅影响 **之后新上传** 的图片
|
||||||
|
|
||||||
## API Token 说明
|
## API Token 说明
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 151 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 |
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 151 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 70 KiB |
@@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"nav": {
|
"nav": {
|
||||||
"api": "API",
|
"api": "API",
|
||||||
|
"gallery": "Gallery",
|
||||||
"stats": "Stats",
|
"stats": "Stats",
|
||||||
"logs": "Activity log",
|
"logs": "Activity log",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
@@ -148,11 +149,13 @@
|
|||||||
"url": "URL",
|
"url": "URL",
|
||||||
"markdown": "Markdown",
|
"markdown": "Markdown",
|
||||||
"html": "HTML",
|
"html": "HTML",
|
||||||
|
"bbcode": "BBCode",
|
||||||
"copied": "Copied to clipboard",
|
"copied": "Copied to clipboard",
|
||||||
"copiedLabel": "Copied {label}",
|
"copiedLabel": "Copied {label}",
|
||||||
"copiedUrl": "URL copied",
|
"copiedUrl": "URL copied",
|
||||||
"copiedMarkdown": "Markdown copied",
|
"copiedMarkdown": "Markdown copied",
|
||||||
"copiedHtml": "HTML copied",
|
"copiedHtml": "HTML copied",
|
||||||
|
"copiedBbcode": "BBCode copied",
|
||||||
"copiedFormat": "Copied {format}",
|
"copiedFormat": "Copied {format}",
|
||||||
"failed": "Copy failed",
|
"failed": "Copy failed",
|
||||||
"failedManual": "Copy failed — select the link manually",
|
"failedManual": "Copy failed — select the link manually",
|
||||||
@@ -180,12 +183,39 @@
|
|||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "System settings",
|
"title": "System settings",
|
||||||
|
"pageTitle": "Settings & preferences",
|
||||||
|
"pageSubtitle": "Manage system configuration and activity logs",
|
||||||
|
"pageSubtitleBasic": "Manage system configuration and upload preferences",
|
||||||
|
"navBasic": "Basic",
|
||||||
|
"navDomains": "Domains & paths",
|
||||||
|
"navAccess": "Access control",
|
||||||
|
"navPreferences": "Preferences",
|
||||||
|
"navLogs": "Activity log",
|
||||||
|
"systemVersion": "Version",
|
||||||
|
"checkUpdate": "Check for updates",
|
||||||
|
"saveSettings": "Save settings",
|
||||||
"subtitle": "Saved to database; environment variables take precedence",
|
"subtitle": "Saved to database; environment variables take precedence",
|
||||||
"featureToggles": "Feature toggles",
|
"featureToggles": "Feature toggles",
|
||||||
|
"featureTogglesHint": "Control registration and system behavior",
|
||||||
|
"pathAndLink": "Paths & links",
|
||||||
|
"pathAndLinkHint": "Control image URL format and upload directory structure",
|
||||||
|
"domainSeparationSection": "Domain separation",
|
||||||
"allowRegistration": "Open registration",
|
"allowRegistration": "Open registration",
|
||||||
"allowRegistrationHint": "Allow new users to register (regular users see only their images)",
|
"allowRegistrationHint": "Allow new users to register (regular users see only their images)",
|
||||||
"accessControl": "Access control",
|
"accessControl": "Access control",
|
||||||
"refererHint": "Referer hotlink protection; comma-separated hostnames, empty = no restriction",
|
"refererHint": "Referer hotlink protection; comma-separated hostnames, empty = no restriction",
|
||||||
|
"refererDomainsLabel": "Allowed domains",
|
||||||
|
"refererTip": "Separate multiple domains with commas (,); wildcards are not supported",
|
||||||
|
"refererExamplesTitle": "Example",
|
||||||
|
"refererExamplesSample": "example.com, static.example.com",
|
||||||
|
"refererScenarioTitle": "Common use case",
|
||||||
|
"refererScenarioDesc": "Allow your main site and static site to embed images",
|
||||||
|
"refererEnabled": "Enabled",
|
||||||
|
"refererUnrestricted": "Unrestricted",
|
||||||
|
"systemInfo": "System",
|
||||||
|
"systemInfoHint": "Current version and updates",
|
||||||
|
"uploadConvenience": "Upload convenience",
|
||||||
|
"defaultCopyFormat": "Default copy format",
|
||||||
"refererPlaceholder": "example.com, www.example.com",
|
"refererPlaceholder": "example.com, www.example.com",
|
||||||
"domainSettings": "Domain settings",
|
"domainSettings": "Domain settings",
|
||||||
"domainSeparationActive": "Domain separation enabled: image host serves images only; site host serves admin and API",
|
"domainSeparationActive": "Domain separation enabled: image host serves images only; site host serves admin and API",
|
||||||
@@ -213,12 +243,15 @@
|
|||||||
"badgeSaved": "Saved",
|
"badgeSaved": "Saved",
|
||||||
"badgeDefault": "Default",
|
"badgeDefault": "Default",
|
||||||
"badgeUnset": "Not set",
|
"badgeUnset": "Not set",
|
||||||
|
"badgeOptional": "Optional",
|
||||||
"tokenEnv": "Environment",
|
"tokenEnv": "Environment",
|
||||||
"tokenDb": "Generated in app",
|
"tokenDb": "Generated in app",
|
||||||
"tokenNone": "Not configured",
|
"tokenNone": "Not configured",
|
||||||
"apiTokenLine": "API Token · {source} ·",
|
"apiTokenLine": "Source: {source}",
|
||||||
"viewReleases": "View releases",
|
"viewReleases": "View releases",
|
||||||
"updateAvailable": "Update available: {version}",
|
"updateAvailable": "Update available: {version}",
|
||||||
|
"upToDate": "You are on the latest version",
|
||||||
|
"checkUpdateFailed": "Failed to check for updates. Please try again later",
|
||||||
"unsavedChanges": "Unsaved changes",
|
"unsavedChanges": "Unsaved changes",
|
||||||
"manageToken": "Manage token",
|
"manageToken": "Manage token",
|
||||||
"envOverride": "Overridden by environment variable; cannot edit in UI",
|
"envOverride": "Overridden by environment variable; cannot edit in UI",
|
||||||
@@ -277,11 +310,36 @@
|
|||||||
"servingPublicShort": "Public",
|
"servingPublicShort": "Public",
|
||||||
"backendName": "Display name",
|
"backendName": "Display name",
|
||||||
"badgeDefault": "Default",
|
"badgeDefault": "Default",
|
||||||
|
"badgeDefaultStorage": "Default storage",
|
||||||
"badgeDisabled": "Disabled",
|
"badgeDisabled": "Disabled",
|
||||||
"badgeEnabled": "Enabled",
|
"badgeEnabled": "Enabled",
|
||||||
|
"overviewTitle": "Storage overview",
|
||||||
|
"overviewSubtitle": "Usage across all storage backends",
|
||||||
|
"overviewTotal": "Total capacity",
|
||||||
|
"overviewUsed": "Used",
|
||||||
|
"overviewFree": "Free",
|
||||||
|
"overviewUsageRate": "Overall usage",
|
||||||
|
"overviewQuota": "Total quota",
|
||||||
|
"overviewInstances": "Backends",
|
||||||
|
"overviewActive": "Active",
|
||||||
|
"capacityDistribution": "Distribution",
|
||||||
|
"backendType": "Type",
|
||||||
|
"storageId": "Storage ID",
|
||||||
|
"storageType": "Storage type",
|
||||||
|
"badgeLocal": "Local",
|
||||||
|
"defaultStorageTip": "Default storage: new uploads are saved to “{name}”. Use “Set as default” on another backend to change this.",
|
||||||
|
"supportedTitle": "Supported backends",
|
||||||
|
"supportedSubtitle": "PicHost supports multiple storage backends for different scenarios",
|
||||||
|
"supportedLocalDesc": "Ideal for small deployments and personal use",
|
||||||
|
"supportedR2Desc": "Highly available, low-cost object storage",
|
||||||
|
"supportedS3Title": "S3 compatible",
|
||||||
|
"supportedS3Desc": "Storage services compatible with the Amazon S3 API",
|
||||||
|
"footerTip": "The default backend receives all new uploads",
|
||||||
"statTotal": "Total",
|
"statTotal": "Total",
|
||||||
"statUsed": "Used",
|
"statUsed": "Used",
|
||||||
"statFree": "Free",
|
"statFree": "Free",
|
||||||
|
"statFileCount": "Files",
|
||||||
|
"statQuota": "Quota",
|
||||||
"usageRate": "Usage",
|
"usageRate": "Usage",
|
||||||
"indexImages": "PicHost images {count} · {size}",
|
"indexImages": "PicHost images {count} · {size}",
|
||||||
"setDefault": "Set as default",
|
"setDefault": "Set as default",
|
||||||
@@ -307,12 +365,21 @@
|
|||||||
"manageStorageHint": "Configure R2 / S3 / COS backends and URL serving"
|
"manageStorageHint": "Configure R2 / S3 / COS backends and URL serving"
|
||||||
},
|
},
|
||||||
"stats": {
|
"stats": {
|
||||||
"title": "Statistics",
|
"title": "Gallery",
|
||||||
"subtitle": "Overview and gallery",
|
"subtitle": "Browse, search, and manage uploaded images",
|
||||||
"uploadToday": "Uploaded today",
|
"uploadToday": "Uploaded today",
|
||||||
"uploadMonth": "Uploaded this month",
|
"uploadMonth": "Uploaded this month",
|
||||||
"uploadTotal": "Total uploads",
|
"uploadTotal": "Total uploads",
|
||||||
"storedCount": "Stored images",
|
"storedCount": "Stored now",
|
||||||
|
"totalFiles": "Total files",
|
||||||
|
"totalOccupied": "{size} used",
|
||||||
|
"storageUsage": "Storage usage",
|
||||||
|
"noQuota": "No quota configured",
|
||||||
|
"vsYesterday": "vs yesterday",
|
||||||
|
"vsLastMonth": "vs last month",
|
||||||
|
"trendUp": "↑ {p}%",
|
||||||
|
"trendDown": "↓ {p}%",
|
||||||
|
"trendFlat": "flat",
|
||||||
"deleteToday": "Deleted today",
|
"deleteToday": "Deleted today",
|
||||||
"deleteMonth": "Deleted this month",
|
"deleteMonth": "Deleted this month",
|
||||||
"deleteTotal": "Total deleted",
|
"deleteTotal": "Total deleted",
|
||||||
@@ -321,14 +388,42 @@
|
|||||||
"sourceDistribution": "Uploads by source",
|
"sourceDistribution": "Uploads by source",
|
||||||
"sourceWeb": "Web",
|
"sourceWeb": "Web",
|
||||||
"sourceApi": "API",
|
"sourceApi": "API",
|
||||||
|
"tagWeb": "Web",
|
||||||
|
"tagApi": "API",
|
||||||
"noData": "No data",
|
"noData": "No data",
|
||||||
"gallery": "Gallery",
|
"gallery": "Gallery",
|
||||||
|
"imagesSection": "All images",
|
||||||
"filterStorageAll": "All storage",
|
"filterStorageAll": "All storage",
|
||||||
"storage": "Storage",
|
"storage": "Storage",
|
||||||
"searchPlaceholder": "Search filename",
|
"searchPlaceholder": "Search filename",
|
||||||
|
"searchPlaceholderWide": "Search filename, tags, or links",
|
||||||
|
"filterType": "Image type",
|
||||||
|
"filterTypeAll": "All types",
|
||||||
|
"filterSource": "Upload source",
|
||||||
|
"filterSourceAll": "All sources",
|
||||||
|
"sourceWeb": "Web upload",
|
||||||
|
"sourceApi": "API upload",
|
||||||
|
"resetFilters": "Reset",
|
||||||
|
"batchActions": "Bulk actions",
|
||||||
|
"selectedItems": "{n} selected",
|
||||||
|
"colFilename": "Filename",
|
||||||
|
"colPreview": "Preview",
|
||||||
|
"colSize": "Size",
|
||||||
|
"colType": "Type",
|
||||||
|
"colSource": "Source",
|
||||||
|
"colUploadedAt": "Uploaded",
|
||||||
|
"colActions": "Actions",
|
||||||
|
"previewBadge": "Image",
|
||||||
"clear": "Clear",
|
"clear": "Clear",
|
||||||
"selected": "{n} selected",
|
"selected": "{n} selected",
|
||||||
"batchDelete": "Delete selected",
|
"batchDelete": "Delete selected",
|
||||||
|
"batchSelect": "Batch select",
|
||||||
|
"viewMode": "View mode",
|
||||||
|
"viewGrid": "Grid view",
|
||||||
|
"viewList": "List view",
|
||||||
|
"selectAll": "Select all",
|
||||||
|
"invertSelection": "Invert",
|
||||||
|
"clearSelection": "Clear selection",
|
||||||
"scrollTop": "Back to top",
|
"scrollTop": "Back to top",
|
||||||
"loadFailed": "Failed to load statistics",
|
"loadFailed": "Failed to load statistics",
|
||||||
"selectFirst": "Select images first",
|
"selectFirst": "Select images first",
|
||||||
@@ -371,6 +466,27 @@
|
|||||||
"image": {
|
"image": {
|
||||||
"empty": "No images",
|
"empty": "No images",
|
||||||
"previewFailed": "Preview failed",
|
"previewFailed": "Preview failed",
|
||||||
|
"openPreview": "View full image",
|
||||||
|
"previewTitle": "Image details",
|
||||||
|
"previewSubtitle": "View image info and links",
|
||||||
|
"previewOriginalName": "Filename",
|
||||||
|
"previewUploadedAt": "Uploaded",
|
||||||
|
"previewSize": "Size",
|
||||||
|
"previewSizeDetail": "{size} ({bytes} bytes)",
|
||||||
|
"previewContentType": "File type",
|
||||||
|
"previewOwner": "Uploader",
|
||||||
|
"previewStorage": "Storage",
|
||||||
|
"previewKey": "Image path",
|
||||||
|
"previewExtension": "Extension",
|
||||||
|
"previewDimensions": "Dimensions",
|
||||||
|
"previewDimensionsUnknown": "Loading…",
|
||||||
|
"previewUploadSource": "Upload source",
|
||||||
|
"uploadSourceUnknown": "Unknown",
|
||||||
|
"previewLinks": "Links & embed",
|
||||||
|
"previewCopyLink": "Copy link",
|
||||||
|
"previewDownload": "Download",
|
||||||
|
"previewOpen": "Open in new tab",
|
||||||
|
"previewClose": "Close",
|
||||||
"uploader": "Uploader: {name}",
|
"uploader": "Uploader: {name}",
|
||||||
"storageBackend": "Storage: {name}"
|
"storageBackend": "Storage: {name}"
|
||||||
},
|
},
|
||||||
@@ -380,6 +496,11 @@
|
|||||||
"confirm": "Delete"
|
"confirm": "Delete"
|
||||||
},
|
},
|
||||||
"pagination": {
|
"pagination": {
|
||||||
|
"totalCount": "{total} {unit}",
|
||||||
|
"pageStatus": "Page {page} / {totalPages}",
|
||||||
|
"perPage": "{size} / page",
|
||||||
|
"pageSize": "Page size",
|
||||||
|
"pageNumber": "Page {page}",
|
||||||
"pageOf": "Page {page} / {totalPages} · {total} {unit}",
|
"pageOf": "Page {page} / {totalPages} · {total} {unit}",
|
||||||
"totalOnly": "{total} {unit}",
|
"totalOnly": "{total} {unit}",
|
||||||
"first": "First page",
|
"first": "First page",
|
||||||
@@ -387,6 +508,8 @@
|
|||||||
"next": "Next page",
|
"next": "Next page",
|
||||||
"last": "Last page",
|
"last": "Last page",
|
||||||
"goTo": "Go",
|
"goTo": "Go",
|
||||||
|
"goToPrefix": "Go to",
|
||||||
|
"goToSuffix": "",
|
||||||
"pagePlaceholder": "Page"
|
"pagePlaceholder": "Page"
|
||||||
},
|
},
|
||||||
"api": {
|
"api": {
|
||||||
@@ -415,6 +538,74 @@
|
|||||||
"newTokenDesc": "Copy and save it now. You can copy again from the field above after closing.",
|
"newTokenDesc": "Copy and save it now. You can copy again from the field above after closing.",
|
||||||
"copyToken": "Copy token",
|
"copyToken": "Copy token",
|
||||||
"saved": "Saved",
|
"saved": "Saved",
|
||||||
|
"searchPlaceholder": "Search endpoints…",
|
||||||
|
"showToken": "Show",
|
||||||
|
"hideToken": "Hide",
|
||||||
|
"helpText": "Need help? Read the full API docs",
|
||||||
|
"helpTitle": "Need help?",
|
||||||
|
"helpSubtitle": "Read the full API docs",
|
||||||
|
"expand": "Expand",
|
||||||
|
"collapse": "Collapse",
|
||||||
|
"viewDocs": "View docs",
|
||||||
|
"requestParams": "Request parameters",
|
||||||
|
"paramName": "Name",
|
||||||
|
"paramType": "Type",
|
||||||
|
"paramLocation": "In",
|
||||||
|
"paramRequired": "Required",
|
||||||
|
"paramDescription": "Description",
|
||||||
|
"required": "Yes",
|
||||||
|
"optional": "No",
|
||||||
|
"requestExample": "Request example",
|
||||||
|
"responseExample": "Response example",
|
||||||
|
"categories": {
|
||||||
|
"image": "Images",
|
||||||
|
"extension": "Plugins",
|
||||||
|
"system": "System"
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"upload": {
|
||||||
|
"image": "Primary upload field",
|
||||||
|
"file": "Compatibility field, single file",
|
||||||
|
"files": "Compatibility field, multiple files",
|
||||||
|
"token": "Twikoo protocol form token"
|
||||||
|
},
|
||||||
|
"list": {
|
||||||
|
"limit": "Page size, default 20, max 100",
|
||||||
|
"page": "Page number, starts at 1"
|
||||||
|
},
|
||||||
|
"search": {
|
||||||
|
"q": "Search keyword, required"
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"key": "Storage path, e.g. images/2026/08/xxx.webp"
|
||||||
|
},
|
||||||
|
"batchDelete": {
|
||||||
|
"keys": "Array of image keys to delete"
|
||||||
|
},
|
||||||
|
"twikoo": {
|
||||||
|
"image": "Image file",
|
||||||
|
"token": "API token"
|
||||||
|
},
|
||||||
|
"backendId": "Storage backend ID, optional"
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"title": "Try it",
|
||||||
|
"headers": "Headers",
|
||||||
|
"query": "Query",
|
||||||
|
"body": "Body",
|
||||||
|
"send": "Send request",
|
||||||
|
"response": "Response",
|
||||||
|
"selectFile": "Select file",
|
||||||
|
"noFileSelected": "No file selected",
|
||||||
|
"tokenPlaceholder": "Enter Auth-Token",
|
||||||
|
"invalidJson": "Invalid JSON",
|
||||||
|
"sendFailed": "Request failed",
|
||||||
|
"networkError": "Network error or unreachable",
|
||||||
|
"notesTitle": "Notes",
|
||||||
|
"noteSuccess": "200 means success with JSON body",
|
||||||
|
"noteError": "4xx / 5xx means failure; check error field",
|
||||||
|
"noteLimit": "Upload limit: up to 10 files, 10 MB each"
|
||||||
|
},
|
||||||
"docs": {
|
"docs": {
|
||||||
"upload": {
|
"upload": {
|
||||||
"title": "Upload images",
|
"title": "Upload images",
|
||||||
@@ -439,6 +630,14 @@
|
|||||||
"twikoo": {
|
"twikoo": {
|
||||||
"title": "Twikoo-compatible upload",
|
"title": "Twikoo-compatible upload",
|
||||||
"desc": "Twikoo / EasyImage 2.0 protocol; stored under images/. Fields: image + token."
|
"desc": "Twikoo / EasyImage 2.0 protocol; stored under images/. Fields: image + token."
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"title": "Get config",
|
||||||
|
"desc": "Public system config; no authentication required."
|
||||||
|
},
|
||||||
|
"count": {
|
||||||
|
"title": "Image count",
|
||||||
|
"desc": "Total images in your visible scope."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"nav": {
|
"nav": {
|
||||||
"api": "API",
|
"api": "API",
|
||||||
|
"gallery": "图库",
|
||||||
"stats": "统计",
|
"stats": "统计",
|
||||||
"logs": "操作日志",
|
"logs": "操作日志",
|
||||||
"settings": "设置",
|
"settings": "设置",
|
||||||
@@ -148,11 +149,13 @@
|
|||||||
"url": "直链",
|
"url": "直链",
|
||||||
"markdown": "Markdown",
|
"markdown": "Markdown",
|
||||||
"html": "HTML",
|
"html": "HTML",
|
||||||
|
"bbcode": "BBCode",
|
||||||
"copied": "已复制到剪贴板",
|
"copied": "已复制到剪贴板",
|
||||||
"copiedLabel": "已复制 {label}",
|
"copiedLabel": "已复制 {label}",
|
||||||
"copiedUrl": "已复制直链",
|
"copiedUrl": "已复制直链",
|
||||||
"copiedMarkdown": "已复制 Markdown",
|
"copiedMarkdown": "已复制 Markdown",
|
||||||
"copiedHtml": "已复制 HTML",
|
"copiedHtml": "已复制 HTML",
|
||||||
|
"copiedBbcode": "已复制 BBCode",
|
||||||
"copiedFormat": "已复制 {format}",
|
"copiedFormat": "已复制 {format}",
|
||||||
"failed": "复制失败",
|
"failed": "复制失败",
|
||||||
"failedManual": "复制失败,请手动选中链接复制",
|
"failedManual": "复制失败,请手动选中链接复制",
|
||||||
@@ -180,12 +183,39 @@
|
|||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "系统设置",
|
"title": "系统设置",
|
||||||
|
"pageTitle": "设置与偏好",
|
||||||
|
"pageSubtitle": "管理系统配置与操作日志",
|
||||||
|
"pageSubtitleBasic": "管理系统配置与上传偏好",
|
||||||
|
"navBasic": "基础设置",
|
||||||
|
"navDomains": "域名与路径",
|
||||||
|
"navAccess": "访问控制",
|
||||||
|
"navPreferences": "偏好设置",
|
||||||
|
"navLogs": "操作日志",
|
||||||
|
"systemVersion": "系统版本",
|
||||||
|
"checkUpdate": "检查更新",
|
||||||
|
"saveSettings": "保存设置",
|
||||||
"subtitle": "保存后写入数据库;环境变量优先级更高",
|
"subtitle": "保存后写入数据库;环境变量优先级更高",
|
||||||
"featureToggles": "功能开关",
|
"featureToggles": "功能开关",
|
||||||
|
"featureTogglesHint": "控制注册与系统行为",
|
||||||
|
"pathAndLink": "路径与链接",
|
||||||
|
"pathAndLinkHint": "控制图片直链格式与上传目录结构",
|
||||||
|
"domainSeparationSection": "域名分离",
|
||||||
"allowRegistration": "开放用户注册",
|
"allowRegistration": "开放用户注册",
|
||||||
"allowRegistrationHint": "允许新用户自行注册(普通用户仅可见自己的图片)",
|
"allowRegistrationHint": "允许新用户自行注册(普通用户仅可见自己的图片)",
|
||||||
"accessControl": "访问控制",
|
"accessControl": "访问控制",
|
||||||
"refererHint": "Referer 防盗链,逗号分隔允许引用的域名,留空不限制",
|
"refererHint": "Referer 防盗链,逗号分隔允许引用的域名,留空不限制",
|
||||||
|
"refererDomainsLabel": "允许引用的域名",
|
||||||
|
"refererTip": "多个域名请使用英文逗号 (,) 分隔,不支持通配符",
|
||||||
|
"refererExamplesTitle": "推荐示例",
|
||||||
|
"refererExamplesSample": "example.com, static.example.com",
|
||||||
|
"refererScenarioTitle": "常见场景",
|
||||||
|
"refererScenarioDesc": "允许主站与静态站点引用图片",
|
||||||
|
"refererEnabled": "已开启",
|
||||||
|
"refererUnrestricted": "未限制",
|
||||||
|
"systemInfo": "系统信息",
|
||||||
|
"systemInfoHint": "当前系统版本与更新",
|
||||||
|
"uploadConvenience": "上传便捷功能",
|
||||||
|
"defaultCopyFormat": "默认复制格式",
|
||||||
"refererPlaceholder": "example.com, www.example.com",
|
"refererPlaceholder": "example.com, www.example.com",
|
||||||
"domainSettings": "域名配置",
|
"domainSettings": "域名配置",
|
||||||
"domainSeparationActive": "已启用域名分离:图片域仅出图,管理域提供后台与 API",
|
"domainSeparationActive": "已启用域名分离:图片域仅出图,管理域提供后台与 API",
|
||||||
@@ -213,12 +243,15 @@
|
|||||||
"badgeSaved": "已保存",
|
"badgeSaved": "已保存",
|
||||||
"badgeDefault": "默认",
|
"badgeDefault": "默认",
|
||||||
"badgeUnset": "未设置",
|
"badgeUnset": "未设置",
|
||||||
|
"badgeOptional": "可选",
|
||||||
"tokenEnv": "环境变量",
|
"tokenEnv": "环境变量",
|
||||||
"tokenDb": "后台生成",
|
"tokenDb": "后台生成",
|
||||||
"tokenNone": "未配置",
|
"tokenNone": "未配置",
|
||||||
"apiTokenLine": "API Token · {source} ·",
|
"apiTokenLine": "来源:{source}",
|
||||||
"viewReleases": "查看发行版",
|
"viewReleases": "查看发行版",
|
||||||
"updateAvailable": "有新版本 {version}",
|
"updateAvailable": "有新版本 {version}",
|
||||||
|
"upToDate": "当前已是最新版本",
|
||||||
|
"checkUpdateFailed": "检查更新失败,请稍后重试",
|
||||||
"unsavedChanges": "有未保存的更改",
|
"unsavedChanges": "有未保存的更改",
|
||||||
"manageToken": "管理 Token",
|
"manageToken": "管理 Token",
|
||||||
"envOverride": "该项已由环境变量覆盖,无法在后台修改",
|
"envOverride": "该项已由环境变量覆盖,无法在后台修改",
|
||||||
@@ -277,11 +310,36 @@
|
|||||||
"servingPublicShort": "公开",
|
"servingPublicShort": "公开",
|
||||||
"backendName": "显示名称",
|
"backendName": "显示名称",
|
||||||
"badgeDefault": "默认",
|
"badgeDefault": "默认",
|
||||||
|
"badgeDefaultStorage": "默认存储",
|
||||||
"badgeDisabled": "已停用",
|
"badgeDisabled": "已停用",
|
||||||
"badgeEnabled": "已启用",
|
"badgeEnabled": "已启用",
|
||||||
|
"overviewTitle": "存储总览",
|
||||||
|
"overviewSubtitle": "所有存储后端使用情况",
|
||||||
|
"overviewTotal": "总容量",
|
||||||
|
"overviewUsed": "已用容量",
|
||||||
|
"overviewFree": "剩余容量",
|
||||||
|
"overviewUsageRate": "总体使用率",
|
||||||
|
"overviewQuota": "总配额",
|
||||||
|
"overviewInstances": "存储实例",
|
||||||
|
"overviewActive": "活跃后台",
|
||||||
|
"capacityDistribution": "容量分布",
|
||||||
|
"backendType": "类型",
|
||||||
|
"storageId": "存储标识",
|
||||||
|
"storageType": "存储类型",
|
||||||
|
"badgeLocal": "本地",
|
||||||
|
"defaultStorageTip": "默认存储提示:新上传的图片将默认保存到「{name}」。可点击其他后端的「设为默认」进行修改。",
|
||||||
|
"supportedTitle": "支持的存储后端",
|
||||||
|
"supportedSubtitle": "PicHost 支持多种存储后端,满足不同场景需求",
|
||||||
|
"supportedLocalDesc": "适合小型部署和个人使用",
|
||||||
|
"supportedR2Desc": "高可用、低成本的对象存储",
|
||||||
|
"supportedS3Title": "S3 兼容",
|
||||||
|
"supportedS3Desc": "兼容 Amazon S3 协议的存储服务",
|
||||||
|
"footerTip": "默认存储后端将自动接收所有新上传的图片",
|
||||||
"statTotal": "总量",
|
"statTotal": "总量",
|
||||||
"statUsed": "已用",
|
"statUsed": "已用",
|
||||||
"statFree": "剩余",
|
"statFree": "剩余",
|
||||||
|
"statFileCount": "文件数量",
|
||||||
|
"statQuota": "配额",
|
||||||
"usageRate": "使用率",
|
"usageRate": "使用率",
|
||||||
"indexImages": "PicHost 图片 {count} 张 · {size}",
|
"indexImages": "PicHost 图片 {count} 张 · {size}",
|
||||||
"setDefault": "设为默认",
|
"setDefault": "设为默认",
|
||||||
@@ -307,12 +365,21 @@
|
|||||||
"manageStorageHint": "配置 R2 / S3 / COS 等多后端与直链策略"
|
"manageStorageHint": "配置 R2 / S3 / COS 等多后端与直链策略"
|
||||||
},
|
},
|
||||||
"stats": {
|
"stats": {
|
||||||
"title": "统计",
|
"title": "图库",
|
||||||
"subtitle": "数据概览与图库记录",
|
"subtitle": "浏览、搜索与管理已上传图片",
|
||||||
"uploadToday": "今日上传",
|
"uploadToday": "今日上传",
|
||||||
"uploadMonth": "本月上传",
|
"uploadMonth": "本月上传",
|
||||||
"uploadTotal": "累计上传",
|
"uploadTotal": "累计上传",
|
||||||
"storedCount": "当前库存",
|
"storedCount": "当前存储",
|
||||||
|
"totalFiles": "总文件数",
|
||||||
|
"totalOccupied": "共占用 {size}",
|
||||||
|
"storageUsage": "存储使用率",
|
||||||
|
"noQuota": "未配置容量上限",
|
||||||
|
"vsYesterday": "较昨日",
|
||||||
|
"vsLastMonth": "较上月",
|
||||||
|
"trendUp": "↑ {p}%",
|
||||||
|
"trendDown": "↓ {p}%",
|
||||||
|
"trendFlat": "持平",
|
||||||
"deleteToday": "今日删除",
|
"deleteToday": "今日删除",
|
||||||
"deleteMonth": "本月删除",
|
"deleteMonth": "本月删除",
|
||||||
"deleteTotal": "累计删除",
|
"deleteTotal": "累计删除",
|
||||||
@@ -321,14 +388,42 @@
|
|||||||
"sourceDistribution": "上传来源分布",
|
"sourceDistribution": "上传来源分布",
|
||||||
"sourceWeb": "网页",
|
"sourceWeb": "网页",
|
||||||
"sourceApi": "API",
|
"sourceApi": "API",
|
||||||
|
"tagWeb": "网页",
|
||||||
|
"tagApi": "API",
|
||||||
"noData": "暂无数据",
|
"noData": "暂无数据",
|
||||||
"gallery": "图库记录",
|
"gallery": "图库记录",
|
||||||
|
"imagesSection": "全部图片",
|
||||||
"filterStorageAll": "全部存储",
|
"filterStorageAll": "全部存储",
|
||||||
"storage": "存储",
|
"storage": "存储",
|
||||||
"searchPlaceholder": "搜索文件名",
|
"searchPlaceholder": "搜索文件名",
|
||||||
"clear": "清除",
|
"searchPlaceholderWide": "搜索文件名、标签或链接",
|
||||||
|
"filterType": "图片类型",
|
||||||
|
"filterTypeAll": "全部类型",
|
||||||
|
"filterSource": "上传来源",
|
||||||
|
"filterSourceAll": "全部来源",
|
||||||
|
"sourceWeb": "网页上传",
|
||||||
|
"sourceApi": "API 上传",
|
||||||
|
"resetFilters": "重置",
|
||||||
|
"batchActions": "批量操作",
|
||||||
|
"selectedItems": "已选择 {n} 项",
|
||||||
|
"colFilename": "文件名",
|
||||||
|
"colPreview": "预览",
|
||||||
|
"colSize": "大小",
|
||||||
|
"colType": "类型",
|
||||||
|
"colSource": "来源",
|
||||||
|
"colUploadedAt": "上传时间",
|
||||||
|
"colActions": "操作",
|
||||||
|
"previewBadge": "图片",
|
||||||
|
"clear": "清空",
|
||||||
"selected": "已选 {n}",
|
"selected": "已选 {n}",
|
||||||
"batchDelete": "批量删除",
|
"batchDelete": "批量删除",
|
||||||
|
"batchSelect": "批量选择",
|
||||||
|
"viewMode": "视图模式",
|
||||||
|
"viewGrid": "网格视图",
|
||||||
|
"viewList": "列表视图",
|
||||||
|
"selectAll": "全选",
|
||||||
|
"invertSelection": "反选",
|
||||||
|
"clearSelection": "取消选择",
|
||||||
"scrollTop": "回到顶部",
|
"scrollTop": "回到顶部",
|
||||||
"loadFailed": "加载统计失败",
|
"loadFailed": "加载统计失败",
|
||||||
"selectFirst": "请先选择图片",
|
"selectFirst": "请先选择图片",
|
||||||
@@ -371,6 +466,27 @@
|
|||||||
"image": {
|
"image": {
|
||||||
"empty": "暂无图片",
|
"empty": "暂无图片",
|
||||||
"previewFailed": "预览失败",
|
"previewFailed": "预览失败",
|
||||||
|
"openPreview": "查看大图",
|
||||||
|
"previewTitle": "图片详情",
|
||||||
|
"previewSubtitle": "查看图片信息与链接",
|
||||||
|
"previewOriginalName": "文件名",
|
||||||
|
"previewUploadedAt": "上传时间",
|
||||||
|
"previewSize": "大小",
|
||||||
|
"previewSizeDetail": "{size}({bytes} 字节)",
|
||||||
|
"previewContentType": "文件类型",
|
||||||
|
"previewOwner": "上传用户",
|
||||||
|
"previewStorage": "存储位置",
|
||||||
|
"previewKey": "图片路径",
|
||||||
|
"previewExtension": "扩展名",
|
||||||
|
"previewDimensions": "尺寸",
|
||||||
|
"previewDimensionsUnknown": "加载中…",
|
||||||
|
"previewUploadSource": "上传方式",
|
||||||
|
"uploadSourceUnknown": "未知",
|
||||||
|
"previewLinks": "链接与嵌入",
|
||||||
|
"previewCopyLink": "复制链接",
|
||||||
|
"previewDownload": "下载原图",
|
||||||
|
"previewOpen": "新窗口打开",
|
||||||
|
"previewClose": "关闭",
|
||||||
"uploader": "上传者:{name}",
|
"uploader": "上传者:{name}",
|
||||||
"storageBackend": "存储:{name}"
|
"storageBackend": "存储:{name}"
|
||||||
},
|
},
|
||||||
@@ -380,6 +496,11 @@
|
|||||||
"confirm": "确认删除"
|
"confirm": "确认删除"
|
||||||
},
|
},
|
||||||
"pagination": {
|
"pagination": {
|
||||||
|
"totalCount": "共 {total} {unit}",
|
||||||
|
"pageStatus": "第 {page} / {totalPages} 页",
|
||||||
|
"perPage": "{size} 条/页",
|
||||||
|
"pageSize": "每页条数",
|
||||||
|
"pageNumber": "第 {page} 页",
|
||||||
"pageOf": "第 {page} / {totalPages} 页 · 共 {total} {unit}",
|
"pageOf": "第 {page} / {totalPages} 页 · 共 {total} {unit}",
|
||||||
"totalOnly": "共 {total} {unit}",
|
"totalOnly": "共 {total} {unit}",
|
||||||
"first": "第一页",
|
"first": "第一页",
|
||||||
@@ -387,6 +508,8 @@
|
|||||||
"next": "下一页",
|
"next": "下一页",
|
||||||
"last": "最后一页",
|
"last": "最后一页",
|
||||||
"goTo": "跳转",
|
"goTo": "跳转",
|
||||||
|
"goToPrefix": "前往",
|
||||||
|
"goToSuffix": "页",
|
||||||
"pagePlaceholder": "页码"
|
"pagePlaceholder": "页码"
|
||||||
},
|
},
|
||||||
"api": {
|
"api": {
|
||||||
@@ -415,6 +538,74 @@
|
|||||||
"newTokenDesc": "请立即复制保存。关闭弹窗后仍可在上方输入框复制,但请尽快更新到你的脚本配置中。",
|
"newTokenDesc": "请立即复制保存。关闭弹窗后仍可在上方输入框复制,但请尽快更新到你的脚本配置中。",
|
||||||
"copyToken": "复制 Token",
|
"copyToken": "复制 Token",
|
||||||
"saved": "我已保存",
|
"saved": "我已保存",
|
||||||
|
"searchPlaceholder": "搜索接口…",
|
||||||
|
"showToken": "显示",
|
||||||
|
"hideToken": "隐藏",
|
||||||
|
"helpText": "需要帮助?查看完整 API 文档",
|
||||||
|
"helpTitle": "需要帮助?",
|
||||||
|
"helpSubtitle": "查看完整 API 文档",
|
||||||
|
"expand": "展开",
|
||||||
|
"collapse": "收起",
|
||||||
|
"viewDocs": "查看文档",
|
||||||
|
"requestParams": "请求参数",
|
||||||
|
"paramName": "参数名",
|
||||||
|
"paramType": "类型",
|
||||||
|
"paramLocation": "位置",
|
||||||
|
"paramRequired": "必填",
|
||||||
|
"paramDescription": "说明",
|
||||||
|
"required": "是",
|
||||||
|
"optional": "否",
|
||||||
|
"requestExample": "请求示例",
|
||||||
|
"responseExample": "响应示例",
|
||||||
|
"categories": {
|
||||||
|
"image": "图片接口",
|
||||||
|
"extension": "插件接口",
|
||||||
|
"system": "系统通用"
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"upload": {
|
||||||
|
"image": "上传图片,主字段",
|
||||||
|
"file": "兼容字段,单图上传",
|
||||||
|
"files": "兼容字段,多图上传",
|
||||||
|
"token": "Twikoo 协议兼容,表单 token"
|
||||||
|
},
|
||||||
|
"list": {
|
||||||
|
"limit": "每页条数,默认 20,最大 100",
|
||||||
|
"page": "页码,从 1 开始"
|
||||||
|
},
|
||||||
|
"search": {
|
||||||
|
"q": "搜索关键词,必填"
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"key": "图片存储路径,如 images/2026/08/xxx.webp"
|
||||||
|
},
|
||||||
|
"batchDelete": {
|
||||||
|
"keys": "要删除的图片 key 数组"
|
||||||
|
},
|
||||||
|
"twikoo": {
|
||||||
|
"image": "上传图片",
|
||||||
|
"token": "API Token"
|
||||||
|
},
|
||||||
|
"backendId": "存储后端 ID,可选"
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"title": "在线调试",
|
||||||
|
"headers": "Headers",
|
||||||
|
"query": "Query",
|
||||||
|
"body": "Body",
|
||||||
|
"send": "发送请求",
|
||||||
|
"response": "响应",
|
||||||
|
"selectFile": "选择文件",
|
||||||
|
"noFileSelected": "未选择任何文件",
|
||||||
|
"tokenPlaceholder": "输入 Auth-Token",
|
||||||
|
"invalidJson": "JSON 格式无效",
|
||||||
|
"sendFailed": "请求发送失败",
|
||||||
|
"networkError": "网络错误或无法连接",
|
||||||
|
"notesTitle": "响应说明",
|
||||||
|
"noteSuccess": "200 表示请求成功,返回 JSON 数据",
|
||||||
|
"noteError": "4xx / 5xx 表示请求失败,查看 error 字段",
|
||||||
|
"noteLimit": "上传限制:单次最多 10 张,单张最大 10 MB"
|
||||||
|
},
|
||||||
"docs": {
|
"docs": {
|
||||||
"upload": {
|
"upload": {
|
||||||
"title": "上传图片",
|
"title": "上传图片",
|
||||||
@@ -439,6 +630,14 @@
|
|||||||
"twikoo": {
|
"twikoo": {
|
||||||
"title": "twikoo 兼容上传",
|
"title": "twikoo 兼容上传",
|
||||||
"desc": "兼容 Twikoo / EasyImage 2.0 协议,图片存入 images/ 目录;字段 image + token。"
|
"desc": "兼容 Twikoo / EasyImage 2.0 协议,图片存入 images/ 目录;字段 image + token。"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"title": "获取配置",
|
||||||
|
"desc": "获取系统公开配置,无需鉴权。"
|
||||||
|
},
|
||||||
|
"count": {
|
||||||
|
"title": "图片数量统计",
|
||||||
|
"desc": "获取当前可见范围内的图片总数。"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "pichost",
|
"name": "pichost",
|
||||||
"version": "1.2.4",
|
"version": "1.2.6",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "pichost",
|
"name": "pichost",
|
||||||
"version": "1.2.4",
|
"version": "1.2.6",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pichost",
|
"name": "pichost",
|
||||||
"version": "1.2.4",
|
"version": "1.2.6",
|
||||||
"description": "Self-hosted image hosting for your NAS / home server — Nuxt admin UI, local disk or S3-compatible storage, server-side WebP compression, referer protection, Twikoo/EasyImage compatible.",
|
"description": "Self-hosted image hosting for your NAS / home server — Nuxt admin UI, local disk or S3-compatible storage, server-side WebP compression, referer protection, Twikoo/EasyImage compatible.",
|
||||||
"homepage": "https://github.com/O96u/PicHost#readme",
|
"homepage": "https://github.com/O96u/PicHost#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import type { ServingMode } from '../../../utils/storage/types'
|
|||||||
|
|
||||||
interface StorageCreateBody {
|
interface StorageCreateBody {
|
||||||
name?: string
|
name?: string
|
||||||
|
provider?: string
|
||||||
config?: {
|
config?: {
|
||||||
endpoint?: string
|
endpoint?: string
|
||||||
region?: string
|
region?: string
|
||||||
@@ -70,6 +71,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const id = insertStorageBackend({
|
const id = insertStorageBackend({
|
||||||
name,
|
name,
|
||||||
|
provider: body.provider?.trim(),
|
||||||
config,
|
config,
|
||||||
secrets: { accessKeyId, secretAccessKey },
|
secrets: { accessKeyId, secretAccessKey },
|
||||||
servingMode: body.servingMode,
|
servingMode: body.servingMode,
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import {
|
|||||||
MAX_LIST_LIMIT
|
MAX_LIST_LIMIT
|
||||||
} from '../../utils/constants'
|
} from '../../utils/constants'
|
||||||
import { createApiError } from '../../utils/api-error'
|
import { createApiError } from '../../utils/api-error'
|
||||||
import { listUserIdUsernameMap } from '../../utils/db'
|
import { getUploadSourcesForKeys, listUserIdUsernameMap } from '../../utils/db'
|
||||||
import { mapStoredImageToItem } from '../../utils/image-response'
|
import { mapStoredImageToItem } from '../../utils/image-response'
|
||||||
import { listStorageBackendNameMap } from '../../utils/storage-backends'
|
import { listStorageBackendNameMap } from '../../utils/storage-backends'
|
||||||
import { readBackendIdQuery } from '../../utils/image-query'
|
import { readBackendIdQuery, readContentTypeQuery, readUploadSourceQuery } from '../../utils/image-query'
|
||||||
import { listImages } from '../../utils/storage'
|
import { listImages } from '../../utils/storage'
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
@@ -31,15 +31,31 @@ export default defineEventHandler(async (event) => {
|
|||||||
if (backendId === null) {
|
if (backendId === null) {
|
||||||
createApiError(event, 'INVALID_REQUEST', '无效的存储后端', 400)
|
createApiError(event, 'INVALID_REQUEST', '无效的存储后端', 400)
|
||||||
}
|
}
|
||||||
|
const contentType = readContentTypeQuery(query)
|
||||||
|
if (contentType === null) {
|
||||||
|
createApiError(event, 'INVALID_REQUEST', '无效的图片类型', 400)
|
||||||
|
}
|
||||||
|
const uploadSource = readUploadSourceQuery(query)
|
||||||
|
if (uploadSource === null) {
|
||||||
|
createApiError(event, 'INVALID_REQUEST', '无效的上传来源', 400)
|
||||||
|
}
|
||||||
const userFilter = await getImageUserFilter(event)
|
const userFilter = await getImageUserFilter(event)
|
||||||
|
|
||||||
const listing = await listImages({ limit, page, userFilter, backendId })
|
const listing = await listImages({
|
||||||
|
limit,
|
||||||
|
page,
|
||||||
|
userFilter,
|
||||||
|
backendId,
|
||||||
|
contentType,
|
||||||
|
uploadSource
|
||||||
|
})
|
||||||
|
|
||||||
const user = await getCurrentUser(event)
|
const user = await getCurrentUser(event)
|
||||||
const ownerMap = user?.role === 'admin' ? listUserIdUsernameMap() : undefined
|
const ownerMap = user?.role === 'admin' ? listUserIdUsernameMap() : undefined
|
||||||
const backendMap = listStorageBackendNameMap()
|
const backendMap = listStorageBackendNameMap()
|
||||||
|
const sourceMap = getUploadSourcesForKeys(listing.items.map(item => item.key))
|
||||||
const items = listing.items.map(stored =>
|
const items = listing.items.map(stored =>
|
||||||
mapStoredImageToItem(event, stored, { ownerMap, backendMap })
|
mapStoredImageToItem(event, stored, { ownerMap, backendMap, sourceMap })
|
||||||
)
|
)
|
||||||
|
|
||||||
items.sort((a, b) => b.uploadedAt.localeCompare(a.uploadedAt))
|
items.sort((a, b) => b.uploadedAt.localeCompare(a.uploadedAt))
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import {
|
|||||||
MAX_LIST_LIMIT
|
MAX_LIST_LIMIT
|
||||||
} from '../../utils/constants'
|
} from '../../utils/constants'
|
||||||
import { createApiError } from '../../utils/api-error'
|
import { createApiError } from '../../utils/api-error'
|
||||||
import { listUserIdUsernameMap } from '../../utils/db'
|
import { getUploadSourcesForKeys, listUserIdUsernameMap } from '../../utils/db'
|
||||||
import { mapStoredImageToItem } from '../../utils/image-response'
|
import { mapStoredImageToItem } from '../../utils/image-response'
|
||||||
import { listStorageBackendNameMap } from '../../utils/storage-backends'
|
import { listStorageBackendNameMap } from '../../utils/storage-backends'
|
||||||
import { readBackendIdQuery } from '../../utils/image-query'
|
import { readBackendIdQuery, readContentTypeQuery, readUploadSourceQuery } from '../../utils/image-query'
|
||||||
import { searchImages } from '../../utils/storage'
|
import { searchImages } from '../../utils/storage'
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
@@ -40,15 +40,32 @@ export default defineEventHandler(async (event) => {
|
|||||||
if (backendId === null) {
|
if (backendId === null) {
|
||||||
createApiError(event, 'INVALID_REQUEST', '无效的存储后端', 400)
|
createApiError(event, 'INVALID_REQUEST', '无效的存储后端', 400)
|
||||||
}
|
}
|
||||||
|
const contentType = readContentTypeQuery(query)
|
||||||
|
if (contentType === null) {
|
||||||
|
createApiError(event, 'INVALID_REQUEST', '无效的图片类型', 400)
|
||||||
|
}
|
||||||
|
const uploadSource = readUploadSourceQuery(query)
|
||||||
|
if (uploadSource === null) {
|
||||||
|
createApiError(event, 'INVALID_REQUEST', '无效的上传来源', 400)
|
||||||
|
}
|
||||||
const userFilter = await getImageUserFilter(event)
|
const userFilter = await getImageUserFilter(event)
|
||||||
|
|
||||||
const result = await searchImages({ query: q, limit, page, userFilter, backendId })
|
const result = await searchImages({
|
||||||
|
query: q,
|
||||||
|
limit,
|
||||||
|
page,
|
||||||
|
userFilter,
|
||||||
|
backendId,
|
||||||
|
contentType,
|
||||||
|
uploadSource
|
||||||
|
})
|
||||||
|
|
||||||
const user = await getCurrentUser(event)
|
const user = await getCurrentUser(event)
|
||||||
const ownerMap = user?.role === 'admin' ? listUserIdUsernameMap() : undefined
|
const ownerMap = user?.role === 'admin' ? listUserIdUsernameMap() : undefined
|
||||||
const backendMap = listStorageBackendNameMap()
|
const backendMap = listStorageBackendNameMap()
|
||||||
|
const sourceMap = getUploadSourcesForKeys(result.items.map(item => item.key))
|
||||||
const items = result.items.map(stored =>
|
const items = result.items.map(stored =>
|
||||||
mapStoredImageToItem(event, stored, { ownerMap, backendMap })
|
mapStoredImageToItem(event, stored, { ownerMap, backendMap, sourceMap })
|
||||||
)
|
)
|
||||||
|
|
||||||
items.sort((a, b) => b.uploadedAt.localeCompare(a.uploadedAt))
|
items.sort((a, b) => b.uploadedAt.localeCompare(a.uploadedAt))
|
||||||
|
|||||||
@@ -7,6 +7,34 @@ import {
|
|||||||
getFolderStorageStats,
|
getFolderStorageStats,
|
||||||
getUserScopedStorageStats
|
getUserScopedStorageStats
|
||||||
} from '../utils/storage'
|
} from '../utils/storage'
|
||||||
|
import { buildBackendCapacity } from '../utils/storage-capacity'
|
||||||
|
import { getActiveBackendRow } from '../utils/storage/resolver'
|
||||||
|
|
||||||
|
interface StorageUsageStat {
|
||||||
|
usedBytes: number
|
||||||
|
totalBytes: number | null
|
||||||
|
percent: number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveStorageUsage(usedBytes: number): Promise<StorageUsageStat> {
|
||||||
|
const backend = getActiveBackendRow()
|
||||||
|
if (!backend) {
|
||||||
|
return { usedBytes, totalBytes: null, percent: null }
|
||||||
|
}
|
||||||
|
|
||||||
|
const capacity = await buildBackendCapacity(
|
||||||
|
backend.id,
|
||||||
|
backend.type,
|
||||||
|
usedBytes,
|
||||||
|
backend.quota_bytes
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
usedBytes,
|
||||||
|
totalBytes: capacity.totalBytes,
|
||||||
|
percent: capacity.percent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const user = await requireUserAuth(event)
|
const user = await requireUserAuth(event)
|
||||||
@@ -14,25 +42,30 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (user.role === 'admin' && userFilter === 'admin') {
|
if (user.role === 'admin' && userFilter === 'admin') {
|
||||||
const [activity, storedCount, byFolder] = await Promise.all([
|
const activity = getActivityStats()
|
||||||
Promise.resolve(getActivityStats()),
|
const [storedCount, byFolder, storageUsage] = await Promise.all([
|
||||||
countImages(),
|
countImages(),
|
||||||
getFolderStorageStats()
|
getFolderStorageStats(),
|
||||||
|
resolveStorageUsage(activity.uploadBytesTotal)
|
||||||
])
|
])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...activity,
|
...activity,
|
||||||
storedCount,
|
storedCount,
|
||||||
byFolder,
|
byFolder,
|
||||||
userCount: countUsers()
|
userCount: countUsers(),
|
||||||
|
storageUsage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const scoped = await getUserScopedStorageStats(user.id)
|
const scoped = await getUserScopedStorageStats(user.id)
|
||||||
|
const storageUsage = await resolveStorageUsage(scoped.uploadBytesTotal)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uploadToday: scoped.uploadToday,
|
uploadToday: scoped.uploadToday,
|
||||||
|
uploadYesterday: scoped.uploadYesterday,
|
||||||
uploadMonth: scoped.uploadMonth,
|
uploadMonth: scoped.uploadMonth,
|
||||||
|
uploadLastMonth: scoped.uploadLastMonth,
|
||||||
deleteToday: 0,
|
deleteToday: 0,
|
||||||
deleteMonth: 0,
|
deleteMonth: 0,
|
||||||
uploadTotal: scoped.storedCount,
|
uploadTotal: scoped.storedCount,
|
||||||
@@ -44,7 +77,8 @@ export default defineEventHandler(async (event) => {
|
|||||||
count: item.count
|
count: item.count
|
||||||
})),
|
})),
|
||||||
storedCount: scoped.storedCount,
|
storedCount: scoped.storedCount,
|
||||||
byFolder: scoped.byFolder
|
byFolder: scoped.byFolder,
|
||||||
|
storageUsage
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logException('stats failed', error)
|
logException('stats failed', error)
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const config = useRuntimeConfig(event)
|
const config = useRuntimeConfig(event)
|
||||||
const currentVersion = String(config.appVersion ?? '')
|
const currentVersion = String(config.appVersion ?? '')
|
||||||
const latest = await fetchLatestGitHubRelease()
|
const query = getQuery(event)
|
||||||
|
const force = query.refresh === '1' || query.refresh === 'true'
|
||||||
|
const latest = await fetchLatestGitHubRelease(force)
|
||||||
|
|
||||||
if (!latest) {
|
if (!latest) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ export function isVersionNewer(candidate: string, current: string): boolean {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchLatestGitHubRelease(): Promise<LatestReleaseInfo | null> {
|
export async function fetchLatestGitHubRelease(force = false): Promise<LatestReleaseInfo | null> {
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
if (cachedRelease && now - cachedRelease.fetchedAt < CACHE_TTL_MS) {
|
if (!force && cachedRelease && now - cachedRelease.fetchedAt < CACHE_TTL_MS) {
|
||||||
return cachedRelease.value
|
return cachedRelease.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -445,6 +445,34 @@ export function insertActivityLog(input: ActivityLogInput): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 按图片 key 查最近一次上传记录的来源(网页 / API) */
|
||||||
|
export function getUploadSourcesForKeys(keys: string[]): Map<string, LogSource> {
|
||||||
|
const result = new Map<string, LogSource>()
|
||||||
|
if (!keys.length) return result
|
||||||
|
|
||||||
|
const placeholders = keys.map(() => '?').join(', ')
|
||||||
|
const rows = getDb().prepare(`
|
||||||
|
SELECT al.key, al.source
|
||||||
|
FROM activity_logs al
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT key, MAX(id) AS max_id
|
||||||
|
FROM activity_logs
|
||||||
|
WHERE action = 'upload' AND key IN (${placeholders})
|
||||||
|
GROUP BY key
|
||||||
|
) latest ON al.id = latest.max_id
|
||||||
|
`).all(...keys) as Array<{ key: string, source: string }>
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const raw = row.source
|
||||||
|
const source = raw === 'twikoo' ? 'api' : raw
|
||||||
|
if (source === 'web' || source === 'api') {
|
||||||
|
result.set(row.key, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
export function listActivityLogs(options: {
|
export function listActivityLogs(options: {
|
||||||
limit: number
|
limit: number
|
||||||
page?: number
|
page?: number
|
||||||
@@ -585,6 +613,15 @@ function countSince(action: LogAction, sinceIso: string): number {
|
|||||||
return row?.total ?? 0
|
return row?.total ?? 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function countBetween(action: LogAction, startIso: string, endIso: string): number {
|
||||||
|
const row = getDb().prepare(`
|
||||||
|
SELECT COUNT(*) AS total
|
||||||
|
FROM activity_logs
|
||||||
|
WHERE action = ? AND created_at >= ? AND created_at < ?
|
||||||
|
`).get(action, startIso, endIso) as unknown as { total: number } | undefined
|
||||||
|
return row?.total ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
function sumUploadBytes(): number {
|
function sumUploadBytes(): number {
|
||||||
const row = getDb().prepare(`
|
const row = getDb().prepare(`
|
||||||
SELECT COALESCE(SUM(size), 0) AS total
|
SELECT COALESCE(SUM(size), 0) AS total
|
||||||
@@ -646,9 +683,23 @@ function startOfMonthIsoInShanghai(now = new Date()): string {
|
|||||||
return new Date(Date.UTC(y, m, 1) - 8 * 60 * 60 * 1000).toISOString()
|
return new Date(Date.UTC(y, m, 1) - 8 * 60 * 60 * 1000).toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startOfYesterdayIsoInShanghai(now = new Date()): string {
|
||||||
|
const startOfDay = startOfDayIsoInShanghai(now)
|
||||||
|
return new Date(new Date(startOfDay).getTime() - 24 * 60 * 60 * 1000).toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
function startOfLastMonthIsoInShanghai(now = new Date()): string {
|
||||||
|
const shifted = new Date(now.getTime() + 8 * 60 * 60 * 1000)
|
||||||
|
const y = shifted.getUTCFullYear()
|
||||||
|
const m = shifted.getUTCMonth()
|
||||||
|
return new Date(Date.UTC(y, m - 1, 1) - 8 * 60 * 60 * 1000).toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
export function getActivityStats(): {
|
export function getActivityStats(): {
|
||||||
uploadToday: number
|
uploadToday: number
|
||||||
|
uploadYesterday: number
|
||||||
uploadMonth: number
|
uploadMonth: number
|
||||||
|
uploadLastMonth: number
|
||||||
deleteToday: number
|
deleteToday: number
|
||||||
deleteMonth: number
|
deleteMonth: number
|
||||||
uploadTotal: number
|
uploadTotal: number
|
||||||
@@ -659,6 +710,8 @@ export function getActivityStats(): {
|
|||||||
} {
|
} {
|
||||||
const startOfDay = startOfDayIsoInShanghai()
|
const startOfDay = startOfDayIsoInShanghai()
|
||||||
const startOfMonth = startOfMonthIsoInShanghai()
|
const startOfMonth = startOfMonthIsoInShanghai()
|
||||||
|
const startOfYesterday = startOfYesterdayIsoInShanghai()
|
||||||
|
const startOfLastMonth = startOfLastMonthIsoInShanghai()
|
||||||
|
|
||||||
const uploadTotalRow = getDb().prepare(`
|
const uploadTotalRow = getDb().prepare(`
|
||||||
SELECT COUNT(*) AS total FROM activity_logs WHERE action = 'upload'
|
SELECT COUNT(*) AS total FROM activity_logs WHERE action = 'upload'
|
||||||
@@ -669,7 +722,9 @@ export function getActivityStats(): {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
uploadToday: countSince('upload', startOfDay),
|
uploadToday: countSince('upload', startOfDay),
|
||||||
|
uploadYesterday: countBetween('upload', startOfYesterday, startOfDay),
|
||||||
uploadMonth: countSince('upload', startOfMonth),
|
uploadMonth: countSince('upload', startOfMonth),
|
||||||
|
uploadLastMonth: countBetween('upload', startOfLastMonth, startOfMonth),
|
||||||
deleteToday: countSince('delete', startOfDay),
|
deleteToday: countSince('delete', startOfDay),
|
||||||
deleteMonth: countSince('delete', startOfMonth),
|
deleteMonth: countSince('delete', startOfMonth),
|
||||||
uploadTotal: uploadTotalRow.total,
|
uploadTotal: uploadTotalRow.total,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { promises as fs } from 'node:fs'
|
import { promises as fs } from 'node:fs'
|
||||||
import { dirname, join } from 'node:path'
|
import { dirname, join } from 'node:path'
|
||||||
import { getDb } from './db'
|
import { getDb, getUploadSourcesForKeys } from './db'
|
||||||
import { getDataDir } from './data-dir'
|
import { getDataDir } from './data-dir'
|
||||||
import { contentTypeFromKey } from './content-type'
|
import { contentTypeFromKey } from './content-type'
|
||||||
import { DEFAULT_FOLDER, toCanonicalImageKey, validateImageKey } from './image-key'
|
import { DEFAULT_FOLDER, toCanonicalImageKey, validateImageKey } from './image-key'
|
||||||
@@ -402,11 +402,31 @@ function paginateSlice<T>(
|
|||||||
return { items, total, page: safePage, pageSize, totalPages }
|
return { items, total, page: safePage, pageSize, totalPages }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterImageRows(
|
||||||
|
rows: ImageIndexRow[],
|
||||||
|
options: {
|
||||||
|
contentType?: string
|
||||||
|
uploadSource?: 'web' | 'api'
|
||||||
|
}
|
||||||
|
): ImageIndexRow[] {
|
||||||
|
let filtered = rows
|
||||||
|
if (options.contentType) {
|
||||||
|
filtered = filtered.filter(row => row.content_type === options.contentType)
|
||||||
|
}
|
||||||
|
if (options.uploadSource) {
|
||||||
|
const sourceMap = getUploadSourcesForKeys(filtered.map(row => row.key))
|
||||||
|
filtered = filtered.filter(row => sourceMap.get(row.key) === options.uploadSource)
|
||||||
|
}
|
||||||
|
return filtered
|
||||||
|
}
|
||||||
|
|
||||||
export async function listImages(options: {
|
export async function listImages(options: {
|
||||||
limit: number
|
limit: number
|
||||||
page?: number
|
page?: number
|
||||||
userFilter?: number | 'admin'
|
userFilter?: number | 'admin'
|
||||||
backendId?: string
|
backendId?: string
|
||||||
|
contentType?: string
|
||||||
|
uploadSource?: 'web' | 'api'
|
||||||
}): Promise<PaginatedResult<StoredImage>> {
|
}): Promise<PaginatedResult<StoredImage>> {
|
||||||
ensureStorageSchema()
|
ensureStorageSchema()
|
||||||
const params: Array<string | number> = []
|
const params: Array<string | number> = []
|
||||||
@@ -421,7 +441,11 @@ export async function listImages(options: {
|
|||||||
ORDER BY uploaded_at DESC, key DESC
|
ORDER BY uploaded_at DESC, key DESC
|
||||||
`).all(...params) as unknown as ImageIndexRow[]
|
`).all(...params) as unknown as ImageIndexRow[]
|
||||||
|
|
||||||
const sliced = paginateSlice(rows, options.limit, options.page)
|
const filtered = filterImageRows(rows, {
|
||||||
|
contentType: options.contentType,
|
||||||
|
uploadSource: options.uploadSource
|
||||||
|
})
|
||||||
|
const sliced = paginateSlice(filtered, options.limit, options.page)
|
||||||
return {
|
return {
|
||||||
...sliced,
|
...sliced,
|
||||||
items: sliced.items.map(rowToStoredImage)
|
items: sliced.items.map(rowToStoredImage)
|
||||||
@@ -434,6 +458,8 @@ export async function searchImages(options: {
|
|||||||
page?: number
|
page?: number
|
||||||
userFilter?: number | 'admin'
|
userFilter?: number | 'admin'
|
||||||
backendId?: string
|
backendId?: string
|
||||||
|
contentType?: string
|
||||||
|
uploadSource?: 'web' | 'api'
|
||||||
}): Promise<PaginatedResult<StoredImage>> {
|
}): Promise<PaginatedResult<StoredImage>> {
|
||||||
ensureStorageSchema()
|
ensureStorageSchema()
|
||||||
const needle = options.query.trim().toLowerCase()
|
const needle = options.query.trim().toLowerCase()
|
||||||
@@ -455,7 +481,11 @@ export async function searchImages(options: {
|
|||||||
|| row.original_name.toLowerCase().includes(needle)
|
|| row.original_name.toLowerCase().includes(needle)
|
||||||
})
|
})
|
||||||
|
|
||||||
const sliced = paginateSlice(matches, options.limit, options.page)
|
const filtered = filterImageRows(matches, {
|
||||||
|
contentType: options.contentType,
|
||||||
|
uploadSource: options.uploadSource
|
||||||
|
})
|
||||||
|
const sliced = paginateSlice(filtered, options.limit, options.page)
|
||||||
return {
|
return {
|
||||||
...sliced,
|
...sliced,
|
||||||
items: sliced.items.map(rowToStoredImage)
|
items: sliced.items.map(rowToStoredImage)
|
||||||
@@ -495,16 +525,32 @@ function startOfMonthIsoInShanghai(now = new Date()): string {
|
|||||||
return new Date(Date.UTC(y, m, 1) - 8 * 60 * 60 * 1000).toISOString()
|
return new Date(Date.UTC(y, m, 1) - 8 * 60 * 60 * 1000).toISOString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startOfLastMonthIsoInShanghai(now = new Date()): string {
|
||||||
|
const shifted = new Date(now.getTime() + 8 * 60 * 60 * 1000)
|
||||||
|
const y = shifted.getUTCFullYear()
|
||||||
|
const m = shifted.getUTCMonth()
|
||||||
|
return new Date(Date.UTC(y, m - 1, 1) - 8 * 60 * 60 * 1000).toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
|
function startOfYesterdayIsoInShanghai(now = new Date()): string {
|
||||||
|
const startOfDay = startOfDayIsoInShanghai(now)
|
||||||
|
return new Date(new Date(startOfDay).getTime() - 24 * 60 * 60 * 1000).toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
export async function getUserScopedStorageStats(userId: number): Promise<{
|
export async function getUserScopedStorageStats(userId: number): Promise<{
|
||||||
storedCount: number
|
storedCount: number
|
||||||
uploadBytesTotal: number
|
uploadBytesTotal: number
|
||||||
uploadToday: number
|
uploadToday: number
|
||||||
|
uploadYesterday: number
|
||||||
uploadMonth: number
|
uploadMonth: number
|
||||||
|
uploadLastMonth: number
|
||||||
byFolder: Array<{ folder: string, count: number, bytes: number }>
|
byFolder: Array<{ folder: string, count: number, bytes: number }>
|
||||||
}> {
|
}> {
|
||||||
ensureStorageSchema()
|
ensureStorageSchema()
|
||||||
const startOfDay = startOfDayIsoInShanghai()
|
const startOfDay = startOfDayIsoInShanghai()
|
||||||
const startOfMonth = startOfMonthIsoInShanghai()
|
const startOfMonth = startOfMonthIsoInShanghai()
|
||||||
|
const startOfYesterday = startOfYesterdayIsoInShanghai()
|
||||||
|
const startOfLastMonth = startOfLastMonthIsoInShanghai()
|
||||||
|
|
||||||
const rows = getDb().prepare(`
|
const rows = getDb().prepare(`
|
||||||
SELECT folder, size, uploaded_at
|
SELECT folder, size, uploaded_at
|
||||||
@@ -515,12 +561,16 @@ export async function getUserScopedStorageStats(userId: number): Promise<{
|
|||||||
const map = new Map<string, { count: number, bytes: number }>()
|
const map = new Map<string, { count: number, bytes: number }>()
|
||||||
let uploadBytesTotal = 0
|
let uploadBytesTotal = 0
|
||||||
let uploadToday = 0
|
let uploadToday = 0
|
||||||
|
let uploadYesterday = 0
|
||||||
let uploadMonth = 0
|
let uploadMonth = 0
|
||||||
|
let uploadLastMonth = 0
|
||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
uploadBytesTotal += row.size
|
uploadBytesTotal += row.size
|
||||||
if (row.uploaded_at >= startOfDay) uploadToday += 1
|
if (row.uploaded_at >= startOfDay) uploadToday += 1
|
||||||
|
if (row.uploaded_at >= startOfYesterday && row.uploaded_at < startOfDay) uploadYesterday += 1
|
||||||
if (row.uploaded_at >= startOfMonth) uploadMonth += 1
|
if (row.uploaded_at >= startOfMonth) uploadMonth += 1
|
||||||
|
if (row.uploaded_at >= startOfLastMonth && row.uploaded_at < startOfMonth) uploadLastMonth += 1
|
||||||
|
|
||||||
const current = map.get(row.folder) ?? { count: 0, bytes: 0 }
|
const current = map.get(row.folder) ?? { count: 0, bytes: 0 }
|
||||||
current.count += 1
|
current.count += 1
|
||||||
@@ -536,7 +586,9 @@ export async function getUserScopedStorageStats(userId: number): Promise<{
|
|||||||
storedCount: rows.length,
|
storedCount: rows.length,
|
||||||
uploadBytesTotal,
|
uploadBytesTotal,
|
||||||
uploadToday,
|
uploadToday,
|
||||||
|
uploadYesterday,
|
||||||
uploadMonth,
|
uploadMonth,
|
||||||
|
uploadLastMonth,
|
||||||
byFolder
|
byFolder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { getStorageBackendRow } from './storage-backends'
|
import { getStorageBackendRow } from './storage-backends'
|
||||||
|
import { ALLOWED_MIME_TYPES } from './constants'
|
||||||
|
|
||||||
export function readBackendIdQuery(
|
export function readBackendIdQuery(
|
||||||
query: Record<string, unknown>
|
query: Record<string, unknown>
|
||||||
@@ -7,3 +8,21 @@ export function readBackendIdQuery(
|
|||||||
if (!raw || raw === 'all') return undefined
|
if (!raw || raw === 'all') return undefined
|
||||||
return getStorageBackendRow(raw)?.id ?? null
|
return getStorageBackendRow(raw)?.id ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function readContentTypeQuery(
|
||||||
|
query: Record<string, unknown>
|
||||||
|
): string | undefined | null {
|
||||||
|
const raw = typeof query.contentType === 'string' ? query.contentType.trim() : ''
|
||||||
|
if (!raw || raw === 'all') return undefined
|
||||||
|
if (!(ALLOWED_MIME_TYPES as readonly string[]).includes(raw)) return null
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
|
||||||
|
export function readUploadSourceQuery(
|
||||||
|
query: Record<string, unknown>
|
||||||
|
): 'web' | 'api' | undefined | null {
|
||||||
|
const raw = typeof query.uploadSource === 'string' ? query.uploadSource.trim() : ''
|
||||||
|
if (!raw || raw === 'all') return undefined
|
||||||
|
if (raw === 'web' || raw === 'api') return raw
|
||||||
|
return null
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { H3Event } from 'h3'
|
import type { H3Event } from 'h3'
|
||||||
import type { ImageItem } from '~/types/image'
|
import type { ImageItem } from '~/types/image'
|
||||||
|
import type { LogSource } from './db'
|
||||||
import type { AllowedMimeType } from './constants'
|
import type { AllowedMimeType } from './constants'
|
||||||
import type { StoredImage } from './storage'
|
import type { StoredImage } from './storage'
|
||||||
import { getImageBaseUrl, isHideFolderInUrl } from './env'
|
import { getImageBaseUrl, isHideFolderInUrl } from './env'
|
||||||
@@ -50,6 +51,7 @@ export function mapStoredImageToItem(
|
|||||||
options?: {
|
options?: {
|
||||||
ownerMap?: Map<number, string>
|
ownerMap?: Map<number, string>
|
||||||
backendMap?: Map<string, { name: string, type: StorageBackendType }>
|
backendMap?: Map<string, { name: string, type: StorageBackendType }>
|
||||||
|
sourceMap?: Map<string, LogSource>
|
||||||
}
|
}
|
||||||
): ImageItem {
|
): ImageItem {
|
||||||
const item = buildImageItem({
|
const item = buildImageItem({
|
||||||
@@ -64,18 +66,16 @@ export function mapStoredImageToItem(
|
|||||||
|
|
||||||
const owner = resolveImageOwner(stored.userId, options?.ownerMap)
|
const owner = resolveImageOwner(stored.userId, options?.ownerMap)
|
||||||
const storage = resolveImageStorage(stored.backendId, options?.backendMap)
|
const storage = resolveImageStorage(stored.backendId, options?.backendMap)
|
||||||
|
const uploadSource = options?.sourceMap?.get(stored.key)
|
||||||
|
|
||||||
if (owner || storage) {
|
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
...(owner ? { owner } : {}),
|
...(owner ? { owner } : {}),
|
||||||
...(storage ? { storage } : {})
|
...(storage ? { storage } : {}),
|
||||||
|
...(uploadSource ? { uploadSource } : {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildImageUrl(
|
export function buildImageUrl(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
key: string,
|
key: string,
|
||||||
|
|||||||
@@ -169,14 +169,17 @@ export async function processSingleImageUpload(
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: buildImageItem({
|
item: {
|
||||||
|
...buildImageItem({
|
||||||
key,
|
key,
|
||||||
event,
|
event,
|
||||||
originalName,
|
originalName,
|
||||||
contentType: compressed.mime,
|
contentType: compressed.mime,
|
||||||
size: compressed.bytes.byteLength,
|
size: compressed.bytes.byteLength,
|
||||||
uploadedAt
|
uploadedAt
|
||||||
})
|
}),
|
||||||
|
uploadSource: input.source ?? 'web'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import {
|
||||||
|
generateStorageBackendId,
|
||||||
|
resolveObjectStorageIdPrefix
|
||||||
|
} from './storage-backends'
|
||||||
|
|
||||||
|
describe('resolveObjectStorageIdPrefix', () => {
|
||||||
|
it('uses explicit provider when given', () => {
|
||||||
|
expect(resolveObjectStorageIdPrefix(
|
||||||
|
{ endpoint: 'https://example.com' },
|
||||||
|
'r2'
|
||||||
|
)).toBe('r2')
|
||||||
|
expect(resolveObjectStorageIdPrefix(
|
||||||
|
{ endpoint: 'https://example.com' },
|
||||||
|
'aws'
|
||||||
|
)).toBe('s3')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('detects provider from endpoint', () => {
|
||||||
|
expect(resolveObjectStorageIdPrefix({
|
||||||
|
endpoint: 'https://abc123.r2.cloudflarestorage.com'
|
||||||
|
})).toBe('r2')
|
||||||
|
expect(resolveObjectStorageIdPrefix({
|
||||||
|
endpoint: 'https://cos.ap-guangzhou.myqcloud.com'
|
||||||
|
})).toBe('cos')
|
||||||
|
expect(resolveObjectStorageIdPrefix({
|
||||||
|
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com'
|
||||||
|
})).toBe('oss')
|
||||||
|
expect(resolveObjectStorageIdPrefix({
|
||||||
|
endpoint: 'https://s3.us-east-1.amazonaws.com'
|
||||||
|
})).toBe('s3')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('generateStorageBackendId', () => {
|
||||||
|
it('uses provider-specific prefix', () => {
|
||||||
|
expect(generateStorageBackendId('r2')).toMatch(/^r2-[0-9a-f]{8}$/)
|
||||||
|
expect(generateStorageBackendId('s3')).toMatch(/^s3-[0-9a-f]{8}$/)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -368,16 +368,39 @@ function getNextSortOrder(): number {
|
|||||||
return row.max_order + 1
|
return row.max_order + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generateStorageBackendId(): string {
|
export type ObjectStorageIdPrefix = 'r2' | 'cos' | 'oss' | 's3'
|
||||||
|
|
||||||
|
/** 根据表单预设或 endpoint 推断新建后端的 id 前缀 */
|
||||||
|
export function resolveObjectStorageIdPrefix(
|
||||||
|
config: Pick<S3BackendConfig, 'endpoint'>,
|
||||||
|
provider?: string
|
||||||
|
): ObjectStorageIdPrefix {
|
||||||
|
const normalized = provider?.trim().toLowerCase()
|
||||||
|
if (normalized === 'r2' || normalized === 'cos' || normalized === 'oss') {
|
||||||
|
return normalized
|
||||||
|
}
|
||||||
|
if (normalized === 'aws' || normalized === 's3') {
|
||||||
|
return 's3'
|
||||||
|
}
|
||||||
|
|
||||||
|
const endpoint = config.endpoint.trim().toLowerCase()
|
||||||
|
if (endpoint.includes('r2.cloudflarestorage.com')) return 'r2'
|
||||||
|
if (endpoint.includes('myqcloud.com')) return 'cos'
|
||||||
|
if (endpoint.includes('aliyuncs.com')) return 'oss'
|
||||||
|
return 's3'
|
||||||
|
}
|
||||||
|
|
||||||
|
export function generateStorageBackendId(prefix: ObjectStorageIdPrefix = 's3'): string {
|
||||||
const bytes = new Uint8Array(4)
|
const bytes = new Uint8Array(4)
|
||||||
crypto.getRandomValues(bytes)
|
crypto.getRandomValues(bytes)
|
||||||
const suffix = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('')
|
const suffix = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('')
|
||||||
return `s3-${suffix}`
|
return `${prefix}-${suffix}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function insertStorageBackend(input: {
|
export function insertStorageBackend(input: {
|
||||||
id?: string
|
id?: string
|
||||||
name: string
|
name: string
|
||||||
|
provider?: string
|
||||||
config: S3BackendConfig
|
config: S3BackendConfig
|
||||||
secrets: { accessKeyId: string, secretAccessKey: string }
|
secrets: { accessKeyId: string, secretAccessKey: string }
|
||||||
servingMode?: ServingMode
|
servingMode?: ServingMode
|
||||||
@@ -387,7 +410,8 @@ export function insertStorageBackend(input: {
|
|||||||
isDefault?: boolean
|
isDefault?: boolean
|
||||||
}): string {
|
}): string {
|
||||||
ensureDefaultBackends()
|
ensureDefaultBackends()
|
||||||
const id = input.id ?? generateStorageBackendId()
|
const idPrefix = resolveObjectStorageIdPrefix(input.config, input.provider)
|
||||||
|
const id = input.id ?? generateStorageBackendId(idPrefix)
|
||||||
const sortOrder = getNextSortOrder()
|
const sortOrder = getNextSortOrder()
|
||||||
|
|
||||||
getDb().prepare(`
|
getDb().prepare(`
|
||||||
|
|||||||
@@ -192,7 +192,9 @@ export async function getUserScopedStorageStats(userId: number): Promise<{
|
|||||||
storedCount: number
|
storedCount: number
|
||||||
uploadBytesTotal: number
|
uploadBytesTotal: number
|
||||||
uploadToday: number
|
uploadToday: number
|
||||||
|
uploadYesterday: number
|
||||||
uploadMonth: number
|
uploadMonth: number
|
||||||
|
uploadLastMonth: number
|
||||||
byFolder: FolderStorageStat[]
|
byFolder: FolderStorageStat[]
|
||||||
}> {
|
}> {
|
||||||
return getUserScopedStorageStatsFromIndex(userId)
|
return getUserScopedStorageStatsFromIndex(userId)
|
||||||
@@ -203,6 +205,8 @@ export async function listImages(options: {
|
|||||||
page?: number
|
page?: number
|
||||||
userFilter?: number | 'admin'
|
userFilter?: number | 'admin'
|
||||||
backendId?: string
|
backendId?: string
|
||||||
|
contentType?: string
|
||||||
|
uploadSource?: 'web' | 'api'
|
||||||
}): Promise<PaginatedResult<StoredImage>> {
|
}): Promise<PaginatedResult<StoredImage>> {
|
||||||
return listImagesFromIndex(options)
|
return listImagesFromIndex(options)
|
||||||
}
|
}
|
||||||
@@ -213,6 +217,8 @@ export async function searchImages(options: {
|
|||||||
page?: number
|
page?: number
|
||||||
userFilter?: number | 'admin'
|
userFilter?: number | 'admin'
|
||||||
backendId?: string
|
backendId?: string
|
||||||
|
contentType?: string
|
||||||
|
uploadSource?: 'web' | 'api'
|
||||||
}): Promise<PaginatedResult<StoredImage>> {
|
}): Promise<PaginatedResult<StoredImage>> {
|
||||||
return searchImagesFromIndex(options)
|
return searchImagesFromIndex(options)
|
||||||
}
|
}
|
||||||