2026-04-23 01:08:18 +08:00
import type { CollectionConfig } from 'payload'
import { independentDocListFilter } from '@/payload/admin/localized-list-filter'
import { getDocLocaleDefault , resolveDocLocale , syncDocLocaleWithRequestLocale } from '@/payload/doc-locale-hook'
const statusField = {
name : 'status' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Status' , zh : '状态' },
2026-04-23 01:08:18 +08:00
type : 'select' as const ,
localized : true ,
defaultValue : 'draft' ,
2026-04-23 10:15:15 +08:00
options : [
{ label : 'Draft / 草稿' , value : 'draft' },
{ label : 'Review / 待审核' , value : 'review' },
{ label : 'Published / 已发布' , value : 'published' },
{ label : 'Archived / 已归档' , value : 'archived' },
],
2026-04-23 01:08:18 +08:00
required : true ,
}
export const Downloads : CollectionConfig = {
slug : 'downloads' ,
hooks : {
beforeChange : [ syncDocLocaleWithRequestLocale ],
beforeValidate : [ syncDocLocaleWithRequestLocale ],
},
admin : {
baseFilter : independentDocListFilter ( 'title' ),
2026-04-23 10:41:19 +08:00
defaultColumns : [ 'title' , 'product' , 'type' , 'version' , 'status' , 'updatedAt' ],
2026-04-23 01:08:18 +08:00
description :
'Firmware packages, manuals, software installers, and release notes tied to products. English and Chinese download entries are maintained as separate documents.' ,
group : { en : 'Catalog' , zh : '产品' },
useAsTitle : 'title' ,
},
labels : {
plural : { en : 'Downloads' , zh : '下载' },
singular : { en : 'Download' , zh : '下载条目' },
},
access : {
read : ({ req }) => {
const locale = resolveDocLocale ( req )
if ( ! locale ) return true
return { docLocale : { equals : locale } }
},
},
fields : [
{
name : 'docLocale' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Doc Locale' , zh : '文档语言' },
2026-04-23 01:08:18 +08:00
type : 'select' ,
required : true ,
defaultValue : getDocLocaleDefault ,
options : [
2026-04-23 10:15:15 +08:00
{ label : 'English / 英文' , value : 'en' },
{ label : '简体中文' , value : 'zh' },
2026-04-23 01:08:18 +08:00
],
admin : {
2026-04-23 10:41:19 +08:00
condition : () => false ,
2026-04-23 01:08:18 +08:00
},
},
2026-04-23 10:15:15 +08:00
{ name : 'title' , label : { en : 'Title' , zh : '标题' }, type : 'text' , required : true , localized : true },
2026-04-23 01:08:18 +08:00
{
name : 'type' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Type' , zh : '分类' },
2026-04-23 01:08:18 +08:00
type : 'select' ,
localized : true ,
required : true ,
2026-04-23 10:15:15 +08:00
options : [
{ label : 'Firmware / 固件' , value : 'firmware' },
{ label : 'Manual / 说明书' , value : 'manual' },
{ label : 'Software / 软件' , value : 'software' },
{ label : 'Other / 其他' , value : 'other' },
],
2026-04-23 01:08:18 +08:00
},
2026-04-23 10:15:15 +08:00
{ name : 'product' , label : { en : 'Product' , zh : '关联产品' }, type : 'relationship' , relationTo : 'products' , required : true },
{ name : 'version' , label : { en : 'Version' , zh : '版本号' }, type : 'text' , localized : true },
{ name : 'releaseDate' , label : { en : 'Release Date' , zh : '发布日期' }, type : 'date' , localized : true },
{ name : 'file' , label : { en : 'File' , zh : '安装包/文件' }, type : 'upload' , relationTo : 'files' , localized : true },
{ name : 'checksum' , label : { en : 'Checksum' , zh : '校验值' }, type : 'text' , localized : true },
{ name : 'changelog' , label : { en : 'Changelog' , zh : '更新日志' }, type : 'richText' , localized : true },
{ name : 'notes' , label : { en : 'Notes' , zh : '附加说明' }, type : 'richText' , localized : true },
2026-04-23 01:08:18 +08:00
{
name : 'visibility' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Visibility' , zh : '显示设置' },
2026-04-23 01:08:18 +08:00
type : 'group' ,
localized : true ,
fields : [
{
name : 'showInDownloadsCenter' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Show in Downloads Center' , zh : '在下载中心显示' },
2026-04-23 01:08:18 +08:00
type : 'checkbox' ,
defaultValue : true ,
admin : {
description : 'Controls whether this item appears in the downloads center and per-product download pages.' ,
},
},
],
},
statusField ,
],
}