feat: add editable software download catalog
This commit is contained in:
+11
-3
@@ -170,11 +170,19 @@ func (a *App) putRecord(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, download := range d.Downloads {
|
if _, provided := fields["downloads"]; !provided {
|
||||||
if strings.TrimSpace(download.Name) == "" || len(download.Name) > 100 || len(download.Version) > 100 || !webURL(download.URL, false) {
|
current, err := a.record("settings", "site")
|
||||||
fail(w, 400, "INVALID_INPUT")
|
var existing Settings
|
||||||
|
if err != nil || decodeData(current.Data, &existing) != nil {
|
||||||
|
fail(w, 409, "CONFLICT")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
d.Downloads = existing.Downloads
|
||||||
|
}
|
||||||
|
d.Downloads = normalizeDownloads(d.Downloads)
|
||||||
|
if !validDownloads(d.Downloads) {
|
||||||
|
fail(w, 400, "INVALID_INPUT")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
value = d
|
value = d
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Normalize on read, leaving original database rows intact until an administrator saves.
|
||||||
|
func normalizeDownloads(input []Download) []Download {
|
||||||
|
output := []Download{}
|
||||||
|
legacy := map[string]int{}
|
||||||
|
for _, item := range input {
|
||||||
|
if item.ID == "" && item.Category == "" && item.Description == "" && item.Files == nil && (item.URL != "" || item.Version != "") {
|
||||||
|
name := strings.TrimSpace(item.Name)
|
||||||
|
index, exists := legacy[name]
|
||||||
|
if !exists {
|
||||||
|
hash := sha256.Sum256([]byte(name))
|
||||||
|
index = len(output)
|
||||||
|
legacy[name] = index
|
||||||
|
output = append(output, Download{ID: fmt.Sprintf("legacy-%x", hash[:12]), Name: name, Category: "software", Files: []DownloadFile{}})
|
||||||
|
}
|
||||||
|
label := strings.TrimSpace(item.Version)
|
||||||
|
if label == "" {
|
||||||
|
label = name
|
||||||
|
}
|
||||||
|
output[index].Files = append(output[index].Files, DownloadFile{Label: label, URL: item.URL})
|
||||||
|
} else {
|
||||||
|
output = append(output, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
func validDownloads(items []Download) bool {
|
||||||
|
if len(items) > 100 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ids := map[string]bool{}
|
||||||
|
for _, item := range items {
|
||||||
|
if !validName(item.ID) || ids[item.ID] || strings.TrimSpace(item.Name) == "" || len(item.Name) > 300 || len(item.Description) > 100000 || len(item.Files) < 1 || len(item.Files) > 100 || item.Version != "" || item.URL != "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if item.Category != "os" && item.Category != "software" && item.Category != "fonts" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ids[item.ID] = true
|
||||||
|
for _, file := range item.Files {
|
||||||
|
if strings.TrimSpace(file.Label) == "" || len(file.Label) > 500 || !navigationURL(file.URL) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDownloadCatalogLegacyCompatibilityAndPersistence(t *testing.T) {
|
||||||
|
c := fixture(t)
|
||||||
|
c.login("admin")
|
||||||
|
initial, _ := c.app.record("settings", "site")
|
||||||
|
var old map[string]any
|
||||||
|
decodeData(initial.Data, &old)
|
||||||
|
old["downloads"] = []map[string]string{
|
||||||
|
{"name": "Ubuntu", "version": "24.04 (amd64)", "url": "https://example.invalid/ubuntu.iso"},
|
||||||
|
{"name": "Ubuntu", "version": "24.04 (arm64)", "url": "https://example.invalid/ubuntu-arm.iso"},
|
||||||
|
{"name": "Tool", "version": "", "url": "https://example.invalid/tool.zip"},
|
||||||
|
}
|
||||||
|
legacy, err := c.app.saveRecord("settings", "site", old, initial.Revision)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var rawBefore, rawAfter string
|
||||||
|
c.app.db.QueryRow("SELECT data FROM records WHERE kind='settings' AND id='site'").Scan(&rawBefore)
|
||||||
|
read := c.call("GET", "/api/v1/public", nil, false)
|
||||||
|
status(t, read, 200)
|
||||||
|
var public struct{ Site Settings }
|
||||||
|
if err := json.Unmarshal(read.Body.Bytes(), &public); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
items := public.Site.Downloads
|
||||||
|
if len(items) != 2 || items[0].Name != "Ubuntu" || len(items[0].Files) != 2 || items[0].Files[1].Label != "24.04 (arm64)" || items[1].Files[0].Label != "Tool" || items[0].Category != "software" || !validName(items[0].ID) || items[0].URL != "" {
|
||||||
|
t.Fatalf("legacy projects or version links lost: %+v", items)
|
||||||
|
}
|
||||||
|
c.app.db.QueryRow("SELECT data FROM records WHERE kind='settings' AND id='site'").Scan(&rawAfter)
|
||||||
|
if rawBefore != rawAfter {
|
||||||
|
t.Fatal("reading public data changed stored settings")
|
||||||
|
}
|
||||||
|
// Old open forms may still submit the former flat download structure.
|
||||||
|
w := c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": old, "revision": legacy.Revision}, true)
|
||||||
|
status(t, w, 200)
|
||||||
|
var saved Record
|
||||||
|
json.Unmarshal(w.Body.Bytes(), &saved)
|
||||||
|
var settings Settings
|
||||||
|
decodeData(saved.Data, &settings)
|
||||||
|
if !reflect.DeepEqual(settings.Downloads, items) {
|
||||||
|
t.Fatal("older form lost downloads or changed stable project IDs")
|
||||||
|
}
|
||||||
|
settings.Downloads[0].Category = "os"
|
||||||
|
settings.Downloads[0].Description = "## Ubuntu\n\n选择适合设备架构的版本。"
|
||||||
|
settings.Downloads[0].Files[0].URL = "/mirrors/ubuntu-releases/24.04/ubuntu.iso"
|
||||||
|
settings.Downloads = append(settings.Downloads, Download{ID: "fonts", Name: "字体", Category: "fonts", Files: []DownloadFile{{Label: "字体压缩包", URL: "https://example.invalid/font.zip"}}})
|
||||||
|
w = c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": settings, "revision": saved.Revision}, true)
|
||||||
|
status(t, w, 200)
|
||||||
|
status(t, c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": settings, "revision": saved.Revision}, true), 409)
|
||||||
|
json.Unmarshal(w.Body.Bytes(), &saved)
|
||||||
|
var omitted map[string]any
|
||||||
|
decodeData(settings, &omitted)
|
||||||
|
delete(omitted, "downloads")
|
||||||
|
w = c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": omitted, "revision": saved.Revision}, true)
|
||||||
|
status(t, w, 200)
|
||||||
|
json.Unmarshal(w.Body.Bytes(), &saved)
|
||||||
|
c.app.db.Close()
|
||||||
|
c.app.db, err = openDatabase(filepath.Join(c.app.cfg.Data, "mirrorouc.db"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
record, _ := c.app.record("settings", "site")
|
||||||
|
var restored Settings
|
||||||
|
decodeData(record.Data, &restored)
|
||||||
|
if !reflect.DeepEqual(restored.Downloads, settings.Downloads) {
|
||||||
|
t.Fatal("catalog changed after an older form save or process restart")
|
||||||
|
}
|
||||||
|
settings.Downloads = []Download{}
|
||||||
|
w = c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": settings, "revision": saved.Revision}, true)
|
||||||
|
status(t, w, 200)
|
||||||
|
json.Unmarshal(w.Body.Bytes(), &saved)
|
||||||
|
decodeData(saved.Data, &restored)
|
||||||
|
if restored.Downloads == nil || len(restored.Downloads) != 0 {
|
||||||
|
t.Fatal("explicitly clearing the catalog was not preserved")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDownloadCatalogValidationAndPermissions(t *testing.T) {
|
||||||
|
c := fixture(t)
|
||||||
|
c.login("admin")
|
||||||
|
record, _ := c.app.record("settings", "site")
|
||||||
|
base := Download{ID: "ubuntu", Name: "Ubuntu", Category: "os", Files: []DownloadFile{{Label: "24.04 LTS (amd64)", URL: "/mirrors/ubuntu-releases/24.04/ubuntu.iso"}}}
|
||||||
|
mutations := []func(*Download){
|
||||||
|
func(d *Download) { d.ID = "" },
|
||||||
|
func(d *Download) { d.Category = "unknown" },
|
||||||
|
func(d *Download) { d.Name = " " },
|
||||||
|
func(d *Download) { d.Files = nil },
|
||||||
|
func(d *Download) { d.Files[0].Label = " " },
|
||||||
|
func(d *Download) { d.Files[0].URL = "javascript:alert(1)" },
|
||||||
|
func(d *Download) { d.Files[0].URL = "//example.invalid/a.iso" },
|
||||||
|
func(d *Download) { d.Files[0].URL = "/\\example.invalid/a.iso" },
|
||||||
|
func(d *Download) { d.Files[0].URL = "https://user:password@example.invalid/a.iso" },
|
||||||
|
func(d *Download) { d.URL = "https://example.invalid/ambiguous-old-field" },
|
||||||
|
}
|
||||||
|
for index, mutate := range mutations {
|
||||||
|
var item Download
|
||||||
|
decodeData(base, &item)
|
||||||
|
mutate(&item)
|
||||||
|
settings := initialSettings()
|
||||||
|
settings.Downloads = []Download{item}
|
||||||
|
w := c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": settings, "revision": record.Revision}, true)
|
||||||
|
if w.Code != 400 {
|
||||||
|
t.Fatalf("invalid download case %d: status %d", index, w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings := initialSettings()
|
||||||
|
settings.Downloads = []Download{base, base}
|
||||||
|
status(t, c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": settings, "revision": record.Revision}, true), 400)
|
||||||
|
settings.Downloads = []Download{base}
|
||||||
|
c.login("editor")
|
||||||
|
status(t, c.call("PUT", "/api/v1/admin/records/settings/site", map[string]any{"data": settings, "revision": record.Revision}, true), 403)
|
||||||
|
}
|
||||||
+16
-3
@@ -13,9 +13,18 @@ type RelatedLink struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
type Download struct {
|
type Download struct {
|
||||||
Name string `json:"name"`
|
ID string `json:"id"`
|
||||||
Version string `json:"version"`
|
Name string `json:"name"`
|
||||||
URL string `json:"url"`
|
Category string `json:"category"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Files []DownloadFile `json:"files"`
|
||||||
|
// Read old settings and submissions without losing existing download links.
|
||||||
|
Version string `json:"version,omitempty"`
|
||||||
|
URL string `json:"url,omitempty"`
|
||||||
|
}
|
||||||
|
type DownloadFile struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
Name Localized `json:"name"`
|
Name Localized `json:"name"`
|
||||||
@@ -122,6 +131,10 @@ func settingsDefaults(data any) any {
|
|||||||
if value, exists := object["relatedLinks"]; !exists || value == nil {
|
if value, exists := object["relatedLinks"]; !exists || value == nil {
|
||||||
object["relatedLinks"] = initialRelatedLinks()
|
object["relatedLinks"] = initialRelatedLinks()
|
||||||
}
|
}
|
||||||
|
var downloads []Download
|
||||||
|
if decodeData(object["downloads"], &downloads) == nil {
|
||||||
|
object["downloads"] = normalizeDownloads(downloads)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -12,6 +12,7 @@ import StatusPage from './components/StatusPage.vue'
|
|||||||
import AdminPage from './components/AdminPage.vue'
|
import AdminPage from './components/AdminPage.vue'
|
||||||
import AnnouncementsPage from './components/AnnouncementsPage.vue'
|
import AnnouncementsPage from './components/AnnouncementsPage.vue'
|
||||||
import MarkdownContent from './components/MarkdownContent.vue'
|
import MarkdownContent from './components/MarkdownContent.vue'
|
||||||
|
import DownloadList from './components/DownloadList.vue'
|
||||||
import { content } from './api'
|
import { content } from './api'
|
||||||
import { announcementUrl } from './announcements'
|
import { announcementUrl } from './announcements'
|
||||||
import { usePublicData } from './usePublicData'
|
import { usePublicData } from './usePublicData'
|
||||||
@@ -277,12 +278,12 @@ onBeforeUnmount(() => {
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<dialog id="content-dialog" ref="dialog" class="content-dialog" aria-labelledby="dialog-title" @close="onDialogClose" @click="($event.target === $event.currentTarget) && closeModal()">
|
<dialog id="content-dialog" ref="dialog" class="content-dialog" :class="{ 'download-dialog': modal === 'downloads' }" aria-labelledby="dialog-title" @close="onDialogClose" @click="($event.target === $event.currentTarget) && closeModal()">
|
||||||
<div class="dialog-inner"><div class="dialog-heading"><h2 id="dialog-title">{{ modalTitle }}</h2><button class="icon-button" :aria-label="t('common.close')" autofocus @click="closeModal"><X :size="21" /></button></div>
|
<div class="dialog-inner"><div class="dialog-heading"><h2 id="dialog-title">{{ modalTitle }}</h2><button class="icon-button" :aria-label="t('common.close')" autofocus @click="closeModal"><X :size="21" /></button></div>
|
||||||
<div class="dialog-content">
|
<div class="dialog-content">
|
||||||
<template v-if="modal === 'mirror' && selectedMirror"><p class="dialog-lead">{{ description(selectedMirror) }}</p><div class="mirror-facts"><span>{{ t('mirrors.columns.status') }}</span><span>{{ t(`mirrors.status.${selectedMirror.status}`) }}</span><span>{{ t('mirrors.columns.updated') }}</span><span>{{ relativeTime(selectedMirror.lastSuccess) }}</span><span>{{ t('mirrors.columns.next') }}</span><span>{{ nextLabel(selectedMirror) }}</span></div><MarkdownContent v-if="selectedMirror.help" :source="selectedMirror.help" lang="zh-CN" /><p v-else class="dialog-hint">{{ t('common.noHelp') }}</p><div class="dialog-actions"><a class="text-button" :href="selectedMirror.browseUrl">{{ t('common.openDirectory') }}<ArrowRight :size="15" /></a><a v-if="selectedMirror.website" :href="selectedMirror.website" target="_blank" rel="noopener noreferrer" class="text-button">{{ t('mirrors.official') }}<ExternalLink :size="14" /></a></div></template>
|
<template v-if="modal === 'mirror' && selectedMirror"><p class="dialog-lead">{{ description(selectedMirror) }}</p><div class="mirror-facts"><span>{{ t('mirrors.columns.status') }}</span><span>{{ t(`mirrors.status.${selectedMirror.status}`) }}</span><span>{{ t('mirrors.columns.updated') }}</span><span>{{ relativeTime(selectedMirror.lastSuccess) }}</span><span>{{ t('mirrors.columns.next') }}</span><span>{{ nextLabel(selectedMirror) }}</span></div><MarkdownContent v-if="selectedMirror.help" :source="selectedMirror.help" lang="zh-CN" /><p v-else class="dialog-hint">{{ t('common.noHelp') }}</p><div class="dialog-actions"><a class="text-button" :href="selectedMirror.browseUrl">{{ t('common.openDirectory') }}<ArrowRight :size="15" /></a><a v-if="selectedMirror.website" :href="selectedMirror.website" target="_blank" rel="noopener noreferrer" class="text-button">{{ t('mirrors.official') }}<ExternalLink :size="14" /></a></div></template>
|
||||||
<template v-else-if="modal === 'help'"><p class="dialog-lead">{{ t('mirrors.helpIntro') }}</p><div class="help-grid"><button v-for="mirror in mirrors" :key="mirror.name" @click="openModal('mirror', mirror)"><span class="distro-mark" :style="{ '--distro-color': mirror.color }" aria-hidden="true">{{ mirror.mark }}</span><span>{{ mirror.name }}</span><ArrowRight :size="15" /></button></div></template>
|
<template v-else-if="modal === 'help'"><p class="dialog-lead">{{ t('mirrors.helpIntro') }}</p><div class="help-grid"><button v-for="mirror in mirrors" :key="mirror.name" @click="openModal('mirror', mirror)"><span class="distro-mark" :style="{ '--distro-color': mirror.color }" aria-hidden="true">{{ mirror.mark }}</span><span>{{ mirror.name }}</span><ArrowRight :size="15" /></button></div></template>
|
||||||
<template v-else-if="modal === 'downloads'"><p class="dialog-lead">{{ t('announcements.downloadsIntro') }}</p><p v-if="!distributions.length" class="dialog-hint">{{ t('common.noDownloads') }}</p><div class="modal-downloads"><a v-for="distro in distributions" :key="distro.name" :href="distro.url" target="_blank" rel="noopener noreferrer"><span>{{ distro.name }} {{ distro.version }}</span><ArrowUpRight :size="18" /></a></div></template>
|
<DownloadList v-else-if="modal === 'downloads'" :items="distributions" />
|
||||||
<template v-else-if="modal === 'about'"><img class="about-seal" :src="site?.avatar || '/assets/ouc-seal.png'" alt="" width="80" height="80" /><p class="article-body">{{ t('common.aboutBody') }}</p><div class="about-links"><a href="https://www.itouc.cn/" target="_blank" rel="noopener noreferrer">{{ t('common.studio') }}<ArrowUpRight :size="15" /></a><a href="https://github.com/tuna/tunasync" target="_blank" rel="noopener noreferrer">{{ t('common.source') }} · tunasync<ArrowUpRight :size="15" /></a></div></template>
|
<template v-else-if="modal === 'about'"><img class="about-seal" :src="site?.avatar || '/assets/ouc-seal.png'" alt="" width="80" height="80" /><p class="article-body">{{ t('common.aboutBody') }}</p><div class="about-links"><a href="https://www.itouc.cn/" target="_blank" rel="noopener noreferrer">{{ t('common.studio') }}<ArrowUpRight :size="15" /></a><a href="https://github.com/tuna/tunasync" target="_blank" rel="noopener noreferrer">{{ t('common.source') }} · tunasync<ArrowUpRight :size="15" /></a></div></template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
export type Localized = Record<string, string>
|
export type Localized = Record<string, string>
|
||||||
export interface SiteLink { title: Localized; url: string }
|
export interface SiteLink { title: Localized; url: string }
|
||||||
export interface RelatedLink extends SiteLink { kind: 'url' | 'help' }
|
export interface RelatedLink extends SiteLink { kind: 'url' | 'help' }
|
||||||
export interface SiteDownload { name: string; version: string; url: string }
|
export type DownloadCategory = 'os' | 'software' | 'fonts'
|
||||||
|
export interface DownloadFile { label: string; url: string }
|
||||||
|
export interface SiteDownload { id: string; name: string; category: DownloadCategory; description: string; files: DownloadFile[] }
|
||||||
export interface SiteSettings {
|
export interface SiteSettings {
|
||||||
name: Localized; description: Localized; logoLight: string; logoDark: string; favicon: string; avatar: string
|
name: Localized; description: Localized; logoLight: string; logoDark: string; favicon: string; avatar: string
|
||||||
email: string; address: Localized; links: SiteLink[]; relatedLinks: RelatedLink[]; downloads: SiteDownload[]
|
email: string; address: Localized; links: SiteLink[]; relatedLinks: RelatedLink[]; downloads: SiteDownload[]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { api, ApiError, jsonBody, setSession, type AdminSession, type AdminUser,
|
|||||||
import { supportedLocales } from '../locales'
|
import { supportedLocales } from '../locales'
|
||||||
import { announcementUrl } from '../announcements'
|
import { announcementUrl } from '../announcements'
|
||||||
import MarkdownContent from './MarkdownContent.vue'
|
import MarkdownContent from './MarkdownContent.vue'
|
||||||
|
import DownloadCatalogEditor from './DownloadCatalogEditor.vue'
|
||||||
|
|
||||||
const { t, te, d, n } = useI18n({ useScope: 'global' })
|
const { t, te, d, n } = useI18n({ useScope: 'global' })
|
||||||
const session = ref<AdminSession | null>(null)
|
const session = ref<AdminSession | null>(null)
|
||||||
@@ -13,13 +14,14 @@ const busy = ref(false)
|
|||||||
const error = ref('')
|
const error = ref('')
|
||||||
const notice = ref('')
|
const notice = ref('')
|
||||||
const tab = ref('overview')
|
const tab = ref('overview')
|
||||||
const tabs = ['overview', 'mirrors', 'announcements', 'config', 'settings', 'users', 'audit']
|
const tabs = ['overview', 'mirrors', 'announcements', 'downloads', 'config', 'settings', 'users', 'audit']
|
||||||
const allowedTabs = computed(() => session.value?.role === 'admin' ? tabs : ['announcements', 'users'])
|
const allowedTabs = computed(() => session.value?.role === 'admin' ? tabs : ['announcements', 'users'])
|
||||||
const credentials = reactive({ username: '', password: '' })
|
const credentials = reactive({ username: '', password: '' })
|
||||||
const overview = ref<Overview | null>(null)
|
const overview = ref<Overview | null>(null)
|
||||||
const articles = ref<ContentRecord<AnnouncementContent>[]>([])
|
const articles = ref<ContentRecord<AnnouncementContent>[]>([])
|
||||||
const metadata = ref<ContentRecord<MirrorMetadata>[]>([])
|
const metadata = ref<ContentRecord<MirrorMetadata>[]>([])
|
||||||
const settings = ref<ContentRecord<SiteSettings> | null>(null)
|
const settings = ref<ContentRecord<SiteSettings> | null>(null)
|
||||||
|
const downloadEditor = ref<InstanceType<typeof DownloadCatalogEditor>>()
|
||||||
const users = ref<AdminUser[]>([])
|
const users = ref<AdminUser[]>([])
|
||||||
const audit = ref<AuditPage>({ items: [], page: 1, pageSize: 10, total: 0, totalPages: 1 })
|
const audit = ref<AuditPage>({ items: [], page: 1, pageSize: 10, total: 0, totalPages: 1 })
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
@@ -80,7 +82,7 @@ async function loadTab(value: string) {
|
|||||||
if (value === 'overview' || value === 'mirrors') await loadOverview()
|
if (value === 'overview' || value === 'mirrors') await loadOverview()
|
||||||
if (value === 'mirrors') metadata.value = await api('/admin/records/mirrors')
|
if (value === 'mirrors') metadata.value = await api('/admin/records/mirrors')
|
||||||
if (value === 'announcements') articles.value = await api('/admin/records/announcements')
|
if (value === 'announcements') articles.value = await api('/admin/records/announcements')
|
||||||
if (value === 'settings') settings.value = (await api<ContentRecord<SiteSettings>[]>('/admin/records/settings'))[0] || null
|
if (value === 'settings' || value === 'downloads') settings.value = (await api<ContentRecord<SiteSettings>[]>('/admin/records/settings'))[0] || null
|
||||||
if (value === 'config') { config.value = await api('/admin/config'); versions.value = await api('/admin/config/versions'); draft.value = null; selectedConfig.value = ''; mirrorConfig.value = null }
|
if (value === 'config') { config.value = await api('/admin/config'); versions.value = await api('/admin/config/versions'); draft.value = null; selectedConfig.value = ''; mirrorConfig.value = null }
|
||||||
if (value === 'users' && session.value?.role === 'admin') users.value = await api('/admin/users')
|
if (value === 'users' && session.value?.role === 'admin') users.value = await api('/admin/users')
|
||||||
if (value === 'audit') await loadAudit()
|
if (value === 'audit') await loadAudit()
|
||||||
@@ -139,6 +141,11 @@ function editMirror(job: SyncJob) {
|
|||||||
mirrorEditor.value.data.description ||= {}; mirrorEditor.value.data.help ||= ''
|
mirrorEditor.value.data.description ||= {}; mirrorEditor.value.data.help ||= ''
|
||||||
}
|
}
|
||||||
async function saveMirror() { if (!mirrorEditor.value) return; mirrorEditor.value = await saveRecord('mirrors', mirrorEditor.value); metadata.value = await api('/admin/records/mirrors') }
|
async function saveMirror() { if (!mirrorEditor.value) return; mirrorEditor.value = await saveRecord('mirrors', mirrorEditor.value); metadata.value = await api('/admin/records/mirrors') }
|
||||||
|
async function saveDownloads() {
|
||||||
|
if (!settings.value) return
|
||||||
|
if (!downloadEditor.value?.validate()) { error.value = t('admin.incompleteDownload'); return }
|
||||||
|
settings.value = await saveRecord('settings', settings.value)
|
||||||
|
}
|
||||||
function command(job: SyncJob, action: string) {
|
function command(job: SyncJob, action: string) {
|
||||||
void ask(t('admin.commandConfirm', { name: job.name, action: t(`admin.${action}`) }), async () => {
|
void ask(t('admin.commandConfirm', { name: job.name, action: t(`admin.${action}`) }), async () => {
|
||||||
await api(`/admin/jobs/${encodeURIComponent(job.name)}/${action}`, { method: 'POST' }); notice.value = t('admin.submitted'); await loadOverview()
|
await api(`/admin/jobs/${encodeURIComponent(job.name)}/${action}`, { method: 'POST' }); notice.value = t('admin.submitted'); await loadOverview()
|
||||||
@@ -219,6 +226,7 @@ onBeforeUnmount(() => clearInterval(poll))
|
|||||||
</form>
|
</form>
|
||||||
<div class="admin-table-wrap articles-table"><table><thead><tr><th>{{ t('admin.articleTitle') }}</th><th>{{ t('admin.status') }}</th><th>{{ t('admin.date') }}</th><th>{{ t('admin.actions') }}</th></tr></thead><tbody><tr v-for="row in sortedArticles" :key="row.id"><td class="article-list-title"><span lang="zh-CN">{{ row.data.title }}</span><span v-if="row.data.pinned" class="article-pin">{{ t('admin.pinned') }}</span></td><td>{{ t(row.data.published ? 'admin.published' : 'admin.draft') }}</td><td><time :datetime="row.data.date">{{ d(new Date(row.data.date), 'article') }}</time></td><td><div class="row-actions"><button :disabled="busy" @click="editArticle(row)">{{ t('admin.edit') }}</button><a v-if="row.data.published" class="admin-public-link" :href="announcementUrl(row.id)" target="_blank" rel="noopener noreferrer">{{ t('admin.viewArticle') }}</a><button :disabled="busy" @click="deleteArticle(row)">{{ t('admin.remove') }}</button></div></td></tr></tbody></table><p v-if="!articles.length">{{ t('admin.empty') }}</p></div>
|
<div class="admin-table-wrap articles-table"><table><thead><tr><th>{{ t('admin.articleTitle') }}</th><th>{{ t('admin.status') }}</th><th>{{ t('admin.date') }}</th><th>{{ t('admin.actions') }}</th></tr></thead><tbody><tr v-for="row in sortedArticles" :key="row.id"><td class="article-list-title"><span lang="zh-CN">{{ row.data.title }}</span><span v-if="row.data.pinned" class="article-pin">{{ t('admin.pinned') }}</span></td><td>{{ t(row.data.published ? 'admin.published' : 'admin.draft') }}</td><td><time :datetime="row.data.date">{{ d(new Date(row.data.date), 'article') }}</time></td><td><div class="row-actions"><button :disabled="busy" @click="editArticle(row)">{{ t('admin.edit') }}</button><a v-if="row.data.published" class="admin-public-link" :href="announcementUrl(row.id)" target="_blank" rel="noopener noreferrer">{{ t('admin.viewArticle') }}</a><button :disabled="busy" @click="deleteArticle(row)">{{ t('admin.remove') }}</button></div></td></tr></tbody></table><p v-if="!articles.length">{{ t('admin.empty') }}</p></div>
|
||||||
</template>
|
</template>
|
||||||
|
<form v-if="tab === 'downloads' && settings" class="admin-form download-admin-form" @submit.prevent="run(saveDownloads)"><DownloadCatalogEditor ref="downloadEditor" v-model="settings.data.downloads" :busy="busy" /><button type="submit" class="primary" :disabled="busy">{{ t('admin.saveDownloads') }}</button></form>
|
||||||
<form v-if="tab === 'settings' && settings" class="admin-form" @submit.prevent="run(async () => { settings = await saveRecord('settings', settings!) })">
|
<form v-if="tab === 'settings' && settings" class="admin-form" @submit.prevent="run(async () => { settings = await saveRecord('settings', settings!) })">
|
||||||
<label>{{ t('admin.contentLanguage') }}<select v-model="editLocale"><option v-for="language in supportedLocales" :key="language" :value="language">{{ t('common.languageName', {}, { locale: language }) }}</option></select></label>
|
<label>{{ t('admin.contentLanguage') }}<select v-model="editLocale"><option v-for="language in supportedLocales" :key="language" :value="language">{{ t('common.languageName', {}, { locale: language }) }}</option></select></label>
|
||||||
<label v-for="field in localizedFields" :key="field">{{ t(field === 'name' ? 'admin.siteName' : `admin.${field}`) }}<textarea v-model="settings.data[field][editLocale]" rows="2" /></label>
|
<label v-for="field in localizedFields" :key="field">{{ t(field === 'name' ? 'admin.siteName' : `admin.${field}`) }}<textarea v-model="settings.data[field][editLocale]" rows="2" /></label>
|
||||||
@@ -235,7 +243,7 @@ onBeforeUnmount(() => clearInterval(poll))
|
|||||||
<button type="button" @click="settings.data.relatedLinks.push({ title: { 'zh-CN': '', 'en-US': '' }, kind: 'url', url: '' })">{{ t('admin.add') }}</button>
|
<button type="button" @click="settings.data.relatedLinks.push({ title: { 'zh-CN': '', 'en-US': '' }, kind: 'url', url: '' })">{{ t('admin.add') }}</button>
|
||||||
</section>
|
</section>
|
||||||
<h3>{{ t('admin.links') }}</h3><div v-for="(link, index) in settings.data.links" :key="index" class="admin-array"><label>{{ t('admin.articleTitle') }}<input v-model="link.title[editLocale]" /></label><label>{{ t('admin.url') }}<input v-model="link.url" type="url" required /></label><button type="button" @click="settings.data.links.splice(index,1)">{{ t('admin.remove') }}</button></div><button type="button" @click="settings.data.links.push({ title: { 'zh-CN': '', 'en-US': '' }, url: '' })">{{ t('admin.add') }}</button>
|
<h3>{{ t('admin.links') }}</h3><div v-for="(link, index) in settings.data.links" :key="index" class="admin-array"><label>{{ t('admin.articleTitle') }}<input v-model="link.title[editLocale]" /></label><label>{{ t('admin.url') }}<input v-model="link.url" type="url" required /></label><button type="button" @click="settings.data.links.splice(index,1)">{{ t('admin.remove') }}</button></div><button type="button" @click="settings.data.links.push({ title: { 'zh-CN': '', 'en-US': '' }, url: '' })">{{ t('admin.add') }}</button>
|
||||||
<h3>{{ t('admin.downloads') }}</h3><div v-for="(download,index) in settings.data.downloads" :key="index" class="admin-array"><label>{{ t('admin.name') }}<input v-model="download.name" required /></label><label>{{ t('admin.version') }}<input v-model="download.version" /></label><label>{{ t('admin.url') }}<input v-model="download.url" type="url" required /></label><button type="button" @click="settings.data.downloads.splice(index,1)">{{ t('admin.remove') }}</button></div><button type="button" @click="settings.data.downloads.push({ name: '', version: '', url: '' })">{{ t('admin.add') }}</button><button class="primary" :disabled="busy">{{ t('admin.save') }}</button>
|
<button class="primary" :disabled="busy">{{ t('admin.save') }}</button>
|
||||||
</form>
|
</form>
|
||||||
<template v-if="tab === 'config' && config">
|
<template v-if="tab === 'config' && config">
|
||||||
<p>{{ t('admin.intervalHint') }}</p><form class="admin-form" @submit.prevent="run(previewConfig)"><label>{{ t('admin.config') }}<select v-model="configScope" @change="draft = null"><option value="global">{{ t('admin.global') }}</option><option value="mirror">{{ t('admin.mirrorConfig') }}</option></select></label>
|
<p>{{ t('admin.intervalHint') }}</p><form class="admin-form" @submit.prevent="run(previewConfig)"><label>{{ t('admin.config') }}<select v-model="configScope" @change="draft = null"><option value="global">{{ t('admin.global') }}</option><option value="mirror">{{ t('admin.mirrorConfig') }}</option></select></label>
|
||||||
@@ -277,6 +285,7 @@ button:hover { border-color: var(--blue); color: var(--blue); } button:disabled
|
|||||||
.admin-tabs button { flex-shrink: 0; border-color: transparent; background: transparent; } .admin-tabs [aria-current] { border-bottom: 2px solid var(--blue); color: var(--blue); border-radius: 0; font-weight: 700; }
|
.admin-tabs button { flex-shrink: 0; border-color: transparent; background: transparent; } .admin-tabs [aria-current] { border-bottom: 2px solid var(--blue); color: var(--blue); border-radius: 0; font-weight: 700; }
|
||||||
.admin-error, .admin-notice { padding: 12px 16px; border-left: 3px solid var(--blue); background: var(--panel); overflow-wrap: anywhere; } .admin-error { border-color: #d65252; }
|
.admin-error, .admin-notice { padding: 12px 16px; border-left: 3px solid var(--blue); background: var(--panel); overflow-wrap: anywhere; } .admin-error { border-color: #d65252; }
|
||||||
.admin-form { display: grid; gap: 18px; max-width: 1100px; } .admin-login { max-width: 420px; }
|
.admin-form { display: grid; gap: 18px; max-width: 1100px; } .admin-login { max-width: 420px; }
|
||||||
|
.download-admin-form { max-width: none; }
|
||||||
label { display: flex; flex-direction: column; gap: 8px; min-width: 0; font-size: 14px; font-weight: 500; }
|
label { display: flex; flex-direction: column; gap: 8px; min-width: 0; font-size: 14px; font-weight: 500; }
|
||||||
input, textarea, select { width: 100%; min-width: 0; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); color: var(--ink); font: inherit; }
|
input, textarea, select { width: 100%; min-width: 0; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); color: var(--ink); font: inherit; }
|
||||||
textarea { resize: vertical; line-height: 1.7; } .check { flex-direction: row; align-items: center; gap: 8px; } .check input { width: 18px; min-height: 18px; accent-color: var(--blue); }
|
textarea { resize: vertical; line-height: 1.7; } .check { flex-direction: row; align-items: center; gap: 8px; } .check input { width: 18px; min-height: 18px; accent-color: var(--blue); }
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import type { SiteDownload } from '../api'
|
||||||
|
import MarkdownContent from './MarkdownContent.vue'
|
||||||
|
|
||||||
|
const items = defineModel<SiteDownload[]>({ required: true })
|
||||||
|
defineProps<{ busy: boolean }>()
|
||||||
|
const { t } = useI18n()
|
||||||
|
const selectedId = ref('')
|
||||||
|
const selected = computed(() => items.value.find(item => item.id === selectedId.value))
|
||||||
|
const selectedIndex = computed(() => items.value.findIndex(item => item.id === selectedId.value))
|
||||||
|
watch(() => items.value.map(item => item.id), ids => {
|
||||||
|
if (!ids.includes(selectedId.value)) selectedId.value = ids[0] || ''
|
||||||
|
}, { immediate: true })
|
||||||
|
function addProject() {
|
||||||
|
const id = Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, '0')).join('')
|
||||||
|
items.value.push({ id, name: '', category: 'software', description: '', files: [{ label: '', url: '' }] })
|
||||||
|
selectedId.value = id
|
||||||
|
}
|
||||||
|
function moveProject(offset: number) {
|
||||||
|
const from = selectedIndex.value, to = from + offset
|
||||||
|
if (from < 0 || to < 0 || to >= items.value.length) return
|
||||||
|
const [item] = items.value.splice(from, 1)
|
||||||
|
if (item) items.value.splice(to, 0, item)
|
||||||
|
}
|
||||||
|
function removeProject() {
|
||||||
|
const from = selectedIndex.value
|
||||||
|
if (from < 0) return
|
||||||
|
items.value.splice(from, 1)
|
||||||
|
selectedId.value = items.value[Math.min(from, items.value.length - 1)]?.id || ''
|
||||||
|
}
|
||||||
|
function moveFile(index: number, offset: number) {
|
||||||
|
const files = selected.value?.files, to = index + offset
|
||||||
|
if (!files || to < 0 || to >= files.length) return
|
||||||
|
const [file] = files.splice(index, 1)
|
||||||
|
if (file) files.splice(to, 0, file)
|
||||||
|
}
|
||||||
|
const invalidProject = computed(() => items.value.find(item => !item.name.trim() || !item.files.length || item.files.some(file => !file.label.trim() || !file.url.trim())))
|
||||||
|
function validate() {
|
||||||
|
if (invalidProject.value) selectedId.value = invalidProject.value.id
|
||||||
|
return !invalidProject.value
|
||||||
|
}
|
||||||
|
defineExpose({ validate })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="catalog-editor">
|
||||||
|
<div class="catalog-toolbar"><button type="button" :disabled="busy || items.length >= 100" @click="addProject">{{ t('admin.addDownloadProject') }}</button><span>{{ t('admin.downloadProjectCount', { count: items.length }) }}</span></div>
|
||||||
|
<div v-if="items.length" class="catalog-layout">
|
||||||
|
<nav class="catalog-projects" :aria-label="t('admin.downloadProjects')"><button v-for="(item, index) in items" :key="item.id" type="button" :disabled="busy" :aria-current="selectedId === item.id ? 'true' : undefined" @click="selectedId = item.id">{{ item.name || t('admin.unnamedDownload', { index: index + 1 }) }}</button></nav>
|
||||||
|
<fieldset v-if="selected" :disabled="busy" class="catalog-fields">
|
||||||
|
<div class="catalog-project-actions"><button type="button" :disabled="selectedIndex === 0" @click="moveProject(-1)">{{ t('admin.moveUp') }}</button><button type="button" :disabled="selectedIndex === items.length - 1" @click="moveProject(1)">{{ t('admin.moveDown') }}</button><button type="button" @click="removeProject">{{ t('admin.removeDownloadProject') }}</button></div>
|
||||||
|
<label>{{ t('admin.softwareName') }}<input v-model="selected.name" maxlength="100" required /></label>
|
||||||
|
<label>{{ t('admin.downloadDescription') }}<textarea v-model="selected.description" rows="6" maxlength="30000" lang="zh-CN" /></label>
|
||||||
|
<details v-if="selected.description" class="catalog-preview"><summary>{{ t('admin.preview') }}</summary><MarkdownContent :source="selected.description" lang="zh-CN" /></details>
|
||||||
|
<section class="catalog-files" aria-labelledby="catalog-file-title"><h3 id="catalog-file-title">{{ t('admin.downloadFiles') }}</h3>
|
||||||
|
<div v-for="(file, index) in selected.files" :key="index" class="catalog-file" role="group" :aria-label="t('admin.downloadFileEntry', { index: index + 1 })">
|
||||||
|
<label>{{ t('admin.downloadLabel') }}<input v-model="file.label" required maxlength="160" /></label>
|
||||||
|
<label>{{ t('admin.url') }}<input v-model="file.url" required maxlength="2047" :placeholder="t('admin.downloadUrlPlaceholder')" /></label>
|
||||||
|
<div class="catalog-file-actions"><button type="button" :disabled="index === 0" @click="moveFile(index, -1)">{{ t('admin.moveUp') }}</button><button type="button" :disabled="index === selected.files.length - 1" @click="moveFile(index, 1)">{{ t('admin.moveDown') }}</button><button type="button" @click="selected.files.splice(index, 1)">{{ t('admin.remove') }}</button></div>
|
||||||
|
</div>
|
||||||
|
<button type="button" :disabled="selected.files.length >= 100" @click="selected.files.push({ label: '', url: '' })">{{ t('admin.addDownloadFile') }}</button>
|
||||||
|
</section>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
<p v-else>{{ t('admin.noDownloadProjects') }}</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.catalog-editor { min-width: 0; }
|
||||||
|
.catalog-toolbar { display: flex; align-items: center; gap: 20px; margin-bottom: 22px; font-size: 14px; }
|
||||||
|
.catalog-layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 30px; align-items: start; }
|
||||||
|
.catalog-projects { display: grid; max-height: 70vh; overflow: auto; gap: 4px; padding-right: 6px; }
|
||||||
|
.catalog-projects button { display: grid; width: 100%; gap: 4px; padding: 12px; border: 0; text-align: left; overflow-wrap: anywhere; }
|
||||||
|
.catalog-projects [aria-current] { background: var(--blue-soft); color: var(--blue); }
|
||||||
|
.catalog-fields { display: grid; min-width: 0; gap: 22px; margin: 0; padding: 0; border: 0; }
|
||||||
|
.catalog-project-actions, .catalog-file-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||||
|
label { display: grid; gap: 8px; min-width: 0; font-size: 14px; }
|
||||||
|
input, textarea { width: 100%; min-width: 0; min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--ink); font: inherit; }
|
||||||
|
textarea { resize: vertical; line-height: 1.7; }
|
||||||
|
button { min-height: 38px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--ink); font: inherit; font-size: 14px; }
|
||||||
|
button:hover { border-color: var(--blue); color: var(--blue); } button:disabled { opacity: .5; cursor: default; }
|
||||||
|
.catalog-preview summary { cursor: pointer; color: var(--blue); } .catalog-preview .markdown-content { margin-top: 16px; }
|
||||||
|
.catalog-files h3 { margin: 0 0 14px; font-size: 20px; }
|
||||||
|
.catalog-file { display: grid; gap: 14px; margin-bottom: 18px; padding: 18px 0; border-top: 1px solid var(--line); }
|
||||||
|
.catalog-file-actions { justify-content: end; }
|
||||||
|
@media (max-width: 760px) {
|
||||||
|
.catalog-layout { grid-template-columns: minmax(0, 1fr); gap: 22px; }
|
||||||
|
.catalog-projects { display: flex; max-height: none; padding: 0 0 8px; overflow-x: auto; }
|
||||||
|
.catalog-projects button { flex: 0 0 150px; }
|
||||||
|
button { min-height: 44px; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, nextTick, ref, watch } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import type { SiteDownload } from '../api'
|
||||||
|
import MarkdownContent from './MarkdownContent.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ items: SiteDownload[] }>()
|
||||||
|
const { t } = useI18n()
|
||||||
|
const selectedId = ref('')
|
||||||
|
const selected = computed(() => props.items.find(item => item.id === selectedId.value))
|
||||||
|
function ensureSelection() {
|
||||||
|
if (!props.items.some(item => item.id === selectedId.value)) selectedId.value = props.items[0]?.id || ''
|
||||||
|
}
|
||||||
|
watch(() => props.items, ensureSelection, { immediate: true })
|
||||||
|
|
||||||
|
async function moveProject(event: KeyboardEvent, index: number) {
|
||||||
|
let next = index
|
||||||
|
if (event.key === 'ArrowDown') next = (index + 1) % props.items.length
|
||||||
|
else if (event.key === 'ArrowUp') next = (index + props.items.length - 1) % props.items.length
|
||||||
|
else if (event.key === 'Home') next = 0
|
||||||
|
else if (event.key === 'End') next = props.items.length - 1
|
||||||
|
else return
|
||||||
|
event.preventDefault()
|
||||||
|
selectedId.value = props.items[next]!.id
|
||||||
|
await nextTick()
|
||||||
|
document.getElementById(`download-project-${selectedId.value}`)?.focus()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="download-catalog">
|
||||||
|
<div class="download-workspace">
|
||||||
|
<div v-if="items.length" class="download-projects" role="tablist" aria-orientation="vertical" :aria-label="t('announcements.chooseSoftware')">
|
||||||
|
<button v-for="(project, index) in items" :id="`download-project-${project.id}`" :key="project.id" role="tab" type="button" :aria-selected="selectedId === project.id" :tabindex="selectedId === project.id ? 0 : -1" aria-controls="download-project-panel" @click="selectedId = project.id" @keydown="moveProject($event, index)">{{ project.name }}</button>
|
||||||
|
</div>
|
||||||
|
<label v-if="items.length" class="download-mobile-select">{{ t('announcements.chooseSoftware') }}<select v-model="selectedId"><option v-for="project in items" :key="project.id" :value="project.id">{{ project.name }}</option></select></label>
|
||||||
|
<section v-if="selected" id="download-project-panel" class="download-detail" role="tabpanel" :aria-labelledby="`download-project-${selected.id}`" tabindex="0">
|
||||||
|
<h3>{{ selected.name }}</h3>
|
||||||
|
<MarkdownContent v-if="selected.description" class="download-description" :source="selected.description" lang="zh-CN" />
|
||||||
|
<ul class="download-files" :aria-label="t('announcements.downloadLinks')"><li v-for="(file, index) in selected.files" :key="`${index}:${file.url}`"><a :href="file.url" target="_blank" rel="noopener noreferrer">{{ file.label }}</a></li></ul>
|
||||||
|
</section>
|
||||||
|
<p v-else class="downloads-empty" role="status">{{ t('common.noDownloads') }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.download-catalog { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
|
||||||
|
.download-workspace { display: grid; grid-template-columns: 210px minmax(0, 1fr); flex: 1; min-height: 0; gap: 28px; }
|
||||||
|
.download-projects { min-height: 0; overflow: auto; overscroll-behavior: contain; padding-right: 6px; }
|
||||||
|
.download-projects button { display: block; width: 100%; min-height: 42px; padding: 10px 14px; border-radius: 2px; color: var(--blue); font-size: 15px; line-height: 1.5; text-align: left; overflow-wrap: anywhere; }
|
||||||
|
.download-projects button:hover { background: var(--blue-soft); }
|
||||||
|
.download-projects [aria-selected='true'] { background: var(--blue); color: var(--on-accent); font-weight: 600; }
|
||||||
|
.download-detail { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 2px 8px 12px 0; overflow-wrap: anywhere; }
|
||||||
|
.download-detail h3 { margin: 0 0 18px; color: var(--ink); font-size: 28px; font-weight: 600; line-height: 1.4; }
|
||||||
|
.download-description { margin-bottom: 22px; font-size: 15px; }
|
||||||
|
.download-files { margin: 0; padding-left: 20px; }
|
||||||
|
.download-files li { padding: 5px 0; color: var(--ink); }
|
||||||
|
.download-files a { color: var(--blue); font-size: 16px; line-height: 1.6; text-underline-offset: 4px; }
|
||||||
|
.download-files a:hover { text-decoration: underline; }
|
||||||
|
.download-mobile-select { display: none; }
|
||||||
|
.downloads-empty { grid-column: 1 / -1; margin: 8px 0; color: var(--ink); font-size: 15px; }
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.download-workspace { display: flex; flex-direction: column; gap: 20px; }
|
||||||
|
.download-projects { display: none; }
|
||||||
|
.download-mobile-select { display: grid; gap: 7px; flex-shrink: 0; color: var(--ink); font-size: 14px; }
|
||||||
|
.download-mobile-select select { width: 100%; min-width: 0; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 2px; background: var(--paper); color: var(--ink); font: inherit; font-size: 16px; }
|
||||||
|
.download-detail { flex: 1; }
|
||||||
|
.download-detail h3 { font-size: 24px; }
|
||||||
|
.download-files li { padding-block: 8px; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
const pairs = {
|
const pairs = {
|
||||||
|
downloadProjects: ['软件项目', 'Software projects'], addDownloadProject: ['添加软件', 'Add software'], removeDownloadProject: ['移除软件', 'Remove software'], softwareName: ['软件名称', 'Software name'],
|
||||||
|
downloadDescription: ['软件说明(中文,Markdown)', 'Description (Chinese, Markdown)'], downloadFiles: ['下载链接', 'Download links'], downloadLabel: ['链接名称(版本 / 架构)', 'Link label (version / architecture)'], addDownloadFile: ['添加下载链接', 'Add download link'], saveDownloads: ['保存下载配置', 'Save download catalog'],
|
||||||
|
downloadFileEntry: ['下载链接 {index}', 'Download link {index}'], downloadProjectCount: ['共 {count} 个软件', '{count} projects'], unnamedDownload: ['未命名软件 {index}', 'Untitled project {index}'], noDownloadProjects: ['暂无软件,点击“添加软件”开始配置。', 'No projects yet. Select “Add software” to get started.'],
|
||||||
|
downloadUrlPlaceholder: ['https:// 或 /mirrors/ 开头的地址', 'https:// URL or /mirrors/ path'], incompleteDownload: ['请填写软件名称,并为每个软件添加至少一条完整的下载链接。', 'Enter a software name and at least one complete download link for each project.'],
|
||||||
editArticle: ['编辑公告', 'Edit announcement'], write: ['编辑', 'Write'], articleView: ['公告编辑视图', 'Announcement editor view'], previewEmpty: ['输入 Markdown 正文后在这里预览。', 'Write Markdown to preview your announcement here.'],
|
editArticle: ['编辑公告', 'Edit announcement'], write: ['编辑', 'Write'], articleView: ['公告编辑视图', 'Announcement editor view'], previewEmpty: ['输入 Markdown 正文后在这里预览。', 'Write Markdown to preview your announcement here.'],
|
||||||
saveDraft: ['保存草稿', 'Save draft'], publishArticle: ['发布公告', 'Publish announcement'], updateArticle: ['更新公告', 'Update announcement'], withdrawArticle: ['撤回为草稿', 'Unpublish as draft'], viewArticle: ['查看公告', 'View announcement'], viewAnnouncements: ['打开公告页', 'Open announcements'],
|
saveDraft: ['保存草稿', 'Save draft'], publishArticle: ['发布公告', 'Publish announcement'], updateArticle: ['更新公告', 'Update announcement'], withdrawArticle: ['撤回为草稿', 'Unpublish as draft'], viewArticle: ['查看公告', 'View announcement'], viewAnnouncements: ['打开公告页', 'Open announcements'],
|
||||||
draftSaved: ['草稿已保存,尚未公开。', 'Draft saved. It is not public.'], articlePublished: ['公告已发布。', 'Announcement published.'], articleUpdated: ['公告已更新。', 'Announcement updated.'], articleWithdrawn: ['公告已撤回并保存为草稿。', 'Announcement unpublished and saved as a draft.'],
|
draftSaved: ['草稿已保存,尚未公开。', 'Draft saved. It is not public.'], articlePublished: ['公告已发布。', 'Announcement published.'], articleUpdated: ['公告已更新。', 'Announcement updated.'], articleWithdrawn: ['公告已撤回并保存为草稿。', 'Announcement unpublished and saved as a draft.'],
|
||||||
|
|||||||
@@ -13,8 +13,13 @@ export default {
|
|||||||
"linkUniversity": "Ocean University of China",
|
"linkUniversity": "Ocean University of China",
|
||||||
"pinned": "Pinned",
|
"pinned": "Pinned",
|
||||||
"newsIntro": "These announcements describe the interface preview.",
|
"newsIntro": "These announcements describe the interface preview.",
|
||||||
"downloadsTitle": "Get installation images",
|
"downloadsTitle": "Downloads",
|
||||||
"downloadsIntro": "Local download directories are not connected yet. These links open official project websites.",
|
"chooseSoftware": "Choose software",
|
||||||
|
"downloadLinks": "Download links",
|
||||||
|
"downloadName": "Name",
|
||||||
|
"downloadVersion": "Version",
|
||||||
|
"downloadAction": "Download",
|
||||||
|
"downloadItem": "Download {name} {version}",
|
||||||
"entries": {
|
"entries": {
|
||||||
"preview": {
|
"preview": {
|
||||||
"title": "A first look at the MirrorOUC interface",
|
"title": "A first look at the MirrorOUC interface",
|
||||||
|
|||||||
@@ -13,8 +13,13 @@ export default {
|
|||||||
"linkUniversity": "中国海洋大学",
|
"linkUniversity": "中国海洋大学",
|
||||||
"pinned": "置顶",
|
"pinned": "置顶",
|
||||||
"newsIntro": "以下为界面预览公告。",
|
"newsIntro": "以下为界面预览公告。",
|
||||||
"downloadsTitle": "获取安装镜像",
|
"downloadsTitle": "常用下载",
|
||||||
"downloadsIntro": "原型暂未接入本站下载目录,以下链接前往各项目官方网站。",
|
"chooseSoftware": "选择软件",
|
||||||
|
"downloadLinks": "下载链接",
|
||||||
|
"downloadName": "名称",
|
||||||
|
"downloadVersion": "版本",
|
||||||
|
"downloadAction": "下载",
|
||||||
|
"downloadItem": "下载 {name} {version}",
|
||||||
"entries": {
|
"entries": {
|
||||||
"preview": {
|
"preview": {
|
||||||
"title": "MirrorOUC 首页界面预览",
|
"title": "MirrorOUC 首页界面预览",
|
||||||
|
|||||||
@@ -164,6 +164,22 @@ h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.04em; }
|
|||||||
|
|
||||||
.content-dialog { width: min(680px, calc(100% - 32px)); max-height: min(710px, calc(100dvh - 44px)); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); box-shadow: var(--dialog-shadow); }.content-dialog::backdrop { background: rgba(0, 0, 0, .57); backdrop-filter: blur(4px); }.dialog-inner { max-height: min(710px, calc(100dvh - 44px)); overflow: auto; }.dialog-heading { position: sticky; z-index: 1; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 22px 25px; border-bottom: 1px solid var(--line); background: var(--panel); }.dialog-heading h2 { font-size: 18px; }.dialog-heading .icon-button { margin: -8px -8px 0 0; }.dialog-content { padding: 25px; }.dialog-lead { margin: 0 0 23px; color: var(--ink-2); font-size: 13px; line-height: 1.75; }.mirror-facts { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px 16px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--ink-3); font-size: 11px; }.mirror-facts > span:nth-child(even) { color: var(--ink); }.directory-preview { display: flex; gap: 13px; align-items: flex-start; margin: 23px 0; padding: 18px; border-radius: 8px; background: var(--panel-blue); color: var(--blue); }.directory-preview h3 { margin: -2px 0 4px; color: var(--ink); font-size: 13px; }.directory-preview p { margin: 0; color: var(--ink-2); font-size: 11px; }.dialog-content h3 { margin: 21px 0 7px; font-size: 13px; }.dialog-hint { color: var(--ink-3); font-size: 11px; line-height: 1.65; }.dialog-content pre { overflow: auto; margin: 12px 0; padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: color-mix(in srgb, var(--paper) 80%, var(--panel)); color: var(--blue); font: 11px ui-monospace, 'Cascadia Code', Consolas, monospace; white-space: pre-wrap; }.dialog-actions { display: flex; align-items: center; gap: 18px; }.secondary-button { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 6px; background: var(--blue); color: var(--on-accent); font-size: 11px; }.secondary-button:hover { background: var(--accent-hover); }.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }.help-grid button, .article-link, .modal-downloads a { display: flex; align-items: center; gap: 11px; width: 100%; padding: 11px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); font-size: 12px; text-align: left; }.help-grid button:hover, .article-link:hover, .modal-downloads a:hover { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }.help-grid button span:nth-child(2), .modal-downloads a span:nth-child(2) { flex: 1; }.help-grid button svg, .modal-downloads a svg { margin-left: auto; }.article-date { display: block; margin-bottom: 18px; color: var(--ink-3); font: 10px ui-monospace, 'Cascadia Code', Consolas, monospace; }.article-body { margin: 0; color: var(--ink); font-size: 13px; line-height: 1.9; }.article-link { justify-content: space-between; margin-bottom: 8px; }.article-link span { flex: 1; }.status-list { display: grid; gap: 1px; border-top: 1px solid var(--line); }.status-list > div { display: flex; justify-content: space-between; align-items: center; min-height: 45px; border-bottom: 1px solid var(--line); }.mono { font: 12px ui-monospace, 'Cascadia Code', Consolas, monospace; }.modal-downloads { display: grid; gap: 9px; }.about-seal { display: block; margin: 0 auto 21px; }.about-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }.about-links a { display: inline-flex; align-items: center; gap: 5px; color: var(--blue); font-size: 12px; }
|
.content-dialog { width: min(680px, calc(100% - 32px)); max-height: min(710px, calc(100dvh - 44px)); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); box-shadow: var(--dialog-shadow); }.content-dialog::backdrop { background: rgba(0, 0, 0, .57); backdrop-filter: blur(4px); }.dialog-inner { max-height: min(710px, calc(100dvh - 44px)); overflow: auto; }.dialog-heading { position: sticky; z-index: 1; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 22px 25px; border-bottom: 1px solid var(--line); background: var(--panel); }.dialog-heading h2 { font-size: 18px; }.dialog-heading .icon-button { margin: -8px -8px 0 0; }.dialog-content { padding: 25px; }.dialog-lead { margin: 0 0 23px; color: var(--ink-2); font-size: 13px; line-height: 1.75; }.mirror-facts { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px 16px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--ink-3); font-size: 11px; }.mirror-facts > span:nth-child(even) { color: var(--ink); }.directory-preview { display: flex; gap: 13px; align-items: flex-start; margin: 23px 0; padding: 18px; border-radius: 8px; background: var(--panel-blue); color: var(--blue); }.directory-preview h3 { margin: -2px 0 4px; color: var(--ink); font-size: 13px; }.directory-preview p { margin: 0; color: var(--ink-2); font-size: 11px; }.dialog-content h3 { margin: 21px 0 7px; font-size: 13px; }.dialog-hint { color: var(--ink-3); font-size: 11px; line-height: 1.65; }.dialog-content pre { overflow: auto; margin: 12px 0; padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: color-mix(in srgb, var(--paper) 80%, var(--panel)); color: var(--blue); font: 11px ui-monospace, 'Cascadia Code', Consolas, monospace; white-space: pre-wrap; }.dialog-actions { display: flex; align-items: center; gap: 18px; }.secondary-button { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 6px; background: var(--blue); color: var(--on-accent); font-size: 11px; }.secondary-button:hover { background: var(--accent-hover); }.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }.help-grid button, .article-link, .modal-downloads a { display: flex; align-items: center; gap: 11px; width: 100%; padding: 11px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); font-size: 12px; text-align: left; }.help-grid button:hover, .article-link:hover, .modal-downloads a:hover { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }.help-grid button span:nth-child(2), .modal-downloads a span:nth-child(2) { flex: 1; }.help-grid button svg, .modal-downloads a svg { margin-left: auto; }.article-date { display: block; margin-bottom: 18px; color: var(--ink-3); font: 10px ui-monospace, 'Cascadia Code', Consolas, monospace; }.article-body { margin: 0; color: var(--ink); font-size: 13px; line-height: 1.9; }.article-link { justify-content: space-between; margin-bottom: 8px; }.article-link span { flex: 1; }.status-list { display: grid; gap: 1px; border-top: 1px solid var(--line); }.status-list > div { display: flex; justify-content: space-between; align-items: center; min-height: 45px; border-bottom: 1px solid var(--line); }.mono { font: 12px ui-monospace, 'Cascadia Code', Consolas, monospace; }.modal-downloads { display: grid; gap: 9px; }.about-seal { display: block; margin: 0 auto 21px; }.about-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }.about-links a { display: inline-flex; align-items: center; gap: 5px; color: var(--blue); font-size: 12px; }
|
||||||
|
|
||||||
|
.content-dialog.download-dialog { --download-dialog-max-height: min(720px, calc(100dvh - 48px)); width: min(960px, calc(100% - 40px)); max-width: none; height: var(--download-dialog-max-height); max-height: var(--download-dialog-max-height); overflow: hidden; border-radius: 2px; border-top: 3px solid var(--blue); background: var(--paper); box-shadow: 0 16px 48px rgba(0, 0, 0, .28); }
|
||||||
|
.content-dialog.download-dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: none; }
|
||||||
|
.download-dialog .dialog-inner { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; max-height: calc(var(--download-dialog-max-height) - 4px); overflow: hidden; }
|
||||||
|
.download-dialog .dialog-heading { position: static; gap: 20px; padding: 22px 24px; border-bottom: 0; background: var(--paper); }
|
||||||
|
.download-dialog .dialog-heading h2 { color: var(--ink); font-size: 24px; font-weight: 600; line-height: 1.4; }
|
||||||
|
.download-dialog .dialog-heading .icon-button { flex-shrink: 0; width: 36px; height: 36px; margin: 0 -6px 0 0; border-radius: 2px; color: var(--ink); }
|
||||||
|
.download-dialog .dialog-content { display: flex; min-width: 0; min-height: 0; overflow: hidden; padding: 0 24px 24px; }
|
||||||
|
:root[data-theme='dark'] .download-dialog .dialog-heading h2 { color: #fff; }
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.content-dialog.download-dialog { --download-dialog-max-height: calc(100dvh - 32px); width: calc(100% - 24px); }
|
||||||
|
.download-dialog .dialog-heading { gap: 12px; padding: 16px 18px; }
|
||||||
|
.download-dialog .dialog-heading h2 { font-size: 22px; }
|
||||||
|
.download-dialog .dialog-heading .icon-button { width: 44px; height: 44px; margin-right: -8px; }
|
||||||
|
.download-dialog .dialog-content { padding: 4px 18px 22px; }
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 1100px) {
|
@media (max-width: 1100px) {
|
||||||
.site-header { min-height: 112px; gap: 22px; padding: 24px; }
|
.site-header { min-height: 112px; gap: 22px; padding: 24px; }
|
||||||
.brand-logo { width: 260px; }
|
.brand-logo { width: 260px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user