Skip to content

Commit 0f74e2f

Browse files
committed
Fix relay icon to use static file URL instead of Blossom upload
- Replace Blossom upload with direct static file URL (/{origin}/logo-dark-192.png) - Remove complex upload logic that was causing 500 errors - Auto-detect domain changes (localhost to production) and update icon URL - Simplify icon management - no server-side upload needed for default icon - Fix malformed Blossom URLs that were causing ERR_NAME_NOT_RESOLVED - Users can still upload custom icons via IconUpload component if needed
1 parent cbb5f25 commit 0f74e2f

File tree

1 file changed

+26
-80
lines changed

1 file changed

+26
-80
lines changed

src/components/settings/RelayInfoSettings.tsx

Lines changed: 26 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect } from 'react';
22
import { Form, Input, Select, Tooltip, message } from 'antd';
33
import {
44
QuestionCircleOutlined,
@@ -11,118 +11,64 @@ import useGenericSettings from '@app/hooks/useGenericSettings';
1111
import { SettingsGroupType } from '@app/types/settings.types';
1212
import BaseSettingsForm from './BaseSettingsForm';
1313
import * as S from './Settings.styles';
14-
import { readToken } from '@app/services/localStorage.service';
15-
import config from '@app/config/config';
1614
const { Option } = Select;
1715
const { TextArea } = Input;
1816

1917
const RelayInfoSettings: React.FC = () => {
2018
const { settings, loading, error, fetchSettings, updateSettings, saveSettings } = useGenericSettings('relay_info');
2119
const [form] = Form.useForm();
22-
const [isUploadingDefaultIcon, setIsUploadingDefaultIcon] = useState(false);
2320

24-
// Function to automatically upload the bee logo
25-
const uploadDefaultIcon = async (): Promise<string | null> => {
26-
try {
27-
setIsUploadingDefaultIcon(true);
28-
29-
// Get JWT token for authentication
30-
const token = readToken();
31-
if (!token) {
32-
console.error('No authentication token available');
33-
return null;
34-
}
35-
36-
// Fetch the bee logo from the public folder
37-
const response = await fetch('/logo-dark-192.png');
38-
if (!response.ok) {
39-
throw new Error('Failed to fetch bee logo');
40-
}
41-
42-
const blob = await response.blob();
43-
const file = new File([blob], 'logo-dark-192.png', { type: 'image/png' });
44-
45-
// Create form data for the API
46-
const formData = new FormData();
47-
formData.append('image', file);
48-
formData.append('panel_url', window.location.origin);
49-
50-
// Upload using panel API
51-
const uploadResponse = await fetch(`${config.baseURL}/api/relay/icon`, {
52-
method: 'POST',
53-
headers: {
54-
'Authorization': `Bearer ${token}`,
55-
},
56-
body: formData
57-
});
58-
59-
if (!uploadResponse.ok) {
60-
const errorData = await uploadResponse.json().catch(() => ({ error: 'Upload failed' }));
61-
throw new Error(errorData.error || `HTTP error! status: ${uploadResponse.status}`);
62-
}
63-
64-
const result = await uploadResponse.json();
65-
console.log('Default icon uploaded successfully:', result.url);
66-
return result.url;
67-
68-
} catch (error) {
69-
console.error('Failed to upload default icon:', error);
70-
return null;
71-
} finally {
72-
setIsUploadingDefaultIcon(false);
73-
}
21+
// Function to get the default bee logo URL (no upload needed)
22+
const getDefaultIconUrl = (): string => {
23+
const currentOrigin = window.location.origin;
24+
return `${currentOrigin}/logo-dark-192.png`;
7425
};
7526

7627
// Update form values when settings change
7728
useEffect(() => {
7829
if (settings) {
79-
form.setFieldsValue(settings);
80-
8130
const currentOrigin = window.location.origin;
31+
const defaultIconUrl = getDefaultIconUrl();
8232
const isEmptyIcon = !settings.relayicon || settings.relayicon.trim() === '';
8333
const isLocalhostIcon = settings.relayicon && settings.relayicon.includes('localhost');
8434
const isProductionDomain = !currentOrigin.includes('localhost');
8535

86-
// Auto-upload default icon if:
36+
// Auto-set default icon URL if:
8737
// 1. Icon is empty, OR
8838
// 2. We're on production domain but icon still points to localhost
8939
if (isEmptyIcon || (isLocalhostIcon && isProductionDomain)) {
90-
console.log('Auto-uploading default icon...', {
40+
console.log('Auto-setting default icon URL...', {
9141
isEmptyIcon,
9242
isLocalhostIcon,
9343
isProductionDomain,
9444
currentOrigin,
95-
currentIcon: settings.relayicon
45+
currentIcon: settings.relayicon,
46+
defaultIconUrl
9647
});
9748

98-
uploadDefaultIcon().then(uploadedUrl => {
99-
if (uploadedUrl) {
100-
// Update the settings with the uploaded URL
101-
updateSettings({ relayicon: uploadedUrl });
102-
form.setFieldsValue({ relayicon: uploadedUrl });
103-
104-
if (isEmptyIcon) {
105-
message.success('Default bee logo set automatically');
106-
} else {
107-
message.success('Icon updated for new domain');
108-
}
109-
}
110-
});
49+
// Update the settings with the default icon URL
50+
updateSettings({ relayicon: defaultIconUrl });
51+
form.setFieldsValue({ relayicon: defaultIconUrl });
52+
53+
if (isEmptyIcon) {
54+
message.success('Default bee logo set automatically');
55+
} else {
56+
message.success('Icon updated for new domain');
57+
}
58+
} else {
59+
form.setFieldsValue(settings);
11160
}
11261
}
11362
}, [settings, form, updateSettings]);
11463

11564
// Handle form value changes
11665
const handleValuesChange = (changedValues: Partial<SettingsGroupType<'relay_info'>>) => {
117-
// If relay icon is being cleared, automatically upload default
66+
// If relay icon is being cleared, automatically set default URL
11867
if (changedValues.relayicon !== undefined && (!changedValues.relayicon || changedValues.relayicon.trim() === '')) {
119-
uploadDefaultIcon().then(uploadedUrl => {
120-
if (uploadedUrl) {
121-
updateSettings({ relayicon: uploadedUrl });
122-
form.setFieldsValue({ relayicon: uploadedUrl });
123-
message.success('Default bee logo set automatically');
124-
}
125-
});
68+
const defaultIconUrl = getDefaultIconUrl();
69+
updateSettings({ relayicon: defaultIconUrl });
70+
form.setFieldsValue({ relayicon: defaultIconUrl });
71+
message.success('Default bee logo set automatically');
12672
return; // Don't update with empty value
12773
}
12874

0 commit comments

Comments
 (0)