-
Notifications
You must be signed in to change notification settings - Fork 6
/
docs.scroll
242 lines (193 loc) · 5.88 KB
/
docs.scroll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
title ScrollHub Documentation
linkTitle Docs
pageHeader.scroll
container 600px
## Overview
ScrollHub is a web server application that provides git-based folder hosting with real-time collaboration features. It's built with Express.js and provides functionality for file management, version control, and live updates.
## Core Features
- File hosting and management
- Git integration
- Real-time collaboration via Server-Sent Events (SSE)
- HTTPS support with dynamic certificate generation
- Upload/download capabilities
- Version history tracking
- Folder cloning and templating
- Analytics and logging
## Main Components
### Server Initialization
```javascript
class ScrollHub {
constructor() {
// Server configuration
this.port = 80
this.maxUploadSize = 100 * 1000 * 1024 // 100MB
this.rootFolder = path.join(os.homedir(), "folders")
// ... other configurations
}
}
```
### Security Features
#### Write Permission Control
- IP-based rate limiting
- Configurable allowed IPs list
- Protection against excessive writes
- Default limit: 30 writes per minute per IP
#### File Extension Security
- Whitelist of allowed file extensions
- Sanitization of folder and file names
- Protection against common web vulnerabilities
### Core Routes
#### File Management
- `/createFolder.htm` - Create new folders
- `/cloneFolder.htm` - Clone existing folders
- `/writeFile.htm` - Write/update files
- `/deleteFile.htm` - Delete files
- `/uploadFile.htm` - File upload endpoint
- `/rename.htm` - Rename files
- `/mv.htm` - Move/rename folders
#### Git Integration
- `/:repo.git/*` - Git repository access
- `/revisions.htm/:folderName` - View commit history
- `/diffs.htm/:folderName` - View file differences
- `/revert.htm/:folderName` - Restore previous versions
#### Real-time Features
- `/requests.htm` - SSE endpoint for real-time updates
- Broadcasts file changes to connected clients
- Supports folder-specific subscriptions
## Usage Examples
### Creating a New Folder
```javascript
// POST to /createFolder.htm
const response = await fetch('/createFolder.htm', {
method: 'POST',
body: new URLSearchParams({
folderName: 'my-project'
})
});
```
### Writing a File
```javascript
// POST to /writeFile.htm
const response = await fetch('/writeFile.htm', {
method: 'POST',
body: new URLSearchParams({
filePath: 'my-project/example.txt',
content: 'Hello, World!'
})
});
```
### Subscribing to Real-time Updates
```javascript
const evtSource = new EventSource('/requests.htm?folderName=my-project');
evtSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Update received:', data.log);
};
```
## Configuration
### Environment Setup
Required directories:
- `rootFolder`: Base directory for all hosted folders
- `templatesFolder`: Directory containing folder templates
- `trashFolder`: Directory for deleted folders
### Security Configuration
```javascript
{
maxUploadSize: 100 * 1000 * 1024, // Maximum upload size in bytes
writeLimit: 30, // Maximum writes per minute per IP
writeWindow: 60 * 1000 // Time window for write limit (ms)
}
```
## Error Handling
The server implements comprehensive error handling:
- Invalid folder/file names
- Unauthorized access attempts
- Rate limiting violations
- File system errors
- Git operation failures
Example error response:
```javascript
{
status: 400,
errorMessage: "Invalid folder name. Must start with a letter a-z..."
}
```
## Folder Structure
```
root/
├── folders/ # User folders
│ ├── project1/
│ └── project2/
├── templates/ # Folder templates
│ ├── blank_template/
│ └── other_templates/
└── trash/ # Deleted folders
```
## Best Practices
1. **Folder Names**
- Must start with a lowercase letter
- Can contain letters, numbers, dots, and underscores
- Must be at least 2 characters long
- Cannot end in common file extensions
2. **File Management**
- Use appropriate file extensions
- Keep file sizes under the upload limit
- Commit changes frequently
- Use meaningful commit messages
3. **Security**
- Implement proper authentication if needed
- Monitor rate limits
- Regularly backup important folders
- Keep certificates up to date
## Technical Notes
1. **Certificate Management**
- Automatic certificate generation for HTTPS
- Certificates cached for performance
- Dynamic SNI support
2. **Performance Considerations**
- File operations are asynchronous
- Git operations are optimized for large repositories
- SSE connections managed efficiently
- Response compression enabled
3. **Monitoring**
- Request logging
- User activity tracking
- Error logging
- Analytics data collection
## Limitations
1. File size limited to 100MB
2. Rate limited to 30 writes per minute per IP
3. Limited to specific file extensions
4. No built-in user authentication system
## Troubleshooting
Common issues and solutions:
1. **Rate Limiting**
- Issue: "Your IP has been temporarily throttled"
- Solution: Wait for the write window to reset or contact administrator
2. **Invalid File Types**
- Issue: "Editing 'xyz' files not yet supported"
- Solution: Use only allowed file extensions
3. **Certificate Errors**
- Issue: SSL certificate errors
- Solution: Wait for automatic certificate generation or check domain configuration
4. **Git Errors**
- Issue: Git operation failures
- Solution: Check repository status and permissions
## Contributing
When contributing to ScrollHub:
1. Follow the existing code style
2. Add tests for new features
3. Update documentation
4. Handle errors appropriately
5. Consider backward compatibility
## Dependencies
Major dependencies:
- Express.js
- Node.js `child_process`
- `git-http-backend`
- `compression`
- `express-fileupload`
- Various file system utilities
## Public Domain
ScrollHub is open source, public domain software.
footer.scroll