2025-08-24 02:31:42 +08:00
|
|
|
|
import { Injectable } from '@nestjs/common';
|
2025-08-23 13:20:01 +08:00
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
|
import { Site } from './site.entity';
|
|
|
|
|
|
import { UpdateSiteSettingsDto } from './site-settings.dto';
|
2025-08-27 11:24:22 +08:00
|
|
|
|
import {
|
|
|
|
|
|
DEFAULT_SITE_CONFIG,
|
|
|
|
|
|
SYSTEM_CONSTANTS,
|
|
|
|
|
|
} from '@wwjConfig/common/constants';
|
2025-08-23 13:20:01 +08:00
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
|
export class SiteSettingsService {
|
|
|
|
|
|
constructor(
|
|
|
|
|
|
@InjectRepository(Site)
|
|
|
|
|
|
private readonly siteRepository: Repository<Site>,
|
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取站点设置
|
|
|
|
|
|
*/
|
|
|
|
|
|
async getSiteSettings() {
|
|
|
|
|
|
// 获取默认站点(id = 1)
|
|
|
|
|
|
const site = await this.siteRepository.findOne({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
where: { site_id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID },
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!site) {
|
|
|
|
|
|
// 如果没有找到站点,返回默认值
|
2025-08-24 02:31:42 +08:00
|
|
|
|
return { ...DEFAULT_SITE_CONFIG };
|
2025-08-23 13:20:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
2025-08-24 02:31:42 +08:00
|
|
|
|
site_name: site.site_name || DEFAULT_SITE_CONFIG.site_name,
|
|
|
|
|
|
site_title: site.site_title || DEFAULT_SITE_CONFIG.site_title,
|
|
|
|
|
|
site_keywords: site.site_keywords || DEFAULT_SITE_CONFIG.site_keywords,
|
2025-08-27 11:24:22 +08:00
|
|
|
|
site_description:
|
|
|
|
|
|
site.site_description || DEFAULT_SITE_CONFIG.site_description,
|
2025-08-24 02:31:42 +08:00
|
|
|
|
site_logo: site.site_logo || DEFAULT_SITE_CONFIG.site_logo,
|
|
|
|
|
|
site_favicon: site.site_favicon || DEFAULT_SITE_CONFIG.site_favicon,
|
|
|
|
|
|
icp_number: site.icp_number || DEFAULT_SITE_CONFIG.icp_number,
|
|
|
|
|
|
copyright: site.copyright || DEFAULT_SITE_CONFIG.copyright,
|
|
|
|
|
|
site_status: site.site_status || DEFAULT_SITE_CONFIG.site_status,
|
|
|
|
|
|
close_reason: site.close_reason || DEFAULT_SITE_CONFIG.close_reason,
|
2025-08-23 13:20:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新站点设置
|
|
|
|
|
|
*/
|
|
|
|
|
|
async updateSiteSettings(updateSiteSettingsDto: UpdateSiteSettingsDto) {
|
|
|
|
|
|
const {
|
|
|
|
|
|
site_name,
|
|
|
|
|
|
site_title,
|
|
|
|
|
|
site_keywords,
|
|
|
|
|
|
site_description,
|
|
|
|
|
|
site_logo,
|
|
|
|
|
|
site_favicon,
|
|
|
|
|
|
icp_number,
|
|
|
|
|
|
copyright,
|
|
|
|
|
|
site_status,
|
|
|
|
|
|
close_reason,
|
|
|
|
|
|
} = updateSiteSettingsDto;
|
|
|
|
|
|
|
|
|
|
|
|
// 查找或创建默认站点
|
|
|
|
|
|
let site = await this.siteRepository.findOne({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
where: { id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID },
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!site) {
|
|
|
|
|
|
// 创建默认站点
|
|
|
|
|
|
site = this.siteRepository.create({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID,
|
|
|
|
|
|
site_name: site_name || DEFAULT_SITE_CONFIG.site_name,
|
|
|
|
|
|
site_title: site_title || DEFAULT_SITE_CONFIG.site_title,
|
|
|
|
|
|
site_keywords: site_keywords || DEFAULT_SITE_CONFIG.site_keywords,
|
2025-08-27 11:24:22 +08:00
|
|
|
|
site_description:
|
|
|
|
|
|
site_description || DEFAULT_SITE_CONFIG.site_description,
|
2025-08-24 02:31:42 +08:00
|
|
|
|
site_logo: site_logo || DEFAULT_SITE_CONFIG.site_logo,
|
|
|
|
|
|
site_favicon: site_favicon || DEFAULT_SITE_CONFIG.site_favicon,
|
|
|
|
|
|
icp_number: icp_number || DEFAULT_SITE_CONFIG.icp_number,
|
|
|
|
|
|
copyright: copyright || DEFAULT_SITE_CONFIG.copyright,
|
|
|
|
|
|
site_status: site_status || DEFAULT_SITE_CONFIG.site_status,
|
|
|
|
|
|
close_reason: close_reason || DEFAULT_SITE_CONFIG.close_reason,
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 更新现有站点
|
|
|
|
|
|
if (site_name !== undefined) site.site_name = site_name;
|
|
|
|
|
|
if (site_title !== undefined) site.site_title = site_title;
|
|
|
|
|
|
if (site_keywords !== undefined) site.site_keywords = site_keywords;
|
2025-08-27 11:24:22 +08:00
|
|
|
|
if (site_description !== undefined)
|
|
|
|
|
|
site.site_description = site_description;
|
2025-08-23 13:20:01 +08:00
|
|
|
|
if (site_logo !== undefined) site.site_logo = site_logo;
|
|
|
|
|
|
if (site_favicon !== undefined) site.site_favicon = site_favicon;
|
|
|
|
|
|
if (icp_number !== undefined) site.icp_number = icp_number;
|
|
|
|
|
|
if (copyright !== undefined) site.copyright = copyright;
|
|
|
|
|
|
if (site_status !== undefined) site.site_status = site_status;
|
|
|
|
|
|
if (close_reason !== undefined) site.close_reason = close_reason;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await this.siteRepository.save(site);
|
|
|
|
|
|
return { message: '站点设置更新成功' };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 重置站点设置为默认值
|
|
|
|
|
|
*/
|
|
|
|
|
|
async resetSiteSettings() {
|
|
|
|
|
|
// 删除现有站点配置
|
2025-08-24 02:31:42 +08:00
|
|
|
|
await this.siteRepository.delete({ id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID });
|
2025-08-23 13:20:01 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建默认站点配置
|
|
|
|
|
|
const defaultSite = this.siteRepository.create({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID,
|
|
|
|
|
|
...DEFAULT_SITE_CONFIG,
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await this.siteRepository.save(defaultSite);
|
2025-08-24 02:31:42 +08:00
|
|
|
|
return { message: '站点设置重置成功' };
|
2025-08-23 13:20:01 +08:00
|
|
|
|
}
|
2025-08-27 11:24:22 +08:00
|
|
|
|
}
|