feat: add application and file domain input fields; support external link configuration

This commit is contained in:
shiyu
2025-10-09 20:10:15 +08:00
parent 36365d7410
commit 7cf335ab19
3 changed files with 54 additions and 12 deletions
+1
View File
@@ -482,6 +482,7 @@ export const en = {
'Root Directory': 'Root Directory', 'Root Directory': 'Root Directory',
'Please input root directory!': 'Please input root directory!', 'Please input root directory!': 'Please input root directory!',
'e.g., data/ or /var/foxel/data': 'e.g., data/ or /var/foxel/data', 'e.g., data/ or /var/foxel/data': 'e.g., data/ or /var/foxel/data',
'Optional, used for external links. Leave empty to use the current site.': 'Optional, used for external links. Leave empty to use the current site.',
'Create Admin': 'Create Admin', 'Create Admin': 'Create Admin',
'Create admin account': 'Create admin account', 'Create admin account': 'Create admin account',
'This is the first account with full permissions': 'This is the first account with full permissions', 'This is the first account with full permissions': 'This is the first account with full permissions',
+1
View File
@@ -495,6 +495,7 @@ export const zh = {
'Root Directory': '根目录', 'Root Directory': '根目录',
'Please input root directory!': '请输入根目录!', 'Please input root directory!': '请输入根目录!',
'e.g., data/ or /var/foxel/data': '例如: data/ 或 /var/foxel/data', 'e.g., data/ or /var/foxel/data': '例如: data/ 或 /var/foxel/data',
'Optional, used for external links. Leave empty to use the current site.': '可选,用于生成外部链接;留空则使用当前站点。',
'Create Admin': '创建管理员', 'Create Admin': '创建管理员',
'Create admin account': '创建管理员账户', 'Create admin account': '创建管理员账户',
'This is the first account with full permissions': '这是系统的第一个账户,将拥有最高权限。', 'This is the first account with full permissions': '这是系统的第一个账户,将拥有最高权限。',
+52 -12
View File
@@ -1,7 +1,8 @@
import { useState } from 'react'; import { useEffect, useState } from 'react';
import { Form, Input, Button, Card, message, Steps, Select, Space, Typography } from 'antd'; import { Form, Input, Button, Card, message, Steps, Select, Space, Typography } from 'antd';
import { UserOutlined, LockOutlined, HddOutlined } from '@ant-design/icons'; import { UserOutlined, LockOutlined, HddOutlined } from '@ant-design/icons';
import { adaptersApi } from '../api/adapters'; import { adaptersApi } from '../api/adapters';
import { setConfig } from '../api/config';
import { useAuth } from '../contexts/AuthContext'; import { useAuth } from '../contexts/AuthContext';
import { useI18n } from '../i18n'; import { useI18n } from '../i18n';
import LanguageSwitcher from '../components/LanguageSwitcher'; import LanguageSwitcher from '../components/LanguageSwitcher';
@@ -15,6 +16,14 @@ const SetupPage = () => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const { login, register } = useAuth(); const { login, register } = useAuth();
const { t } = useI18n(); const { t } = useI18n();
useEffect(() => {
const origin = window.location.origin;
form.setFieldsValue({
app_domain: origin,
file_domain: origin,
});
}, [form]);
const onFinish = async (values: any) => { const onFinish = async (values: any) => {
setLoading(true); setLoading(true);
try { try {
@@ -22,17 +31,34 @@ const SetupPage = () => {
await login(values.username, values.password); await login(values.username, values.password);
message.success(t('Initialization succeeded! Logging you in...')); message.success(t('Initialization succeeded! Logging you in...'));
setTimeout(async () => { setTimeout(async () => {
await adaptersApi.create({ try {
name: values.adapter_name, const tasks: Promise<unknown>[] = [];
type: values.adapter_type, const appDomain = values.app_domain?.trim();
config: { const fileDomain = values.file_domain?.trim();
root: values.root_dir if (appDomain) {
}, tasks.push(setConfig('APP_DOMAIN', appDomain));
sub_path: null, }
path: values.path, if (fileDomain) {
enabled: true tasks.push(setConfig('FILE_DOMAIN', fileDomain));
}); }
window.location.href = '/'; if (tasks.length) {
await Promise.all(tasks);
}
await adaptersApi.create({
name: values.adapter_name,
type: values.adapter_type,
config: {
root: values.root_dir
},
sub_path: null,
path: values.path,
enabled: true
});
window.location.href = '/';
} catch (configError: any) {
console.error(configError);
message.error(configError.response?.data?.msg || t('Initialization failed, please try later'));
}
}, 2000); }, 2000);
} catch (error: any) { } catch (error: any) {
console.log(error) console.log(error)
@@ -122,6 +148,20 @@ const SetupPage = () => {
> >
<Input size="large" placeholder={t('e.g., data/ or /var/foxel/data')} /> <Input size="large" placeholder={t('e.g., data/ or /var/foxel/data')} />
</Form.Item> </Form.Item>
<Form.Item
label={t('App Domain')}
name="app_domain"
extra={t('Optional, used for external links. Leave empty to use the current site.')}
>
<Input size="large" placeholder="https://your-app-domain.com" />
</Form.Item>
<Form.Item
label={t('File Domain')}
name="file_domain"
extra={t('Optional, used for external links. Leave empty to use the current site.')}
>
<Input size="large" placeholder="https://files.your-domain.com" />
</Form.Item>
</> </>
) )
}, },