POST 설정 정규화 로직 분리
This commit is contained in:
@@ -14,30 +14,21 @@ import {
|
||||
normalizeSocialLinks
|
||||
} from '~/lib/social-links.js'
|
||||
import {
|
||||
DEFAULT_POST_TAG_LIMIT,
|
||||
MAX_POST_TAG_LIMIT,
|
||||
MIN_POST_TAG_LIMIT,
|
||||
normalizePostTagLimit
|
||||
} from '~/lib/post-tag-limit.js'
|
||||
import {
|
||||
DEFAULT_FEATURED_POST_LIMIT,
|
||||
DEFAULT_HOME_LATEST_POST_LIMIT,
|
||||
DEFAULT_PAGE_SECTION_ITEM_LIMIT,
|
||||
DEFAULT_POST_LIST_PAGE_SIZE,
|
||||
DEFAULT_TAG_POST_LIST_PAGE_SIZE,
|
||||
DISPLAY_COUNT_OPTIONS,
|
||||
POST_LIST_COUNT_OPTIONS,
|
||||
normalizeDisplayCount
|
||||
POST_LIST_COUNT_OPTIONS
|
||||
} from '~/lib/display-count-settings.js'
|
||||
import {
|
||||
DEFAULT_UPLOAD_MAX_FILE_COUNT,
|
||||
DEFAULT_UPLOAD_MAX_TOTAL_SIZE,
|
||||
UPLOAD_FILE_COUNT_OPTIONS,
|
||||
UPLOAD_TOTAL_SIZE_OPTIONS,
|
||||
formatUploadSizeLimit,
|
||||
normalizeUploadMaxFileCount,
|
||||
normalizeUploadMaxTotalSize
|
||||
formatUploadSizeLimit
|
||||
} from '~/lib/upload-size-limit.js'
|
||||
import {
|
||||
POST_SETTINGS_FIELDS,
|
||||
assignPostSettingsSection,
|
||||
createDefaultPostSettingsSnapshot,
|
||||
hasPostSettingsSectionChanges,
|
||||
normalizePostSettingsSection
|
||||
} from '~/lib/admin-post-settings-section.js'
|
||||
|
||||
definePageMeta({
|
||||
layout: 'admin'
|
||||
@@ -167,17 +158,7 @@ const socialSnapshot = reactive({
|
||||
socialLinks: []
|
||||
})
|
||||
/** 편집 시작 시점의 POST 설정(취소 시 복원용) */
|
||||
const postSnapshot = reactive({
|
||||
showPostUpdatedAt: false,
|
||||
postTagLimit: DEFAULT_POST_TAG_LIMIT,
|
||||
homeLatestPostLimit: DEFAULT_HOME_LATEST_POST_LIMIT,
|
||||
postListPageSize: DEFAULT_POST_LIST_PAGE_SIZE,
|
||||
tagPostListPageSize: DEFAULT_TAG_POST_LIST_PAGE_SIZE,
|
||||
featuredPostLimit: DEFAULT_FEATURED_POST_LIMIT,
|
||||
pageSectionItemLimit: DEFAULT_PAGE_SECTION_ITEM_LIMIT,
|
||||
uploadMaxFileCount: DEFAULT_UPLOAD_MAX_FILE_COUNT,
|
||||
uploadMaxTotalSize: DEFAULT_UPLOAD_MAX_TOTAL_SIZE
|
||||
})
|
||||
const postSnapshot = reactive(createDefaultPostSettingsSnapshot())
|
||||
/** 편집 시작 시점의 메인 화면 커버(취소 시 복원용) */
|
||||
const homeCoverSnapshot = reactive({
|
||||
homeCoverImageUrl: '',
|
||||
@@ -240,6 +221,7 @@ const {
|
||||
} = await useFetch('/admin/api/settings/backup-summary', {
|
||||
default: () => null
|
||||
})
|
||||
const initialPostSettings = normalizePostSettingsSection(settings.value)
|
||||
|
||||
const form = reactive({
|
||||
title: settings.value?.title || 'sori.studio',
|
||||
@@ -250,15 +232,7 @@ const form = reactive({
|
||||
faviconUrl: settings.value?.faviconUrl || '',
|
||||
copyrightText: settings.value?.copyrightText || '©2026 sori.studio',
|
||||
socialLinks: normalizeSocialLinks(settings.value?.socialLinks || []),
|
||||
showPostUpdatedAt: Boolean(settings.value?.showPostUpdatedAt),
|
||||
postTagLimit: normalizePostTagLimit(settings.value?.postTagLimit),
|
||||
homeLatestPostLimit: normalizeDisplayCount(settings.value?.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT),
|
||||
postListPageSize: normalizeDisplayCount(settings.value?.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE),
|
||||
tagPostListPageSize: normalizeDisplayCount(settings.value?.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE),
|
||||
featuredPostLimit: normalizeDisplayCount(settings.value?.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT),
|
||||
pageSectionItemLimit: normalizeDisplayCount(settings.value?.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT),
|
||||
uploadMaxFileCount: normalizeUploadMaxFileCount(settings.value?.uploadMaxFileCount),
|
||||
uploadMaxTotalSize: normalizeUploadMaxTotalSize(settings.value?.uploadMaxTotalSize),
|
||||
...initialPostSettings,
|
||||
homeCoverImageUrl: settings.value?.homeCoverImageUrl || '',
|
||||
homeCoverDarkImageUrl: settings.value?.homeCoverDarkImageUrl || '',
|
||||
homeCoverTitle: settings.value?.homeCoverTitle || '',
|
||||
@@ -315,17 +289,7 @@ const hasSocialChanges = computed(() => editSocial.value
|
||||
* @returns {boolean} 변경 여부
|
||||
*/
|
||||
const hasPostChanges = computed(() => editPost.value
|
||||
&& (
|
||||
form.showPostUpdatedAt !== postSnapshot.showPostUpdatedAt
|
||||
|| normalizePostTagLimit(form.postTagLimit) !== normalizePostTagLimit(postSnapshot.postTagLimit)
|
||||
|| normalizeDisplayCount(form.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT) !== normalizeDisplayCount(postSnapshot.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT)
|
||||
|| normalizeDisplayCount(form.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE) !== normalizeDisplayCount(postSnapshot.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE)
|
||||
|| normalizeDisplayCount(form.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE) !== normalizeDisplayCount(postSnapshot.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE)
|
||||
|| normalizeDisplayCount(form.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT) !== normalizeDisplayCount(postSnapshot.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT)
|
||||
|| normalizeDisplayCount(form.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT) !== normalizeDisplayCount(postSnapshot.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT)
|
||||
|| normalizeUploadMaxFileCount(form.uploadMaxFileCount) !== normalizeUploadMaxFileCount(postSnapshot.uploadMaxFileCount)
|
||||
|| normalizeUploadMaxTotalSize(form.uploadMaxTotalSize) !== normalizeUploadMaxTotalSize(postSnapshot.uploadMaxTotalSize)
|
||||
))
|
||||
&& hasPostSettingsSectionChanges(form, postSnapshot))
|
||||
|
||||
/**
|
||||
* 메인 화면 커버 변경 여부
|
||||
@@ -1102,15 +1066,7 @@ const buildSiteSettingsPayload = (fields = null) => {
|
||||
faviconUrl: form.faviconUrl,
|
||||
copyrightText: form.copyrightText,
|
||||
socialLinks: normalizeSocialLinks(form.socialLinks),
|
||||
showPostUpdatedAt: Boolean(form.showPostUpdatedAt),
|
||||
postTagLimit: normalizePostTagLimit(form.postTagLimit),
|
||||
homeLatestPostLimit: normalizeDisplayCount(form.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT),
|
||||
postListPageSize: normalizeDisplayCount(form.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE),
|
||||
tagPostListPageSize: normalizeDisplayCount(form.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE),
|
||||
featuredPostLimit: normalizeDisplayCount(form.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT),
|
||||
pageSectionItemLimit: normalizeDisplayCount(form.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT),
|
||||
uploadMaxFileCount: normalizeUploadMaxFileCount(form.uploadMaxFileCount),
|
||||
uploadMaxTotalSize: normalizeUploadMaxTotalSize(form.uploadMaxTotalSize),
|
||||
...normalizePostSettingsSection(form),
|
||||
homeCoverImageUrl: form.homeCoverImageUrl || '',
|
||||
homeCoverDarkImageUrl: form.homeCoverDarkImageUrl || '',
|
||||
homeCoverTitle: form.homeCoverTitle || '',
|
||||
@@ -1329,23 +1285,8 @@ const saveSocialSection = async () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const beginEditPost = () => {
|
||||
postSnapshot.showPostUpdatedAt = form.showPostUpdatedAt
|
||||
postSnapshot.postTagLimit = normalizePostTagLimit(form.postTagLimit)
|
||||
postSnapshot.homeLatestPostLimit = normalizeDisplayCount(form.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT)
|
||||
postSnapshot.postListPageSize = normalizeDisplayCount(form.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE)
|
||||
postSnapshot.tagPostListPageSize = normalizeDisplayCount(form.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE)
|
||||
postSnapshot.featuredPostLimit = normalizeDisplayCount(form.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT)
|
||||
postSnapshot.pageSectionItemLimit = normalizeDisplayCount(form.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT)
|
||||
postSnapshot.uploadMaxFileCount = normalizeUploadMaxFileCount(form.uploadMaxFileCount)
|
||||
postSnapshot.uploadMaxTotalSize = normalizeUploadMaxTotalSize(form.uploadMaxTotalSize)
|
||||
form.postTagLimit = normalizePostTagLimit(form.postTagLimit)
|
||||
form.homeLatestPostLimit = postSnapshot.homeLatestPostLimit
|
||||
form.postListPageSize = postSnapshot.postListPageSize
|
||||
form.tagPostListPageSize = postSnapshot.tagPostListPageSize
|
||||
form.featuredPostLimit = postSnapshot.featuredPostLimit
|
||||
form.pageSectionItemLimit = postSnapshot.pageSectionItemLimit
|
||||
form.uploadMaxFileCount = postSnapshot.uploadMaxFileCount
|
||||
form.uploadMaxTotalSize = postSnapshot.uploadMaxTotalSize
|
||||
assignPostSettingsSection(postSnapshot, form)
|
||||
assignPostSettingsSection(form, postSnapshot)
|
||||
editPost.value = true
|
||||
}
|
||||
|
||||
@@ -1354,15 +1295,7 @@ const beginEditPost = () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const cancelEditPost = () => {
|
||||
form.showPostUpdatedAt = postSnapshot.showPostUpdatedAt
|
||||
form.postTagLimit = normalizePostTagLimit(postSnapshot.postTagLimit)
|
||||
form.homeLatestPostLimit = normalizeDisplayCount(postSnapshot.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT)
|
||||
form.postListPageSize = normalizeDisplayCount(postSnapshot.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE)
|
||||
form.tagPostListPageSize = normalizeDisplayCount(postSnapshot.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE)
|
||||
form.featuredPostLimit = normalizeDisplayCount(postSnapshot.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT)
|
||||
form.pageSectionItemLimit = normalizeDisplayCount(postSnapshot.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT)
|
||||
form.uploadMaxFileCount = normalizeUploadMaxFileCount(postSnapshot.uploadMaxFileCount)
|
||||
form.uploadMaxTotalSize = normalizeUploadMaxTotalSize(postSnapshot.uploadMaxTotalSize)
|
||||
assignPostSettingsSection(form, postSnapshot)
|
||||
editPost.value = false
|
||||
}
|
||||
|
||||
@@ -1378,37 +1311,12 @@ const savePostSection = async () => {
|
||||
const ok = await persistSiteSettings({
|
||||
successToast: 'POST 설정이 저장되었습니다.',
|
||||
savingFlag: savingPost,
|
||||
fields: [
|
||||
'showPostUpdatedAt',
|
||||
'postTagLimit',
|
||||
'homeLatestPostLimit',
|
||||
'postListPageSize',
|
||||
'tagPostListPageSize',
|
||||
'featuredPostLimit',
|
||||
'pageSectionItemLimit',
|
||||
'uploadMaxFileCount',
|
||||
'uploadMaxTotalSize'
|
||||
]
|
||||
fields: POST_SETTINGS_FIELDS
|
||||
})
|
||||
|
||||
if (ok) {
|
||||
postSnapshot.showPostUpdatedAt = form.showPostUpdatedAt
|
||||
postSnapshot.postTagLimit = normalizePostTagLimit(form.postTagLimit)
|
||||
postSnapshot.homeLatestPostLimit = normalizeDisplayCount(form.homeLatestPostLimit, DEFAULT_HOME_LATEST_POST_LIMIT)
|
||||
postSnapshot.postListPageSize = normalizeDisplayCount(form.postListPageSize, DEFAULT_POST_LIST_PAGE_SIZE)
|
||||
postSnapshot.tagPostListPageSize = normalizeDisplayCount(form.tagPostListPageSize, DEFAULT_TAG_POST_LIST_PAGE_SIZE)
|
||||
postSnapshot.featuredPostLimit = normalizeDisplayCount(form.featuredPostLimit, DEFAULT_FEATURED_POST_LIMIT)
|
||||
postSnapshot.pageSectionItemLimit = normalizeDisplayCount(form.pageSectionItemLimit, DEFAULT_PAGE_SECTION_ITEM_LIMIT)
|
||||
postSnapshot.uploadMaxFileCount = normalizeUploadMaxFileCount(form.uploadMaxFileCount)
|
||||
postSnapshot.uploadMaxTotalSize = normalizeUploadMaxTotalSize(form.uploadMaxTotalSize)
|
||||
form.postTagLimit = postSnapshot.postTagLimit
|
||||
form.homeLatestPostLimit = postSnapshot.homeLatestPostLimit
|
||||
form.postListPageSize = postSnapshot.postListPageSize
|
||||
form.tagPostListPageSize = postSnapshot.tagPostListPageSize
|
||||
form.featuredPostLimit = postSnapshot.featuredPostLimit
|
||||
form.pageSectionItemLimit = postSnapshot.pageSectionItemLimit
|
||||
form.uploadMaxFileCount = postSnapshot.uploadMaxFileCount
|
||||
form.uploadMaxTotalSize = postSnapshot.uploadMaxTotalSize
|
||||
assignPostSettingsSection(postSnapshot, form)
|
||||
assignPostSettingsSection(form, postSnapshot)
|
||||
editPost.value = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user