v1.2.9: 라이브 에디터·홈 피드·메인 커버 개선
라이브 모드 코드/콜아웃/토글 편집, 슬래시 명령, 홈 Latest List·Compact·Cards 보기, 사이트 설정 메인 화면 커버(720px) 및 HomeHero 반영. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -94,6 +94,9 @@ const mapSiteSettingsRow = (row) => ({
|
||||
faviconUrl: row.favicon_url || '',
|
||||
copyrightText: row.copyright_text,
|
||||
showPostUpdatedAt: Boolean(row.show_post_updated_at),
|
||||
homeCoverImageUrl: row.home_cover_image_url || '',
|
||||
homeCoverTitle: row.home_cover_title || '',
|
||||
homeCoverText: row.home_cover_text || '',
|
||||
updatedAt: row.updated_at.toISOString()
|
||||
})
|
||||
|
||||
@@ -810,6 +813,9 @@ export const updateSiteSettings = async (input) => {
|
||||
favicon_url,
|
||||
copyright_text,
|
||||
show_post_updated_at,
|
||||
home_cover_image_url,
|
||||
home_cover_title,
|
||||
home_cover_text,
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
@@ -822,6 +828,9 @@ export const updateSiteSettings = async (input) => {
|
||||
${input.faviconUrl || ''},
|
||||
${input.copyrightText},
|
||||
${input.showPostUpdatedAt ? true : false},
|
||||
${input.homeCoverImageUrl || ''},
|
||||
${input.homeCoverTitle || ''},
|
||||
${input.homeCoverText || ''},
|
||||
now()
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE
|
||||
@@ -834,6 +843,9 @@ export const updateSiteSettings = async (input) => {
|
||||
favicon_url = EXCLUDED.favicon_url,
|
||||
copyright_text = EXCLUDED.copyright_text,
|
||||
show_post_updated_at = EXCLUDED.show_post_updated_at,
|
||||
home_cover_image_url = EXCLUDED.home_cover_image_url,
|
||||
home_cover_title = EXCLUDED.home_cover_title,
|
||||
home_cover_text = EXCLUDED.home_cover_text,
|
||||
updated_at = now()
|
||||
RETURNING *
|
||||
`
|
||||
@@ -877,6 +889,39 @@ export const updateSiteLogo = async (input) => {
|
||||
return mapSiteSettingsRow(rows[0])
|
||||
}
|
||||
|
||||
/**
|
||||
* 메인 화면 커버 이미지 URL을 수정한다.
|
||||
* @param {{ homeCoverImageUrl: string }} input - 커버 이미지 URL
|
||||
* @returns {Promise<Object>} 수정된 사이트 설정
|
||||
*/
|
||||
export const updateSiteHomeCoverImage = async (input) => {
|
||||
const sql = getPostgresClient()
|
||||
|
||||
if (!sql) {
|
||||
throw new Error('DATABASE_REQUIRED')
|
||||
}
|
||||
|
||||
const rows = await sql`
|
||||
INSERT INTO site_settings (
|
||||
id,
|
||||
home_cover_image_url,
|
||||
updated_at
|
||||
)
|
||||
VALUES (
|
||||
1,
|
||||
${input.homeCoverImageUrl || ''},
|
||||
now()
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE
|
||||
SET
|
||||
home_cover_image_url = EXCLUDED.home_cover_image_url,
|
||||
updated_at = now()
|
||||
RETURNING *
|
||||
`
|
||||
|
||||
return mapSiteSettingsRow(rows[0])
|
||||
}
|
||||
|
||||
/**
|
||||
* 네비게이션 항목 목록 조회
|
||||
* @param {Object} options - 조회 옵션
|
||||
|
||||
90
server/routes/admin/api/settings/home-cover.post.js
Normal file
90
server/routes/admin/api/settings/home-cover.post.js
Normal file
@@ -0,0 +1,90 @@
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { createError, readMultipartFormData } from 'h3'
|
||||
import sharp from 'sharp'
|
||||
import { requireAdminSession } from '../../../../utils/admin-auth'
|
||||
import { updateSiteHomeCoverImage } from '../../../../repositories/content-repository'
|
||||
import { upsertMediaMetadataCategory } from '../../../../utils/media-library'
|
||||
|
||||
const allowedImageTypes = new Set(['image/jpeg', 'image/png', 'image/webp'])
|
||||
|
||||
const homeCoverWidth = 720
|
||||
|
||||
/**
|
||||
* 시스템 자산 파일명 접미사
|
||||
* @returns {string}
|
||||
*/
|
||||
const createSystemAssetSuffix = () => {
|
||||
const now = new Date()
|
||||
const year = now.getFullYear()
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0')
|
||||
|
||||
return `${year}${month}-${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 메인 화면 커버 이미지 업로드 API
|
||||
* @param {import('h3').H3Event} event - 요청 이벤트
|
||||
* @returns {Promise<Object>} 수정된 사이트 설정
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdminSession(event)
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
const maxFileSize = Number(config.maxFileSize || 10485760)
|
||||
const formData = await readMultipartFormData(event)
|
||||
const file = (formData || []).find((part) => part.name === 'file' && part.filename)
|
||||
|
||||
if (!file) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: '업로드할 커버 이미지가 없습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
if (!allowedImageTypes.has(file.type)) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: 'JPG, PNG, WebP 이미지만 커버로 사용할 수 있습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
if (file.data.length > maxFileSize) {
|
||||
throw createError({
|
||||
statusCode: 413,
|
||||
message: '업로드 가능한 파일 크기를 초과했습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
const metadata = await sharp(file.data).metadata()
|
||||
if (!metadata.width || !metadata.height) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: '이미지 메타데이터를 읽을 수 없습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
const uploadBaseUrl = String(config.uploadDir || '/uploads').replace(/\/+$/g, '') || '/uploads'
|
||||
const publicBasePath = uploadBaseUrl.replace(/^\/+/, '')
|
||||
const directoryPath = join(process.cwd(), 'public', publicBasePath, 'system')
|
||||
const assetSuffix = createSystemAssetSuffix()
|
||||
const coverFileName = `home-cover-${assetSuffix}.webp`
|
||||
const coverPath = join(directoryPath, coverFileName)
|
||||
const homeCoverImageUrl = `${uploadBaseUrl}/system/${coverFileName}`
|
||||
|
||||
await mkdir(directoryPath, { recursive: true })
|
||||
|
||||
const coverBuffer = await sharp(file.data)
|
||||
.rotate()
|
||||
.resize({
|
||||
width: homeCoverWidth,
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.webp({ quality: 88 })
|
||||
.toBuffer()
|
||||
|
||||
await writeFile(coverPath, coverBuffer)
|
||||
await upsertMediaMetadataCategory(homeCoverImageUrl, '시스템')
|
||||
|
||||
return updateSiteHomeCoverImage({ homeCoverImageUrl })
|
||||
})
|
||||
@@ -8,7 +8,10 @@ export const adminSiteSettingsInputSchema = z.object({
|
||||
logoUrl: z.string().trim().max(500).optional().default(''),
|
||||
faviconUrl: z.string().trim().max(500).optional().default(''),
|
||||
copyrightText: z.string().trim().min(1),
|
||||
showPostUpdatedAt: z.boolean().optional().default(false)
|
||||
showPostUpdatedAt: z.boolean().optional().default(false),
|
||||
homeCoverImageUrl: z.string().trim().max(500).optional().default(''),
|
||||
homeCoverTitle: z.string().trim().max(120).optional().default(''),
|
||||
homeCoverText: z.string().trim().max(280).optional().default('')
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,9 @@ export const getDefaultSiteSettings = () => {
|
||||
faviconUrl: '',
|
||||
copyrightText: `©${new Date().getFullYear()} ${title}`,
|
||||
showPostUpdatedAt: false,
|
||||
homeCoverImageUrl: '',
|
||||
homeCoverTitle: '',
|
||||
homeCoverText: '',
|
||||
updatedAt: null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user