feat: Add S3_EXCLUDE_REGEX configuration option for file exclusion support. (#15)

This commit is contained in:
J2ephyr
2025-06-19 14:39:41 +08:00
committed by GitHub
parent ed82daa5a0
commit fbb31bda30
7 changed files with 14 additions and 1 deletions

View File

@@ -5,3 +5,4 @@ S3_BUCKET_NAME=images
S3_PREFIX=
S3_ENDPOINT=
S3_CUSTOM_DOMAIN=
S3_EXCLUDE_REGEX=

View File

@@ -107,6 +107,7 @@ S3_ENDPOINT=https://s3.amazonaws.com
S3_BUCKET_NAME=your_bucket_name
S3_PREFIX=photos/
S3_CUSTOM_DOMAIN=your_custom_domain.com
S3_EXCLUDE_REGEX=
```
### 4. Site Configuration
@@ -207,6 +208,7 @@ Create `builder.config.json` file for advanced configuration:
- `endpoint`: S3 endpoint (optional)
- `prefix`: File prefix
- `customDomain`: Custom domain
- `excludeRegex`: Regular expression to exclude files (optional)
#### Build Options (`options`)

View File

@@ -102,6 +102,7 @@ S3_ENDPOINT=https://s3.amazonaws.com
S3_BUCKET_NAME=your_bucket_name
S3_PREFIX=photos/
S3_CUSTOM_DOMAIN=your_custom_domain.com
S3_EXCLUDE_REGEX=
```
### 4. 站点配置
@@ -202,6 +203,7 @@ pnpm dev
- `endpoint`: S3 端点(可选)
- `prefix`: 文件前缀
- `customDomain`: 自定义域名
- `excludeRegex`: 排除文件的正则表达式(可选)
#### 构建选项 (`options`)
@@ -318,4 +320,4 @@ MIT License © 2025 Innei
---
如果这个项目对你有帮助,请给个 ⭐️ Star 支持一下!
如果这个项目对你有帮助,请给个 ⭐️ Star 支持一下!

View File

@@ -85,6 +85,7 @@ export const defaultBuilderConfig: BuilderConfig = {
secretAccessKey: env.S3_SECRET_ACCESS_KEY,
prefix: env.S3_PREFIX,
customDomain: env.S3_CUSTOM_DOMAIN,
excludeRegex: env.S3_EXCLUDE_REGEX,
},
options: {

1
env.ts
View File

@@ -15,6 +15,7 @@ export const env = createEnv({
S3_BUCKET_NAME: z.string().min(1).optional(),
S3_PREFIX: z.string().default('').optional(),
S3_CUSTOM_DOMAIN: z.string().default('').optional(),
S3_EXCLUDE_REGEX: z.string().optional(),
},
runtimeEnv: process.env,
isServer: typeof window === 'undefined',

View File

@@ -54,6 +54,7 @@ export type S3Config = {
secretAccessKey?: string
prefix?: string
customDomain?: string
excludeRegex?: string
}
export type GitHubConfig = {

View File

@@ -89,11 +89,16 @@ export class S3StorageProvider implements StorageProvider {
const listResponse = await s3Client.send(listCommand)
const objects = listResponse.Contents || []
const excludeRegex = this.config.excludeRegex
? new RegExp(this.config.excludeRegex)
: null
// 过滤出图片文件并转换为通用格式
const imageObjects = objects
.filter((obj: _Object) => {
if (!obj.Key) return false
if (excludeRegex && excludeRegex.test(obj.Key)) return false
const ext = path.extname(obj.Key).toLowerCase()
return SUPPORTED_FORMATS.has(ext)
})