Skip to content

Commit bf9eb77

Browse files
committed
project: write simple backend program for now
0 parents  commit bf9eb77

10 files changed

+1029
-0
lines changed

.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
*.test
8+
*.out
9+
10+
# Output of the go coverage tool
11+
*.out
12+
13+
# Config files containing secrets
14+
rclone.conf
15+
*.bak
16+
17+
# Dependency directories
18+
vendor/
19+
20+
# Environment files
21+
.env
22+
.env.local
23+
24+
# Go workspace file
25+
go.work
26+
27+
# Temporary files
28+
*.tmp
29+
30+
# IDE specific files
31+
.idea/
32+
.vscode/
33+
*.swp
34+
*.swo
35+
36+
# OS generated files
37+
.DS_Store
38+
.DS_Store?
39+
._*
40+
.Spotlight-V100
41+
.Trashes
42+
ehthumbs.db
43+
Thumbs.db
44+
45+
# Vercel
46+
.vercel

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Sauraj Kumar Singh
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# OneDrive Upload API
2+
3+
A serverless API service for uploading files to OneDrive with support for multiple remote configurations.
4+
5+
## API Endpoint
6+
7+
### POST /upload
8+
9+
Upload a file to OneDrive.
10+
11+
**Request Format:**
12+
- Content-Type: `multipart/form-data`
13+
14+
**Form Fields:**
15+
- `file`: (required) The file to upload
16+
- `remote`: (required) Remote configuration to use (`hakimionedrive`, `oned`, or `saurajcf`)
17+
- `remoteFolder`: (optional) Folder path in OneDrive where the file should be uploaded
18+
- `remoteFileName`: (optional) Custom name for the uploaded file
19+
- `chunkSize`: (required) Upload chunk size in MB (2, 4, 8, or 16)
20+
21+
**Success Response:**
22+
```json
23+
{
24+
"status": "success",
25+
"message": "File uploaded successfully",
26+
"downloadURL": "https://your-index.vercel.app/path/to/file",
27+
"fileSize": 1234567,
28+
"fileName": "example.pdf"
29+
}
30+
```
31+
32+
**Error Response:**
33+
```json
34+
{
35+
"error": "Error message here",
36+
"details": "Detailed error information"
37+
}
38+
```
39+
40+
## Deployment
41+
42+
### Prerequisites
43+
1. OneDrive API credentials in rclone.conf
44+
2. Vercel account and Vercel CLI installed
45+
46+
### Deploy to Vercel
47+
48+
1. Clone this repository
49+
```bash
50+
git clone https://github.com/ksauraj/ksau-oned-api.git
51+
cd ksau-oned-api
52+
```
53+
54+
2. Add your rclone.conf file to the project root
55+
56+
3. Deploy to Vercel
57+
```bash
58+
vercel
59+
```
60+
61+
### Local Development
62+
63+
1. Clone the repository and add your rclone.conf file
64+
65+
2. Start the development server
66+
```bash
67+
go run main.go
68+
```
69+
70+
The server will start on http://localhost:8080 with the following endpoint:
71+
- Upload endpoint: http://localhost:8080/upload
72+
73+
## Configuration
74+
75+
The API supports multiple OneDrive remotes which are configured in the code:
76+
77+
```go
78+
var rootFolders = map[string]string{
79+
"hakimionedrive": "Public",
80+
"oned": "",
81+
"saurajcf": "MY_BOMT_STUFFS",
82+
}
83+
84+
var baseURLs = map[string]string{
85+
"hakimionedrive": "https://onedrive-vercel-index-kohl-eight-30.vercel.app",
86+
"oned": "https://index.sauraj.eu.org",
87+
"saurajcf": "https://my-index-azure.vercel.app",
88+
}
89+
```
90+
91+
## Error Handling and Logging
92+
93+
The API includes comprehensive error handling and logging:
94+
- Request validation with detailed error messages
95+
- File size and type validation
96+
- Detailed logging of upload process
97+
- Proper cleanup of temporary files
98+
- Memory limits to prevent server overload
99+
100+
## Security
101+
102+
- The API uses CORS headers to allow requests from any origin
103+
- Request size limits and validations are in place
104+
- Proper cleanup of temporary files
105+
- Keep your rclone.conf secure and never commit it to version control
106+
107+
## License
108+
109+
See [LICENSE](LICENSE) file for details.

0 commit comments

Comments
 (0)