Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/build-windows-x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build Windows x64

permissions:
contents: read
actions: read

on:
push:
branches:
- main
paths:
- 'app/**'
- 'packages/**'
- '.github/workflows/build-windows-x64.yml'
workflow_dispatch:
inputs:
app_version:
type: string
description: 'App Version (optional)'
required: false
default: '0.0.1'

jobs:
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: |
packages/backend
packages/backend-server
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo-about binary
id: cache-cargo-about
uses: actions/cache@v4
with:
path: ~/.cargo/bin/cargo-about
key: ${{ runner.os }}-cargo-about-0.8.2

- name: Install cargo-about
if: steps.cache-cargo-about.outputs.cache-hit != 'true'
run: cargo install cargo-about --version 0.8.2

- name: Install dependencies
run: |
yarn config set network-timeout 300000
yarn install --frozen-lockfile --network-timeout 300000

- name: Build Windows x64
run: yarn build:desktop:win:x64
env:
APP_VERSION: ${{ inputs.app_version || '0.0.1' }}
M_VITE_APP_VERSION: ${{ inputs.app_version || '0.0.1' }}
P_VITE_APP_VERSION: ${{ inputs.app_version || '0.0.1' }}
R_VITE_APP_VERSION: ${{ inputs.app_version || '0.0.1' }}

HUSKY: 0
NODE_OPTIONS: --max_old_space_size=8192

PRODUCT_NAME: 'Surf'
M_VITE_PRODUCT_NAME: 'Surf'
BUILD_RESOURCES_DIR: build/resources/prod

- name: Upload Windows Installer
uses: actions/upload-artifact@v4
with:
name: surf-windows-x64-installer
path: |
app/dist/*.exe
app/dist/*.yml
retention-days: 30

- name: Output download info
run: |
echo "::notice::构建完成!请到 Actions 页面下载构建产物"
echo "::notice::Artifact 名称: surf-windows-x64-installer"
echo "::notice::保留时间: 30 天"
96 changes: 96 additions & 0 deletions BOCHA_SEARCH_API_CONFIG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# 博查 Web Search API 配置指南

## 概述

本系统已添加对博查 Web Search API 的支持,该 API 兼容 Bing Search API 格式。

## API 配置

### 1. 搜索引擎选择

在 `WebSearch.svelte` 组件中,可以通过修改 `searchEngineConfig` 来切换搜索引擎:

```typescript
const searchEngineConfig: SearchEngineConfig = {
engine: 'duckduckgo', // 可改为 'bocha'
apiKey: undefined
}
```

### 2. 使用博查 API

要启用博查搜索,将配置修改为:

```typescript
const searchEngineConfig: SearchEngineConfig = {
engine: 'bocha',
apiKey: 'YOUR_BOCHA_API_KEY' // 替换为实际的 API Key
}
```

### 3. 自定义配置

博查 API 支持以下配置选项:

- `apiKey`: 博查 API 密钥(必需)
- `baseUrl`: API 端点地址(默认:`https://api.bochaai.com/api/v1/web-search`)
- `country`: 国家/地区代码(默认:`CN`)
- `language`: 语言代码(默认:`zh-CN`)

完整配置示例:

```typescript
const bochaConfig: BochaSearchConfig = {
apiKey: 'YOUR_BOCHA_API_KEY',
baseUrl: 'https://api.bochaai.com/api/v1/web-search',
country: 'CN',
language: 'zh-CN'
}

const searchAPI = new BochaSearchAPI(bochaConfig)
```

## API 返回格式

博查 API 返回的数据格式应如下:

```json
{
"data": {
"webPages": {
"value": [
{
"name": "结果标题",
"url": "https://example.com",
"snippet": "结果摘要"
}
]
}
}
}
```

或者兼容格式:

```json
{
"results": [
{
"title": "结果标题",
"url": "https://example.com"
}
]
}
```

## 实现文件

- `/workspace/packages/web-parser/src/search/bocha.ts` - 博查 API 实现
- `/workspace/packages/web-parser/src/search/index.ts` - 导出配置
- `/workspace/app/src/renderer/Resource/components/WebSearch.svelte` - 搜索引擎使用

## 注意事项

1. 需要有效的博查 API 密钥才能使用
2. API 密钥应通过安全的方式存储和传递,不要硬编码在源代码中
3. 建议在生产环境中使用环境变量或配置文件管理 API 密钥
29 changes: 28 additions & 1 deletion app/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,36 @@ import { esbuildConsolidatePreloads } from './plugins/merge-chunks'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import { createConcatLicensesPlugin, createLicensePlugin } from './plugins/license'
import { createRustLicensePlugin } from './plugins/rust-license'
import { copyFileSync, mkdirSync, existsSync } from 'fs'
import { join } from 'path'

const IS_DEV = process.env.NODE_ENV === 'development'

// Plugin to copy i18n files to output directory
function copyI18nPlugin() {
return {
name: 'copy-i18n',
closeBundle() {
const srcDir = resolve(__dirname, 'src/main/i18n')
const destDir = resolve(__dirname, 'out/main/i18n')

if (existsSync(srcDir)) {
if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true })
}

const files = ['en-US.json', 'zh-CN.json']
for (const file of files) {
const srcFile = join(srcDir, file)
const destFile = join(destDir, file)
copyFileSync(srcFile, destFile)
}
console.log('Copied i18n files to out/main/i18n/')
}
}
}
}

// TODO: actually fix the warnings in the code
const silenceWarnings = IS_DEV || process.env.SILENCE_WARNINGS === 'true'

Expand Down Expand Up @@ -40,7 +67,7 @@ const cssConfig = silenceWarnings
export default defineConfig({
main: {
envPrefix: 'M_VITE_',
plugins: [externalizeDepsPlugin(), createLicensePlugin('main')],
plugins: [externalizeDepsPlugin(), createLicensePlugin('main'), copyI18nPlugin()],
build: {
rollupOptions: {
input: {
Expand Down
Loading