feat(auth): add configuration options for user registration and anonymous image hosting

This commit is contained in:
shiyu
2025-06-10 16:42:39 +08:00
parent b5931de344
commit 853efaa2fe
6 changed files with 167 additions and 92 deletions

View File

@@ -43,7 +43,9 @@ const allDescriptions: Record<string, Record<string, string>> = {
},
AppSettings: {
ServerUrl: '服务器URL',
MaxConcurrentTasks: '后台任务最大并发处理数量 (例如: 图像分析、标签生成等)'
MaxConcurrentTasks: '后台任务最大并发处理数量 (例如: 图像分析、标签生成等)',
EnableRegistration: '是否允许新用户注册 (true/false)',
EnableAnonymousImageHosting: '是否允许匿名用户上传图片 (true/false)'
},
Upload: {
HighQualityImageCompressionQuality: '高清图片的压缩质量,越高图片质量越好但文件越大。范围 50-100。',
@@ -52,6 +54,7 @@ const allDescriptions: Record<string, Record<string, string>> = {
}
};
const booleanAppSettings = ['EnableRegistration', 'EnableAnonymousImageHosting'];
const System: React.FC = () => {
const isMobile = useIsMobile();
@@ -115,9 +118,13 @@ const System: React.FC = () => {
const formInstance = formsMap[formInstanceKey];
if (formInstance) {
const initialGroupValues: Record<string, string> = {};
const initialGroupValues: Record<string, any> = {}; // Changed to any for boolean values
Object.keys(configGroups[group]).forEach(key => {
if (!secretFieldsMap[group]?.includes(key)) {
if (group === 'AppSettings' && booleanAppSettings.includes(key)) {
initialGroupValues[key] = configGroups[group][key] === 'true';
} else if (group === 'Upload' && ['ThumbnailMaxWidth', 'ThumbnailCompressionQuality', 'HighQualityImageCompressionQuality'].includes(key)) {
initialGroupValues[key] = parseInt(configGroups[group][key] || (key === 'ThumbnailMaxWidth' ? '400' : (key === 'ThumbnailCompressionQuality' ? '75' : '95')), 10);
} else if (!secretFieldsMap[group]?.includes(key)) {
initialGroupValues[key] = configGroups[group][key];
} else {
initialGroupValues[key] = '';
@@ -211,9 +218,13 @@ const System: React.FC = () => {
const handleSaveSingleConfig = async (formInstance: any, groupName: string, key: string) => {
try {
await formInstance.validateFields([key]);
const value = formInstance.getFieldValue(key);
let value = formInstance.getFieldValue(key);
const isSecret = secretFields[groupName]?.includes(key);
if (groupName === 'AppSettings' && booleanAppSettings.includes(key) && typeof value === 'boolean') {
value = String(value);
}
if (isSecret && (value === '' || value === undefined)) {
message.info(`未输入 ${key} 的新值,不作更改。`);
return;
@@ -242,7 +253,12 @@ const System: React.FC = () => {
// 计算需要保存的总数
for (const key of itemKeys) {
const value = values[key];
let value = values[key];
if (groupName === 'AppSettings' && booleanAppSettings.includes(key) && typeof value === 'boolean') {
value = String(value);
} else if (groupName === 'Upload' && typeof value === 'number') { // Ensure numbers are converted to strings for saving
value = String(value);
}
const isSecret = secretFields[groupName]?.includes(key);
if (!(isSecret && (value === '' || value === undefined)) &&
(isSecret || configs[groupName]?.[key] !== value)) {
@@ -265,9 +281,15 @@ const System: React.FC = () => {
});
for (const key of itemKeys) {
const value = values[key];
let value = values[key];
const isSecret = secretFields[groupName]?.includes(key);
if (groupName === 'AppSettings' && booleanAppSettings.includes(key) && typeof value === 'boolean') {
value = String(value);
} else if (groupName === 'Upload' && typeof value === 'number') { // Ensure numbers are converted to strings for saving
value = String(value);
}
if (isSecret && (value === '' || value === undefined)) {
continue;
}