27 lines
724 B
JavaScript
27 lines
724 B
JavaScript
import { setHeader } from 'h3'
|
|
import { getSiteSettings } from '../repositories/content-repository'
|
|
|
|
/**
|
|
* ads.txt 본문을 정규화한다.
|
|
* @param {string} value - 관리자 설정에 저장된 ads.txt 본문
|
|
* @returns {string} text/plain 응답 본문
|
|
*/
|
|
const normalizeAdsTxt = (value) => {
|
|
const text = String(value || '').trim()
|
|
|
|
return text ? `${text}\n` : ''
|
|
}
|
|
|
|
/**
|
|
* 루트 ads.txt 응답
|
|
* @param {import('h3').H3Event} event - 요청 이벤트
|
|
* @returns {Promise<string>} ads.txt 본문
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
setHeader(event, 'Content-Type', 'text/plain; charset=utf-8')
|
|
|
|
const settings = await getSiteSettings()
|
|
|
|
return normalizeAdsTxt(settings.adsTxt)
|
|
})
|