mirror of
https://github.com/Afilmory/afilmory
synced 2026-04-24 23:05:05 +00:00
feat: Add S3_EXCLUDE_REGEX configuration option for file exclusion support. (#15)
This commit is contained in:
@@ -5,3 +5,4 @@ S3_BUCKET_NAME=images
|
|||||||
S3_PREFIX=
|
S3_PREFIX=
|
||||||
S3_ENDPOINT=
|
S3_ENDPOINT=
|
||||||
S3_CUSTOM_DOMAIN=
|
S3_CUSTOM_DOMAIN=
|
||||||
|
S3_EXCLUDE_REGEX=
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ S3_ENDPOINT=https://s3.amazonaws.com
|
|||||||
S3_BUCKET_NAME=your_bucket_name
|
S3_BUCKET_NAME=your_bucket_name
|
||||||
S3_PREFIX=photos/
|
S3_PREFIX=photos/
|
||||||
S3_CUSTOM_DOMAIN=your_custom_domain.com
|
S3_CUSTOM_DOMAIN=your_custom_domain.com
|
||||||
|
S3_EXCLUDE_REGEX=
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Site Configuration
|
### 4. Site Configuration
|
||||||
@@ -207,6 +208,7 @@ Create `builder.config.json` file for advanced configuration:
|
|||||||
- `endpoint`: S3 endpoint (optional)
|
- `endpoint`: S3 endpoint (optional)
|
||||||
- `prefix`: File prefix
|
- `prefix`: File prefix
|
||||||
- `customDomain`: Custom domain
|
- `customDomain`: Custom domain
|
||||||
|
- `excludeRegex`: Regular expression to exclude files (optional)
|
||||||
|
|
||||||
#### Build Options (`options`)
|
#### Build Options (`options`)
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ S3_ENDPOINT=https://s3.amazonaws.com
|
|||||||
S3_BUCKET_NAME=your_bucket_name
|
S3_BUCKET_NAME=your_bucket_name
|
||||||
S3_PREFIX=photos/
|
S3_PREFIX=photos/
|
||||||
S3_CUSTOM_DOMAIN=your_custom_domain.com
|
S3_CUSTOM_DOMAIN=your_custom_domain.com
|
||||||
|
S3_EXCLUDE_REGEX=
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. 站点配置
|
### 4. 站点配置
|
||||||
@@ -202,6 +203,7 @@ pnpm dev
|
|||||||
- `endpoint`: S3 端点(可选)
|
- `endpoint`: S3 端点(可选)
|
||||||
- `prefix`: 文件前缀
|
- `prefix`: 文件前缀
|
||||||
- `customDomain`: 自定义域名
|
- `customDomain`: 自定义域名
|
||||||
|
- `excludeRegex`: 排除文件的正则表达式(可选)
|
||||||
|
|
||||||
#### 构建选项 (`options`)
|
#### 构建选项 (`options`)
|
||||||
|
|
||||||
@@ -318,4 +320,4 @@ MIT License © 2025 Innei
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
如果这个项目对你有帮助,请给个 ⭐️ Star 支持一下!
|
如果这个项目对你有帮助,请给个 ⭐️ Star 支持一下!
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ export const defaultBuilderConfig: BuilderConfig = {
|
|||||||
secretAccessKey: env.S3_SECRET_ACCESS_KEY,
|
secretAccessKey: env.S3_SECRET_ACCESS_KEY,
|
||||||
prefix: env.S3_PREFIX,
|
prefix: env.S3_PREFIX,
|
||||||
customDomain: env.S3_CUSTOM_DOMAIN,
|
customDomain: env.S3_CUSTOM_DOMAIN,
|
||||||
|
excludeRegex: env.S3_EXCLUDE_REGEX,
|
||||||
},
|
},
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
|
|||||||
1
env.ts
1
env.ts
@@ -15,6 +15,7 @@ export const env = createEnv({
|
|||||||
S3_BUCKET_NAME: z.string().min(1).optional(),
|
S3_BUCKET_NAME: z.string().min(1).optional(),
|
||||||
S3_PREFIX: z.string().default('').optional(),
|
S3_PREFIX: z.string().default('').optional(),
|
||||||
S3_CUSTOM_DOMAIN: z.string().default('').optional(),
|
S3_CUSTOM_DOMAIN: z.string().default('').optional(),
|
||||||
|
S3_EXCLUDE_REGEX: z.string().optional(),
|
||||||
},
|
},
|
||||||
runtimeEnv: process.env,
|
runtimeEnv: process.env,
|
||||||
isServer: typeof window === 'undefined',
|
isServer: typeof window === 'undefined',
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export type S3Config = {
|
|||||||
secretAccessKey?: string
|
secretAccessKey?: string
|
||||||
prefix?: string
|
prefix?: string
|
||||||
customDomain?: string
|
customDomain?: string
|
||||||
|
excludeRegex?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GitHubConfig = {
|
export type GitHubConfig = {
|
||||||
|
|||||||
@@ -89,11 +89,16 @@ export class S3StorageProvider implements StorageProvider {
|
|||||||
|
|
||||||
const listResponse = await s3Client.send(listCommand)
|
const listResponse = await s3Client.send(listCommand)
|
||||||
const objects = listResponse.Contents || []
|
const objects = listResponse.Contents || []
|
||||||
|
const excludeRegex = this.config.excludeRegex
|
||||||
|
? new RegExp(this.config.excludeRegex)
|
||||||
|
: null
|
||||||
|
|
||||||
// 过滤出图片文件并转换为通用格式
|
// 过滤出图片文件并转换为通用格式
|
||||||
const imageObjects = objects
|
const imageObjects = objects
|
||||||
.filter((obj: _Object) => {
|
.filter((obj: _Object) => {
|
||||||
if (!obj.Key) return false
|
if (!obj.Key) return false
|
||||||
|
if (excludeRegex && excludeRegex.test(obj.Key)) return false
|
||||||
|
|
||||||
const ext = path.extname(obj.Key).toLowerCase()
|
const ext = path.extname(obj.Key).toLowerCase()
|
||||||
return SUPPORTED_FORMATS.has(ext)
|
return SUPPORTED_FORMATS.has(ext)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user