Skip to content

Commit 9a6fc07

Browse files
committed
updated the ratelimit docs
1 parent 0ac8c7d commit 9a6fc07

File tree

3 files changed

+404
-262
lines changed

3 files changed

+404
-262
lines changed

components/UppyProvider.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,7 @@ export const UppyProvider: React.FC<{ children: React.ReactNode }> = ({
5858
}).use(Tus, {
5959
endpoint: process.env.NEXT_PUBLIC_WORKERS_API_ENDPOINT,
6060
limit: 5,
61-
withCredentials: true,
62-
overridePatchMethod: true,
63-
removeFingerprintOnSuccess: true,
6461
retryDelays: [0, 1000, 3000, 5000],
65-
onBeforeRequest: (req, file) => {
66-
req.setHeader(
67-
'Authorization',
68-
`Bearer ${process.env.NEXT_PUBLIC_WORKERS_API_KEY}`
69-
);
70-
},
7162
chunkSize: MIN_CHUNK_SIZE, // Set initial chunk size
7263
onProgress: (bytesUploaded) => {
7364
const currentTime = Date.now();

content/docs/api/configuration.mdx

Lines changed: 141 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ title: Configuration
33
description: Complete guide to Tusflow`s API configuration options
44
---
55

6-
import { Callout } from 'fumadocs-ui/components/callout'
7-
import { Steps } from 'fumadocs-ui/components/steps'
8-
import { Tab, Tabs } from 'fumadocs-ui/components/tabs'
6+
import { Callout } from 'fumadocs-ui/components/callout';
7+
import { Steps } from 'fumadocs-ui/components/steps';
8+
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
99

1010
## Overview
1111

1212
Tusflow's configuration is managed through:
13+
1314
1. Environment variables in `wrangler.toml`
1415
2. TypeScript configuration modules in `config/`
1516

@@ -36,6 +37,7 @@ AWS_BUCKET_NAME = ""
3637
UPSTASH_REDIS_REST_URL = ""
3738
UPSTASH_REDIS_REST_TOKEN = ""
3839
UNKEY_API_ID = ""
40+
UNKEY_ROOT_KEY = ""
3941

4042
[observability]
4143
enabled = true
@@ -50,30 +52,30 @@ Configure upload behavior in `upload-config.ts`:
5052

5153
```typescript
5254
export const UPLOAD_CONFIG = {
53-
DOMAIN: '',
54-
CHUNK_SIZE: {
55-
MIN: 5 * 1024 * 1024, // 5MB
56-
MAX: 50 * 1024 * 1024, // 50MB
57-
TARGET_UPLOAD_TIME: 1 // 1 second
58-
},
59-
RETRY: {
60-
MAX_ATTEMPTS: 3,
61-
DELAY: 500 // 500ms
62-
},
63-
CIRCUIT_BREAKER: {
64-
TIMEOUT: 25000, // 25 seconds
65-
FAILURE_THRESHOLD: 3,
66-
RESET_TIMEOUT: 5000 // 5 seconds
67-
},
68-
UPLOAD: {
69-
INCOMPLETE_TTL: 24 * 60 * 60, // 24 hours
70-
MAX_PARTS: 10000,
71-
TIMEOUT: 25000 // 25 seconds
72-
},
73-
PARALLEL_UPLOADS: {
74-
MAX_CONCURRENT: 10,
75-
BATCH_SIZE: 5
76-
}
55+
DOMAIN: '',
56+
CHUNK_SIZE: {
57+
MIN: 5 * 1024 * 1024, // 5MB
58+
MAX: 50 * 1024 * 1024, // 50MB
59+
TARGET_UPLOAD_TIME: 1, // 1 second
60+
},
61+
RETRY: {
62+
MAX_ATTEMPTS: 3,
63+
DELAY: 500, // 500ms
64+
},
65+
CIRCUIT_BREAKER: {
66+
TIMEOUT: 25000, // 25 seconds
67+
FAILURE_THRESHOLD: 3,
68+
RESET_TIMEOUT: 5000, // 5 seconds
69+
},
70+
UPLOAD: {
71+
INCOMPLETE_TTL: 24 * 60 * 60, // 24 hours
72+
MAX_PARTS: 10000,
73+
TIMEOUT: 25000, // 25 seconds
74+
},
75+
PARALLEL_UPLOADS: {
76+
MAX_CONCURRENT: 10,
77+
BATCH_SIZE: 5,
78+
},
7779
};
7880
```
7981

@@ -83,11 +85,11 @@ Set worker limits in `workers-config.ts`:
8385

8486
```typescript
8587
export const WORKER_CONSTRAINTS = {
86-
MAX_EXECUTION_TIME: 25000, // 25 seconds
87-
MEMORY_LIMIT: 128 * 1024 * 1024, // 128MB
88-
CHUNK_MEMORY_LIMIT: 50 * 1024 * 1024, // 50MB
89-
NETWORK_OVERHEAD: 1.2, // 20% overhead
90-
CONCURRENT_UPLOADS: 5
88+
MAX_EXECUTION_TIME: 25000, // 25 seconds
89+
MEMORY_LIMIT: 128 * 1024 * 1024, // 128MB
90+
CHUNK_MEMORY_LIMIT: 50 * 1024 * 1024, // 50MB
91+
NETWORK_OVERHEAD: 1.2, // 20% overhead
92+
CONCURRENT_UPLOADS: 5,
9193
};
9294
```
9395

@@ -97,23 +99,23 @@ Configure TUS protocol in `tus-config.ts`:
9799

98100
```typescript
99101
export const TUS_CONFIG = {
100-
VERSION: '1.0.0',
101-
SUPPORTED_VERSIONS: ['1.0.0', '1.0.0'],
102-
MAX_SIZE: 1024 * 1024 * 1024, // 1GB
103-
EXTENSIONS: [
104-
'creation',
105-
'creation-with-upload',
106-
'termination',
107-
'concatenation',
108-
'checksum',
109-
'expiration'
110-
],
111-
CHECKSUM_ALGORITHMS: ['sha1', 'md5'],
112-
HEADERS: {
113-
RESUMABLE: 'Tus-Resumable',
114-
VERSION: 'Tus-Version',
115-
// ... other headers
116-
}
102+
VERSION: '1.0.0',
103+
SUPPORTED_VERSIONS: ['1.0.0', '1.0.0'],
104+
MAX_SIZE: 1024 * 1024 * 1024, // 1GB
105+
EXTENSIONS: [
106+
'creation',
107+
'creation-with-upload',
108+
'termination',
109+
'concatenation',
110+
'checksum',
111+
'expiration',
112+
],
113+
CHECKSUM_ALGORITHMS: ['sha1', 'md5'],
114+
HEADERS: {
115+
RESUMABLE: 'Tus-Resumable',
116+
VERSION: 'Tus-Version',
117+
// ... other headers
118+
},
117119
};
118120
```
119121

@@ -123,23 +125,27 @@ Configure rate limits in `ratelimit-config.ts`:
123125

124126
```typescript
125127
export const RATE_LIMIT = {
126-
ENABLE: false,
127-
KEY_PREFIX: 'ratelimit:',
128-
BLOCK_DURATION: 60 * 60, // 1 hour
129-
LIMITS: {
130-
POST: {
131-
tokens: 50, // New uploads
132-
interval: 3600 // 1 hour
133-
},
134-
PATCH: {
135-
tokens: 500, // Chunk uploads
136-
interval: 3600
137-
},
138-
DEFAULT: {
139-
tokens: 100,
140-
interval: 3600
141-
}
142-
}
128+
ENABLE: true,
129+
NAMESPACE: 'tusflow-api',
130+
BLOCK_DURATION: 60 * 60, // 1 hour
131+
// Different limits for different endpoints
132+
LIMITS: {
133+
// For initiating new uploads
134+
POST: {
135+
tokens: 50, // Number of requests
136+
interval: 3600, // Time window in seconds (1 hour)
137+
},
138+
// For upload chunks
139+
PATCH: {
140+
tokens: 500, // More tokens for chunk uploads
141+
interval: 3600,
142+
},
143+
// For other operations (HEAD, DELETE)
144+
DEFAULT: {
145+
tokens: 100,
146+
interval: 3600,
147+
},
148+
},
143149
};
144150
```
145151

@@ -149,20 +155,20 @@ Manage security in `security-config.ts`:
149155

150156
```typescript
151157
export const SECURITY_CONFIG = {
152-
ALLOWED_ORIGINS: ['*'],
153-
ALLOWED_METHODS: ['GET', 'POST', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS'],
154-
ALLOWED_HEADERS: [
155-
'Content-Type',
156-
'Upload-Length',
157-
'Upload-Metadata',
158-
// ... other headers
159-
],
160-
EXPOSE_HEADERS: [
161-
'Location',
162-
'Upload-Offset',
163-
// ... other headers
164-
],
165-
CREDENTIALS: true
158+
ALLOWED_ORIGINS: ['*'],
159+
ALLOWED_METHODS: ['GET', 'POST', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS'],
160+
ALLOWED_HEADERS: [
161+
'Content-Type',
162+
'Upload-Length',
163+
'Upload-Metadata',
164+
// ... other headers
165+
],
166+
EXPOSE_HEADERS: [
167+
'Location',
168+
'Upload-Offset',
169+
// ... other headers
170+
],
171+
CREDENTIALS: true,
166172
};
167173
```
168174

@@ -172,13 +178,19 @@ Set file validation rules in `fileValidation-config.ts`:
172178

173179
```typescript
174180
export const FILE_VALIDATION = {
175-
ENABLE_TYPE_VALIDATION: true,
176-
ALLOWED_FILE_TYPES: [
177-
'.pdf', '.doc', '.docx', '.txt',
178-
'.jpg', '.jpeg', '.png', '.mp4'
179-
],
180-
MAX_FILE_SIZE: 100 * 1024 * 1024, // 100MB
181-
MIN_FILE_SIZE: 1024 // 1KB
181+
ENABLE_TYPE_VALIDATION: true,
182+
ALLOWED_FILE_TYPES: [
183+
'.pdf',
184+
'.doc',
185+
'.docx',
186+
'.txt',
187+
'.jpg',
188+
'.jpeg',
189+
'.png',
190+
'.mp4',
191+
],
192+
MAX_FILE_SIZE: 100 * 1024 * 1024, // 100MB
193+
MIN_FILE_SIZE: 1024, // 1KB
182194
};
183195
```
184196

@@ -188,19 +200,19 @@ Define error messages in `error-config.ts`:
188200

189201
```typescript
190202
export const ERROR_MESSAGES = {
191-
UPLOAD: {
192-
LENGTH_REQUIRED: 'Upload-Length or Upload-Defer-Length header required',
193-
INVALID_OFFSET: 'Invalid Upload-Offset header',
194-
// ... other upload errors
195-
},
196-
S3: {
197-
MULTIPART_INIT_FAILED: 'Failed to initialize multipart upload',
198-
// ... other S3 errors
199-
},
200-
RATE_LIMIT: {
201-
LIMIT_EXCEEDED: 'Rate limit exceeded. Please try again later.',
202-
// ... other rate limit errors
203-
}
203+
UPLOAD: {
204+
LENGTH_REQUIRED: 'Upload-Length or Upload-Defer-Length header required',
205+
INVALID_OFFSET: 'Invalid Upload-Offset header',
206+
// ... other upload errors
207+
},
208+
S3: {
209+
MULTIPART_INIT_FAILED: 'Failed to initialize multipart upload',
210+
// ... other S3 errors
211+
},
212+
RATE_LIMIT: {
213+
LIMIT_EXCEEDED: 'Rate limit exceeded. Please try again later.',
214+
// ... other rate limit errors
215+
},
204216
};
205217
```
206218

@@ -210,9 +222,9 @@ Configure caching in `cache-config.ts`:
210222

211223
```typescript
212224
export const CACHE_CONFIG = {
213-
CACHE_NAME: 'Tusflow-api-cache',
214-
MAX_AGE: UPLOAD_CONFIG.UPLOAD.INCOMPLETE_TTL,
215-
VARY_HEADERS: ['Accept', 'Accept-Encoding', 'Authorization']
225+
CACHE_NAME: 'Tusflow-api-cache',
226+
MAX_AGE: UPLOAD_CONFIG.UPLOAD.INCOMPLETE_TTL,
227+
VARY_HEADERS: ['Accept', 'Accept-Encoding', 'Authorization'],
216228
};
217229
```
218230

@@ -225,21 +237,25 @@ export const CACHE_CONFIG = {
225237
- Set appropriate file size limits
226238
- Configure authentication
227239

228-
### Performance Tuning
229-
- Adjust chunk sizes based on network conditions
230-
- Configure parallel upload limits
231-
- Set appropriate timeouts
232-
- Enable caching where possible
233-
234-
### Error Handling
235-
- Configure meaningful error messages
236-
- Set up proper logging
237-
- Implement retry strategies
238-
- Monitor error rates
240+
### Performance Tuning
241+
242+
- Adjust chunk sizes based on network conditions
243+
- Configure parallel upload limits
244+
- Set appropriate timeouts
245+
- Enable caching where possible
246+
247+
### Error Handling
248+
249+
- Configure meaningful error messages
250+
- Set up proper logging
251+
- Implement retry strategies
252+
- Monitor error rates
253+
239254
</Steps>
240255

241256
<Callout type="warning">
242-
Always test configuration changes in a staging environment before deploying to production.
257+
Always test configuration changes in a staging environment before deploying to
258+
production.
243259
</Callout>
244260

245261
## Configuration Import
@@ -248,17 +264,18 @@ Import and use configurations in your application:
248264

249265
```typescript
250266
import {
251-
UPLOAD_CONFIG,
252-
WORKER_CONSTRAINTS,
253-
TUS_CONFIG,
254-
RATE_LIMIT,
255-
SECURITY_CONFIG,
256-
FILE_VALIDATION,
257-
ERROR_MESSAGES,
258-
CACHE_CONFIG
267+
CACHE_CONFIG,
268+
ERROR_MESSAGES,
269+
FILE_VALIDATION,
270+
RATE_LIMIT,
271+
SECURITY_CONFIG,
272+
TUS_CONFIG,
273+
UPLOAD_CONFIG,
274+
WORKER_CONSTRAINTS,
259275
} from '@/config';
260276

261277
// Example usage
262278
const maxChunkSize = UPLOAD_CONFIG.CHUNK_SIZE.MAX;
263279
const allowedTypes = FILE_VALIDATION.ALLOWED_FILE_TYPES;
264-
const corsOrigins = SECURITY_CONFIG.ALLOWED_ORIGINS;
280+
const corsOrigins = SECURITY_CONFIG.ALLOWED_ORIGINS;
281+
```

0 commit comments

Comments
 (0)