Skip to content

Commit a7b6529

Browse files
committed
Simplify icon upload to use new backend API
- Replace complex client-side Blossom upload with simple API call - Use POST /api/relay/icon endpoint with JWT authentication - Send panel_url (auto-detected from window.location.origin) and image file - Backend now handles Kind 117 event creation, Blossom storage, and config updates - Remove dependency on direct Blossom upload utilities - Improve error handling and user feedback
1 parent c38c658 commit a7b6529

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

src/components/common/IconUpload.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, { useState, useRef, useEffect } from 'react';
22
import { Input, Upload, Button, message, Tabs, Avatar } from 'antd';
33
import { UploadOutlined, LinkOutlined, LoadingOutlined } from '@ant-design/icons';
4-
import { uploadToBlossom, isValidUrl, isImageUrl } from '@app/utils/blossomUpload';
4+
import { isValidUrl, isImageUrl } from '@app/utils/blossomUpload';
5+
import { readToken } from '@app/services/localStorage.service';
6+
import config from '@app/config/config';
57
import type { RcFile } from 'antd/es/upload/interface';
68

79
interface IconUploadProps {
@@ -38,7 +40,7 @@ const IconUpload: React.FC<IconUploadProps> = ({
3840
}
3941
};
4042

41-
// Handle file upload
43+
// Handle file upload using new simplified API
4244
const handleFileUpload = async (file: RcFile): Promise<boolean> => {
4345
try {
4446
setUploading(true);
@@ -55,10 +57,35 @@ const IconUpload: React.FC<IconUploadProps> = ({
5557
return false;
5658
}
5759

58-
// Upload to Blossom server
59-
const result = await uploadToBlossom(file);
60+
// Get JWT token for authentication
61+
const token = readToken();
62+
if (!token) {
63+
message.error('Authentication required. Please log in.');
64+
return false;
65+
}
66+
67+
// Create form data for the API
68+
const formData = new FormData();
69+
formData.append('image', file);
70+
formData.append('panel_url', window.location.origin); // Auto-detect current panel URL
71+
72+
// Upload using panel API
73+
const response = await fetch(`${config.baseURL}/api/relay/icon`, {
74+
method: 'POST',
75+
headers: {
76+
'Authorization': `Bearer ${token}`,
77+
},
78+
body: formData
79+
});
80+
81+
if (!response.ok) {
82+
const errorData = await response.json().catch(() => ({ error: 'Upload failed' }));
83+
throw new Error(errorData.error || `HTTP error! status: ${response.status}`);
84+
}
85+
86+
const result = await response.json();
6087

61-
// Update URL input and parent component
88+
// Update URL input and parent component with the returned URL
6289
setUrlInput(result.url);
6390
onChange?.(result.url);
6491

0 commit comments

Comments
 (0)