feat: update ESLint config and add socks-proxy-agent dependency

- Added 'local/**' to ESLint ignores
- Included 'socks-proxy-agent' package in dependencies
- Refactored download function to improve readability and maintainability
- Cleaned up unused code in messages state management
This commit is contained in:
kangfenmao 2025-03-21 11:26:45 +08:00
parent 28c5231741
commit 2ca0a62efa
7 changed files with 61 additions and 95 deletions

View File

@ -53,6 +53,6 @@ export default defineConfig([
} }
], ],
{ {
ignores: ['node_modules/**', 'dist/**', 'out/**', '.gitignore', 'scripts/cloudflare-worker.js'] ignores: ['node_modules/**', 'dist/**', 'out/**', 'local/**', '.gitignore', 'scripts/cloudflare-worker.js']
} }
]) ])

View File

@ -85,6 +85,7 @@
"npx-scope-finder": "^1.2.0", "npx-scope-finder": "^1.2.0",
"officeparser": "^4.1.1", "officeparser": "^4.1.1",
"p-queue": "^8.1.0", "p-queue": "^8.1.0",
"socks-proxy-agent": "^8.0.3",
"tar": "^7.4.3", "tar": "^7.4.3",
"tokenx": "^0.4.1", "tokenx": "^0.4.1",
"undici": "^7.4.0", "undici": "^7.4.0",

View File

@ -16,21 +16,23 @@ async function downloadWithRedirects(url, destinationPath) {
const proxyAgent = new SocksProxyAgent(proxyUrl) const proxyAgent = new SocksProxyAgent(proxyUrl)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const request = (url) => { const request = (url) => {
https.get(url, { agent: proxyAgent }, (response) => { https
if (response.statusCode == 301 || response.statusCode == 302) { .get(url, { agent: proxyAgent }, (response) => {
request(response.headers.location) if (response.statusCode == 301 || response.statusCode == 302) {
return request(response.headers.location)
} return
if (response.statusCode !== 200) { }
reject(new Error(`Download failed: ${response.statusCode} ${response.statusMessage}`)) if (response.statusCode !== 200) {
return reject(new Error(`Download failed: ${response.statusCode} ${response.statusMessage}`))
} return
const file = fs.createWriteStream(destinationPath) }
response.pipe(file) const file = fs.createWriteStream(destinationPath)
file.on('finish', () => resolve()) response.pipe(file)
}).on('error', (err) => { file.on('finish', () => resolve())
reject(err) })
}) .on('error', (err) => {
reject(err)
})
} }
request(url) request(url)
}) })

View File

@ -1,6 +1,6 @@
import { electronApp, optimizer } from '@electron-toolkit/utils' import { electronApp, optimizer } from '@electron-toolkit/utils'
import { app, ipcMain } from 'electron'
import { replaceDevtoolsFont } from '@main/utils/windowUtil' import { replaceDevtoolsFont } from '@main/utils/windowUtil'
import { app, ipcMain } from 'electron'
import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer' import installExtension, { REDUX_DEVTOOLS } from 'electron-devtools-installer'
import { registerIpc } from './ipc' import { registerIpc } from './ipc'

View File

@ -262,46 +262,46 @@ const WebDavSettings: FC = () => {
</SettingRow> </SettingRow>
</> </>
)} )}
<> <>
<Modal <Modal
title={t('settings.data.webdav.backup.modal.title')} title={t('settings.data.webdav.backup.modal.title')}
open={isModalVisible} open={isModalVisible}
onOk={handleBackup} onOk={handleBackup}
onCancel={handleCancel} onCancel={handleCancel}
okButtonProps={{ loading: backuping }}> okButtonProps={{ loading: backuping }}>
<Input <Input
value={customFileName} value={customFileName}
onChange={(e) => setCustomFileName(e.target.value)} onChange={(e) => setCustomFileName(e.target.value)}
placeholder={t('settings.data.webdav.backup.modal.filename.placeholder')} placeholder={t('settings.data.webdav.backup.modal.filename.placeholder')}
/>
</Modal>
<Modal
title={t('settings.data.webdav.restore.modal.title')}
open={isRestoreModalVisible}
onOk={handleRestore}
onCancel={() => setIsRestoreModalVisible(false)}
okButtonProps={{ loading: restoring }}
width={600}>
<div style={{ position: 'relative' }}>
<Select
style={{ width: '100%' }}
placeholder={t('settings.data.webdav.restore.modal.select.placeholder')}
value={selectedFile}
onChange={setSelectedFile}
options={backupFiles.map(formatFileOption)}
loading={loadingFiles}
showSearch
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
/> />
{loadingFiles && ( </Modal>
<div style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}>
<Spin /> <Modal
</div> title={t('settings.data.webdav.restore.modal.title')}
)} open={isRestoreModalVisible}
</div> onOk={handleRestore}
</Modal> onCancel={() => setIsRestoreModalVisible(false)}
</> okButtonProps={{ loading: restoring }}
width={600}>
<div style={{ position: 'relative' }}>
<Select
style={{ width: '100%' }}
placeholder={t('settings.data.webdav.restore.modal.select.placeholder')}
value={selectedFile}
onChange={setSelectedFile}
options={backupFiles.map(formatFileOption)}
loading={loadingFiles}
showSearch
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
/>
{loadingFiles && (
<div style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }}>
<Spin />
</div>
)}
</div>
</Modal>
</>
</SettingGroup> </SettingGroup>
) )
} }

View File

@ -28,31 +28,6 @@ const initialState: MessagesState = {
error: null error: null
} }
// const MAX_RECENT_TOPICS = 10
// // 只初始化最近的会话消息
// export const initializeMessagesState = createAsyncThunk('messages/initialize', async () => {
// try {
// // 获取所有会话的基本信息
// const recentTopics = await TopicManager.getTopicLimit(MAX_RECENT_TOPICS)
// console.log('recentTopics', recentTopics)
// const messagesByTopic: Record<string, Message[]> = {}
// // 只加载最近会话的消息
// for (const topic of recentTopics) {
// if (topic.messages && topic.messages.length > 0) {
// const messages = topic.messages.map((msg) => ({ ...msg }))
// messagesByTopic[topic.id] = messages
// }
// }
// return messagesByTopic
// } catch (error) {
// console.error('Failed to initialize recent messages:', error)
// return {}
// }
// })
// 新增准备会话消息的函数,实现懒加载机制 // 新增准备会话消息的函数,实现懒加载机制
export const prepareTopicMessages = createAsyncThunk( export const prepareTopicMessages = createAsyncThunk(
'messages/prepareTopic', 'messages/prepareTopic',
@ -144,7 +119,7 @@ const messagesSlice = createSlice({
if (message) { if (message) {
Object.assign(message, updates) Object.assign(message, updates)
db.topics.update(topicId, { db.topics.update(topicId, {
messages: topicMessages.map((m) => (m.id === message.id ? cloneDeep(message) : m)) messages: topicMessages.map((m) => (m.id === message.id ? cloneDeep(message) : cloneDeep(m)))
}) })
} }
} }
@ -210,19 +185,6 @@ const messagesSlice = createSlice({
} }
} }
} }
// extraReducers: (builder) => {
// builder
// .addCase(initializeMessagesState.pending, (state) => {
// state.error = null
// })
// .addCase(initializeMessagesState.fulfilled, (state, action) => {
// console.log('initializeMessagesState.fulfilled', action.payload)
// state.messagesByTopic = action.payload
// })
// .addCase(initializeMessagesState.rejected, (state, action) => {
// state.error = action.error.message || 'Failed to load messages'
// })
// }
}) })
const handleResponseMessageUpdate = ( const handleResponseMessageUpdate = (

View File

@ -3411,6 +3411,7 @@ __metadata:
rollup-plugin-visualizer: "npm:^5.12.0" rollup-plugin-visualizer: "npm:^5.12.0"
sass: "npm:^1.77.2" sass: "npm:^1.77.2"
shiki: "npm:^1.22.2" shiki: "npm:^1.22.2"
socks-proxy-agent: "npm:^8.0.3"
string-width: "npm:^7.2.0" string-width: "npm:^7.2.0"
styled-components: "npm:^6.1.11" styled-components: "npm:^6.1.11"
tar: "npm:^7.4.3" tar: "npm:^7.4.3"