Skip to content

Commit 6707f21

Browse files
committed
feat: STORE_PREFIX, close #92
1 parent 2780fc6 commit 6707f21

File tree

6 files changed

+11
-3
lines changed

6 files changed

+11
-3
lines changed

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ STORE_BUCKET=notea
44
PASSWORD=123
55
STORE_END_POINT=http://localhost:9000
66
STORE_FORCE_PATH_STYLE=true
7+
STORE_PREFIX=

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ PASSWORD=123
55
# STORE_END_POINT=
66
# STORE_REGION=
77
# STORE_FORCE_PATH_STYLE=
8+
STORE_PREFIX=

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Contribution examples are welcome.
166166
| STORE_END_POINT | Host name or an IP address. | | | |
167167
| STORE_REGION | region | us-east-1 | | |
168168
| STORE_FORCE_PATH_STYLE | Whether to force path style URLs for S3 objects | false | | |
169+
| STORE_PREFIX | Storage path prefix | '' | | |
169170
| COOKIE_SECURE | Only works under https: scheme **If the website is not https, you may not be able to log in, and you need to set it to false** | true | | |
170171
| BASE_URL | The domain of the website, used for SEO | | | |
171172
| DISABLE_PASSWORD | Disable password protection. This means that you need to implement authentication on the server yourself, but the route `/share/:id` needs to be accessible anonymously, if you need share page. [#31](https://github.com/QingWei-Li/notea/issues/31) | false | | |

libs/server/store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { getEnv } from 'libs/shared/env'
22
import { StoreS3 } from './providers/s3'
33

4-
export function createStore(prefix = '') {
4+
export function createStore() {
55
return new StoreS3({
66
accessKey: getEnv('STORE_ACCESS_KEY', undefined, true),
77
secretKey: getEnv('STORE_SECRET_KEY', undefined, true),
88
endPoint: getEnv('STORE_END_POINT'),
99
bucket: getEnv('STORE_BUCKET', 'notea'),
1010
region: getEnv('STORE_REGION', 'us-east-1'),
1111
pathStyle: getEnv('STORE_FORCE_PATH_STYLE', false),
12-
prefix,
12+
prefix: getEnv('STORE_PREFIX', ''),
1313
})
1414
}
1515

libs/server/store/providers/base.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export interface ObjectOptions {
1414

1515
export abstract class StoreProvider {
1616
constructor({ prefix }: StoreProviderConfig) {
17-
this.prefix = prefix
17+
this.prefix = prefix?.replace(/\/$/, '')
18+
19+
if (this.prefix) {
20+
this.prefix += '/'
21+
}
1822
}
1923

2024
prefix?: string

libs/shared/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type AllowedEnvs =
1111
| 'DISABLE_PASSWORD'
1212
| 'DIRECT_RESPONSE_ATTACHMENT'
1313
| 'IS_DEMO'
14+
| 'STORE_PREFIX'
1415

1516
export function getEnv<T>(
1617
env: AllowedEnvs,

0 commit comments

Comments
 (0)