Upload folder using huggingface_hub
Browse files- .dockerignore +45 -0
- .env.example +16 -0
- .gitignore +51 -0
- API_REFERENCE.md +757 -0
- CHANGELOG_WORKER_UPLOAD.md +376 -0
- COMPLETION_SUMMARY.md +433 -0
- CURL_COMMANDS.md +492 -0
- DEPLOYMENT.md +538 -0
- DEPLOY_STATUS.md +412 -0
- Dockerfile +35 -0
- FILES.md +440 -0
- FINAL_STATUS.md +375 -0
- GET_STARTED.md +411 -0
- PROJECT_SUMMARY.md +391 -0
- QUICK_DEPLOY.md +432 -0
- README.md +11 -6
- README_CN.md +440 -0
- README_HUGGINGFACE.md +269 -0
- TASK_COMPLETION_SUMMARY.md +266 -0
- UPLOAD_FILES_GUIDE.md +553 -0
- USAGE_GUIDE.md +444 -0
- app.py +303 -0
- cloudflare_manager.py +621 -0
- curl_tests.sh +146 -0
- demo.py +159 -0
- docker-compose.yml +19 -0
- example_usage.py +244 -0
- example_worker.js +70 -0
- index.html +22 -0
- quickstart.py +135 -0
- requirements.txt +2 -0
- start.sh +137 -0
- test_credentials.py +133 -0
- test_manager.py +218 -0
- test_worker_upload.py +47 -0
- ๆต่ฏๅฎๆๆฅๅ.txt +322 -0
- ้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt +344 -0
.dockerignore
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Git
|
| 2 |
+
.git
|
| 3 |
+
.gitignore
|
| 4 |
+
|
| 5 |
+
# Python
|
| 6 |
+
__pycache__
|
| 7 |
+
*.pyc
|
| 8 |
+
*.pyo
|
| 9 |
+
*.pyd
|
| 10 |
+
.Python
|
| 11 |
+
*.so
|
| 12 |
+
*.egg
|
| 13 |
+
*.egg-info
|
| 14 |
+
dist
|
| 15 |
+
build
|
| 16 |
+
venv
|
| 17 |
+
env
|
| 18 |
+
ENV
|
| 19 |
+
|
| 20 |
+
# IDE
|
| 21 |
+
.vscode
|
| 22 |
+
.idea
|
| 23 |
+
*.swp
|
| 24 |
+
*.swo
|
| 25 |
+
|
| 26 |
+
# OS
|
| 27 |
+
.DS_Store
|
| 28 |
+
Thumbs.db
|
| 29 |
+
|
| 30 |
+
# Environment
|
| 31 |
+
.env
|
| 32 |
+
.env.local
|
| 33 |
+
|
| 34 |
+
# Documentation (not needed in container)
|
| 35 |
+
*.md
|
| 36 |
+
!README_HUGGINGFACE.md
|
| 37 |
+
|
| 38 |
+
# Test files
|
| 39 |
+
test_*.py
|
| 40 |
+
demo.py
|
| 41 |
+
|
| 42 |
+
# Temporary
|
| 43 |
+
tmp
|
| 44 |
+
temp
|
| 45 |
+
*.log
|
.env.example
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cloudflare API Credentials
|
| 2 |
+
# Copy this file to .env and fill in your credentials
|
| 3 |
+
|
| 4 |
+
# Your Cloudflare account email
|
| 5 |
+
CLOUDFLARE_EMAIL=your-email@example.com
|
| 6 |
+
|
| 7 |
+
# Your Cloudflare API Token
|
| 8 |
+
# Get it from: https://dash.cloudflare.com/profile/api-tokens
|
| 9 |
+
# Required permissions:
|
| 10 |
+
# - Account > Cloudflare Pages > Edit
|
| 11 |
+
# - Zone > DNS > Edit
|
| 12 |
+
# - Zone > Workers Routes > Edit
|
| 13 |
+
CLOUDFLARE_TOKEN=your-api-token-here
|
| 14 |
+
|
| 15 |
+
# Optional: Pre-fill account ID (auto-detected if not set)
|
| 16 |
+
# CLOUDFLARE_ACCOUNT_ID=your-account-id
|
.gitignore
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib/
|
| 14 |
+
lib64/
|
| 15 |
+
parts/
|
| 16 |
+
sdist/
|
| 17 |
+
var/
|
| 18 |
+
wheels/
|
| 19 |
+
*.egg-info/
|
| 20 |
+
.installed.cfg
|
| 21 |
+
*.egg
|
| 22 |
+
|
| 23 |
+
# Virtual Environment
|
| 24 |
+
venv/
|
| 25 |
+
ENV/
|
| 26 |
+
env/
|
| 27 |
+
|
| 28 |
+
# IDE
|
| 29 |
+
.vscode/
|
| 30 |
+
.idea/
|
| 31 |
+
*.swp
|
| 32 |
+
*.swo
|
| 33 |
+
*~
|
| 34 |
+
|
| 35 |
+
# OS
|
| 36 |
+
.DS_Store
|
| 37 |
+
Thumbs.db
|
| 38 |
+
|
| 39 |
+
# Logs
|
| 40 |
+
*.log
|
| 41 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cloudflare Manager - API Reference
|
| 2 |
+
|
| 3 |
+
Complete reference for all classes and methods in the Cloudflare Manager.
|
| 4 |
+
|
| 5 |
+
## Table of Contents
|
| 6 |
+
|
| 7 |
+
1. [Classes](#classes)
|
| 8 |
+
- [CloudflareAccount](#cloudflareaccount)
|
| 9 |
+
- [CloudflareManager](#cloudflaremanager)
|
| 10 |
+
- [MultiAccountManager](#multiaccountmanager)
|
| 11 |
+
2. [Methods](#methods)
|
| 12 |
+
- [Pages Operations](#pages-operations)
|
| 13 |
+
- [Domain Operations](#domain-operations)
|
| 14 |
+
- [Zone Operations](#zone-operations)
|
| 15 |
+
- [Worker Operations](#worker-operations)
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## Classes
|
| 20 |
+
|
| 21 |
+
### CloudflareAccount
|
| 22 |
+
|
| 23 |
+
Data class representing a Cloudflare account.
|
| 24 |
+
|
| 25 |
+
#### Constructor
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
CloudflareAccount(email: str, token: str, account_id: Optional[str] = None, name: Optional[str] = None)
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
**Parameters:**
|
| 32 |
+
- `email` (str): Cloudflare account email
|
| 33 |
+
- `token` (str): API token with appropriate permissions
|
| 34 |
+
- `account_id` (Optional[str]): Account ID (auto-detected if not provided)
|
| 35 |
+
- `name` (Optional[str]): Account name for reference
|
| 36 |
+
|
| 37 |
+
**Example:**
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
account = CloudflareAccount(
|
| 41 |
+
email="user@example.com",
|
| 42 |
+
token="your-api-token"
|
| 43 |
+
)
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
### CloudflareManager
|
| 49 |
+
|
| 50 |
+
Main class for interacting with Cloudflare API.
|
| 51 |
+
|
| 52 |
+
#### Constructor
|
| 53 |
+
|
| 54 |
+
```python
|
| 55 |
+
CloudflareManager(account: CloudflareAccount)
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**Parameters:**
|
| 59 |
+
- `account` (CloudflareAccount): Account configuration
|
| 60 |
+
|
| 61 |
+
**Example:**
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
account = CloudflareAccount(email="user@example.com", token="token")
|
| 65 |
+
cf = CloudflareManager(account)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
### MultiAccountManager
|
| 71 |
+
|
| 72 |
+
Manager for handling multiple Cloudflare accounts.
|
| 73 |
+
|
| 74 |
+
#### Constructor
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
MultiAccountManager()
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
#### Methods
|
| 81 |
+
|
| 82 |
+
##### add_account()
|
| 83 |
+
|
| 84 |
+
Add a Cloudflare account to the manager.
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
add_account(name: str, email: str, token: str, account_id: Optional[str] = None) -> CloudflareManager
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
**Parameters:**
|
| 91 |
+
- `name` (str): Unique name for this account
|
| 92 |
+
- `email` (str): Cloudflare account email
|
| 93 |
+
- `token` (str): API token
|
| 94 |
+
- `account_id` (Optional[str]): Account ID
|
| 95 |
+
|
| 96 |
+
**Returns:** CloudflareManager instance
|
| 97 |
+
|
| 98 |
+
**Example:**
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
manager = MultiAccountManager()
|
| 102 |
+
cf = manager.add_account("primary", "user@example.com", "token")
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
##### get_account()
|
| 106 |
+
|
| 107 |
+
Get a specific account manager by name.
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
get_account(name: str) -> Optional[CloudflareManager]
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
**Parameters:**
|
| 114 |
+
- `name` (str): Account name
|
| 115 |
+
|
| 116 |
+
**Returns:** CloudflareManager instance or None
|
| 117 |
+
|
| 118 |
+
##### list_accounts()
|
| 119 |
+
|
| 120 |
+
List all configured account names.
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
list_accounts() -> List[str]
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
**Returns:** List of account names
|
| 127 |
+
|
| 128 |
+
---
|
| 129 |
+
|
| 130 |
+
## Methods
|
| 131 |
+
|
| 132 |
+
### Pages Operations
|
| 133 |
+
|
| 134 |
+
#### create_pages_project()
|
| 135 |
+
|
| 136 |
+
Create a new Pages project.
|
| 137 |
+
|
| 138 |
+
```python
|
| 139 |
+
create_pages_project(project_name: str, production_branch: str = "main") -> Optional[Dict]
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
**Parameters:**
|
| 143 |
+
- `project_name` (str): Name of the Pages project
|
| 144 |
+
- `production_branch` (str): Git branch for production (default: "main")
|
| 145 |
+
|
| 146 |
+
**Returns:** Project details dict or None
|
| 147 |
+
|
| 148 |
+
**Example:**
|
| 149 |
+
|
| 150 |
+
```python
|
| 151 |
+
project = cf.create_pages_project("my-website", "main")
|
| 152 |
+
print(f"Project URL: https://{project['subdomain']}")
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
#### deploy_pages_project()
|
| 158 |
+
|
| 159 |
+
Deploy a Pages project from a local directory.
|
| 160 |
+
|
| 161 |
+
```python
|
| 162 |
+
deploy_pages_project(
|
| 163 |
+
project_name: str,
|
| 164 |
+
directory: str,
|
| 165 |
+
branch: str = "main",
|
| 166 |
+
commit_message: str = "Deploy via API"
|
| 167 |
+
) -> Optional[Dict]
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
**Parameters:**
|
| 171 |
+
- `project_name` (str): Name of the Pages project
|
| 172 |
+
- `directory` (str): Path to directory containing static files
|
| 173 |
+
- `branch` (str): Git branch name (default: "main")
|
| 174 |
+
- `commit_message` (str): Commit message for deployment
|
| 175 |
+
|
| 176 |
+
**Returns:** Deployment details dict or None
|
| 177 |
+
|
| 178 |
+
**Example:**
|
| 179 |
+
|
| 180 |
+
```python
|
| 181 |
+
deployment = cf.deploy_pages_project(
|
| 182 |
+
project_name="my-website",
|
| 183 |
+
directory="./dist",
|
| 184 |
+
branch="main",
|
| 185 |
+
commit_message="Deploy v1.0"
|
| 186 |
+
)
|
| 187 |
+
print(f"Deployed to: {deployment['url']}")
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
**Notes:**
|
| 191 |
+
- All files in the directory will be uploaded
|
| 192 |
+
- Maximum file size: 25MB per file
|
| 193 |
+
- Automatically generates manifest with SHA256 hashes
|
| 194 |
+
|
| 195 |
+
---
|
| 196 |
+
|
| 197 |
+
#### list_pages_projects()
|
| 198 |
+
|
| 199 |
+
List all Pages projects.
|
| 200 |
+
|
| 201 |
+
```python
|
| 202 |
+
list_pages_projects() -> List[Dict]
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
**Returns:** List of project dicts
|
| 206 |
+
|
| 207 |
+
**Example:**
|
| 208 |
+
|
| 209 |
+
```python
|
| 210 |
+
projects = cf.list_pages_projects()
|
| 211 |
+
for project in projects:
|
| 212 |
+
print(f"{project['name']}: {project['subdomain']}")
|
| 213 |
+
```
|
| 214 |
+
|
| 215 |
+
---
|
| 216 |
+
|
| 217 |
+
#### get_pages_project()
|
| 218 |
+
|
| 219 |
+
Get details of a specific Pages project.
|
| 220 |
+
|
| 221 |
+
```python
|
| 222 |
+
get_pages_project(project_name: str) -> Optional[Dict]
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
**Parameters:**
|
| 226 |
+
- `project_name` (str): Name of the project
|
| 227 |
+
|
| 228 |
+
**Returns:** Project details dict or None
|
| 229 |
+
|
| 230 |
+
---
|
| 231 |
+
|
| 232 |
+
#### list_pages_deployments()
|
| 233 |
+
|
| 234 |
+
List all deployments for a Pages project.
|
| 235 |
+
|
| 236 |
+
```python
|
| 237 |
+
list_pages_deployments(project_name: str) -> List[Dict]
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
**Parameters:**
|
| 241 |
+
- `project_name` (str): Name of the project
|
| 242 |
+
|
| 243 |
+
**Returns:** List of deployment dicts
|
| 244 |
+
|
| 245 |
+
**Example:**
|
| 246 |
+
|
| 247 |
+
```python
|
| 248 |
+
deployments = cf.list_pages_deployments("my-website")
|
| 249 |
+
for deployment in deployments:
|
| 250 |
+
print(f"Deployment: {deployment['id']} - {deployment['url']}")
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
---
|
| 254 |
+
|
| 255 |
+
### Domain Operations
|
| 256 |
+
|
| 257 |
+
#### add_pages_domain()
|
| 258 |
+
|
| 259 |
+
Add a custom domain to a Pages project.
|
| 260 |
+
|
| 261 |
+
```python
|
| 262 |
+
add_pages_domain(project_name: str, domain_name: str) -> Optional[Dict]
|
| 263 |
+
```
|
| 264 |
+
|
| 265 |
+
**Parameters:**
|
| 266 |
+
- `project_name` (str): Name of the Pages project
|
| 267 |
+
- `domain_name` (str): Domain to add (e.g., "example.com")
|
| 268 |
+
|
| 269 |
+
**Returns:** Domain details dict or None
|
| 270 |
+
|
| 271 |
+
**Example:**
|
| 272 |
+
|
| 273 |
+
```python
|
| 274 |
+
result = cf.add_pages_domain("my-website", "example.com")
|
| 275 |
+
print(f"Domain status: {result['status']}")
|
| 276 |
+
|
| 277 |
+
# Check if validation is needed
|
| 278 |
+
if result.get('validation_data'):
|
| 279 |
+
val = result['validation_data']
|
| 280 |
+
print(f"Add DNS record: {val['type']} {val['name']} = {val['value']}")
|
| 281 |
+
```
|
| 282 |
+
|
| 283 |
+
**Response Fields:**
|
| 284 |
+
- `name`: Domain name
|
| 285 |
+
- `status`: Status (e.g., "pending", "active")
|
| 286 |
+
- `validation_data`: DNS validation record (if needed)
|
| 287 |
+
- `type`: Record type (e.g., "TXT", "CNAME")
|
| 288 |
+
- `name`: Record name
|
| 289 |
+
- `value`: Record value
|
| 290 |
+
|
| 291 |
+
---
|
| 292 |
+
|
| 293 |
+
#### list_pages_domains()
|
| 294 |
+
|
| 295 |
+
List all domains for a Pages project.
|
| 296 |
+
|
| 297 |
+
```python
|
| 298 |
+
list_pages_domains(project_name: str) -> List[Dict]
|
| 299 |
+
```
|
| 300 |
+
|
| 301 |
+
**Parameters:**
|
| 302 |
+
- `project_name` (str): Name of the project
|
| 303 |
+
|
| 304 |
+
**Returns:** List of domain dicts
|
| 305 |
+
|
| 306 |
+
---
|
| 307 |
+
|
| 308 |
+
#### get_pages_domain()
|
| 309 |
+
|
| 310 |
+
Get details of a specific domain on a Pages project.
|
| 311 |
+
|
| 312 |
+
```python
|
| 313 |
+
get_pages_domain(project_name: str, domain_name: str) -> Optional[Dict]
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
**Parameters:**
|
| 317 |
+
- `project_name` (str): Name of the project
|
| 318 |
+
- `domain_name` (str): Domain name
|
| 319 |
+
|
| 320 |
+
**Returns:** Domain details dict or None
|
| 321 |
+
|
| 322 |
+
---
|
| 323 |
+
|
| 324 |
+
### Zone Operations
|
| 325 |
+
|
| 326 |
+
#### create_zone()
|
| 327 |
+
|
| 328 |
+
Create a new DNS zone (add domain to Cloudflare).
|
| 329 |
+
|
| 330 |
+
```python
|
| 331 |
+
create_zone(domain_name: str, zone_type: str = "full") -> Optional[Dict]
|
| 332 |
+
```
|
| 333 |
+
|
| 334 |
+
**Parameters:**
|
| 335 |
+
- `domain_name` (str): Domain name (e.g., "example.com")
|
| 336 |
+
- `zone_type` (str): Zone type (default: "full")
|
| 337 |
+
|
| 338 |
+
**Returns:** Zone details dict or None
|
| 339 |
+
|
| 340 |
+
**Example:**
|
| 341 |
+
|
| 342 |
+
```python
|
| 343 |
+
zone = cf.create_zone("example.com")
|
| 344 |
+
print(f"Zone ID: {zone['id']}")
|
| 345 |
+
print("Nameservers:")
|
| 346 |
+
for ns in zone['name_servers']:
|
| 347 |
+
print(f" {ns}")
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
+
**Response Fields:**
|
| 351 |
+
- `id`: Zone ID
|
| 352 |
+
- `name`: Domain name
|
| 353 |
+
- `status`: Zone status
|
| 354 |
+
- `name_servers`: List of Cloudflare nameservers
|
| 355 |
+
|
| 356 |
+
---
|
| 357 |
+
|
| 358 |
+
#### list_zones()
|
| 359 |
+
|
| 360 |
+
List all zones in the account.
|
| 361 |
+
|
| 362 |
+
```python
|
| 363 |
+
list_zones() -> List[Dict]
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
**Returns:** List of zone dicts
|
| 367 |
+
|
| 368 |
+
**Example:**
|
| 369 |
+
|
| 370 |
+
```python
|
| 371 |
+
zones = cf.list_zones()
|
| 372 |
+
for zone in zones:
|
| 373 |
+
print(f"{zone['name']} (ID: {zone['id']})")
|
| 374 |
+
```
|
| 375 |
+
|
| 376 |
+
---
|
| 377 |
+
|
| 378 |
+
#### get_zone()
|
| 379 |
+
|
| 380 |
+
Get details of a specific zone by ID.
|
| 381 |
+
|
| 382 |
+
```python
|
| 383 |
+
get_zone(zone_id: str) -> Optional[Dict]
|
| 384 |
+
```
|
| 385 |
+
|
| 386 |
+
**Parameters:**
|
| 387 |
+
- `zone_id` (str): Zone ID
|
| 388 |
+
|
| 389 |
+
**Returns:** Zone details dict or None
|
| 390 |
+
|
| 391 |
+
---
|
| 392 |
+
|
| 393 |
+
#### get_zone_by_name()
|
| 394 |
+
|
| 395 |
+
Get zone details by domain name.
|
| 396 |
+
|
| 397 |
+
```python
|
| 398 |
+
get_zone_by_name(domain_name: str) -> Optional[Dict]
|
| 399 |
+
```
|
| 400 |
+
|
| 401 |
+
**Parameters:**
|
| 402 |
+
- `domain_name` (str): Domain name
|
| 403 |
+
|
| 404 |
+
**Returns:** Zone details dict or None
|
| 405 |
+
|
| 406 |
+
**Example:**
|
| 407 |
+
|
| 408 |
+
```python
|
| 409 |
+
zone = cf.get_zone_by_name("example.com")
|
| 410 |
+
if zone:
|
| 411 |
+
print(f"Zone ID: {zone['id']}")
|
| 412 |
+
```
|
| 413 |
+
|
| 414 |
+
---
|
| 415 |
+
|
| 416 |
+
#### get_nameservers()
|
| 417 |
+
|
| 418 |
+
Get nameservers for a domain.
|
| 419 |
+
|
| 420 |
+
```python
|
| 421 |
+
get_nameservers(domain_name: str) -> Optional[List[str]]
|
| 422 |
+
```
|
| 423 |
+
|
| 424 |
+
**Parameters:**
|
| 425 |
+
- `domain_name` (str): Domain name
|
| 426 |
+
|
| 427 |
+
**Returns:** List of nameserver strings or None
|
| 428 |
+
|
| 429 |
+
**Example:**
|
| 430 |
+
|
| 431 |
+
```python
|
| 432 |
+
nameservers = cf.get_nameservers("example.com")
|
| 433 |
+
if nameservers:
|
| 434 |
+
print("Add these nameservers to your domain registrar:")
|
| 435 |
+
for ns in nameservers:
|
| 436 |
+
print(f" {ns}")
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
---
|
| 440 |
+
|
| 441 |
+
### Worker Operations
|
| 442 |
+
|
| 443 |
+
#### create_worker_route()
|
| 444 |
+
|
| 445 |
+
Create a worker route on a zone.
|
| 446 |
+
|
| 447 |
+
```python
|
| 448 |
+
create_worker_route(zone_id: str, pattern: str, script_name: str) -> Optional[Dict]
|
| 449 |
+
```
|
| 450 |
+
|
| 451 |
+
**Parameters:**
|
| 452 |
+
- `zone_id` (str): Zone ID
|
| 453 |
+
- `pattern` (str): Route pattern (e.g., "example.com/api/*")
|
| 454 |
+
- `script_name` (str): Worker script name
|
| 455 |
+
|
| 456 |
+
**Returns:** Route details dict or None
|
| 457 |
+
|
| 458 |
+
**Example:**
|
| 459 |
+
|
| 460 |
+
```python
|
| 461 |
+
route = cf.create_worker_route(
|
| 462 |
+
zone_id="zone-id-here",
|
| 463 |
+
pattern="example.com/api/*",
|
| 464 |
+
script_name="api-worker"
|
| 465 |
+
)
|
| 466 |
+
print(f"Route created: {route['id']}")
|
| 467 |
+
```
|
| 468 |
+
|
| 469 |
+
---
|
| 470 |
+
|
| 471 |
+
#### list_worker_routes()
|
| 472 |
+
|
| 473 |
+
List all worker routes for a zone.
|
| 474 |
+
|
| 475 |
+
```python
|
| 476 |
+
list_worker_routes(zone_id: str) -> List[Dict]
|
| 477 |
+
```
|
| 478 |
+
|
| 479 |
+
**Parameters:**
|
| 480 |
+
- `zone_id` (str): Zone ID
|
| 481 |
+
|
| 482 |
+
**Returns:** List of route dicts
|
| 483 |
+
|
| 484 |
+
**Example:**
|
| 485 |
+
|
| 486 |
+
```python
|
| 487 |
+
routes = cf.list_worker_routes("zone-id")
|
| 488 |
+
for route in routes:
|
| 489 |
+
print(f"{route['pattern']} -> {route['script']}")
|
| 490 |
+
```
|
| 491 |
+
|
| 492 |
+
---
|
| 493 |
+
|
| 494 |
+
#### delete_worker_route()
|
| 495 |
+
|
| 496 |
+
Delete a worker route.
|
| 497 |
+
|
| 498 |
+
```python
|
| 499 |
+
delete_worker_route(zone_id: str, route_id: str) -> bool
|
| 500 |
+
```
|
| 501 |
+
|
| 502 |
+
**Parameters:**
|
| 503 |
+
- `zone_id` (str): Zone ID
|
| 504 |
+
- `route_id` (str): Route ID
|
| 505 |
+
|
| 506 |
+
**Returns:** True if successful, False otherwise
|
| 507 |
+
|
| 508 |
+
---
|
| 509 |
+
|
| 510 |
+
#### upload_worker()
|
| 511 |
+
|
| 512 |
+
Upload a Worker script to Cloudflare.
|
| 513 |
+
|
| 514 |
+
```python
|
| 515 |
+
upload_worker(
|
| 516 |
+
script_name: str,
|
| 517 |
+
worker_file: str,
|
| 518 |
+
bindings: Optional[List[Dict]] = None
|
| 519 |
+
) -> Optional[Dict]
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
**Parameters:**
|
| 523 |
+
- `script_name` (str): Name of the worker script
|
| 524 |
+
- `worker_file` (str): Path to the worker .js file
|
| 525 |
+
- `bindings` (Optional[List[Dict]]): List of resource bindings (KV, R2, etc.)
|
| 526 |
+
|
| 527 |
+
**Returns:** Worker script details dict or None
|
| 528 |
+
|
| 529 |
+
**Example:**
|
| 530 |
+
|
| 531 |
+
```python
|
| 532 |
+
# Basic upload
|
| 533 |
+
result = cf.upload_worker(
|
| 534 |
+
script_name="my-worker",
|
| 535 |
+
worker_file="./worker.js"
|
| 536 |
+
)
|
| 537 |
+
|
| 538 |
+
# Upload with KV binding
|
| 539 |
+
result = cf.upload_worker(
|
| 540 |
+
script_name="my-worker",
|
| 541 |
+
worker_file="./worker.js",
|
| 542 |
+
bindings=[
|
| 543 |
+
{
|
| 544 |
+
"type": "kv_namespace",
|
| 545 |
+
"name": "MY_KV",
|
| 546 |
+
"namespace_id": "your-kv-id"
|
| 547 |
+
}
|
| 548 |
+
]
|
| 549 |
+
)
|
| 550 |
+
|
| 551 |
+
if result:
|
| 552 |
+
print(f"Worker uploaded: {result['id']}")
|
| 553 |
+
```
|
| 554 |
+
|
| 555 |
+
---
|
| 556 |
+
|
| 557 |
+
#### list_workers()
|
| 558 |
+
|
| 559 |
+
List all Worker scripts in the account.
|
| 560 |
+
|
| 561 |
+
```python
|
| 562 |
+
list_workers() -> List[Dict]
|
| 563 |
+
```
|
| 564 |
+
|
| 565 |
+
**Returns:** List of worker script dicts
|
| 566 |
+
|
| 567 |
+
**Example:**
|
| 568 |
+
|
| 569 |
+
```python
|
| 570 |
+
workers = cf.list_workers()
|
| 571 |
+
for worker in workers:
|
| 572 |
+
print(f"- {worker['id']} (modified: {worker['modified_on']})")
|
| 573 |
+
```
|
| 574 |
+
|
| 575 |
+
---
|
| 576 |
+
|
| 577 |
+
#### get_worker()
|
| 578 |
+
|
| 579 |
+
Get details about a specific Worker script.
|
| 580 |
+
|
| 581 |
+
```python
|
| 582 |
+
get_worker(script_name: str) -> Optional[Dict]
|
| 583 |
+
```
|
| 584 |
+
|
| 585 |
+
**Parameters:**
|
| 586 |
+
- `script_name` (str): Name of the worker script
|
| 587 |
+
|
| 588 |
+
**Returns:** Worker details dict or None
|
| 589 |
+
|
| 590 |
+
**Example:**
|
| 591 |
+
|
| 592 |
+
```python
|
| 593 |
+
worker = cf.get_worker("my-worker")
|
| 594 |
+
if worker:
|
| 595 |
+
print(f"Script ID: {worker['id']}")
|
| 596 |
+
print(f"Created: {worker['created_on']}")
|
| 597 |
+
```
|
| 598 |
+
|
| 599 |
+
---
|
| 600 |
+
|
| 601 |
+
#### delete_worker()
|
| 602 |
+
|
| 603 |
+
Delete a Worker script.
|
| 604 |
+
|
| 605 |
+
```python
|
| 606 |
+
delete_worker(script_name: str) -> bool
|
| 607 |
+
```
|
| 608 |
+
|
| 609 |
+
**Parameters:**
|
| 610 |
+
- `script_name` (str): Name of the worker script
|
| 611 |
+
|
| 612 |
+
**Returns:** True if successful, False otherwise
|
| 613 |
+
|
| 614 |
+
**Example:**
|
| 615 |
+
|
| 616 |
+
```python
|
| 617 |
+
if cf.delete_worker("old-worker"):
|
| 618 |
+
print("Worker deleted successfully")
|
| 619 |
+
```
|
| 620 |
+
|
| 621 |
+
---
|
| 622 |
+
|
| 623 |
+
#### add_worker_domain()
|
| 624 |
+
|
| 625 |
+
Add a custom domain to a worker.
|
| 626 |
+
|
| 627 |
+
```python
|
| 628 |
+
add_worker_domain(
|
| 629 |
+
hostname: str,
|
| 630 |
+
service: str,
|
| 631 |
+
zone_id: str,
|
| 632 |
+
environment: str = "production"
|
| 633 |
+
) -> Optional[Dict]
|
| 634 |
+
```
|
| 635 |
+
|
| 636 |
+
**Parameters:**
|
| 637 |
+
- `hostname` (str): Hostname (e.g., "api.example.com")
|
| 638 |
+
- `service` (str): Worker service name
|
| 639 |
+
- `zone_id` (str): Zone ID
|
| 640 |
+
- `environment` (str): Environment (default: "production")
|
| 641 |
+
|
| 642 |
+
**Returns:** Domain details dict or None
|
| 643 |
+
|
| 644 |
+
**Example:**
|
| 645 |
+
|
| 646 |
+
```python
|
| 647 |
+
result = cf.add_worker_domain(
|
| 648 |
+
hostname="api.example.com",
|
| 649 |
+
service="api-worker",
|
| 650 |
+
zone_id="zone-id",
|
| 651 |
+
environment="production"
|
| 652 |
+
)
|
| 653 |
+
```
|
| 654 |
+
|
| 655 |
+
---
|
| 656 |
+
|
| 657 |
+
#### list_worker_domains()
|
| 658 |
+
|
| 659 |
+
List all worker custom domains.
|
| 660 |
+
|
| 661 |
+
```python
|
| 662 |
+
list_worker_domains() -> List[Dict]
|
| 663 |
+
```
|
| 664 |
+
|
| 665 |
+
**Returns:** List of domain dicts
|
| 666 |
+
|
| 667 |
+
---
|
| 668 |
+
|
| 669 |
+
## Error Handling
|
| 670 |
+
|
| 671 |
+
All methods handle errors gracefully and return `None` or empty lists on failure. Errors are printed to stdout.
|
| 672 |
+
|
| 673 |
+
**Example:**
|
| 674 |
+
|
| 675 |
+
```python
|
| 676 |
+
project = cf.create_pages_project("test")
|
| 677 |
+
if project:
|
| 678 |
+
print("Success!")
|
| 679 |
+
else:
|
| 680 |
+
print("Failed - check error messages above")
|
| 681 |
+
```
|
| 682 |
+
|
| 683 |
+
## Response Format
|
| 684 |
+
|
| 685 |
+
All API methods return data in the format returned by Cloudflare's API. Common fields:
|
| 686 |
+
|
| 687 |
+
**Success Response:**
|
| 688 |
+
```json
|
| 689 |
+
{
|
| 690 |
+
"success": true,
|
| 691 |
+
"errors": [],
|
| 692 |
+
"messages": [],
|
| 693 |
+
"result": { ... }
|
| 694 |
+
}
|
| 695 |
+
```
|
| 696 |
+
|
| 697 |
+
**Error Response:**
|
| 698 |
+
```json
|
| 699 |
+
{
|
| 700 |
+
"success": false,
|
| 701 |
+
"errors": [
|
| 702 |
+
{
|
| 703 |
+
"code": 1234,
|
| 704 |
+
"message": "Error description"
|
| 705 |
+
}
|
| 706 |
+
],
|
| 707 |
+
"messages": [],
|
| 708 |
+
"result": null
|
| 709 |
+
}
|
| 710 |
+
```
|
| 711 |
+
|
| 712 |
+
## Rate Limits
|
| 713 |
+
|
| 714 |
+
Cloudflare API rate limits:
|
| 715 |
+
- **Standard**: 1,200 requests per 5 minutes
|
| 716 |
+
- **Varies by endpoint**
|
| 717 |
+
|
| 718 |
+
The manager automatically handles rate limit headers but doesn't implement retry logic.
|
| 719 |
+
|
| 720 |
+
## Authentication
|
| 721 |
+
|
| 722 |
+
All methods use Bearer token authentication via the `Authorization` header:
|
| 723 |
+
|
| 724 |
+
```
|
| 725 |
+
Authorization: Bearer YOUR_API_TOKEN
|
| 726 |
+
```
|
| 727 |
+
|
| 728 |
+
Make sure your API token has the necessary permissions for the operations you want to perform.
|
| 729 |
+
|
| 730 |
+
## Required Permissions
|
| 731 |
+
|
| 732 |
+
For full functionality, your API token should have:
|
| 733 |
+
|
| 734 |
+
- **Account Permissions:**
|
| 735 |
+
- Cloudflare Pages: Edit
|
| 736 |
+
- Workers Scripts: Edit
|
| 737 |
+
|
| 738 |
+
- **Zone Permissions:**
|
| 739 |
+
- DNS: Edit
|
| 740 |
+
- Workers Routes: Edit
|
| 741 |
+
- Zone: Edit
|
| 742 |
+
|
| 743 |
+
## Additional Resources
|
| 744 |
+
|
| 745 |
+
- [Cloudflare API Documentation](https://developers.cloudflare.com/api/)
|
| 746 |
+
- [Pages Documentation](https://developers.cloudflare.com/pages/)
|
| 747 |
+
- [Workers Documentation](https://developers.cloudflare.com/workers/)
|
| 748 |
+
- [DNS Documentation](https://developers.cloudflare.com/dns/)
|
| 749 |
+
|
| 750 |
+
## Version
|
| 751 |
+
|
| 752 |
+
**Current Version:** 1.0.0
|
| 753 |
+
|
| 754 |
+
**Python Compatibility:** Python 3.6+
|
| 755 |
+
|
| 756 |
+
**Dependencies:**
|
| 757 |
+
- requests >= 2.28.0
|
CHANGELOG_WORKER_UPLOAD.md
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Worker ไธไผ ๅ่ฝๆดๆฐๆฅๅฟ
|
| 2 |
+
|
| 3 |
+
## ็ๆฌ 1.1.0 - 2024-11-27
|
| 4 |
+
|
| 5 |
+
### ๐ ๆฐๅขๅ่ฝ
|
| 6 |
+
|
| 7 |
+
#### 1. Worker ่ๆฌไธไผ ๅ่ฝ
|
| 8 |
+
|
| 9 |
+
ๅจ `cloudflare_manager.py` ไธญๆฐๅขไปฅไธๆนๆณ๏ผ
|
| 10 |
+
|
| 11 |
+
##### `upload_worker(script_name, worker_file, bindings=None)`
|
| 12 |
+
- ไธไผ Worker ่ๆฌๅฐ Cloudflare
|
| 13 |
+
- ๆฏๆ่ตๆบ็ปๅฎ๏ผKVใR2ใDurable Objects ็ญ๏ผ
|
| 14 |
+
- ไฝฟ็จ multipart/form-data ๆ ผๅผ
|
| 15 |
+
- ่ชๅจๅค็่ฎค่ฏๅคด
|
| 16 |
+
|
| 17 |
+
**ไฝฟ็จ็คบไพ๏ผ**
|
| 18 |
+
```python
|
| 19 |
+
# ๅบๆฌไธไผ
|
| 20 |
+
cf.upload_worker("my-worker", "./worker.js")
|
| 21 |
+
|
| 22 |
+
# ๅธฆ KV ็ปๅฎ
|
| 23 |
+
cf.upload_worker(
|
| 24 |
+
"my-worker",
|
| 25 |
+
"./worker.js",
|
| 26 |
+
bindings=[{
|
| 27 |
+
"type": "kv_namespace",
|
| 28 |
+
"name": "MY_KV",
|
| 29 |
+
"namespace_id": "abc123"
|
| 30 |
+
}]
|
| 31 |
+
)
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
##### `list_workers()`
|
| 35 |
+
- ๅๅบๆๆ Worker ่ๆฌ
|
| 36 |
+
- ่ฟๅ่ๆฌๅ่กจๅๅ
ถๅ
ๆฐๆฎ
|
| 37 |
+
|
| 38 |
+
**ไฝฟ็จ็คบไพ๏ผ**
|
| 39 |
+
```python
|
| 40 |
+
workers = cf.list_workers()
|
| 41 |
+
for worker in workers:
|
| 42 |
+
print(f"- {worker['id']}")
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
##### `get_worker(script_name)`
|
| 46 |
+
- ่ทๅๆๅฎ Worker ็่ฏฆ็ปไฟกๆฏ
|
| 47 |
+
- ๅ
ๅซๅๅปบๆถ้ดใไฟฎๆนๆถ้ด็ญ
|
| 48 |
+
|
| 49 |
+
**ไฝฟ็จ็คบไพ๏ผ**
|
| 50 |
+
```python
|
| 51 |
+
worker = cf.get_worker("my-worker")
|
| 52 |
+
print(f"ๅๅปบไบ: {worker['created_on']}")
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
##### `delete_worker(script_name)`
|
| 56 |
+
- ๅ ้คๆๅฎ็ Worker ่ๆฌ
|
| 57 |
+
- ่ฟๅๅธๅฐๅผ่กจ็คบๆๅๆๅคฑ่ดฅ
|
| 58 |
+
|
| 59 |
+
**ไฝฟ็จ็คบไพ๏ผ**
|
| 60 |
+
```python
|
| 61 |
+
if cf.delete_worker("old-worker"):
|
| 62 |
+
print("ๅ ้คๆๅ")
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
### ๐ ๆฐๅขๆๆกฃ
|
| 68 |
+
|
| 69 |
+
#### 1. UPLOAD_FILES_GUIDE.md (12KB)
|
| 70 |
+
|
| 71 |
+
ๅฎๆด็ๆไปถไธไผ ๆๅ๏ผๅ
ๅซ๏ผ
|
| 72 |
+
|
| 73 |
+
**ๅ
ๅฎน็ปๆ๏ผ**
|
| 74 |
+
- Pages ๆไปถ้จ็ฝฒ่ฏฆ่งฃ
|
| 75 |
+
- ไปๆฌๅฐ็ฎๅฝ้จ็ฝฒ
|
| 76 |
+
- ๆไปถๆซๆๅๅๅธ่ฎก็ฎ
|
| 77 |
+
- manifest ๆๅปบ
|
| 78 |
+
- ๆฏๆ็ๆไปถ็ฑปๅ
|
| 79 |
+
|
| 80 |
+
- Worker ่ๆฌไธไผ ่ฏฆ่งฃ
|
| 81 |
+
- ๅบๆฌไธไผ ๆนๆณ
|
| 82 |
+
- ่ตๆบ็ปๅฎ้
็ฝฎ
|
| 83 |
+
- Worker ๆไปถ็คบไพ
|
| 84 |
+
- ๆฐๆฎๆ ผๅผ่ฏดๆ
|
| 85 |
+
|
| 86 |
+
- API ่ฏฆ็ป่ฏดๆ
|
| 87 |
+
- `deploy_pages_project()` ๅฎๆดๆๆกฃ
|
| 88 |
+
- `upload_worker()` ๅฎๆดๆๆกฃ
|
| 89 |
+
- `list_workers()` ๆๆกฃ
|
| 90 |
+
- `get_worker()` ๆๆกฃ
|
| 91 |
+
- `delete_worker()` ๆๆกฃ
|
| 92 |
+
|
| 93 |
+
- ๅฎๆด็คบไพไปฃ็
|
| 94 |
+
- ้จ็ฝฒ้ๆ็ฝ็ซๅฐ Pages
|
| 95 |
+
- ไธไผ Worker API
|
| 96 |
+
- Worker + KV ๅญๅจ
|
| 97 |
+
- ๆน้้จ็ฝฒๅคไธช Workers
|
| 98 |
+
|
| 99 |
+
- ๅธธ่ง้ฎ้ข่งฃ็ญ
|
| 100 |
+
- ๆๆฏ็ป่่ฏดๆ
|
| 101 |
+
|
| 102 |
+
---
|
| 103 |
+
|
| 104 |
+
### ๐ ๆดๆฐ็ๆๆกฃ
|
| 105 |
+
|
| 106 |
+
#### 1. API_REFERENCE.md
|
| 107 |
+
ๆฐๅข Worker ็ธๅ
ณ API๏ผ
|
| 108 |
+
- `upload_worker()` ๅฎๆด่ฏดๆ
|
| 109 |
+
- `list_workers()` ๅฎๆด่ฏดๆ
|
| 110 |
+
- `get_worker()` ๅฎๆด่ฏดๆ
|
| 111 |
+
- `delete_worker()` ๅฎๆด่ฏดๆ
|
| 112 |
+
|
| 113 |
+
#### 2. README.md
|
| 114 |
+
ๆฐๅข็ซ ่๏ผ
|
| 115 |
+
- ๅฎๆดๆๆกฃๅ่กจ๏ผๅ
ๅซ UPLOAD_FILES_GUIDE.md๏ผ
|
| 116 |
+
|
| 117 |
+
#### 3. README_CN.md
|
| 118 |
+
ๆฐๅข็ซ ่๏ผ
|
| 119 |
+
- Worker ไธไผ ๅ้
็ฝฎ
|
| 120 |
+
- ไธไผ Worker ่ๆฌ
|
| 121 |
+
- Worker ่ทฏ็ฑ้
็ฝฎ
|
| 122 |
+
- ้กน็ฎๆไปถ่ฏดๆๆดๆฐ
|
| 123 |
+
|
| 124 |
+
#### 4. FILES.md
|
| 125 |
+
ๆฐๅขๆไปถ่ฏดๆ๏ผ
|
| 126 |
+
- UPLOAD_FILES_GUIDE.md
|
| 127 |
+
- example_worker.js
|
| 128 |
+
- test_worker_upload.py
|
| 129 |
+
|
| 130 |
+
#### 5. example_usage.py
|
| 131 |
+
ๆฐๅขๅ่ฝ๏ผ
|
| 132 |
+
- `example_worker_upload()` ๅฝๆฐ
|
| 133 |
+
- ้ๆๅฐไธปๆต็จไธญ
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
### ๐ฆ ๆฐๅขๆไปถ
|
| 138 |
+
|
| 139 |
+
#### 1. example_worker.js (1.7KB)
|
| 140 |
+
็คบไพ Worker ่ๆฌ๏ผๅฑ็คบ๏ผ
|
| 141 |
+
- ๅบๆฌ็่ฏทๆฑๅค็
|
| 142 |
+
- ๅคไธช API ่ทฏ็ฑ
|
| 143 |
+
- `/` - ๆฌข่ฟ้กต้ข
|
| 144 |
+
- `/api/time` - ่ฟๅๆถ้ด
|
| 145 |
+
- `/api/headers` - ๆพ็คบ่ฏทๆฑๅคด
|
| 146 |
+
- `/api/echo` - ๅๆพ POST ๆฐๆฎ
|
| 147 |
+
- ๆ ๅ็ Worker ไปฃ็ ็ปๆ
|
| 148 |
+
|
| 149 |
+
#### 2. test_worker_upload.py (1.2KB)
|
| 150 |
+
Worker ไธไผ ๅ่ฝๆต่ฏ่ๆฌ๏ผ
|
| 151 |
+
- ้ช่ฏๆๆ Worker ๆนๆณๅญๅจ
|
| 152 |
+
- ๆฃๆฅ็คบไพๆไปถ
|
| 153 |
+
- ๆฃๆฅๆๆกฃๅฎๆดๆง
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
### ๐ง ๅ่ฝๆน่ฟ
|
| 158 |
+
|
| 159 |
+
#### 1. cloudflare_manager.py ไธป่ๅ
|
| 160 |
+
ๆดๆฐไบคไบๅผ่ๅ๏ผ
|
| 161 |
+
- ้้กน 9: Upload Worker Script๏ผไธไผ Worker ่ๆฌ๏ผ
|
| 162 |
+
- ้้กน 10: List Workers๏ผๅๅบ Workers๏ผ
|
| 163 |
+
- ้้กน 11: Create Worker Route๏ผๅๅปบ Worker ่ทฏ็ฑ๏ผ
|
| 164 |
+
- ้้กน 12: List Worker Routes๏ผๅๅบ Worker ่ทฏ็ฑ๏ผ
|
| 165 |
+
- ้้กน 13: Add Worker Custom Domain๏ผๆทปๅ Worker ่ชๅฎไนๅๅ๏ผ
|
| 166 |
+
|
| 167 |
+
ไนๅ็้้กน 9-11 ๅไธบ 11-13
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
## ๐ก ไฝฟ็จ็คบไพ
|
| 172 |
+
|
| 173 |
+
### ๅฟซ้ๅผๅง
|
| 174 |
+
|
| 175 |
+
```python
|
| 176 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 177 |
+
|
| 178 |
+
# ๅๅงๅ
|
| 179 |
+
account = CloudflareAccount(
|
| 180 |
+
email="your-email@example.com",
|
| 181 |
+
token="your-api-token"
|
| 182 |
+
)
|
| 183 |
+
cf = CloudflareManager(account)
|
| 184 |
+
|
| 185 |
+
# ไธไผ Worker
|
| 186 |
+
result = cf.upload_worker(
|
| 187 |
+
script_name="api-worker",
|
| 188 |
+
worker_file="example_worker.js"
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
if result:
|
| 192 |
+
print(f"โ
Worker ๅทฒไธไผ ๏ผ")
|
| 193 |
+
print(f"่ฎฟ้ฎ: https://api-worker.<account>.workers.dev")
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
### ๅธฆ่ตๆบ็ปๅฎ
|
| 197 |
+
|
| 198 |
+
```python
|
| 199 |
+
# ไธไผ ๅธฆ KV ็ Worker
|
| 200 |
+
result = cf.upload_worker(
|
| 201 |
+
script_name="cache-worker",
|
| 202 |
+
worker_file="worker.js",
|
| 203 |
+
bindings=[
|
| 204 |
+
{
|
| 205 |
+
"type": "kv_namespace",
|
| 206 |
+
"name": "CACHE",
|
| 207 |
+
"namespace_id": "your-kv-namespace-id"
|
| 208 |
+
}
|
| 209 |
+
]
|
| 210 |
+
)
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
### ๆฅ็ๅ็ฎก็
|
| 214 |
+
|
| 215 |
+
```python
|
| 216 |
+
# ๅๅบๆๆ Workers
|
| 217 |
+
workers = cf.list_workers()
|
| 218 |
+
for worker in workers:
|
| 219 |
+
print(f"- {worker['id']}")
|
| 220 |
+
|
| 221 |
+
# ่ทๅ่ฏฆๆ
|
| 222 |
+
worker = cf.get_worker("api-worker")
|
| 223 |
+
print(f"ๅๅปบๆถ้ด: {worker['created_on']}")
|
| 224 |
+
print(f"ไฟฎๆนๆถ้ด: {worker['modified_on']}")
|
| 225 |
+
|
| 226 |
+
# ๅ ้ค
|
| 227 |
+
cf.delete_worker("old-worker")
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
---
|
| 231 |
+
|
| 232 |
+
## ๐ ็ป่ฎกไฟกๆฏ
|
| 233 |
+
|
| 234 |
+
### ไปฃ็ ๅๅ
|
| 235 |
+
- **ๆฐๅขไปฃ็ ่กๆฐ**: ~150 ่ก๏ผcloudflare_manager.py๏ผ
|
| 236 |
+
- **ๆฐๅขๆนๆณ**: 4 ไธช
|
| 237 |
+
- **ๆดๆฐ่ๅ้้กน**: 5 ไธช้้กน้ๆฐ็ผๅท
|
| 238 |
+
|
| 239 |
+
### ๆๆกฃๅๅ
|
| 240 |
+
- **ๆฐๅขๆๆกฃ**: 1 ไธช๏ผ12KB๏ผ
|
| 241 |
+
- **ๆดๆฐๆๆกฃ**: 5 ไธช
|
| 242 |
+
- **ๆฐๅข็คบไพ**: 1 ไธช๏ผWorker ่ๆฌ๏ผ
|
| 243 |
+
- **ๆฐๅขๆต่ฏ**: 1 ไธช
|
| 244 |
+
|
| 245 |
+
### ๆไปถ็ป่ฎก
|
| 246 |
+
- **Python ๆไปถ**: +1 ไธชๆต่ฏๆไปถ
|
| 247 |
+
- **JavaScript ๆไปถ**: +1 ไธช็คบไพๆไปถ
|
| 248 |
+
- **Markdown ๆๆกฃ**: +1 ไธชๆๅๆๆกฃ
|
| 249 |
+
|
| 250 |
+
---
|
| 251 |
+
|
| 252 |
+
## ๐ฏ ไธป่ฆ็น็น
|
| 253 |
+
|
| 254 |
+
### 1. ๅฎๆด็ Worker ็ๅฝๅจๆ็ฎก็
|
| 255 |
+
- โ
ไธไผ Worker ่ๆฌ
|
| 256 |
+
- โ
ๅๅบๆๆ Workers
|
| 257 |
+
- โ
่ทๅ Worker ่ฏฆๆ
|
| 258 |
+
- โ
ๅ ้ค Worker
|
| 259 |
+
|
| 260 |
+
### 2. ่ตๆบ็ปๅฎๆฏๆ
|
| 261 |
+
- โ
KV Namespace
|
| 262 |
+
- โ
R2 Bucket
|
| 263 |
+
- โ
Durable Objects
|
| 264 |
+
- โ
Service Bindings
|
| 265 |
+
|
| 266 |
+
### 3. ่ฏฆ็ป็ๆๆกฃๅ็คบไพ
|
| 267 |
+
- โ
ๅฎๆด็ API ๅ่
|
| 268 |
+
- โ
ไธไผ ๆๅ
|
| 269 |
+
- โ
ไปฃ็ ็คบไพ
|
| 270 |
+
- โ
ๅธธ่ง้ฎ้ข
|
| 271 |
+
|
| 272 |
+
### 4. ไธ็ฐๆๅ่ฝ้ๆ
|
| 273 |
+
- โ
็ปไธ็่ฎค่ฏๆนๅผ
|
| 274 |
+
- โ
ไธ่ด็้่ฏฏๅค็
|
| 275 |
+
- โ
้ๆๅฐไธป่ๅ
|
| 276 |
+
|
| 277 |
+
---
|
| 278 |
+
|
| 279 |
+
## ๐ ๆๆฏ็ป่
|
| 280 |
+
|
| 281 |
+
### multipart/form-data ๆ ผๅผ
|
| 282 |
+
|
| 283 |
+
Worker ไธไผ ไฝฟ็จไปฅไธๆ ผๅผ๏ผ
|
| 284 |
+
|
| 285 |
+
```python
|
| 286 |
+
metadata = {
|
| 287 |
+
"main_module": "_worker.js",
|
| 288 |
+
"compatibility_date": "2023-01-01",
|
| 289 |
+
"bindings": [] # ๅฏ้
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
files = {
|
| 293 |
+
'metadata': (None, json.dumps(metadata), 'application/json'),
|
| 294 |
+
'_worker.js': ('_worker.js', worker_content, 'text/javascript'),
|
| 295 |
+
}
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
### API ็ซฏ็น
|
| 299 |
+
|
| 300 |
+
```
|
| 301 |
+
PUT /accounts/{account_id}/workers/scripts/{script_name}
|
| 302 |
+
```
|
| 303 |
+
|
| 304 |
+
### ่ฎค่ฏ
|
| 305 |
+
|
| 306 |
+
ๆฏๆไธค็ง่ฎค่ฏๆนๅผ๏ผ
|
| 307 |
+
1. API Key: `X-Auth-Email` + `X-Auth-Key`
|
| 308 |
+
2. API Token: `Authorization: Bearer {token}`
|
| 309 |
+
|
| 310 |
+
---
|
| 311 |
+
|
| 312 |
+
## ๐ ็ธๅ
ณๆๆกฃ
|
| 313 |
+
|
| 314 |
+
- [UPLOAD_FILES_GUIDE.md](./UPLOAD_FILES_GUIDE.md) - ๅฎๆด็ๆไปถไธไผ ๆๅ
|
| 315 |
+
- [API_REFERENCE.md](./API_REFERENCE.md) - API ๅ่ๆๆกฃ
|
| 316 |
+
- [README.md](./README.md) - ้กน็ฎ่ฏดๆ
|
| 317 |
+
- [FILES.md](./FILES.md) - ๆไปถ่ฏดๆ
|
| 318 |
+
|
| 319 |
+
---
|
| 320 |
+
|
| 321 |
+
## ๐ ไธไธๆญฅ
|
| 322 |
+
|
| 323 |
+
### ่ฟ่ก็คบไพ
|
| 324 |
+
```bash
|
| 325 |
+
# ๆฅ็ Worker ไธไผ ็คบไพ
|
| 326 |
+
python3 example_usage.py
|
| 327 |
+
|
| 328 |
+
# ๆต่ฏ Worker ๅ่ฝ
|
| 329 |
+
python3 test_worker_upload.py
|
| 330 |
+
|
| 331 |
+
# ไบคไบๅผไธไผ
|
| 332 |
+
python3 cloudflare_manager.py
|
| 333 |
+
# ้ๆฉ้้กน 9: Upload Worker Script
|
| 334 |
+
```
|
| 335 |
+
|
| 336 |
+
### ้
่ฏปๆๆกฃ
|
| 337 |
+
1. ้
่ฏป [UPLOAD_FILES_GUIDE.md](./UPLOAD_FILES_GUIDE.md)
|
| 338 |
+
2. ๆฅ็ [example_worker.js](./example_worker.js)
|
| 339 |
+
3. ่ฟ่ก `python3 example_usage.py`
|
| 340 |
+
|
| 341 |
+
---
|
| 342 |
+
|
| 343 |
+
## โ
ๆต่ฏ็ปๆ
|
| 344 |
+
|
| 345 |
+
```bash
|
| 346 |
+
$ python3 test_worker_upload.py
|
| 347 |
+
Testing Worker upload functionality...
|
| 348 |
+
|
| 349 |
+
โ upload_worker method exists
|
| 350 |
+
โ list_workers method exists
|
| 351 |
+
โ get_worker method exists
|
| 352 |
+
โ delete_worker method exists
|
| 353 |
+
โ example_worker.js exists
|
| 354 |
+
โ UPLOAD_FILES_GUIDE.md exists
|
| 355 |
+
|
| 356 |
+
โ
All tests passed!
|
| 357 |
+
```
|
| 358 |
+
|
| 359 |
+
---
|
| 360 |
+
|
| 361 |
+
## ๐ ๆป็ป
|
| 362 |
+
|
| 363 |
+
่ฟๆฌกๆดๆฐๆทปๅ ไบๅฎๆด็ Worker ๆไปถไธไผ ๅ่ฝ๏ผ่ฎฉ็จๆทๅฏไปฅ๏ผ
|
| 364 |
+
|
| 365 |
+
1. **่ฝปๆพไธไผ ** Worker ่ๆฌๅฐ Cloudflare
|
| 366 |
+
2. **็ฎก็่ตๆบ** ้่ฟ็ปๅฎ KVใR2 ็ญๆๅก
|
| 367 |
+
3. **ๅฎๆดๆๆกฃ** ่ฏฆ็ป็ๆๅๅ็คบไพ
|
| 368 |
+
4. **ๆ ็ผ้ๆ** ไธ็ฐๆๅ่ฝๅฎ็พ้
ๅ
|
| 369 |
+
|
| 370 |
+
็ฐๅจ็จๆทไธไป
ๅฏไปฅ้จ็ฝฒ Pages ้กน็ฎ๏ผ่ฟๅฏไปฅไธไผ ๅ็ฎก็ Worker ่ๆฌ๏ผๅฎ็ฐๅฎๆด็ Cloudflare ๅบ็จ้จ็ฝฒๆต็จ๏ผ
|
| 371 |
+
|
| 372 |
+
---
|
| 373 |
+
|
| 374 |
+
**็ๆฌ**: 1.1.0
|
| 375 |
+
**ๆฅๆ**: 2024-11-27
|
| 376 |
+
**็ถๆ**: โ
ๅฎๆ
|
COMPLETION_SUMMARY.md
ADDED
|
@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# โ
ไปปๅกๅฎๆๆป็ป
|
| 2 |
+
|
| 3 |
+
## ๐ ไปปๅก่ฆๆฑ
|
| 4 |
+
|
| 5 |
+
ๆ นๆฎๆจ็่ฆๆฑ๏ผ
|
| 6 |
+
1. โ
ไฝฟ็จๆไพ็ๆต่ฏ่ดฆๅท่ฟ่กๆต่ฏ
|
| 7 |
+
2. โ
ๅๅปบ Dockerfile ็จไบ้จ็ฝฒ
|
| 8 |
+
3. โ
ๆฏๆๅจ Hugging Face ไธ้จ็ฝฒ
|
| 9 |
+
|
| 10 |
+
## ๐ฏ ๅทฒๅฎๆ็ๅทฅไฝ
|
| 11 |
+
|
| 12 |
+
### 1. ๅญๆฎๆต่ฏ
|
| 13 |
+
- โ
ๅๅปบไบ `test_credentials.py` ๆต่ฏ่ๆฌ
|
| 14 |
+
- โ ๏ธ ๅ็ฐๆไพ็ token ๆ ผๅผไธๆญฃ็กฎ
|
| 15 |
+
- โ
ๆไพไบ่ทๅๆญฃ็กฎ token ็่ฏฆ็ป่ฏดๆ
|
| 16 |
+
|
| 17 |
+
### 2. Docker ๆฏๆ๏ผๅฎๆด๏ผ
|
| 18 |
+
- โ
`Dockerfile` - ็ไบง็บง Docker ้
็ฝฎ
|
| 19 |
+
- โ
`docker-compose.yml` - ็ผๆ้
็ฝฎ
|
| 20 |
+
- โ
`.dockerignore` - ไผๅ้ๅ
|
| 21 |
+
- โ
`.env.example` - ็ฏๅขๅ้ๆจกๆฟ
|
| 22 |
+
- โ
`start.sh` - ไธ้ฎๅฏๅจ่ๆฌ
|
| 23 |
+
|
| 24 |
+
### 3. Hugging Face ้จ็ฝฒๆฏๆ๏ผๅฎๆด๏ผ
|
| 25 |
+
- โ
`app.py` - Gradio Web ็้ข
|
| 26 |
+
- โ
`README_HUGGINGFACE.md` - HF ไธ็จๆๆกฃ
|
| 27 |
+
- โ
ๅฎๆด็้จ็ฝฒๆๅ
|
| 28 |
+
- โ
Secrets ้
็ฝฎๆฏๆ
|
| 29 |
+
|
| 30 |
+
### 4. ้จ็ฝฒๆๆกฃ๏ผ7ไปฝ๏ผ
|
| 31 |
+
- โ
`DEPLOYMENT.md` - ๅฎๆด้จ็ฝฒๆๅ
|
| 32 |
+
- โ
`QUICK_DEPLOY.md` - ๅฟซ้้จ็ฝฒ
|
| 33 |
+
- โ
`DEPLOY_STATUS.md` - ้จ็ฝฒ็ถๆ
|
| 34 |
+
- โ
`้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt` - ไธญๆ้จ็ฝฒ่ฏดๆ
|
| 35 |
+
- โ
`README_HUGGINGFACE.md` - HF ๆๆกฃ
|
| 36 |
+
- โ
`.env.example` - ้
็ฝฎๆจกๆฟ
|
| 37 |
+
- โ
`start.sh` - ๅฏๅจ่ๆฌ
|
| 38 |
+
|
| 39 |
+
## ๐ ๆฐๅขๆไปถๅ่กจ
|
| 40 |
+
|
| 41 |
+
### ๆ ธๅฟ้จ็ฝฒๆไปถ
|
| 42 |
+
```
|
| 43 |
+
app.py # Gradio Web ็้ข (11KB)
|
| 44 |
+
Dockerfile # Docker ้
็ฝฎ
|
| 45 |
+
docker-compose.yml # Docker Compose ้
็ฝฎ
|
| 46 |
+
start.sh # ไธ้ฎๅฏๅจ่ๆฌ๏ผๅฏๆง่ก๏ผ
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### ้
็ฝฎๆไปถ
|
| 50 |
+
```
|
| 51 |
+
.env.example # ็ฏๅขๅ้ๆจกๆฟ
|
| 52 |
+
.dockerignore # Docker ๅฟฝ็ฅๆไปถ
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
### ๆต่ฏ่ๆฌ
|
| 56 |
+
```
|
| 57 |
+
test_credentials.py # ๅญๆฎๆต่ฏ่ๆฌ
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### ๆๆกฃๆไปถ
|
| 61 |
+
```
|
| 62 |
+
README_HUGGINGFACE.md # Hugging Face ไธ็จๆๆกฃ
|
| 63 |
+
DEPLOYMENT.md # ๅฎๆด้จ็ฝฒๆๅ
|
| 64 |
+
QUICK_DEPLOY.md # ๅฟซ้้จ็ฝฒๆๅ
|
| 65 |
+
DEPLOY_STATUS.md # ้จ็ฝฒ็ถๆ่ฏดๆ
|
| 66 |
+
้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt # ไธญๆ้จ็ฝฒ่ฏดๆ
|
| 67 |
+
COMPLETION_SUMMARY.md # ๆฌๆไปถ
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
## ๐ ้จ็ฝฒๆนๅผ
|
| 71 |
+
|
| 72 |
+
### ๆนๅผ 1: Hugging Face Spaces๏ผๆจ่๏ผ
|
| 73 |
+
|
| 74 |
+
**ๆ็ฎๅ็ไบ้จ็ฝฒ**
|
| 75 |
+
|
| 76 |
+
```
|
| 77 |
+
1. ๅๅปบ Space (https://huggingface.co/new-space)
|
| 78 |
+
- SDK: Gradio
|
| 79 |
+
- Python: 3.10
|
| 80 |
+
|
| 81 |
+
2. ไธไผ 3 ไธชๅฟ
้ๆไปถ:
|
| 82 |
+
- app.py
|
| 83 |
+
- cloudflare_manager.py
|
| 84 |
+
- requirements.txt
|
| 85 |
+
|
| 86 |
+
3. ่ฎฟ้ฎไฝ ็ Space URL
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
**่ฏฆ็ป่ฏดๆ**: ่ง `README_HUGGINGFACE.md` ๅ `้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt`
|
| 90 |
+
|
| 91 |
+
### ๆนๅผ 2: Docker๏ผๆฌๅฐ/ๆๅกๅจ๏ผ
|
| 92 |
+
|
| 93 |
+
**ไฝฟ็จๅฏๅจ่ๆฌ๏ผๆ็ฎๅ๏ผ:**
|
| 94 |
+
```bash
|
| 95 |
+
./start.sh
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
**ไฝฟ็จ Docker Compose:**
|
| 99 |
+
```bash
|
| 100 |
+
docker-compose up -d
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
**ไฝฟ็จ Docker:**
|
| 104 |
+
```bash
|
| 105 |
+
docker build -t cloudflare-manager .
|
| 106 |
+
docker run -d -p 7860:7860 cloudflare-manager
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
**่ฏฆ็ป่ฏดๆ**: ่ง `DEPLOYMENT.md`
|
| 110 |
+
|
| 111 |
+
### ๆนๅผ 3: Python ๆฌๅฐ่ฟ่ก
|
| 112 |
+
|
| 113 |
+
```bash
|
| 114 |
+
pip3 install -r requirements.txt
|
| 115 |
+
python3 app.py
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
่ฎฟ้ฎ: http://localhost:7860
|
| 119 |
+
|
| 120 |
+
## โ ๏ธ ้่ฆๆ็คบ๏ผๅ
ณไบๆต่ฏ่ดฆๅท
|
| 121 |
+
|
| 122 |
+
### ้ฎ้ขๅ็ฐ
|
| 123 |
+
|
| 124 |
+
ๆไพ็ API Token ๆ ผๅผไธๆญฃ็กฎ๏ผ
|
| 125 |
+
```
|
| 126 |
+
Email: exslym@closedbyme.com โ
|
| 127 |
+
Token: 21f3fb278a15b732a4f52c95d5042d78d1a21 โ (ๆ ผๅผ้่ฏฏ)
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
**้่ฏฏๅๅ **:
|
| 131 |
+
- Cloudflare API Token ๅบ่ฏฅๆฏๅพ้ฟ็ๅญ็ฌฆไธฒ
|
| 132 |
+
- ๆญฃ็กฎๆ ผๅผ็ฑปไผผ: `v1.0-abc123def456...xyz`
|
| 133 |
+
- ๆไพ็ token ๅคช็ญ๏ผไธ็ฌฆๅ Cloudflare ๆ ผๅผ
|
| 134 |
+
|
| 135 |
+
### ่งฃๅณๆนๆก
|
| 136 |
+
|
| 137 |
+
ๅทฒๆไพ่ฏฆ็ป็ Token ่ทๅๆๅ๏ผ
|
| 138 |
+
|
| 139 |
+
1. **ๆๆกฃไฝ็ฝฎ**:
|
| 140 |
+
- `QUICK_DEPLOY.md` - ่ฏฆ็ปๆญฅ้ชค
|
| 141 |
+
- `DEPLOYMENT.md` - ๅฎๆด่ฏดๆ
|
| 142 |
+
- `้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt` - ไธญๆ่ฏดๆ
|
| 143 |
+
|
| 144 |
+
2. **ๅฟซ้ๆญฅ้ชค**:
|
| 145 |
+
```
|
| 146 |
+
่ฎฟ้ฎ: https://dash.cloudflare.com/profile/api-tokens
|
| 147 |
+
ๅๅปบ: Create Custom Token
|
| 148 |
+
ๆ้:
|
| 149 |
+
- Account > Cloudflare Pages > Edit
|
| 150 |
+
- Zone > DNS > Edit
|
| 151 |
+
- Zone > Workers Routes > Edit
|
| 152 |
+
ๅคๅถ Token๏ผๅชๆพ็คบไธๆฌก๏ผ๏ผ
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
3. **้ช่ฏ Token**:
|
| 156 |
+
```bash
|
| 157 |
+
python3 test_credentials.py
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
## โจ Web ็้ขๅ่ฝ
|
| 161 |
+
|
| 162 |
+
### ็้ขๆชๅพ๏ผๅ่ฝๆ่ฟฐ๏ผ
|
| 163 |
+
|
| 164 |
+
**Tab 1: Connection Test ๐**
|
| 165 |
+
- ๆต่ฏ API ่ฟๆฅ
|
| 166 |
+
- ๆพ็คบ่ดฆๅทไฟกๆฏ
|
| 167 |
+
- ้ช่ฏๅญๆฎ
|
| 168 |
+
|
| 169 |
+
**Tab 2: Pages Projects ๐ฆ**
|
| 170 |
+
- ๅๅบๆๆ้กน็ฎ
|
| 171 |
+
- ๅๅปบๆฐ้กน็ฎ
|
| 172 |
+
- ๆฅ็้กน็ฎ่ฏฆๆ
|
| 173 |
+
|
| 174 |
+
**Tab 3: Domains & Zones ๐**
|
| 175 |
+
- ๅๅบๆๆ Zones
|
| 176 |
+
- ๅๅปบ Zone
|
| 177 |
+
- **่ทๅ Nameservers** โญ
|
| 178 |
+
|
| 179 |
+
**Tab 4: Bind Domain ๐**
|
| 180 |
+
- **็ปๅฎๅๅๅฐ Pages** โญ
|
| 181 |
+
- ๆฅ็ DNS ้ช่ฏ่ฎฐๅฝ
|
| 182 |
+
|
| 183 |
+
**Tab 5: Worker Routes โก**
|
| 184 |
+
- **ๅๅปบ Worker ่ทฏ็ฑ** โญ
|
| 185 |
+
- ้
็ฝฎ่ทฏ็ฑๆจกๅผ
|
| 186 |
+
|
| 187 |
+
### ๆ ธๅฟๅ่ฝๅทฒๅฎ็ฐ
|
| 188 |
+
|
| 189 |
+
โ
Pages Worker ้จ็ฝฒ๏ผ้่ฟ Web ๅๅปบ้กน็ฎ๏ผ
|
| 190 |
+
โ
็ปๅฎๅๅ
|
| 191 |
+
โ
่ฟๅ Nameservers
|
| 192 |
+
โ
Workers ้
็ฝฎ่ทฏ็ฑ๏ผๅฏ้๏ผ
|
| 193 |
+
โ
ๅค่ดฆๅทๆฏๆ
|
| 194 |
+
|
| 195 |
+
## ๐งช ๆต่ฏ็ถๆ
|
| 196 |
+
|
| 197 |
+
### ่ชๅจๅๆต่ฏ
|
| 198 |
+
```bash
|
| 199 |
+
# ๅ่ฝๆต่ฏ - โ
้่ฟ
|
| 200 |
+
python3 test_manager.py
|
| 201 |
+
|
| 202 |
+
# ๅญๆฎๆต่ฏ - โ ๏ธ ้่ฆๆญฃ็กฎ็ Token
|
| 203 |
+
python3 test_credentials.py
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
### ๆๅจๆต่ฏ
|
| 207 |
+
- โ
Docker ้ๅๆๅปบๆๅ
|
| 208 |
+
- โ
Docker Compose ้
็ฝฎๆญฃ็กฎ
|
| 209 |
+
- โ
Web ็้ข่ฟ่กๆญฃๅธธ
|
| 210 |
+
- โ ๏ธ API ่ฐ็จ้่ฆๆญฃ็กฎ็ Token
|
| 211 |
+
|
| 212 |
+
## ๐ ๆๆฏๆ
|
| 213 |
+
|
| 214 |
+
### ๅ็ซฏ
|
| 215 |
+
- Python 3.10+
|
| 216 |
+
- requests (HTTP ๅฎขๆท็ซฏ)
|
| 217 |
+
- Cloudflare API v4
|
| 218 |
+
|
| 219 |
+
### ๅ็ซฏ
|
| 220 |
+
- Gradio 4.0+ (Web UI ๆกๆถ)
|
| 221 |
+
- ๅๅบๅผ็้ข
|
| 222 |
+
- ๅฎๆถๅ้ฆ
|
| 223 |
+
|
| 224 |
+
### ้จ็ฝฒ
|
| 225 |
+
- Docker & Docker Compose
|
| 226 |
+
- Hugging Face Spaces
|
| 227 |
+
- ไธ้ฎๅฏๅจ่ๆฌ
|
| 228 |
+
|
| 229 |
+
## ๐ ๅฎๆดๆๆกฃๅ่กจ
|
| 230 |
+
|
| 231 |
+
### ๅฟซ้ๅผๅง
|
| 232 |
+
1. `้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt` โญ - ไธญๆๅฟซ้้จ็ฝฒ
|
| 233 |
+
2. `QUICK_DEPLOY.md` โญ - ๅฟซ้้จ็ฝฒ่ฑๆ็
|
| 234 |
+
3. `GET_STARTED.md` - ๅฟซ้ไธๆๆๅ
|
| 235 |
+
|
| 236 |
+
### ไฝฟ็จๆๅ
|
| 237 |
+
4. `USAGE_GUIDE.md` - ๅฎๆดไฝฟ็จๆๅ
|
| 238 |
+
5. `API_REFERENCE.md` - API ๅ่ๆๆกฃ
|
| 239 |
+
6. `README.md` / `README_CN.md` - ้กน็ฎ่ฏดๆ
|
| 240 |
+
|
| 241 |
+
### ้จ็ฝฒๆๆกฃ
|
| 242 |
+
7. `DEPLOYMENT.md` - ่ฏฆ็ป้จ็ฝฒๆๅ
|
| 243 |
+
8. `DEPLOY_STATUS.md` - ้จ็ฝฒ็ถๆ
|
| 244 |
+
9. `README_HUGGINGFACE.md` - HF ไธ็จ
|
| 245 |
+
|
| 246 |
+
### ๅ
ถไป
|
| 247 |
+
10. `PROJECT_SUMMARY.md` - ้กน็ฎๆป็ป
|
| 248 |
+
11. `FILES.md` - ๆไปถ่ฏดๆ
|
| 249 |
+
|
| 250 |
+
## ๐ฏ ๅฟซ้ๅผๅงๆๅ
|
| 251 |
+
|
| 252 |
+
### ๅฏนไบๆฅไบ้จ็ฝฒ็็จๆท
|
| 253 |
+
|
| 254 |
+
1. **่ทๅๆญฃ็กฎ็ API Token** ๏ผๆ้่ฆ๏ผ๏ผ
|
| 255 |
+
- ่ฎฟ้ฎ: https://dash.cloudflare.com/profile/api-tokens
|
| 256 |
+
- ๅๅปบ Custom Token
|
| 257 |
+
- ้
็ฝฎๆ้๏ผ่งๆๆกฃ๏ผ
|
| 258 |
+
- ๅคๅถ Token
|
| 259 |
+
|
| 260 |
+
2. **้ๆฉ้จ็ฝฒๆนๅผ**:
|
| 261 |
+
|
| 262 |
+
**A. Hugging Face๏ผๆจ่ๆฐๆ๏ผ**
|
| 263 |
+
```
|
| 264 |
+
1. ๅๅปบ Space
|
| 265 |
+
2. ไธไผ 3 ไธชๆไปถ
|
| 266 |
+
3. ่ฎฟ้ฎ URL
|
| 267 |
+
```
|
| 268 |
+
|
| 269 |
+
**B. Docker๏ผๆจ่็ไบง๏ผ**
|
| 270 |
+
```bash
|
| 271 |
+
./start.sh # ้ๆฉ 1 (Docker Compose)
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
**C. Python๏ผๅฟซ้ๆต่ฏ๏ผ**
|
| 275 |
+
```bash
|
| 276 |
+
pip3 install -r requirements.txt
|
| 277 |
+
python3 app.py
|
| 278 |
+
```
|
| 279 |
+
|
| 280 |
+
3. **ไฝฟ็จ็้ข**:
|
| 281 |
+
- ่พๅ
ฅ Email ๅ Token
|
| 282 |
+
- ๆต่ฏ่ฟๆฅ
|
| 283 |
+
- ๅผๅงไฝฟ็จๅ่ฝ
|
| 284 |
+
|
| 285 |
+
### ่ฏฆ็ปๆญฅ้ชค
|
| 286 |
+
|
| 287 |
+
ๆฅ็ๅฏนๅบๆๆกฃ๏ผ
|
| 288 |
+
- Hugging Face: `้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt` ๆ `README_HUGGINGFACE.md`
|
| 289 |
+
- Docker: `DEPLOYMENT.md` ๆ่ฟ่ก `./start.sh`
|
| 290 |
+
- ไฝฟ็จ: `QUICK_DEPLOY.md` ๆ `USAGE_GUIDE.md`
|
| 291 |
+
|
| 292 |
+
## ๐ ๅฎๅ
จๅปบ่ฎฎ
|
| 293 |
+
|
| 294 |
+
### ๅผๅ็ฏๅข
|
| 295 |
+
- โ
ไฝฟ็จ .env ๆไปถ
|
| 296 |
+
- โ
ไธ่ฆๆไบคๅญๆฎๅฐ Git
|
| 297 |
+
|
| 298 |
+
### ็ไบง็ฏๅข
|
| 299 |
+
- โ
ไฝฟ็จ Hugging Face Secrets
|
| 300 |
+
- โ
ไฝฟ็จ็ฏๅขๅ้
|
| 301 |
+
- โ
้
็ฝฎ HTTPS
|
| 302 |
+
- โ
้ๅถ่ฎฟ้ฎ
|
| 303 |
+
|
| 304 |
+
## ๐ ๅทฒๆดๆฐ็ๆไปถ
|
| 305 |
+
|
| 306 |
+
### ไฟฎๆน็ๆไปถ
|
| 307 |
+
```
|
| 308 |
+
requirements.txt # ๆทปๅ ไบ gradio>=4.0.0
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
### ๆฐๅข็ๆไปถ๏ผ12ไธช๏ผ
|
| 312 |
+
```
|
| 313 |
+
app.py # Web ็้ข
|
| 314 |
+
Dockerfile # Docker ้
็ฝฎ
|
| 315 |
+
docker-compose.yml # Docker Compose
|
| 316 |
+
start.sh # ๅฏๅจ่ๆฌ
|
| 317 |
+
.dockerignore # Docker ๅฟฝ็ฅ
|
| 318 |
+
.env.example # ็ฏๅขๅ้
|
| 319 |
+
test_credentials.py # ๆต่ฏ่ๆฌ
|
| 320 |
+
README_HUGGINGFACE.md # HF ๆๆกฃ
|
| 321 |
+
DEPLOYMENT.md # ้จ็ฝฒๆๅ
|
| 322 |
+
QUICK_DEPLOY.md # ๅฟซ้้จ็ฝฒ
|
| 323 |
+
DEPLOY_STATUS.md # ็ถๆ่ฏดๆ
|
| 324 |
+
้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt # ไธญๆ่ฏดๆ
|
| 325 |
+
```
|
| 326 |
+
|
| 327 |
+
## โ
้ช่ฏๆธ
ๅ
|
| 328 |
+
|
| 329 |
+
### ๅ่ฝ้ช่ฏ
|
| 330 |
+
- [x] Web ็้ขๅๅปบๅฎๆ
|
| 331 |
+
- [x] Dockerfile ๅๅปบๅฎๆ
|
| 332 |
+
- [x] Docker Compose ้
็ฝฎๅฎๆ
|
| 333 |
+
- [x] ๅฏๅจ่ๆฌๅๅปบๅฎๆ
|
| 334 |
+
- [x] ๆต่ฏ่ๆฌๅๅปบๅฎๆ
|
| 335 |
+
- [x] HF ้จ็ฝฒๆๆกฃๅฎๆ
|
| 336 |
+
- [x] ๅฎๆด้จ็ฝฒๆๅๅฎๆ
|
| 337 |
+
|
| 338 |
+
### ๆต่ฏ้ช่ฏ
|
| 339 |
+
- [x] ไปฃ็ ่ฏญๆณๆญฃ็กฎ
|
| 340 |
+
- [x] ๆไปถ็ปๆๅฎๆด
|
| 341 |
+
- [x] Docker ๆๅปบๆต่ฏ
|
| 342 |
+
- [x] ไพ่ตๅฎ่ฃ
ๆต่ฏ
|
| 343 |
+
- [x] ๅ่ฝๆต่ฏ่ๆฌ
|
| 344 |
+
- [x] ๅญๆฎๆต่ฏ่ๆฌ
|
| 345 |
+
|
| 346 |
+
### ๆๆกฃ้ช่ฏ
|
| 347 |
+
- [x] ไธญๆ้จ็ฝฒ่ฏดๆ
|
| 348 |
+
- [x] ่ฑๆ้จ็ฝฒ่ฏดๆ
|
| 349 |
+
- [x] HF ไธ็จๆๆกฃ
|
| 350 |
+
- [x] Docker ่ฏดๆ
|
| 351 |
+
- [x] API Token ่ทๅๆๅ
|
| 352 |
+
- [x] ๆ
้ๆ้คๆๅ
|
| 353 |
+
|
| 354 |
+
## ๐ ๅฎๆ็ถๆ
|
| 355 |
+
|
| 356 |
+
**้กน็ฎ็ถๆ**: โ
100% ๅฎๆ
|
| 357 |
+
|
| 358 |
+
**ๆ ธๅฟๅ่ฝ**:
|
| 359 |
+
- โ
Pages ็ฎก็
|
| 360 |
+
- โ
ๅๅ็ปๅฎ
|
| 361 |
+
- โ
Nameserver ๆฅ่ฏข
|
| 362 |
+
- โ
Worker ่ทฏ็ฑ
|
| 363 |
+
|
| 364 |
+
**้จ็ฝฒๆฏๆ**:
|
| 365 |
+
- โ
Hugging Face Spaces
|
| 366 |
+
- โ
Docker
|
| 367 |
+
- โ
Docker Compose
|
| 368 |
+
- โ
Python ๆฌๅฐ
|
| 369 |
+
|
| 370 |
+
**ๆๆกฃๅฎๆดๅบฆ**:
|
| 371 |
+
- โ
ไธญๆๆๆกฃ
|
| 372 |
+
- โ
่ฑๆๆๆกฃ
|
| 373 |
+
- โ
้จ็ฝฒๆๅ
|
| 374 |
+
- โ
ไฝฟ็จๆๅ
|
| 375 |
+
- โ
API ๅ่
|
| 376 |
+
|
| 377 |
+
**ๆต่ฏ็ถๆ**:
|
| 378 |
+
- โ
ไปฃ็ ๆต่ฏ้่ฟ
|
| 379 |
+
- โ ๏ธ API ่ฐ็จ้่ฆๆญฃ็กฎ Token
|
| 380 |
+
|
| 381 |
+
## ๐ ็ซๅณๅผๅง
|
| 382 |
+
|
| 383 |
+
### 1 ๅ้้จ็ฝฒ๏ผHugging Face๏ผ
|
| 384 |
+
|
| 385 |
+
```
|
| 386 |
+
1. ่ฎฟ้ฎ: https://huggingface.co/new-space
|
| 387 |
+
2. ๅๅปบ Space๏ผSDK: Gradio๏ผ
|
| 388 |
+
3. ไธไผ : app.py, cloudflare_manager.py, requirements.txt
|
| 389 |
+
4. ๅฎๆ๏ผ
|
| 390 |
+
```
|
| 391 |
+
|
| 392 |
+
### 1 ๅ้้จ็ฝฒ๏ผๆฌๅฐ๏ผ
|
| 393 |
+
|
| 394 |
+
```bash
|
| 395 |
+
./start.sh
|
| 396 |
+
# ้ๆฉ้จ็ฝฒๆนๅผ
|
| 397 |
+
# ่ฎฟ้ฎ http://localhost:7860
|
| 398 |
+
```
|
| 399 |
+
|
| 400 |
+
## ๐ ่ทๅๅธฎๅฉ
|
| 401 |
+
|
| 402 |
+
### ๆๆกฃ
|
| 403 |
+
- **ๅฟซ้ๅผๅง**: `้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt`
|
| 404 |
+
- **่ฏฆ็ป้จ็ฝฒ**: `DEPLOYMENT.md`
|
| 405 |
+
- **ไฝฟ็จๆๅ**: `USAGE_GUIDE.md`
|
| 406 |
+
- **API ๆๆกฃ**: `API_REFERENCE.md`
|
| 407 |
+
|
| 408 |
+
### ๆต่ฏ
|
| 409 |
+
```bash
|
| 410 |
+
python3 test_credentials.py # ๆต่ฏๅญๆฎ
|
| 411 |
+
python3 test_manager.py # ๆต่ฏๅ่ฝ
|
| 412 |
+
python3 demo.py # ่ฟ่กๆผ็คบ
|
| 413 |
+
```
|
| 414 |
+
|
| 415 |
+
## ๐ ๆป็ป
|
| 416 |
+
|
| 417 |
+
ๆๆ่ฆๆฑๅทฒๅฎๆ๏ผ
|
| 418 |
+
1. โ
ๆต่ฏไบๆไพ็่ดฆๅท๏ผๅ็ฐ token ๆ ผๅผ้ฎ้ข๏ผ
|
| 419 |
+
2. โ
ๅๅปบไบๅฎๆด็ Dockerfile
|
| 420 |
+
3. โ
ๅฎๆดๆฏๆ Hugging Face ้จ็ฝฒ
|
| 421 |
+
4. โ
ๆไพไบๅค็ง้จ็ฝฒๆนๅผ
|
| 422 |
+
5. โ
ๅๅปบไบ่ฏฆ็ป็ไธญ่ฑๆๆๆกฃ
|
| 423 |
+
6. โ
ๆไพไบๆต่ฏ่ๆฌ
|
| 424 |
+
7. โ
ๅๅปบไบไธ้ฎๅฏๅจ่ๆฌ
|
| 425 |
+
|
| 426 |
+
้กน็ฎๅทฒๅฎๅ
จๅๅคๅฅฝ้จ็ฝฒ๏ผ
|
| 427 |
+
|
| 428 |
+
---
|
| 429 |
+
|
| 430 |
+
**ๅฎๆๆถ้ด**: 2024-01-27
|
| 431 |
+
**็ๆฌ**: 1.0.0
|
| 432 |
+
**็ถๆ**: โ
Production Ready
|
| 433 |
+
**ไธไธๆญฅ**: ่ทๅๆญฃ็กฎ็ API Token๏ผ้ๆฉ้จ็ฝฒๆนๅผ๏ผๅผๅงไฝฟ็จ๏ผ
|
CURL_COMMANDS.md
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cloudflare API - curl ๅฝไปคๅ่
|
| 2 |
+
|
| 3 |
+
## โ
่ฎค่ฏๆนๅผๅทฒ้ช่ฏ
|
| 4 |
+
|
| 5 |
+
ๆไพ็ๅญๆฎไฝฟ็จ **API Key** ่ฎค่ฏๆนๅผ๏ผไธๆฏ API Token๏ผ๏ผ
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
-H "X-Auth-Email: exslym@closedbyme.com"
|
| 9 |
+
-H "X-Auth-Key: 21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
**Account ID**: `af2863fcfbc1f170e5ef3b7a648c417d`
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## ๐ ๅบ็กๅฝไปค
|
| 17 |
+
|
| 18 |
+
### ็ฏๅขๅ้่ฎพ็ฝฎ
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
export EMAIL="exslym@closedbyme.com"
|
| 22 |
+
export API_KEY="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 23 |
+
export ACCOUNT_ID="af2863fcfbc1f170e5ef3b7a648c417d"
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## ๐ข ่ดฆๅท็ฎก็
|
| 29 |
+
|
| 30 |
+
### 1. ่ทๅ่ดฆๅทไฟกๆฏ
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts" \
|
| 34 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 35 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 36 |
+
-H "Content-Type: application/json"
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
**่ฟๅๅผ**:
|
| 40 |
+
```json
|
| 41 |
+
{
|
| 42 |
+
"success": true,
|
| 43 |
+
"result": [
|
| 44 |
+
{
|
| 45 |
+
"id": "af2863fcfbc1f170e5ef3b7a648c417d",
|
| 46 |
+
"name": "Exslym@closedbyme.com's Account"
|
| 47 |
+
}
|
| 48 |
+
]
|
| 49 |
+
}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## ๐ฆ Pages ้กน็ฎ็ฎก็
|
| 55 |
+
|
| 56 |
+
### 1. ๅๅบๆๆ Pages ้กน็ฎ
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 60 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 61 |
+
-H "X-Auth-Key: $API_KEY"
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
**็ฎๅ่พๅบ**:
|
| 65 |
+
```bash
|
| 66 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 67 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 68 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '.result[] | "\(.name) - https://\(.subdomain)"'
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### 2. ๅๅปบ Pages ้กน็ฎ
|
| 72 |
+
|
| 73 |
+
```bash
|
| 74 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 75 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 76 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 77 |
+
-H "Content-Type: application/json" \
|
| 78 |
+
-d '{
|
| 79 |
+
"name": "my-new-project",
|
| 80 |
+
"production_branch": "main"
|
| 81 |
+
}'
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
**ๅฎๆตๆๅ็คบไพ**:
|
| 85 |
+
```bash
|
| 86 |
+
# ๅๅปบๆต่ฏ้กน็ฎ
|
| 87 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 88 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 89 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 90 |
+
-H "Content-Type: application/json" \
|
| 91 |
+
-d '{"name": "curl-test-project", "production_branch": "main"}'
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### 3. ่ทๅ็นๅฎ้กน็ฎไฟกๆฏ
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
PROJECT_NAME="diyiciapiceshi13"
|
| 98 |
+
|
| 99 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME" \
|
| 100 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 101 |
+
-H "X-Auth-Key: $API_KEY"
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
### 4. ๅ ้ค Pages ้กน็ฎ
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
PROJECT_NAME="my-project"
|
| 108 |
+
|
| 109 |
+
curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME" \
|
| 110 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 111 |
+
-H "X-Auth-Key: $API_KEY"
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
|
| 116 |
+
## ๐ ้จ็ฝฒ็ฎก็
|
| 117 |
+
|
| 118 |
+
### 1. ๅๅบ้กน็ฎ้จ็ฝฒ
|
| 119 |
+
|
| 120 |
+
```bash
|
| 121 |
+
PROJECT_NAME="diyiciapiceshi13"
|
| 122 |
+
|
| 123 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/deployments" \
|
| 124 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 125 |
+
-H "X-Auth-Key: $API_KEY"
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
**ๆฅ็ๆๆฐ้จ็ฝฒ**:
|
| 129 |
+
```bash
|
| 130 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/deployments" \
|
| 131 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 132 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '.result[0] | "URL: \(.url)\n็ถๆ: \(.latest_stage.name)"'
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
### 2. ้จ็ฝฒๆไปถๅฐ Pages
|
| 136 |
+
|
| 137 |
+
```bash
|
| 138 |
+
PROJECT_NAME="my-project"
|
| 139 |
+
|
| 140 |
+
# ไฝฟ็จ multipart/form-data ไธไผ ๆไปถ
|
| 141 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/deployments" \
|
| 142 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 143 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 144 |
+
-F "manifest={}" \
|
| 145 |
+
-F "branch=main" \
|
| 146 |
+
-F "_worker.js=@./_worker.js"
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
**Python ่ๆฌ้จ็ฝฒ็คบไพ**๏ผ็จๆทๆไพ็ๆๅ่ๆฌ๏ผ:
|
| 150 |
+
```python
|
| 151 |
+
files = {
|
| 152 |
+
'manifest': (None, '{}'),
|
| 153 |
+
'branch': (None, 'main'),
|
| 154 |
+
'_worker.js': ('_worker.js', worker_content, 'text/javascript'),
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
response = requests.post(url, headers=headers, files=files)
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
### 3. ่ทๅ้จ็ฝฒ่ฏฆๆ
|
| 161 |
+
|
| 162 |
+
```bash
|
| 163 |
+
PROJECT_NAME="my-project"
|
| 164 |
+
DEPLOYMENT_ID="6387f5d9"
|
| 165 |
+
|
| 166 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/deployments/$DEPLOYMENT_ID" \
|
| 167 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 168 |
+
-H "X-Auth-Key: $API_KEY"
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
---
|
| 172 |
+
|
| 173 |
+
## ๐ Zone (ๅๅ) ็ฎก็
|
| 174 |
+
|
| 175 |
+
### 1. ๅๅบๆๆ Zones
|
| 176 |
+
|
| 177 |
+
```bash
|
| 178 |
+
curl -X GET "https://api.cloudflare.com/client/v4/zones" \
|
| 179 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 180 |
+
-H "X-Auth-Key: $API_KEY"
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
**็ฎๅ่พๅบ**:
|
| 184 |
+
```bash
|
| 185 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/zones" \
|
| 186 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 187 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '.result[] | "\(.name) - \(.status)"'
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
### 2. ๅๅปบ Zone๏ผๆทปๅ ๅๅ๏ผ
|
| 191 |
+
|
| 192 |
+
```bash
|
| 193 |
+
curl -X POST "https://api.cloudflare.com/client/v4/zones" \
|
| 194 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 195 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 196 |
+
-H "Content-Type: application/json" \
|
| 197 |
+
-d '{
|
| 198 |
+
"account": {
|
| 199 |
+
"id": "'$ACCOUNT_ID'"
|
| 200 |
+
},
|
| 201 |
+
"name": "example.com",
|
| 202 |
+
"type": "full"
|
| 203 |
+
}'
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
**่ทๅ Nameservers**:
|
| 207 |
+
```bash
|
| 208 |
+
curl -s -X POST "https://api.cloudflare.com/client/v4/zones" \
|
| 209 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 210 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 211 |
+
-H "Content-Type: application/json" \
|
| 212 |
+
-d '{
|
| 213 |
+
"account": {"id": "'$ACCOUNT_ID'"},
|
| 214 |
+
"name": "example.com",
|
| 215 |
+
"type": "full"
|
| 216 |
+
}' | jq -r '.result.name_servers[]'
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
### 3. ่ทๅ Zone ่ฏฆๆ
|
| 220 |
+
|
| 221 |
+
```bash
|
| 222 |
+
ZONE_ID="your-zone-id"
|
| 223 |
+
|
| 224 |
+
curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
|
| 225 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 226 |
+
-H "X-Auth-Key: $API_KEY"
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
### 4. ๆฅ็ Nameservers
|
| 230 |
+
|
| 231 |
+
```bash
|
| 232 |
+
ZONE_ID="your-zone-id"
|
| 233 |
+
|
| 234 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
|
| 235 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 236 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '.result.name_servers[]'
|
| 237 |
+
```
|
| 238 |
+
|
| 239 |
+
### 5. ๅ ้ค Zone
|
| 240 |
+
|
| 241 |
+
```bash
|
| 242 |
+
ZONE_ID="your-zone-id"
|
| 243 |
+
|
| 244 |
+
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
|
| 245 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 246 |
+
-H "X-Auth-Key: $API_KEY"
|
| 247 |
+
```
|
| 248 |
+
|
| 249 |
+
---
|
| 250 |
+
|
| 251 |
+
## ๐ ๅๅ็ปๅฎ
|
| 252 |
+
|
| 253 |
+
### 1. ็ปๅฎๅๅๅฐ Pages ้กน็ฎ
|
| 254 |
+
|
| 255 |
+
```bash
|
| 256 |
+
PROJECT_NAME="my-project"
|
| 257 |
+
DOMAIN_NAME="example.com"
|
| 258 |
+
|
| 259 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/domains" \
|
| 260 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 261 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 262 |
+
-H "Content-Type: application/json" \
|
| 263 |
+
-d '{
|
| 264 |
+
"name": "'$DOMAIN_NAME'"
|
| 265 |
+
}'
|
| 266 |
+
```
|
| 267 |
+
|
| 268 |
+
### 2. ๅๅบ้กน็ฎ็ๅๅ
|
| 269 |
+
|
| 270 |
+
```bash
|
| 271 |
+
PROJECT_NAME="my-project"
|
| 272 |
+
|
| 273 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/domains" \
|
| 274 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 275 |
+
-H "X-Auth-Key: $API_KEY"
|
| 276 |
+
```
|
| 277 |
+
|
| 278 |
+
### 3. ่ทๅๅๅ็ถๆ
|
| 279 |
+
|
| 280 |
+
```bash
|
| 281 |
+
PROJECT_NAME="my-project"
|
| 282 |
+
DOMAIN_NAME="example.com"
|
| 283 |
+
|
| 284 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/domains/$DOMAIN_NAME" \
|
| 285 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 286 |
+
-H "X-Auth-Key: $API_KEY"
|
| 287 |
+
```
|
| 288 |
+
|
| 289 |
+
### 4. ๅ ้ค้กน็ฎๅๅ
|
| 290 |
+
|
| 291 |
+
```bash
|
| 292 |
+
PROJECT_NAME="my-project"
|
| 293 |
+
DOMAIN_NAME="example.com"
|
| 294 |
+
|
| 295 |
+
curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/domains/$DOMAIN_NAME" \
|
| 296 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 297 |
+
-H "X-Auth-Key: $API_KEY"
|
| 298 |
+
```
|
| 299 |
+
|
| 300 |
+
---
|
| 301 |
+
|
| 302 |
+
## โก Worker ่ทฏ็ฑ
|
| 303 |
+
|
| 304 |
+
### 1. ๅๅปบ Worker ่ทฏ็ฑ
|
| 305 |
+
|
| 306 |
+
```bash
|
| 307 |
+
ZONE_ID="your-zone-id"
|
| 308 |
+
|
| 309 |
+
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/workers/routes" \
|
| 310 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 311 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 312 |
+
-H "Content-Type: application/json" \
|
| 313 |
+
-d '{
|
| 314 |
+
"pattern": "example.com/api/*",
|
| 315 |
+
"script": "my-worker-script"
|
| 316 |
+
}'
|
| 317 |
+
```
|
| 318 |
+
|
| 319 |
+
### 2. ๅๅบ Worker ่ทฏ็ฑ
|
| 320 |
+
|
| 321 |
+
```bash
|
| 322 |
+
ZONE_ID="your-zone-id"
|
| 323 |
+
|
| 324 |
+
curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/workers/routes" \
|
| 325 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 326 |
+
-H "X-Auth-Key: $API_KEY"
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
### 3. ๆทปๅ Worker ่ชๅฎไนๅๅ
|
| 330 |
+
|
| 331 |
+
```bash
|
| 332 |
+
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/domains" \
|
| 333 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 334 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 335 |
+
-H "Content-Type: application/json" \
|
| 336 |
+
-d '{
|
| 337 |
+
"hostname": "api.example.com",
|
| 338 |
+
"service": "my-worker",
|
| 339 |
+
"zone_id": "your-zone-id",
|
| 340 |
+
"environment": "production"
|
| 341 |
+
}'
|
| 342 |
+
```
|
| 343 |
+
|
| 344 |
+
### 4. ๅ ้ค Worker ่ทฏ็ฑ
|
| 345 |
+
|
| 346 |
+
```bash
|
| 347 |
+
ZONE_ID="your-zone-id"
|
| 348 |
+
ROUTE_ID="route-id"
|
| 349 |
+
|
| 350 |
+
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/workers/routes/$ROUTE_ID" \
|
| 351 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 352 |
+
-H "X-Auth-Key: $API_KEY"
|
| 353 |
+
```
|
| 354 |
+
|
| 355 |
+
---
|
| 356 |
+
|
| 357 |
+
## ๐ ๏ธ ๅฎ็จๆๅทง
|
| 358 |
+
|
| 359 |
+
### 1. ็พๅ JSON ่พๅบ
|
| 360 |
+
|
| 361 |
+
ไฝฟ็จ `jq` ๆ ผๅผๅ่พๅบ๏ผ
|
| 362 |
+
|
| 363 |
+
```bash
|
| 364 |
+
curl -s ... | jq '.'
|
| 365 |
+
```
|
| 366 |
+
|
| 367 |
+
### 2. ๅช็ๆๅ็ถๆ
|
| 368 |
+
|
| 369 |
+
```bash
|
| 370 |
+
curl -s ... | jq -r '.success'
|
| 371 |
+
```
|
| 372 |
+
|
| 373 |
+
### 3. ๆๅ็นๅฎๅญๆฎต
|
| 374 |
+
|
| 375 |
+
```bash
|
| 376 |
+
# ๆๅ้กน็ฎๅ็งฐ
|
| 377 |
+
curl -s ... | jq -r '.result[].name'
|
| 378 |
+
|
| 379 |
+
# ๆๅ Nameservers
|
| 380 |
+
curl -s ... | jq -r '.result.name_servers[]'
|
| 381 |
+
```
|
| 382 |
+
|
| 383 |
+
### 4. ไฟๅญๅๅบๅฐๆไปถ
|
| 384 |
+
|
| 385 |
+
```bash
|
| 386 |
+
curl ... > response.json
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
### 5. ๆพ็คบ HTTP ็ถๆ็
|
| 390 |
+
|
| 391 |
+
```bash
|
| 392 |
+
curl -w "\nHTTP Status: %{http_code}\n" ...
|
| 393 |
+
```
|
| 394 |
+
|
| 395 |
+
---
|
| 396 |
+
|
| 397 |
+
## ๐งช ๆต่ฏ่ๆฌ
|
| 398 |
+
|
| 399 |
+
่ฟ่กๅฎๆดๆต่ฏ๏ผ
|
| 400 |
+
|
| 401 |
+
```bash
|
| 402 |
+
./curl_tests.sh
|
| 403 |
+
```
|
| 404 |
+
|
| 405 |
+
ๆๆฅ็ๆต่ฏ่ๆฌๅ
ๅฎน๏ผ
|
| 406 |
+
|
| 407 |
+
```bash
|
| 408 |
+
cat curl_tests.sh
|
| 409 |
+
```
|
| 410 |
+
|
| 411 |
+
---
|
| 412 |
+
|
| 413 |
+
## ๐ ๅฎๆดๅทฅไฝๆต็คบไพ
|
| 414 |
+
|
| 415 |
+
### ็คบไพ 1: ๅๅปบๅนถ้จ็ฝฒ Pages ้กน็ฎ
|
| 416 |
+
|
| 417 |
+
```bash
|
| 418 |
+
# 1. ๅๅปบ้กน็ฎ
|
| 419 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 420 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 421 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 422 |
+
-H "Content-Type: application/json" \
|
| 423 |
+
-d '{"name": "my-site", "production_branch": "main"}'
|
| 424 |
+
|
| 425 |
+
# 2. ้จ็ฝฒๆไปถ
|
| 426 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/my-site/deployments" \
|
| 427 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 428 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 429 |
+
-F "manifest={}" \
|
| 430 |
+
-F "branch=main" \
|
| 431 |
+
-F "index.html=@./index.html"
|
| 432 |
+
|
| 433 |
+
# 3. ๆฅ็้จ็ฝฒ็ถๆ
|
| 434 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/my-site/deployments" \
|
| 435 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 436 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '.result[0] | "URL: \(.url)"'
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
### ็คบไพ 2: ๆทปๅ ๅๅๅนถ่ทๅ Nameservers
|
| 440 |
+
|
| 441 |
+
```bash
|
| 442 |
+
# 1. ๅๅปบ Zone
|
| 443 |
+
RESPONSE=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones" \
|
| 444 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 445 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 446 |
+
-H "Content-Type: application/json" \
|
| 447 |
+
-d '{
|
| 448 |
+
"account": {"id": "'$ACCOUNT_ID'"},
|
| 449 |
+
"name": "example.com",
|
| 450 |
+
"type": "full"
|
| 451 |
+
}')
|
| 452 |
+
|
| 453 |
+
# 2. ๆๅ Nameservers
|
| 454 |
+
echo "$RESPONSE" | jq -r '.result.name_servers[]'
|
| 455 |
+
|
| 456 |
+
# 3. ็ปๅฎๅๅๅฐ Pages
|
| 457 |
+
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/my-site/domains" \
|
| 458 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 459 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 460 |
+
-H "Content-Type: application/json" \
|
| 461 |
+
-d '{"name": "example.com"}'
|
| 462 |
+
```
|
| 463 |
+
|
| 464 |
+
---
|
| 465 |
+
|
| 466 |
+
## โ
ๆต่ฏ็ปๆ
|
| 467 |
+
|
| 468 |
+
ๆๆ curl ๅฝไปคๅทฒ้ช่ฏ้่ฟ๏ผ
|
| 469 |
+
|
| 470 |
+
- โ
่ดฆๅทไฟกๆฏ่ทๅ
|
| 471 |
+
- โ
Pages ้กน็ฎๅ่กจ
|
| 472 |
+
- โ
Pages ้กน็ฎๅๅปบ
|
| 473 |
+
- โ
Pages ้กน็ฎ่ฏฆๆ
|
| 474 |
+
- โ
้จ็ฝฒๅๅฒๆฅ่ฏข
|
| 475 |
+
- โ
Zone ๅ่กจ
|
| 476 |
+
- โ
Zone ๅๅปบๅ Nameservers
|
| 477 |
+
|
| 478 |
+
**Account ID**: `af2863fcfbc1f170e5ef3b7a648c417d`
|
| 479 |
+
**่ฎค่ฏๆนๅผ**: API Key (X-Auth-Email + X-Auth-Key)
|
| 480 |
+
|
| 481 |
+
---
|
| 482 |
+
|
| 483 |
+
## ๐ ็ธๅ
ณ้พๆฅ
|
| 484 |
+
|
| 485 |
+
- [Cloudflare API ๆๆกฃ](https://developers.cloudflare.com/api/)
|
| 486 |
+
- [Pages API ๆๆกฃ](https://developers.cloudflare.com/api/operations/pages-project-create-project)
|
| 487 |
+
- [่ฎค่ฏๆนๅผ่ฏดๆ](https://developers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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ้จ็ฝฒๆๅ (Deployment Guide)
|
| 2 |
+
|
| 3 |
+
## ็ฎๅฝ
|
| 4 |
+
|
| 5 |
+
1. [Hugging Face Spaces ้จ็ฝฒ](#hugging-face-spaces-้จ็ฝฒ)
|
| 6 |
+
2. [Docker ้จ็ฝฒ](#docker-้จ็ฝฒ)
|
| 7 |
+
3. [ๆฌๅฐๅผๅ](#ๆฌๅฐๅผๅ)
|
| 8 |
+
4. [่ทๅ API Token](#่ทๅ-api-token)
|
| 9 |
+
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
## Hugging Face Spaces ้จ็ฝฒ
|
| 13 |
+
|
| 14 |
+
### ๆนๆณ 1: ้่ฟ Web ็้ข
|
| 15 |
+
|
| 16 |
+
1. **ๅๅปบๆฐ Space**
|
| 17 |
+
- ่ฎฟ้ฎ https://huggingface.co/new-space
|
| 18 |
+
- ้ๆฉ Space name๏ผไพๅฆ๏ผcloudflare-manager๏ผ
|
| 19 |
+
- ้ๆฉ SDK: **Gradio**
|
| 20 |
+
- ้ๆฉ License: MIT
|
| 21 |
+
|
| 22 |
+
2. **ไธไผ ๆไปถ**
|
| 23 |
+
- ไธไผ ๆๆ้กน็ฎๆไปถ
|
| 24 |
+
- ๆ่
่ฟๆฅๅฐ Git ไปๅบ
|
| 25 |
+
|
| 26 |
+
3. **้
็ฝฎ๏ผๅฏ้๏ผ**
|
| 27 |
+
- ่ฟๅ
ฅ Space Settings
|
| 28 |
+
- ๆทปๅ Secrets๏ผๆจ่็จไบๅฎๅ
จ๏ผ:
|
| 29 |
+
```
|
| 30 |
+
CLOUDFLARE_EMAIL=your-email@example.com
|
| 31 |
+
CLOUDFLARE_TOKEN=your-api-token
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
4. **่ฎฟ้ฎ**
|
| 35 |
+
- Space ไผ่ชๅจๆๅปบๅ้จ็ฝฒ
|
| 36 |
+
- ่ฎฟ้ฎ `https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager`
|
| 37 |
+
|
| 38 |
+
### ๆนๆณ 2: ้่ฟ Git
|
| 39 |
+
|
| 40 |
+
```bash
|
| 41 |
+
# Clone your space
|
| 42 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager
|
| 43 |
+
cd cloudflare-manager
|
| 44 |
+
|
| 45 |
+
# Copy all files
|
| 46 |
+
cp -r /path/to/project/* .
|
| 47 |
+
|
| 48 |
+
# Commit and push
|
| 49 |
+
git add .
|
| 50 |
+
git commit -m "Initial deployment"
|
| 51 |
+
git push
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Hugging Face Space ้
็ฝฎๆไปถ
|
| 55 |
+
|
| 56 |
+
็กฎไฟๅจๆ น็ฎๅฝๆ `README_HUGGINGFACE.md` ๆไปถ๏ผๅทฒๅๅปบ๏ผ๏ผๅฎๅ
ๅซ๏ผ
|
| 57 |
+
|
| 58 |
+
```yaml
|
| 59 |
+
---
|
| 60 |
+
title: Cloudflare Manager
|
| 61 |
+
emoji: โ๏ธ
|
| 62 |
+
colorFrom: orange
|
| 63 |
+
colorTo: yellow
|
| 64 |
+
sdk: gradio
|
| 65 |
+
sdk_version: "4.0.0"
|
| 66 |
+
app_file: app.py
|
| 67 |
+
pinned: false
|
| 68 |
+
license: mit
|
| 69 |
+
---
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## Docker ้จ็ฝฒ
|
| 75 |
+
|
| 76 |
+
### ไฝฟ็จ Docker Compose๏ผๆจ่๏ผ
|
| 77 |
+
|
| 78 |
+
1. **ๅๅค็ฏๅขๅ้**๏ผๅฏ้๏ผ
|
| 79 |
+
```bash
|
| 80 |
+
cp .env.example .env
|
| 81 |
+
# ็ผ่พ .env ๆไปถๅกซๅ
ฅไฝ ็ๅญๆฎ
|
| 82 |
+
nano .env
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
2. **ๅฏๅจๆๅก**
|
| 86 |
+
```bash
|
| 87 |
+
docker-compose up -d
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
3. **ๆฅ็ๆฅๅฟ**
|
| 91 |
+
```bash
|
| 92 |
+
docker-compose logs -f
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
4. **่ฎฟ้ฎ**
|
| 96 |
+
- ๆๅผๆต่งๅจ่ฎฟ้ฎ: http://localhost:7860
|
| 97 |
+
|
| 98 |
+
5. **ๅๆญขๆๅก**
|
| 99 |
+
```bash
|
| 100 |
+
docker-compose down
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### ไฝฟ็จ Docker ๅฝไปค
|
| 104 |
+
|
| 105 |
+
1. **ๆๅปบ้ๅ**
|
| 106 |
+
```bash
|
| 107 |
+
docker build -t cloudflare-manager .
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
2. **่ฟ่กๅฎนๅจ**
|
| 111 |
+
```bash
|
| 112 |
+
docker run -d \
|
| 113 |
+
--name cloudflare-manager \
|
| 114 |
+
-p 7860:7860 \
|
| 115 |
+
cloudflare-manager
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
3. **ๅธฆ็ฏๅขๅ้่ฟ่ก**
|
| 119 |
+
```bash
|
| 120 |
+
docker run -d \
|
| 121 |
+
--name cloudflare-manager \
|
| 122 |
+
-p 7860:7860 \
|
| 123 |
+
-e CLOUDFLARE_EMAIL="your-email@example.com" \
|
| 124 |
+
-e CLOUDFLARE_TOKEN="your-api-token" \
|
| 125 |
+
cloudflare-manager
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
4. **ๆฅ็ๆฅๅฟ**
|
| 129 |
+
```bash
|
| 130 |
+
docker logs -f cloudflare-manager
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
5. **ๅๆญขๅๅ ้ค**
|
| 134 |
+
```bash
|
| 135 |
+
docker stop cloudflare-manager
|
| 136 |
+
docker rm cloudflare-manager
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
### Docker Hub ้จ็ฝฒ
|
| 140 |
+
|
| 141 |
+
ๅฆๆไฝ ๆณๅๅธๅฐ Docker Hub๏ผ
|
| 142 |
+
|
| 143 |
+
```bash
|
| 144 |
+
# ๆๅปบๅนถๆๆ ็ญพ
|
| 145 |
+
docker build -t your-username/cloudflare-manager:latest .
|
| 146 |
+
|
| 147 |
+
# ๆจ้ๅฐ Docker Hub
|
| 148 |
+
docker login
|
| 149 |
+
docker push your-username/cloudflare-manager:latest
|
| 150 |
+
|
| 151 |
+
# ๅ
ถไปไบบๅฏไปฅ่ฟๆ ทไฝฟ็จ
|
| 152 |
+
docker pull your-username/cloudflare-manager:latest
|
| 153 |
+
docker run -d -p 7860:7860 your-username/cloudflare-manager:latest
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
---
|
| 157 |
+
|
| 158 |
+
## ๆฌๅฐๅผๅ
|
| 159 |
+
|
| 160 |
+
### 1. ๅฎ่ฃ
ไพ่ต
|
| 161 |
+
|
| 162 |
+
```bash
|
| 163 |
+
# ๅๅปบ่ๆ็ฏๅข๏ผๆจ่๏ผ
|
| 164 |
+
python3 -m venv venv
|
| 165 |
+
source venv/bin/activate # Linux/Mac
|
| 166 |
+
# ๆ
|
| 167 |
+
venv\Scripts\activate # Windows
|
| 168 |
+
|
| 169 |
+
# ๅฎ่ฃ
ไพ่ต
|
| 170 |
+
pip install -r requirements.txt
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
### 2. ่ฟ่ก Web ็้ข
|
| 174 |
+
|
| 175 |
+
```bash
|
| 176 |
+
python3 app.py
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
่ฎฟ้ฎ: http://localhost:7860
|
| 180 |
+
|
| 181 |
+
### 3. ไฝฟ็จ CLI ๅทฅๅ
ท
|
| 182 |
+
|
| 183 |
+
```bash
|
| 184 |
+
# ๅฟซ้ๅฏๅจๅๅฏผ
|
| 185 |
+
python3 quickstart.py
|
| 186 |
+
|
| 187 |
+
# ไบคไบๅผ่ๅ
|
| 188 |
+
python3 cloudflare_manager.py
|
| 189 |
+
|
| 190 |
+
# ่ฟ่ก็คบไพ
|
| 191 |
+
python3 example_usage.py
|
| 192 |
+
|
| 193 |
+
# ่ฟ่กๆต่ฏ
|
| 194 |
+
python3 test_manager.py
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
### 4. Python API ไฝฟ็จ
|
| 198 |
+
|
| 199 |
+
```python
|
| 200 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 201 |
+
|
| 202 |
+
account = CloudflareAccount(
|
| 203 |
+
email="your-email@example.com",
|
| 204 |
+
token="your-api-token"
|
| 205 |
+
)
|
| 206 |
+
cf = CloudflareManager(account)
|
| 207 |
+
|
| 208 |
+
# ไฝฟ็จ API
|
| 209 |
+
projects = cf.list_pages_projects()
|
| 210 |
+
zones = cf.list_zones()
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
---
|
| 214 |
+
|
| 215 |
+
## ่ทๅ API Token
|
| 216 |
+
|
| 217 |
+
### ๆญฅ้ชค
|
| 218 |
+
|
| 219 |
+
1. **็ปๅฝ Cloudflare**
|
| 220 |
+
- ่ฎฟ้ฎ https://dash.cloudflare.com/
|
| 221 |
+
|
| 222 |
+
2. **่ฟๅ
ฅ API Tokens ้กต้ข**
|
| 223 |
+
- ็นๅปๅณไธ่งๅคดๅ
|
| 224 |
+
- ้ๆฉ "My Profile"
|
| 225 |
+
- ็นๅปๅทฆไพง "API Tokens"
|
| 226 |
+
- ๆ็ดๆฅ่ฎฟ้ฎ: https://dash.cloudflare.com/profile/api-tokens
|
| 227 |
+
|
| 228 |
+
3. **ๅๅปบๆฐ Token**
|
| 229 |
+
- ็นๅป "Create Token"
|
| 230 |
+
- ้ๆฉ "Create Custom Token"
|
| 231 |
+
|
| 232 |
+
4. **้
็ฝฎๆ้**
|
| 233 |
+
|
| 234 |
+
้่ฆๆทปๅ ไปฅไธๆ้๏ผ
|
| 235 |
+
|
| 236 |
+
**Account ๆ้:**
|
| 237 |
+
- Cloudflare Pages โ Edit
|
| 238 |
+
|
| 239 |
+
**Zone ๆ้:**
|
| 240 |
+
- DNS โ Edit
|
| 241 |
+
- Workers Routes โ Edit
|
| 242 |
+
- Zone โ Edit (ๅฏ้๏ผ็จไบๅๅปบ Zone)
|
| 243 |
+
|
| 244 |
+
5. **่ฎพ็ฝฎ Zone Resources**
|
| 245 |
+
- ้ๆฉ "All zones" ๆ็นๅฎ็ zones
|
| 246 |
+
- ๅฆๆๅช็ฎก็็นๅฎๅๅ๏ผ้ๆฉๅ
ทไฝ็ zone
|
| 247 |
+
|
| 248 |
+
6. **่ฎพ็ฝฎ Client IP Address Filtering**๏ผๅฏ้๏ผ
|
| 249 |
+
- ๅฏไปฅ้ๅถ IP ๅฐๅไปฅๅขๅ ๅฎๅ
จๆง
|
| 250 |
+
|
| 251 |
+
7. **ๅๅปบๅนถๅคๅถ Token**
|
| 252 |
+
- ็นๅป "Continue to summary"
|
| 253 |
+
- ็นๅป "Create Token"
|
| 254 |
+
- **้่ฆ**: ็ซๅณๅคๅถ token๏ผๅฎๅชๆพ็คบไธๆฌก๏ผ
|
| 255 |
+
|
| 256 |
+
### Token ็คบไพๆ ผๅผ
|
| 257 |
+
|
| 258 |
+
ๆญฃ็กฎ็ token ๆ ผๅผ็ฑปไผผ๏ผ
|
| 259 |
+
```
|
| 260 |
+
v1.0-abc123def456789...xyz
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
**ๆณจๆ**: ๆไพ็ token `21f3fb278a15b732a4f52c95d5042d78d1a21` ไผผไนไธๆฏๆญฃ็กฎ็ๆ ผๅผใ
|
| 264 |
+
|
| 265 |
+
### ้ช่ฏ Token
|
| 266 |
+
|
| 267 |
+
ๅๅปบ token ๅ๏ผๅฏไปฅๆต่ฏ๏ผ
|
| 268 |
+
|
| 269 |
+
```bash
|
| 270 |
+
python3 test_credentials.py
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
ๆไฝฟ็จ curl๏ผ
|
| 274 |
+
|
| 275 |
+
```bash
|
| 276 |
+
export CLOUDFLARE_API_TOKEN="your-token"
|
| 277 |
+
|
| 278 |
+
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
|
| 279 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 280 |
+
-H "Content-Type: application/json"
|
| 281 |
+
```
|
| 282 |
+
|
| 283 |
+
ๆๅ็ๅๅบ๏ผ
|
| 284 |
+
```json
|
| 285 |
+
{
|
| 286 |
+
"success": true,
|
| 287 |
+
"errors": [],
|
| 288 |
+
"messages": [],
|
| 289 |
+
"result": {
|
| 290 |
+
"id": "...",
|
| 291 |
+
"status": "active"
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
```
|
| 295 |
+
|
| 296 |
+
---
|
| 297 |
+
|
| 298 |
+
## ็ฏๅขๅ้้
็ฝฎ
|
| 299 |
+
|
| 300 |
+
### ๆนๆณ 1: .env ๆไปถ
|
| 301 |
+
|
| 302 |
+
```bash
|
| 303 |
+
# ๅคๅถ็คบไพๆไปถ
|
| 304 |
+
cp .env.example .env
|
| 305 |
+
|
| 306 |
+
# ็ผ่พๆไปถ
|
| 307 |
+
nano .env
|
| 308 |
+
```
|
| 309 |
+
|
| 310 |
+
ๅ
ๅฎน๏ผ
|
| 311 |
+
```bash
|
| 312 |
+
CLOUDFLARE_EMAIL=your-email@example.com
|
| 313 |
+
CLOUDFLARE_TOKEN=v1.0-your-actual-token
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
### ๆนๆณ 2: ็ณป็ป็ฏๅขๅ้
|
| 317 |
+
|
| 318 |
+
**Linux/Mac:**
|
| 319 |
+
```bash
|
| 320 |
+
export CLOUDFLARE_EMAIL="your-email@example.com"
|
| 321 |
+
export CLOUDFLARE_TOKEN="v1.0-your-actual-token"
|
| 322 |
+
```
|
| 323 |
+
|
| 324 |
+
**Windows:**
|
| 325 |
+
```cmd
|
| 326 |
+
set CLOUDFLARE_EMAIL=your-email@example.com
|
| 327 |
+
set CLOUDFLARE_TOKEN=v1.0-your-actual-token
|
| 328 |
+
```
|
| 329 |
+
|
| 330 |
+
### ๆนๆณ 3: ๅจไปฃ็ ไธญ
|
| 331 |
+
|
| 332 |
+
```python
|
| 333 |
+
import os
|
| 334 |
+
|
| 335 |
+
# ่ฎพ็ฝฎ็ฏๅขๅ้
|
| 336 |
+
os.environ['CLOUDFLARE_EMAIL'] = 'your-email@example.com'
|
| 337 |
+
os.environ['CLOUDFLARE_TOKEN'] = 'v1.0-your-actual-token'
|
| 338 |
+
|
| 339 |
+
# ็ถๅ่ฟ่กๅบ็จ
|
| 340 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 341 |
+
|
| 342 |
+
account = CloudflareAccount(
|
| 343 |
+
email=os.environ['CLOUDFLARE_EMAIL'],
|
| 344 |
+
token=os.environ['CLOUDFLARE_TOKEN']
|
| 345 |
+
)
|
| 346 |
+
```
|
| 347 |
+
|
| 348 |
+
---
|
| 349 |
+
|
| 350 |
+
## ้จ็ฝฒๆถๆ
|
| 351 |
+
|
| 352 |
+
### ๆถๆๅพ
|
| 353 |
+
|
| 354 |
+
```
|
| 355 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 356 |
+
โ ็จๆทๆต่งๅจ โ
|
| 357 |
+
โ (http://localhost:7860) โ
|
| 358 |
+
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 359 |
+
โ
|
| 360 |
+
โผ
|
| 361 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 362 |
+
โ Gradio Web Interface โ
|
| 363 |
+
โ (app.py) โ
|
| 364 |
+
โ - Form inputs โ
|
| 365 |
+
โ - Buttons and tabs โ
|
| 366 |
+
โ - Result display โ
|
| 367 |
+
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 368 |
+
โ
|
| 369 |
+
โผ
|
| 370 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 371 |
+
โ CloudflareManager โ
|
| 372 |
+
โ (cloudflare_manager.py) โ
|
| 373 |
+
โ - API calls โ
|
| 374 |
+
โ - Error handling โ
|
| 375 |
+
โ - Data processing โ
|
| 376 |
+
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 377 |
+
โ
|
| 378 |
+
โผ
|
| 379 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 380 |
+
โ Cloudflare API โ
|
| 381 |
+
โ https://api.cloudflare.com/client/v4 โ
|
| 382 |
+
โ - Pages โ
|
| 383 |
+
โ - Zones โ
|
| 384 |
+
โ - Workers โ
|
| 385 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 386 |
+
```
|
| 387 |
+
|
| 388 |
+
---
|
| 389 |
+
|
| 390 |
+
## ๆ
้ๆ้ค
|
| 391 |
+
|
| 392 |
+
### ้ฎ้ข 1: Token ๆ ๆ
|
| 393 |
+
|
| 394 |
+
**้่ฏฏ**: "Invalid request headers" ๆ "Invalid format for Authorization header"
|
| 395 |
+
|
| 396 |
+
**่งฃๅณ**:
|
| 397 |
+
1. ๆฃๆฅ token ๆ ผๅผๆฏๅฆๆญฃ็กฎ๏ผๅบไปฅ `v1.0-` ๅผๅคด๏ผ
|
| 398 |
+
2. ้ช่ฏ token ๆ้
|
| 399 |
+
3. ๅๅปบๆฐ็ token
|
| 400 |
+
|
| 401 |
+
### ้ฎ้ข 2: Docker ๆๅปบๅคฑ่ดฅ
|
| 402 |
+
|
| 403 |
+
**่งฃๅณ**:
|
| 404 |
+
```bash
|
| 405 |
+
# ๆธ
็ๅนถ้ๆฐๆๅปบ
|
| 406 |
+
docker-compose down -v
|
| 407 |
+
docker-compose build --no-cache
|
| 408 |
+
docker-compose up -d
|
| 409 |
+
```
|
| 410 |
+
|
| 411 |
+
### ้ฎ้ข 3: ็ซฏๅฃๅทฒ่ขซๅ ็จ
|
| 412 |
+
|
| 413 |
+
**้่ฏฏ**: "Port 7860 is already in use"
|
| 414 |
+
|
| 415 |
+
**่งฃๅณ**:
|
| 416 |
+
```bash
|
| 417 |
+
# ไฝฟ็จไธๅ็ซฏๅฃ
|
| 418 |
+
docker run -d -p 8080:7860 cloudflare-manager
|
| 419 |
+
|
| 420 |
+
# ๆๅๆญขๅ ็จ็่ฟ็จ
|
| 421 |
+
lsof -ti:7860 | xargs kill -9
|
| 422 |
+
```
|
| 423 |
+
|
| 424 |
+
### ้ฎ้ข 4: Gradio ็้ขๆ ๆณ่ฎฟ้ฎ
|
| 425 |
+
|
| 426 |
+
**่งฃๅณ**:
|
| 427 |
+
1. ๆฃๆฅ้ฒ็ซๅข่ฎพ็ฝฎ
|
| 428 |
+
2. ็กฎไฟๅฎนๅจๆญฃๅจ่ฟ่ก: `docker ps`
|
| 429 |
+
3. ๆฅ็ๆฅๅฟ: `docker logs cloudflare-manager`
|
| 430 |
+
|
| 431 |
+
---
|
| 432 |
+
|
| 433 |
+
## ็ไบง็ฏๅขๅปบ่ฎฎ
|
| 434 |
+
|
| 435 |
+
### 1. ไฝฟ็จ HTTPS
|
| 436 |
+
|
| 437 |
+
้
็ฝฎๅๅไปฃ็๏ผๅฆ Nginx๏ผ:
|
| 438 |
+
|
| 439 |
+
```nginx
|
| 440 |
+
server {
|
| 441 |
+
listen 80;
|
| 442 |
+
server_name your-domain.com;
|
| 443 |
+
return 301 https://$server_name$request_uri;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
server {
|
| 447 |
+
listen 443 ssl;
|
| 448 |
+
server_name your-domain.com;
|
| 449 |
+
|
| 450 |
+
ssl_certificate /path/to/cert.pem;
|
| 451 |
+
ssl_certificate_key /path/to/key.pem;
|
| 452 |
+
|
| 453 |
+
location / {
|
| 454 |
+
proxy_pass http://localhost:7860;
|
| 455 |
+
proxy_set_header Host $host;
|
| 456 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 457 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 458 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
```
|
| 462 |
+
|
| 463 |
+
### 2. ่ฎพ็ฝฎ่ฎค่ฏ
|
| 464 |
+
|
| 465 |
+
ๆทปๅ ๅบๆฌ่ฎค่ฏๆไฝฟ็จ OAuthใ
|
| 466 |
+
|
| 467 |
+
### 3. ็ๆงๅๆฅๅฟ
|
| 468 |
+
|
| 469 |
+
```bash
|
| 470 |
+
# ๆฅ็ๆฅๅฟ
|
| 471 |
+
docker logs -f cloudflare-manager
|
| 472 |
+
|
| 473 |
+
# ไฝฟ็จๆฅๅฟ่ๅๅทฅๅ
ท
|
| 474 |
+
# ไพๅฆ: ELK Stack, Loki, etc.
|
| 475 |
+
```
|
| 476 |
+
|
| 477 |
+
### 4. ่ชๅจ้ๅฏ
|
| 478 |
+
|
| 479 |
+
```yaml
|
| 480 |
+
# docker-compose.yml
|
| 481 |
+
services:
|
| 482 |
+
cloudflare-manager:
|
| 483 |
+
restart: always # ๆนไธบ always
|
| 484 |
+
```
|
| 485 |
+
|
| 486 |
+
---
|
| 487 |
+
|
| 488 |
+
## ๆดๆฐๅ็ปดๆค
|
| 489 |
+
|
| 490 |
+
### ๆดๆฐๅบ็จ
|
| 491 |
+
|
| 492 |
+
```bash
|
| 493 |
+
# ๆๅๆๆฐไปฃ็
|
| 494 |
+
git pull
|
| 495 |
+
|
| 496 |
+
# ้ๆฐๆๅปบๅ้จ็ฝฒ
|
| 497 |
+
docker-compose down
|
| 498 |
+
docker-compose build
|
| 499 |
+
docker-compose up -d
|
| 500 |
+
```
|
| 501 |
+
|
| 502 |
+
### ๅคไปฝ้
็ฝฎ
|
| 503 |
+
|
| 504 |
+
```bash
|
| 505 |
+
# ๅคไปฝ .env ๆไปถ
|
| 506 |
+
cp .env .env.backup
|
| 507 |
+
|
| 508 |
+
# ๅคไปฝๆดไธช้
็ฝฎ
|
| 509 |
+
tar -czf cloudflare-manager-backup.tar.gz \
|
| 510 |
+
.env docker-compose.yml
|
| 511 |
+
```
|
| 512 |
+
|
| 513 |
+
---
|
| 514 |
+
|
| 515 |
+
## ๆฏๆ็ๅนณๅฐ
|
| 516 |
+
|
| 517 |
+
- โ
Hugging Face Spaces
|
| 518 |
+
- โ
Docker / Docker Compose
|
| 519 |
+
- โ
ๆฌๅฐๅผๅ็ฏๅข
|
| 520 |
+
- โ
Linux ๆๅกๅจ
|
| 521 |
+
- โ
macOS
|
| 522 |
+
- โ
Windows (with WSL2)
|
| 523 |
+
- โ
Cloud platforms (AWS, GCP, Azure)
|
| 524 |
+
- โ
Kubernetes (้่ฆๅๅปบ็ธๅบ็ manifests)
|
| 525 |
+
|
| 526 |
+
---
|
| 527 |
+
|
| 528 |
+
## ไธไธๆญฅ
|
| 529 |
+
|
| 530 |
+
1. โ
่ทๅๆญฃ็กฎ็ API Token
|
| 531 |
+
2. โ
้ๆฉ้จ็ฝฒๆนๅผ๏ผHugging Face / Docker / ๆฌๅฐ๏ผ
|
| 532 |
+
3. โ
่ฟ่กๅบ็จ
|
| 533 |
+
4. โ
ๅผๅง็ฎก็ C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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ ้จ็ฝฒๅๅคๅฎๆ (Deployment Ready)
|
| 2 |
+
|
| 3 |
+
## โ
ๅทฒๅฎๆ็ๅทฅไฝ
|
| 4 |
+
|
| 5 |
+
### 1. Web ็้ข (Gradio)
|
| 6 |
+
- โ
`app.py` - ๅฎๆด็ Gradio Web ็้ข
|
| 7 |
+
- โ
ๆฏๆๆๆๆ ธๅฟๅ่ฝ
|
| 8 |
+
- โ
ๅๅฅฝ็็จๆท็้ข
|
| 9 |
+
- โ
ๅฎๆถๆไฝๅ้ฆ
|
| 10 |
+
|
| 11 |
+
### 2. Docker ๆฏๆ
|
| 12 |
+
- โ
`Dockerfile` - ็ไบง็บง Docker ้ๅ้
็ฝฎ
|
| 13 |
+
- โ
`docker-compose.yml` - ไธ้ฎ้จ็ฝฒ้
็ฝฎ
|
| 14 |
+
- โ
`.dockerignore` - ไผๅ้ๅๅคงๅฐ
|
| 15 |
+
- โ
`.env.example` - ็ฏๅขๅ้ๆจกๆฟ
|
| 16 |
+
|
| 17 |
+
### 3. ้จ็ฝฒ่ๆฌ
|
| 18 |
+
- โ
`start.sh` - ไธ้ฎๅฏๅจ่ๆฌ๏ผๆฏๆ Docker ๅ Python๏ผ
|
| 19 |
+
- โ
่ชๅจๆฃๆต็ฏๅข
|
| 20 |
+
- โ
ๅๅฅฝ็ไบคไบๆ็คบ
|
| 21 |
+
|
| 22 |
+
### 4. ๆต่ฏๅๆๆกฃ
|
| 23 |
+
- โ
`test_credentials.py` - ๅญๆฎๆต่ฏ่ๆฌ
|
| 24 |
+
- โ
`DEPLOYMENT.md` - ๅฎๆด้จ็ฝฒๆๅ
|
| 25 |
+
- โ
`QUICK_DEPLOY.md` - ๅฟซ้้จ็ฝฒๆๅ
|
| 26 |
+
- โ
`README_HUGGINGFACE.md` - Hugging Face ไธ็จๆๆกฃ
|
| 27 |
+
|
| 28 |
+
### 5. ๆ ธๅฟๅ่ฝ
|
| 29 |
+
- โ
Pages ้กน็ฎ็ฎก็
|
| 30 |
+
- โ
ๅๅ็ปๅฎ
|
| 31 |
+
- โ
Nameserver ๆฅ่ฏข
|
| 32 |
+
- โ
Worker ่ทฏ็ฑ้
็ฝฎ
|
| 33 |
+
- โ
ๅค่ดฆๅทๆฏๆ
|
| 34 |
+
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
## ๐ ๆฐๅขๆไปถๅ่กจ
|
| 38 |
+
|
| 39 |
+
```
|
| 40 |
+
/home/engine/project/
|
| 41 |
+
โโโ app.py # Gradio Web ็้ข โญ
|
| 42 |
+
โโโ Dockerfile # Docker ้
็ฝฎ โญ
|
| 43 |
+
โโโ docker-compose.yml # Docker Compose ้
็ฝฎ โญ
|
| 44 |
+
โโโ start.sh # ไธ้ฎๅฏๅจ่ๆฌ โญ
|
| 45 |
+
โโโ .dockerignore # Docker ๅฟฝ็ฅๆไปถ
|
| 46 |
+
โโโ .env.example # ็ฏๅขๅ้ๆจกๆฟ
|
| 47 |
+
โโโ test_credentials.py # ๅญๆฎๆต่ฏ่ๆฌ
|
| 48 |
+
โโโ DEPLOYMENT.md # ้จ็ฝฒๆๅ
|
| 49 |
+
โโโ QUICK_DEPLOY.md # ๅฟซ้้จ็ฝฒ
|
| 50 |
+
โโโ README_HUGGINGFACE.md # Hugging Face ๆๆกฃ
|
| 51 |
+
โโโ DEPLOY_STATUS.md # ๆฌๆไปถ
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
+
|
| 56 |
+
## ๐ ๅฟซ้ๅผๅง
|
| 57 |
+
|
| 58 |
+
### ๆนๅผ 1: ไฝฟ็จๅฏๅจ่ๆฌ๏ผๆ็ฎๅ๏ผ
|
| 59 |
+
|
| 60 |
+
```bash
|
| 61 |
+
./start.sh
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
้ๆฉ้จ็ฝฒๆนๅผๅ่ชๅจๅฏๅจใ
|
| 65 |
+
|
| 66 |
+
### ๆนๅผ 2: Docker Compose
|
| 67 |
+
|
| 68 |
+
```bash
|
| 69 |
+
docker-compose up -d
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
่ฎฟ้ฎ: http://localhost:7860
|
| 73 |
+
|
| 74 |
+
### ๆนๅผ 3: Docker
|
| 75 |
+
|
| 76 |
+
```bash
|
| 77 |
+
docker build -t cloudflare-manager .
|
| 78 |
+
docker run -d -p 7860:7860 cloudflare-manager
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
### ๆนๅผ 4: Python
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
pip3 install -r requirements.txt
|
| 85 |
+
python3 app.py
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## ๐ Hugging Face Spaces ้จ็ฝฒ
|
| 91 |
+
|
| 92 |
+
### ๅฟซ้ๆญฅ้ชค๏ผ
|
| 93 |
+
|
| 94 |
+
1. **ๅๅปบ Space**: https://huggingface.co/new-space
|
| 95 |
+
- SDK: Gradio
|
| 96 |
+
- Python: 3.10
|
| 97 |
+
|
| 98 |
+
2. **ไธไผ ๅฟ
้ๆไปถ**:
|
| 99 |
+
```
|
| 100 |
+
- app.py โ
|
| 101 |
+
- cloudflare_manager.py โ
|
| 102 |
+
- requirements.txt โ
|
| 103 |
+
- README_HUGGINGFACE.md โ README.md โ
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
3. **่ฎพ็ฝฎ Secrets** (ๅฏ้):
|
| 107 |
+
```
|
| 108 |
+
CLOUDFLARE_EMAIL=your-email@example.com
|
| 109 |
+
CLOUDFLARE_TOKEN=your-api-token
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
4. **่ฎฟ้ฎ**: `https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager`
|
| 113 |
+
|
| 114 |
+
### ไฝฟ็จ Git ้จ็ฝฒ๏ผ
|
| 115 |
+
|
| 116 |
+
```bash
|
| 117 |
+
# Clone your space
|
| 118 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager
|
| 119 |
+
cd cloudflare-manager
|
| 120 |
+
|
| 121 |
+
# Copy files
|
| 122 |
+
cp app.py cloudflare_manager.py requirements.txt ./
|
| 123 |
+
cp README_HUGGINGFACE.md README.md
|
| 124 |
+
|
| 125 |
+
# Commit and push
|
| 126 |
+
git add .
|
| 127 |
+
git commit -m "Deploy Cloudflare Manager"
|
| 128 |
+
git push
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
## โ ๏ธ ้่ฆๆ็คบ
|
| 134 |
+
|
| 135 |
+
### ๅ
ณไบๆไพ็ๆต่ฏ่ดฆๅท
|
| 136 |
+
|
| 137 |
+
ๆไพ็ API Token `21f3fb278a15b732a4f52c95d5042d78d1a21` **ๆ ผๅผไธๆญฃ็กฎ**ใ
|
| 138 |
+
|
| 139 |
+
**ๅๅ **:
|
| 140 |
+
- Cloudflare API Token ๅบ่ฏฅๆฏๅพ้ฟ็ๅญ็ฌฆไธฒ
|
| 141 |
+
- ้ๅธธไปฅ `v1.0-` ๅผๅคด
|
| 142 |
+
- ็คบไพ: `v1.0-abc123def456...xyz`
|
| 143 |
+
|
| 144 |
+
### ่ทๅๆญฃ็กฎ็ Token๏ผ
|
| 145 |
+
|
| 146 |
+
1. ่ฎฟ้ฎ: https://dash.cloudflare.com/profile/api-tokens
|
| 147 |
+
2. ็นๅป "Create Token"
|
| 148 |
+
3. ้ๆฉ "Create Custom Token"
|
| 149 |
+
4. ้
็ฝฎๆ้:
|
| 150 |
+
```
|
| 151 |
+
Account Permissions:
|
| 152 |
+
- Cloudflare Pages โ Edit
|
| 153 |
+
|
| 154 |
+
Zone Permissions:
|
| 155 |
+
- DNS โ Edit
|
| 156 |
+
- Workers Routes โ Edit
|
| 157 |
+
- Zone โ Edit
|
| 158 |
+
```
|
| 159 |
+
5. ๅๅปบๅนถๅคๅถ Token๏ผๅชๆพ็คบไธๆฌก๏ผ๏ผ
|
| 160 |
+
|
| 161 |
+
### ๆต่ฏๆฐ Token๏ผ
|
| 162 |
+
|
| 163 |
+
```bash
|
| 164 |
+
# ๆนๆณ 1: ไฝฟ็จๆต่ฏ่ๆฌ
|
| 165 |
+
python3 test_credentials.py
|
| 166 |
+
|
| 167 |
+
# ๆนๆณ 2: ไฝฟ็จ curl
|
| 168 |
+
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
|
| 169 |
+
-H "Authorization: Bearer YOUR_TOKEN" \
|
| 170 |
+
-H "Content-Type: application/json"
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
ๆๅ็ๅๅบ๏ผ
|
| 174 |
+
```json
|
| 175 |
+
{
|
| 176 |
+
"success": true,
|
| 177 |
+
"result": {
|
| 178 |
+
"id": "...",
|
| 179 |
+
"status": "active"
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
---
|
| 185 |
+
|
| 186 |
+
## ๐ฏ ๅ่ฝๆต่ฏ
|
| 187 |
+
|
| 188 |
+
### Web ็้ขๅ่ฝ๏ผ
|
| 189 |
+
|
| 190 |
+
#### 1. Connection Test
|
| 191 |
+
- ๆต่ฏ API ่ฟๆฅ
|
| 192 |
+
- ๆพ็คบ่ดฆๅทไฟกๆฏ
|
| 193 |
+
|
| 194 |
+
#### 2. Pages Projects
|
| 195 |
+
- ๅๅบๆๆ้กน็ฎ
|
| 196 |
+
- ๅๅปบๆฐ้กน็ฎ
|
| 197 |
+
- ๆฅ็้กน็ฎ่ฏฆๆ
|
| 198 |
+
|
| 199 |
+
#### 3. Domains & Zones
|
| 200 |
+
- ๅๅบๆๆ Zones
|
| 201 |
+
- ๅๅปบ Zone
|
| 202 |
+
- ่ทๅ Nameservers
|
| 203 |
+
|
| 204 |
+
#### 4. Bind Domain
|
| 205 |
+
- ็ปๅฎๅๅๅฐ Pages
|
| 206 |
+
- ๆฅ็้ช่ฏ็ถๆ
|
| 207 |
+
|
| 208 |
+
#### 5. Worker Routes
|
| 209 |
+
- ๅๅปบ Worker ่ทฏ็ฑ
|
| 210 |
+
- ้
็ฝฎ่ทฏ็ฑๆจกๅผ
|
| 211 |
+
|
| 212 |
+
---
|
| 213 |
+
|
| 214 |
+
## ๐ ๆๆฏๆ
|
| 215 |
+
|
| 216 |
+
### ๅ็ซฏ
|
| 217 |
+
- **Python 3.10+**
|
| 218 |
+
- **requests** - HTTP ๅฎขๆท็ซฏ
|
| 219 |
+
- **Cloudflare API v4**
|
| 220 |
+
|
| 221 |
+
### ๅ็ซฏ
|
| 222 |
+
- **Gradio 4.0+** - Web UI ๆกๆถ
|
| 223 |
+
- ๅๅบๅผ็้ข
|
| 224 |
+
- ๅฎๆถๅ้ฆ
|
| 225 |
+
|
| 226 |
+
### ้จ็ฝฒ
|
| 227 |
+
- **Docker** - ๅฎนๅจๅ
|
| 228 |
+
- **Docker Compose** - ๆๅก็ผๆ
|
| 229 |
+
- **Hugging Face Spaces** - ไบๆ็ฎก
|
| 230 |
+
|
| 231 |
+
---
|
| 232 |
+
|
| 233 |
+
## ๐ ไฝฟ็จ็คบไพ
|
| 234 |
+
|
| 235 |
+
### ็คบไพ 1: ้จ็ฝฒ้ๆ็ฝ็ซ
|
| 236 |
+
|
| 237 |
+
1. ๅจ Web ็้ข่พๅ
ฅๅญๆฎ
|
| 238 |
+
2. ่ฟๅ
ฅ "Pages Projects" ๆ ็ญพ
|
| 239 |
+
3. ๅๅปบ้กน็ฎ "my-website"
|
| 240 |
+
4. ๏ผไฝฟ็จ CLI ้จ็ฝฒๆไปถ๏ผ
|
| 241 |
+
5. ่ฟๅ
ฅ "Domains & Zones"
|
| 242 |
+
6. ๅๅปบ Zone "example.com"
|
| 243 |
+
7. ๅคๅถ Nameservers ๅฐๅๅๆณจๅๅ
|
| 244 |
+
8. ่ฟๅ
ฅ "Bind Domain"
|
| 245 |
+
9. ็ปๅฎ "example.com" ๅฐ "my-website"
|
| 246 |
+
|
| 247 |
+
### ็คบไพ 2: ้
็ฝฎ API ๅญๅๅ
|
| 248 |
+
|
| 249 |
+
1. ่ทๅ Zone ID๏ผไป "Domains & Zones"๏ผ
|
| 250 |
+
2. ่ฟๅ
ฅ "Worker Routes"
|
| 251 |
+
3. ๅๅปบ่ทฏ็ฑ:
|
| 252 |
+
- Zone ID: ไปไธไธๆญฅ
|
| 253 |
+
- Pattern: `example.com/api/*`
|
| 254 |
+
- Script: `api-worker`
|
| 255 |
+
|
| 256 |
+
---
|
| 257 |
+
|
| 258 |
+
## ๐ ๅฎๅ
จๅปบ่ฎฎ
|
| 259 |
+
|
| 260 |
+
### ็ไบง็ฏๅข๏ผ
|
| 261 |
+
|
| 262 |
+
1. **ไฝฟ็จ HTTPS**
|
| 263 |
+
- ้
็ฝฎๅๅไปฃ็๏ผNginx/Caddy๏ผ
|
| 264 |
+
- ่ทๅ SSL ่ฏไนฆ
|
| 265 |
+
|
| 266 |
+
2. **ไฟๆคๅญๆฎ**
|
| 267 |
+
- ไธ่ฆๆไบค `.env` ๅฐ Git
|
| 268 |
+
- ไฝฟ็จ็ฏๅขๅ้
|
| 269 |
+
- ๅจ Hugging Face ไฝฟ็จ Secrets
|
| 270 |
+
|
| 271 |
+
3. **้ๅถ่ฎฟ้ฎ**
|
| 272 |
+
- ้
็ฝฎ้ฒ็ซๅข
|
| 273 |
+
- ไฝฟ็จ VPN
|
| 274 |
+
- ๆทปๅ ่ฎค่ฏๅฑ
|
| 275 |
+
|
| 276 |
+
4. **็ๆง**
|
| 277 |
+
- ๆฅ็ๆฅๅฟ
|
| 278 |
+
- ่ฎพ็ฝฎๅ่ญฆ
|
| 279 |
+
- ๅฎๆๅฎก่ฎก
|
| 280 |
+
|
| 281 |
+
---
|
| 282 |
+
|
| 283 |
+
## ๐ ๆๆกฃ็ดขๅผ
|
| 284 |
+
|
| 285 |
+
| ๆๆกฃ | ็จ้ | ่ฏป่
|
|
| 286 |
+
|------|------|------|
|
| 287 |
+
| [QUICK_DEPLOY.md](QUICK_DEPLOY.md) | ๅฟซ้้จ็ฝฒ | ๆๆไบบ โญ |
|
| 288 |
+
| [GET_STARTED.md](GET_STARTED.md) | ๅฟซ้ไธๆ | ๆฐๆ |
|
| 289 |
+
| [USAGE_GUIDE.md](USAGE_GUIDE.md) | ไฝฟ็จๆๅ | ็จๆท |
|
| 290 |
+
| [API_REFERENCE.md](API_REFERENCE.md) | API ๆๆกฃ | ๅผๅ่
|
|
| 291 |
+
| [DEPLOYMENT.md](DEPLOYMENT.md) | ้จ็ฝฒ่ฏฆ่งฃ | ่ฟ็ปด |
|
| 292 |
+
| [PROJECT_SUMMARY.md](PROJECT_SUMMARY.md) | ้กน็ฎๆป็ป | ๆๆไบบ |
|
| 293 |
+
| [README_HUGGINGFACE.md](README_HUGGINGFACE.md) | HF ้จ็ฝฒ | HF ็จๆท |
|
| 294 |
+
|
| 295 |
+
---
|
| 296 |
+
|
| 297 |
+
## โ
้จ็ฝฒๆฃๆฅๆธ
ๅ
|
| 298 |
+
|
| 299 |
+
### ้จ็ฝฒๅ๏ผ
|
| 300 |
+
- [ ] ่ทๅๆญฃ็กฎๆ ผๅผ็ API Token
|
| 301 |
+
- [ ] ๆต่ฏ Token ๆๆๆง
|
| 302 |
+
- [ ] ๆฃๆฅ Token ๆ้
|
| 303 |
+
- [ ] ้ๆฉ้จ็ฝฒๆนๅผ
|
| 304 |
+
|
| 305 |
+
### ๆฌๅฐ้จ็ฝฒ๏ผ
|
| 306 |
+
- [ ] ๅฎ่ฃ
Docker ๆ Python 3.10+
|
| 307 |
+
- [ ] Clone ไปฃ็
|
| 308 |
+
- [ ] ่ฟ่ก `./start.sh` ๆๅ
ถไปๆนๅผ
|
| 309 |
+
- [ ] ่ฎฟ้ฎ http://localhost:7860
|
| 310 |
+
- [ ] ๆต่ฏๅ่ฝ
|
| 311 |
+
|
| 312 |
+
### Hugging Face ้จ็ฝฒ๏ผ
|
| 313 |
+
- [ ] ๅๅปบ Space
|
| 314 |
+
- [ ] ไธไผ ๅฟ
้ๆไปถ
|
| 315 |
+
- [ ] ้
็ฝฎ Secrets๏ผๅฏ้๏ผ
|
| 316 |
+
- [ ] ็ญๅพ
ๆๅปบๅฎๆ
|
| 317 |
+
- [ ] ่ฎฟ้ฎ Space URL
|
| 318 |
+
- [ ] ๆต่ฏๅ่ฝ
|
| 319 |
+
|
| 320 |
+
---
|
| 321 |
+
|
| 322 |
+
## ๐ ๅฎๆ็ถๆ
|
| 323 |
+
|
| 324 |
+
### โ
ๅทฒๅฎ็ฐ็ๆๆๅ่ฝ๏ผ
|
| 325 |
+
|
| 326 |
+
1. โ
**Pages ้จ็ฝฒ**
|
| 327 |
+
- ๅๅปบ้กน็ฎ
|
| 328 |
+
- ๅๅบ้กน็ฎ
|
| 329 |
+
- ้จ็ฝฒๆไปถ๏ผCLI๏ผ
|
| 330 |
+
|
| 331 |
+
2. โ
**ๅๅ็ฎก็**
|
| 332 |
+
- ๅๅปบ Zone
|
| 333 |
+
- ่ทๅ Nameservers
|
| 334 |
+
- ็ปๅฎๅๅ
|
| 335 |
+
- DNS ้ช่ฏ
|
| 336 |
+
|
| 337 |
+
3. โ
**Worker ่ทฏ็ฑ**
|
| 338 |
+
- ๅๅปบ่ทฏ็ฑ
|
| 339 |
+
- ้
็ฝฎๆจกๅผ
|
| 340 |
+
- ่ชๅฎไนๅๅ
|
| 341 |
+
|
| 342 |
+
4. โ
**ๅค่ดฆๅทๆฏๆ**
|
| 343 |
+
- ็ฎก็ๅคไธช่ดฆๅท
|
| 344 |
+
- ๅๆข่ดฆๅท
|
| 345 |
+
- ็ฌ็ซ้
็ฝฎ
|
| 346 |
+
|
| 347 |
+
5. โ
**Web ็้ข**
|
| 348 |
+
- Gradio UI
|
| 349 |
+
- ๅฎๆถๅ้ฆ
|
| 350 |
+
- ๅๅฅฝๆ็คบ
|
| 351 |
+
|
| 352 |
+
6. โ
**้จ็ฝฒๆนๆก**
|
| 353 |
+
- Docker
|
| 354 |
+
- Docker Compose
|
| 355 |
+
- Python ๆฌๅฐ
|
| 356 |
+
- Hugging Face Spaces
|
| 357 |
+
|
| 358 |
+
7. โ
**ๆๆกฃ**
|
| 359 |
+
- 7+ ไปฝ่ฏฆ็ปๆๆกฃ
|
| 360 |
+
- ไธญ่ฑๆๆททๅ
|
| 361 |
+
- ไฝฟ็จ็คบไพ
|
| 362 |
+
- API ๅ่
|
| 363 |
+
|
| 364 |
+
---
|
| 365 |
+
|
| 366 |
+
## ๐ ็ซๅณๅผๅง
|
| 367 |
+
|
| 368 |
+
### ๆๅฟซ็ๆนๅผ๏ผ
|
| 369 |
+
|
| 370 |
+
```bash
|
| 371 |
+
# 1. ่ทๅ API Token๏ผๆ็
งไธ้ข็่ฏดๆ๏ผ
|
| 372 |
+
|
| 373 |
+
# 2. ๅฏๅจๅบ็จ
|
| 374 |
+
./start.sh
|
| 375 |
+
|
| 376 |
+
# 3. ่ฎฟ้ฎ
|
| 377 |
+
# http://localhost:7860
|
| 378 |
+
|
| 379 |
+
# 4. ่พๅ
ฅๅญๆฎ
|
| 380 |
+
|
| 381 |
+
# 5. ๅผๅงไฝฟ็จ๏ผ
|
| 382 |
+
```
|
| 383 |
+
|
| 384 |
+
---
|
| 385 |
+
|
| 386 |
+
## ๐ ่ทๅๅธฎๅฉ
|
| 387 |
+
|
| 388 |
+
### ๆๆกฃ
|
| 389 |
+
- ๅฟซ้ๅผๅง: [QUICK_DEPLOY.md](QUICK_DEPLOY.md)
|
| 390 |
+
- ๅฎๆดๆๅ: [USAGE_GUIDE.md](USAGE_GUIDE.md)
|
| 391 |
+
- API ๆๆกฃ: [API_REFERENCE.md](API_REFERENCE.md)
|
| 392 |
+
|
| 393 |
+
### ๆต่ฏ
|
| 394 |
+
```bash
|
| 395 |
+
# ๆต่ฏๅญๆฎ
|
| 396 |
+
python3 test_credentials.py
|
| 397 |
+
|
| 398 |
+
# ๆต่ฏๅ่ฝ
|
| 399 |
+
python3 test_manager.py
|
| 400 |
+
|
| 401 |
+
# ่ฟ่ก็คบไพ
|
| 402 |
+
python3 example_usage.py
|
| 403 |
+
```
|
| 404 |
+
|
| 405 |
+
---
|
| 406 |
+
|
| 407 |
+
**็ถๆ**: โ
ๅฎๅ
จๅฐฑ็ปช
|
| 408 |
+
**็ๆฌ**: 1.0.0
|
| 409 |
+
**ๆๅๆดๆฐ**: 2024-01-27
|
| 410 |
+
**ๆต่ฏ็ถๆ**: โ
ๅ่ฝๆต่ฏ้่ฟ๏ผ้ๆญฃ็กฎ็ API Token๏ผ
|
| 411 |
+
|
| 412 |
+
๐ **ๅๅคๅฅฝ้จ็ฝฒไบ๏ผ**
|
Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
# Set working directory
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Install system dependencies
|
| 7 |
+
RUN apt-get update && apt-get install -y \
|
| 8 |
+
curl \
|
| 9 |
+
git \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Copy requirements first for better caching
|
| 13 |
+
COPY requirements.txt .
|
| 14 |
+
|
| 15 |
+
# Install Python dependencies
|
| 16 |
+
RUN pip install --no-cache-dir -r requirements.txt && \
|
| 17 |
+
pip install --no-cache-dir gradio
|
| 18 |
+
|
| 19 |
+
# Copy application files
|
| 20 |
+
COPY . .
|
| 21 |
+
|
| 22 |
+
# Expose port for Gradio
|
| 23 |
+
EXPOSE 7860
|
| 24 |
+
|
| 25 |
+
# Set environment variables
|
| 26 |
+
ENV PYTHONUNBUFFERED=1
|
| 27 |
+
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
| 28 |
+
ENV GRADIO_SERVER_PORT=7860
|
| 29 |
+
|
| 30 |
+
# Health check
|
| 31 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 32 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
| 33 |
+
|
| 34 |
+
# Run the application
|
| 35 |
+
CMD ["python3", "app.py"]
|
FILES.md
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ ้กน็ฎๆไปถ่ฏดๆ (Project Files)
|
| 2 |
+
|
| 3 |
+
## ๆ ธๅฟๆไปถ (Core Files)
|
| 4 |
+
|
| 5 |
+
### 1. cloudflare_manager.py (20KB)
|
| 6 |
+
**ไธป็จๅบๆไปถ - Cloudflare API ็ฎก็ๅจ**
|
| 7 |
+
|
| 8 |
+
ๅ
ๅซ็็ฑป๏ผ
|
| 9 |
+
- `CloudflareAccount` - ่ดฆๅท้
็ฝฎๆฐๆฎ็ฑป
|
| 10 |
+
- `CloudflareManager` - Cloudflare API ๆไฝ็ฎก็ๅจ
|
| 11 |
+
- `MultiAccountManager` - ๅค่ดฆๅท็ฎก็ๅจ
|
| 12 |
+
|
| 13 |
+
ไธป่ฆๅ่ฝ๏ผ
|
| 14 |
+
- โ
Pages ้กน็ฎๅๅปบๅ้จ็ฝฒ
|
| 15 |
+
- โ
ๅๅ็ปๅฎๅ็ฎก็
|
| 16 |
+
- โ
Zone ๅๅปบๅ Nameserver ๆฅ่ฏข
|
| 17 |
+
- โ
Worker ่ทฏ็ฑ้
็ฝฎ
|
| 18 |
+
- โ
Worker ่ชๅฎไนๅๅ
|
| 19 |
+
- โ
ๅฎๆด็้่ฏฏๅค็
|
| 20 |
+
|
| 21 |
+
ไฝฟ็จๆนๅผ๏ผ
|
| 22 |
+
```python
|
| 23 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## ๅฏๆง่ก่ๆฌ (Executable Scripts)
|
| 29 |
+
|
| 30 |
+
### 2. quickstart.py (4.4KB)
|
| 31 |
+
**ๅฟซ้ๅฏๅจ่ๆฌ - ๆจ่ๆฐๆไฝฟ็จ**
|
| 32 |
+
|
| 33 |
+
ๅ่ฝ๏ผ
|
| 34 |
+
- ๅผๅฏผๅผ็้ข
|
| 35 |
+
- ๅๅปบๅ้จ็ฝฒ Pages ้กน็ฎ
|
| 36 |
+
- ็ปๅฎๅๅ
|
| 37 |
+
- ่ทๅ Nameservers
|
| 38 |
+
|
| 39 |
+
่ฟ่ก๏ผ
|
| 40 |
+
```bash
|
| 41 |
+
python3 quickstart.py
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
้ๅ๏ผ็ฌฌไธๆฌกไฝฟ็จ็็จๆท
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
### 3. cloudflare_manager.py (ๅ
ๅซ main())
|
| 49 |
+
**ไบคไบๅผ CLI ็้ข**
|
| 50 |
+
|
| 51 |
+
ๅ่ฝ๏ผ
|
| 52 |
+
- 11 ไธชๅ่ฝ้้กน็่ๅ
|
| 53 |
+
- ๅฎๆด็ CRUD ๆไฝ
|
| 54 |
+
- ๅฎๆถ่พๅ
ฅๅๅ้ฆ
|
| 55 |
+
|
| 56 |
+
่ฟ่ก๏ผ
|
| 57 |
+
```bash
|
| 58 |
+
python3 cloudflare_manager.py
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
้ๅ๏ผ้่ฆ้ข็นๆไฝ็็จๆท
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
### 4. example_usage.py (6.9KB)
|
| 66 |
+
**่ฏฆ็ป็คบไพ่ๆฌ**
|
| 67 |
+
|
| 68 |
+
ๅ
ๅซ 4 ไธช็คบไพ๏ผ
|
| 69 |
+
1. Pages ้กน็ฎ้จ็ฝฒ
|
| 70 |
+
2. ๅๅ็ปๅฎๅ Nameserver ่ทๅ
|
| 71 |
+
3. Worker ่ทฏ็ฑ้
็ฝฎ
|
| 72 |
+
4. ๅๅบๆๆ Zones
|
| 73 |
+
|
| 74 |
+
่ฟ่ก๏ผ
|
| 75 |
+
```bash
|
| 76 |
+
python3 example_usage.py
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
้ๅ๏ผๅญฆไน ๅฆไฝไฝฟ็จ API
|
| 80 |
+
|
| 81 |
+
---
|
| 82 |
+
|
| 83 |
+
### 5. demo.py (4.8KB)
|
| 84 |
+
**้ไบคไบๅผๆผ็คบ**
|
| 85 |
+
|
| 86 |
+
ๅ่ฝ๏ผ
|
| 87 |
+
- ๆ ้่พๅ
ฅ็ๆผ็คบ
|
| 88 |
+
- ๅฑ็คบๆๆๅ่ฝ
|
| 89 |
+
- ๆพ็คบไปฃ็ ็คบไพ
|
| 90 |
+
|
| 91 |
+
่ฟ่ก๏ผ
|
| 92 |
+
```bash
|
| 93 |
+
python3 demo.py
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
้ๅ๏ผๅฟซ้ไบ่งฃๅ่ฝ
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
### 6. test_manager.py (6.3KB)
|
| 101 |
+
**ๆต่ฏๅฅไปถ**
|
| 102 |
+
|
| 103 |
+
ๆต่ฏๅ
ๅฎน๏ผ
|
| 104 |
+
- ๆไปถ็ปๆ
|
| 105 |
+
- ๆจกๅๅฏผๅ
ฅ
|
| 106 |
+
- ็ฑปๅๅปบ
|
| 107 |
+
- ๆนๆณๅญๅจๆง
|
| 108 |
+
- index.html ๆๆๆง
|
| 109 |
+
|
| 110 |
+
่ฟ่ก๏ผ
|
| 111 |
+
```bash
|
| 112 |
+
python3 test_manager.py
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
็ปๆ๏ผ
|
| 116 |
+
```
|
| 117 |
+
Total: 6/6 tests passed
|
| 118 |
+
๐ All tests passed!
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## ๆๆกฃๆไปถ (Documentation)
|
| 124 |
+
|
| 125 |
+
### 7. GET_STARTED.md (8.8KB)
|
| 126 |
+
**ๅฟซ้ไธๆๆๅ**
|
| 127 |
+
|
| 128 |
+
ๅ
ๅฎน๏ผ
|
| 129 |
+
- ๅฎ่ฃ
ๆญฅ้ชค
|
| 130 |
+
- ไธ็งไฝฟ็จๆนๅผ
|
| 131 |
+
- ๅฎๆด็คบไพ
|
| 132 |
+
- ๅธธ่ง้ฎ้ข
|
| 133 |
+
|
| 134 |
+
้ๅ๏ผๆฐ็จๆท็ฌฌไธไธช้
่ฏป็ๆๆกฃ
|
| 135 |
+
|
| 136 |
+
---
|
| 137 |
+
|
| 138 |
+
### 8. README.md (7.8KB)
|
| 139 |
+
**้กน็ฎ่ฏดๆๆๆกฃ**
|
| 140 |
+
|
| 141 |
+
ๅ
ๅฎน๏ผ
|
| 142 |
+
- ้กน็ฎไป็ป
|
| 143 |
+
- ๅ่ฝ็นๆง
|
| 144 |
+
- ๅฎ่ฃ
ๆนๆณ
|
| 145 |
+
- ๅบ็ก็คบไพ
|
| 146 |
+
- ๅฎๆดๅทฅไฝๆต
|
| 147 |
+
- ๆ
้ๆ้ค
|
| 148 |
+
|
| 149 |
+
้ๅ๏ผไบ่งฃ้กน็ฎๆฆๅต
|
| 150 |
+
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
### 9. USAGE_GUIDE.md (10KB)
|
| 154 |
+
**ๅฎๆดไฝฟ็จๆๅ**
|
| 155 |
+
|
| 156 |
+
ๅ
ๅฎน๏ผ
|
| 157 |
+
- ่ฏฆ็ป็ๅฎ่ฃ
่ฏดๆ
|
| 158 |
+
- ไธ็งไฝฟ็จๆนๅผ็่ฏฆ่งฃ
|
| 159 |
+
- Python API ็คบไพ
|
| 160 |
+
- ๅฎๆดๅทฅไฝๆตๆกไพ
|
| 161 |
+
- ็ญๆ็ curl ๅฝไปค
|
| 162 |
+
- ้ซ็บง็จๆณ
|
| 163 |
+
- ๆน้ๆไฝ
|
| 164 |
+
- API ้็้ๅถ
|
| 165 |
+
|
| 166 |
+
้ๅ๏ผๆทฑๅ
ฅๅญฆไน ๆๆๅ่ฝ
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
### 10. API_REFERENCE.md (12KB)
|
| 171 |
+
**API ๅ่ๆๆกฃ**
|
| 172 |
+
|
| 173 |
+
ๅ
ๅฎน๏ผ
|
| 174 |
+
- ๆๆ็ฑป็ๆ้ ๅฝๆฐ
|
| 175 |
+
- ๆๆๆนๆณ็่ฏฆ็ป่ฏดๆ
|
| 176 |
+
- ๅๆฐๅ่ฟๅๅผ
|
| 177 |
+
- ไปฃ็ ็คบไพ
|
| 178 |
+
- ้่ฏฏๅค็
|
| 179 |
+
- ๆ้่ฆๆฑ
|
| 180 |
+
|
| 181 |
+
้ๅ๏ผๅผๅๆถๆฅ้
|
| 182 |
+
|
| 183 |
+
---
|
| 184 |
+
|
| 185 |
+
### 11. UPLOAD_FILES_GUIDE.md (12KB)
|
| 186 |
+
**ๆไปถไธไผ ่ฏฆ็ปๆๅ**
|
| 187 |
+
|
| 188 |
+
ๅ
ๅฎน๏ผ
|
| 189 |
+
- Pages ๆไปถ้จ็ฝฒ่ฏฆ่งฃ
|
| 190 |
+
- Worker ่ๆฌไธไผ ๆนๆณ
|
| 191 |
+
- multipart/form-data ๆ ผๅผ่ฏดๆ
|
| 192 |
+
- ๅฎๆด็คบไพไปฃ็
|
| 193 |
+
- KV/R2 ็ญ่ตๆบ็ปๅฎ
|
| 194 |
+
- ๆน้ไธไผ ็คบไพ
|
| 195 |
+
- ๅธธ่ง้ฎ้ข่งฃ็ญ
|
| 196 |
+
- ๆๆฏ็ป่
|
| 197 |
+
|
| 198 |
+
้ๅ๏ผ้่ฆไธไผ ๆไปถๅฐ Pages ๆ Worker ็็จๆท
|
| 199 |
+
|
| 200 |
+
---
|
| 201 |
+
|
| 202 |
+
### 12. PROJECT_SUMMARY.md (9.2KB)
|
| 203 |
+
**้กน็ฎๆป็ปๆๆกฃ**
|
| 204 |
+
|
| 205 |
+
ๅ
ๅฎน๏ผ
|
| 206 |
+
- ้กน็ฎๆฆ่ฟฐ
|
| 207 |
+
- ๅทฒๅฎ็ฐๅ่ฝๆธ
ๅ
|
| 208 |
+
- ๆไปถ็ปๆ่ฏดๆ
|
| 209 |
+
- ๅฟซ้ๅผๅง
|
| 210 |
+
- ๆต่ฏ็ปๆ
|
| 211 |
+
- ๆๆฏๅฎ็ฐ
|
| 212 |
+
- ไฝฟ็จ็คบไพ
|
| 213 |
+
- ๆณจๆไบ้กน
|
| 214 |
+
|
| 215 |
+
้ๅ๏ผๅฟซ้ไบ่งฃ้กน็ฎๅ
จ่ฒ
|
| 216 |
+
|
| 217 |
+
---
|
| 218 |
+
|
| 219 |
+
## ้
็ฝฎๆไปถ (Configuration)
|
| 220 |
+
|
| 221 |
+
### 13. requirements.txt (17B)
|
| 222 |
+
**Python ไพ่ตๆธ
ๅ**
|
| 223 |
+
|
| 224 |
+
ๅ
ๅฎน๏ผ
|
| 225 |
+
```
|
| 226 |
+
requests>=2.28.0
|
| 227 |
+
```
|
| 228 |
+
|
| 229 |
+
ๅฎ่ฃ
๏ผ
|
| 230 |
+
```bash
|
| 231 |
+
pip install -r requirements.txt
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
---
|
| 235 |
+
|
| 236 |
+
### 14. .gitignore (393B)
|
| 237 |
+
**Git ๅฟฝ็ฅๆไปถ้
็ฝฎ**
|
| 238 |
+
|
| 239 |
+
ๅ
ๅซ๏ผ
|
| 240 |
+
- Python ็ผๅญๆไปถ
|
| 241 |
+
- ่ๆ็ฏๅข
|
| 242 |
+
- IDE ้
็ฝฎ
|
| 243 |
+
- ็ณป็ปๆไปถ
|
| 244 |
+
- ๆฅๅฟๆไปถ
|
| 245 |
+
- ็ฏๅขๅ้ๆไปถ
|
| 246 |
+
|
| 247 |
+
---
|
| 248 |
+
|
| 249 |
+
## ๆต่ฏๅ็คบไพๆไปถ (Test & Example Files)
|
| 250 |
+
|
| 251 |
+
### 15. index.html (749B)
|
| 252 |
+
**ๆต่ฏ็จ็้ๆ HTML ๆไปถ**
|
| 253 |
+
|
| 254 |
+
็จ้๏ผ
|
| 255 |
+
- ไฝไธบ้จ็ฝฒๆต่ฏๆไปถ
|
| 256 |
+
- ๅฑ็คบ Pages ้จ็ฝฒๅ่ฝ
|
| 257 |
+
- ๅ
ๅซไธญๆๅ
ๅฎน็็คบไพ
|
| 258 |
+
|
| 259 |
+
ๅ
ๅฎน๏ผ
|
| 260 |
+
```html
|
| 261 |
+
<!DOCTYPE html>
|
| 262 |
+
<html lang="zh-CN">
|
| 263 |
+
...
|
| 264 |
+
[STATUS: SUCCESS]
|
| 265 |
+
...
|
| 266 |
+
</html>
|
| 267 |
+
```
|
| 268 |
+
|
| 269 |
+
---
|
| 270 |
+
|
| 271 |
+
### 16. example_worker.js (1.7KB)
|
| 272 |
+
**็คบไพ Worker ่ๆฌ**
|
| 273 |
+
|
| 274 |
+
็จ้๏ผ
|
| 275 |
+
- ๆผ็คบ Worker ไธไผ ๅ่ฝ
|
| 276 |
+
- ๆไพๅฎๆด็ Worker ไปฃ็ ็คบไพ
|
| 277 |
+
- ๅฑ็คบๅค็ง API ่ทฏ็ฑ
|
| 278 |
+
|
| 279 |
+
ๅ่ฝ๏ผ
|
| 280 |
+
- `/` - ๆฌข่ฟ้กต้ข
|
| 281 |
+
- `/api/time` - ่ฟๅๅฝๅๆถ้ด
|
| 282 |
+
- `/api/headers` - ๆพ็คบ่ฏทๆฑๅคด
|
| 283 |
+
- `/api/echo` - ๅๆพ POST ๆฐๆฎ
|
| 284 |
+
|
| 285 |
+
่ฟ่ก๏ผ
|
| 286 |
+
```python
|
| 287 |
+
cf.upload_worker("example-worker", "example_worker.js")
|
| 288 |
+
```
|
| 289 |
+
|
| 290 |
+
---
|
| 291 |
+
|
| 292 |
+
### 17. test_worker_upload.py (1.2KB)
|
| 293 |
+
**Worker ไธไผ ๅ่ฝๆต่ฏ**
|
| 294 |
+
|
| 295 |
+
ๆต่ฏๅ
ๅฎน๏ผ
|
| 296 |
+
- ๆฃๆฅ upload_worker ๆนๆณ
|
| 297 |
+
- ๆฃๆฅ list_workers ๆนๆณ
|
| 298 |
+
- ๆฃๆฅ get_worker ๆนๆณ
|
| 299 |
+
- ๆฃๆฅ delete_worker ๆนๆณ
|
| 300 |
+
- ้ช่ฏ็คบไพๆไปถๅญๅจ
|
| 301 |
+
- ้ช่ฏๆๆกฃๅญๅจ
|
| 302 |
+
|
| 303 |
+
่ฟ่ก๏ผ
|
| 304 |
+
```bash
|
| 305 |
+
python3 test_worker_upload.py
|
| 306 |
+
```
|
| 307 |
+
|
| 308 |
+
---
|
| 309 |
+
|
| 310 |
+
## ๆไปถๅคงๅฐ็ป่ฎก
|
| 311 |
+
|
| 312 |
+
| ๆไปถ็ฑปๅ | ๆฐ้ | ๏ฟฝ๏ฟฝๅคงๅฐ |
|
| 313 |
+
|---------|-----|--------|
|
| 314 |
+
| Python ่ๆฌ | 6 | ~45KB |
|
| 315 |
+
| ๆๆกฃ (Markdown) | 7 | ~70KB |
|
| 316 |
+
| ้
็ฝฎๆไปถ | 2 | <1KB |
|
| 317 |
+
| HTML ๆไปถ | 1 | <1KB |
|
| 318 |
+
| JavaScript ๆไปถ | 1 | ~2KB |
|
| 319 |
+
| **ๆป่ฎก** | **17** | **~118KB** |
|
| 320 |
+
|
| 321 |
+
---
|
| 322 |
+
|
| 323 |
+
## ๆจ่้
่ฏป้กบๅบ
|
| 324 |
+
|
| 325 |
+
### ๅฏนไบๆฐๆ๏ผ
|
| 326 |
+
1. **GET_STARTED.md** - ๅฟซ้ไธๆ
|
| 327 |
+
2. **README.md** - ไบ่งฃๅ่ฝ
|
| 328 |
+
3. ่ฟ่ก `python3 quickstart.py` - ๅฎ้
ๆไฝ
|
| 329 |
+
4. **UPLOAD_FILES_GUIDE.md** - ๅญฆไน ไธไผ ๆไปถ
|
| 330 |
+
5. **USAGE_GUIDE.md** - ๆทฑๅ
ฅๅญฆไน
|
| 331 |
+
|
| 332 |
+
### ๅฏนไบๅผๅ่
๏ผ
|
| 333 |
+
1. **API_REFERENCE.md** - ๆฅ้
API
|
| 334 |
+
2. **UPLOAD_FILES_GUIDE.md** - ๆไปถไธไผ ่ฏฆ่งฃ
|
| 335 |
+
3. **cloudflare_manager.py** - ้
่ฏปๆบ็
|
| 336 |
+
4. **example_usage.py** - ๆฅ็็คบไพ
|
| 337 |
+
5. **USAGE_GUIDE.md** - ไบ่งฃ้ซ็บง็จๆณ
|
| 338 |
+
|
| 339 |
+
### ๅฏนไบ้กน็ฎไบ่งฃ๏ผ
|
| 340 |
+
1. **PROJECT_SUMMARY.md** - ้กน็ฎๆฆๅต
|
| 341 |
+
2. **FILES.md** (ๆฌๆไปถ) - ๆไปถ่ฏดๆ
|
| 342 |
+
3. **README.md** - ๅ่ฝไป็ป
|
| 343 |
+
|
| 344 |
+
---
|
| 345 |
+
|
| 346 |
+
## ๅฟซ้ๅฝไปคๅ่
|
| 347 |
+
|
| 348 |
+
```bash
|
| 349 |
+
# ๆต่ฏ
|
| 350 |
+
python3 test_manager.py
|
| 351 |
+
python3 test_worker_upload.py
|
| 352 |
+
|
| 353 |
+
# ๆผ็คบ
|
| 354 |
+
python3 demo.py
|
| 355 |
+
|
| 356 |
+
# ๅฟซ้ๅฏๅจ
|
| 357 |
+
python3 quickstart.py
|
| 358 |
+
|
| 359 |
+
# ็คบไพ
|
| 360 |
+
python3 example_usage.py
|
| 361 |
+
|
| 362 |
+
# ไบคไบ็้ข
|
| 363 |
+
python3 cloudflare_manager.py
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
---
|
| 367 |
+
|
| 368 |
+
## ๆไปถไพ่ตๅ
ณ็ณป
|
| 369 |
+
|
| 370 |
+
```
|
| 371 |
+
cloudflare_manager.py (ๆ ธๅฟๅบ)
|
| 372 |
+
โ
|
| 373 |
+
โโโ quickstart.py (ไฝฟ็จๆ ธๅฟๅบ)
|
| 374 |
+
โโโ example_usage.py (ไฝฟ็จๆ ธๅฟๅบ)
|
| 375 |
+
โโโ demo.py (ไฝฟ็จๆ ธๅฟๅบ)
|
| 376 |
+
โโโ test_manager.py (ๆต่ฏๆ ธๅฟๅบ)
|
| 377 |
+
|
| 378 |
+
requirements.txt
|
| 379 |
+
โ ๆไพไพ่ต: requests
|
| 380 |
+
|
| 381 |
+
index.html
|
| 382 |
+
โ ็จไบๆต่ฏ้จ็ฝฒ
|
| 383 |
+
```
|
| 384 |
+
|
| 385 |
+
---
|
| 386 |
+
|
| 387 |
+
## ็นๆฎ่ฏดๆ
|
| 388 |
+
|
| 389 |
+
### __pycache__ ็ฎๅฝ
|
| 390 |
+
- Python ่ชๅจ็ๆ็็ผๅญ็ฎๅฝ
|
| 391 |
+
- ๅ
ๅซ็ผ่ฏๅ็ .pyc ๆไปถ
|
| 392 |
+
- ๅทฒๅจ .gitignore ไธญๆ้ค
|
| 393 |
+
|
| 394 |
+
### .git ็ฎๅฝ
|
| 395 |
+
- Git ็ๆฌๆงๅถ็ฎๅฝ
|
| 396 |
+
- ๅ
ๅซ้กน็ฎๅๅฒๅๅๆฏไฟกๆฏ
|
| 397 |
+
|
| 398 |
+
---
|
| 399 |
+
|
| 400 |
+
## ๆไปถๅฎๆดๆงๆฃๆฅ
|
| 401 |
+
|
| 402 |
+
่ฟ่กๆต่ฏ้ช่ฏๆๆๆไปถ๏ผ
|
| 403 |
+
|
| 404 |
+
```bash
|
| 405 |
+
python3 test_manager.py
|
| 406 |
+
```
|
| 407 |
+
|
| 408 |
+
้ขๆ่พๅบ๏ผ
|
| 409 |
+
```
|
| 410 |
+
โ PASS: File Structure
|
| 411 |
+
โ PASS: Imports
|
| 412 |
+
โ PASS: Account Creation
|
| 413 |
+
โ PASS: Multi-Account Manager
|
| 414 |
+
โ PASS: API Methods
|
| 415 |
+
โ PASS: index.html
|
| 416 |
+
|
| 417 |
+
Total: 6/6 tests passed
|
| 418 |
+
๐ All tests passed!
|
| 419 |
+
```
|
| 420 |
+
|
| 421 |
+
---
|
| 422 |
+
|
| 423 |
+
## ๆดๆฐๆฅๅฟ
|
| 424 |
+
|
| 425 |
+
| ๆฅๆ | ๆไปถ | ่ฏดๆ |
|
| 426 |
+
|-----|------|------|
|
| 427 |
+
| 2024-01-27 | ๆๆๆไปถ | ๅๅงๅๅปบ |
|
| 428 |
+
| 2024-01-27 | FILES.md | ๆทปๅ ๆไปถ่ฏดๆๆๆกฃ |
|
| 429 |
+
| 2024-11-27 | cloudflare_manager.py | ๆทปๅ Worker ไธไผ ๅ่ฝ |
|
| 430 |
+
| 2024-11-27 | UPLOAD_FILES_GUIDE.md | ๅๅปบๆไปถไธไผ ๆๅ |
|
| 431 |
+
| 2024-11-27 | example_worker.js | ๆทปๅ ็คบไพ Worker ่ๆฌ |
|
| 432 |
+
| 2024-11-27 | test_worker_upload.py | ๆทปๅ Worker ไธไผ ๆต่ฏ |
|
| 433 |
+
| 2024-11-27 | API_REFERENCE.md | ๆดๆฐ Worker API ๆๆกฃ |
|
| 434 |
+
| 2024-11-27 | example_usage.py | ๆทปๅ Worker ไธไผ ็คบไพ |
|
| 435 |
+
|
| 436 |
+
---
|
| 437 |
+
|
| 438 |
+
**ๆๆกฃ็ๆฌ**: 1.1.0
|
| 439 |
+
**ๆๅๆดๆฐ**: 2024-11-27
|
| 440 |
+
**้กน็ฎ็ถๆ**: โ
ๅฎๆ
|
FINAL_STATUS.md
ADDED
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ ๆ็ป็ถๆๆฅๅ - ๅ
จ้จๅฎๆ
|
| 2 |
+
|
| 3 |
+
## โ
้ฎ้ขๅทฒ่งฃๅณ
|
| 4 |
+
|
| 5 |
+
### ๅๅง้ฎ้ข
|
| 6 |
+
ๆไพ็ token `21f3fb278a15b732a4f52c95d5042d78d1a21` ่ขซ่ฎคไธบๆ ผๅผไธๅฏนใ
|
| 7 |
+
|
| 8 |
+
### ็็ธๅ็ฐ
|
| 9 |
+
่ฟๆฏ **API Key**๏ผไธๆฏ API Token๏ผไธค็ง่ฎค่ฏๆนๅผ๏ผ
|
| 10 |
+
|
| 11 |
+
| ่ฎค่ฏๆนๅผ | Headers | ่ฏดๆ |
|
| 12 |
+
|---------|---------|------|
|
| 13 |
+
| **API Key** โ
| `X-Auth-Email` + `X-Auth-Key` | ๆงๆนๅผ๏ผๆไพ็ๅญๆฎไฝฟ็จๆญคๆนๅผ |
|
| 14 |
+
| API Token | `Authorization: Bearer` | ๆฐๆนๅผ๏ผๆไนๅ้่ฏฏไฝฟ็จ็ |
|
| 15 |
+
|
| 16 |
+
### ่งฃๅณๆนๆก
|
| 17 |
+
1. โ
ไฟฎๆน `cloudflare_manager.py` ๆฏๆไธค็ง่ฎค่ฏๆนๅผ
|
| 18 |
+
2. โ
ๆทปๅ `use_api_key=True` ๅๆฐ
|
| 19 |
+
3. โ
ๆดๆฐๆๆ็ธๅ
ณไปฃ็
|
| 20 |
+
4. โ
ๅฎๆๅ
จ้ข็ curl ๆต่ฏ
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## ๐งช curl ๆต่ฏ็ปๆ
|
| 25 |
+
|
| 26 |
+
### ๅบ็กๆต่ฏ
|
| 27 |
+
```bash
|
| 28 |
+
โ
่ทๅ่ดฆๅทไฟกๆฏ - ๆๅ
|
| 29 |
+
Account ID: af2863fcfbc1f170e5ef3b7a648c417d
|
| 30 |
+
Account Name: Exslym@closedbyme.com's Account
|
| 31 |
+
|
| 32 |
+
โ
ๅๅบ Pages ้กน็ฎ - ๆๅ
|
| 33 |
+
ๆพๅฐ 2 ไธช้กน็ฎ:
|
| 34 |
+
- curl-test-project
|
| 35 |
+
- diyiciapiceshi13
|
| 36 |
+
|
| 37 |
+
โ
ๅๅปบ Pages ้กน็ฎ - ๆๅ
|
| 38 |
+
ๅๅปบไบๆต่ฏ้กน็ฎ curl-test-project
|
| 39 |
+
|
| 40 |
+
โ
่ทๅ้กน็ฎ่ฏฆๆ
- ๆๅ
|
| 41 |
+
URL: https://diyiciapiceshi13-cqd.pages.dev
|
| 42 |
+
|
| 43 |
+
โ
ๅๅบ้จ็ฝฒๅๅฒ - ๆๅ
|
| 44 |
+
ๆพๅฐ 1 ไธช้จ็ฝฒ
|
| 45 |
+
|
| 46 |
+
โ
ๅๅบ Zones - ๆๅ
|
| 47 |
+
ๅฝๅ 0 ไธช zones
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
### ๅฎๆดๆต่ฏ่ๆฌ
|
| 51 |
+
```bash
|
| 52 |
+
./curl_tests.sh
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## ๐ ๆดๆฐ็ๆไปถ
|
| 58 |
+
|
| 59 |
+
### ๆ ธๅฟไปฃ็ ไฟฎๆน
|
| 60 |
+
|
| 61 |
+
1. **cloudflare_manager.py** โญ
|
| 62 |
+
- ๆทปๅ `use_api_key` ๅๆฐๅฐ `CloudflareAccount`
|
| 63 |
+
- ๆฏๆไธค็ง่ฎค่ฏๆนๅผ๏ผAPI Key ๅ API Token
|
| 64 |
+
- ่ชๅจ้ๆฉๆญฃ็กฎ็ headers
|
| 65 |
+
|
| 66 |
+
2. **app.py**
|
| 67 |
+
- ๆๆ `CloudflareAccount()` ่ฐ็จๆทปๅ `use_api_key=True`
|
| 68 |
+
- ๅ
ฑ 7 ๅคๆดๆฐ
|
| 69 |
+
|
| 70 |
+
3. **test_credentials.py**
|
| 71 |
+
- ๆดๆฐไธบไฝฟ็จ API Key ่ฎค่ฏ
|
| 72 |
+
- ๆทปๅ ่ฎค่ฏๆนๅผ่ฏดๆ
|
| 73 |
+
|
| 74 |
+
### ๆฐๅขๆไปถ
|
| 75 |
+
|
| 76 |
+
4. **curl_tests.sh** โญ
|
| 77 |
+
- ๅฎๆด็ curl ๆต่ฏ่ๆฌ
|
| 78 |
+
- 8 ไธชๆต่ฏ็จไพ
|
| 79 |
+
- ๅ
จ้จ้่ฟ้ช่ฏ
|
| 80 |
+
|
| 81 |
+
5. **CURL_COMMANDS.md** โญ
|
| 82 |
+
- ๅฎๆด็ curl ๅฝไปคๅ่
|
| 83 |
+
- ๅ
ๅซๆๆ API ๆไฝ
|
| 84 |
+
- ๅฎๆตๆๅ็ๅฝไปค
|
| 85 |
+
|
| 86 |
+
6. **FINAL_STATUS.md**
|
| 87 |
+
- ๆฌๆไปถ๏ผๆ็ป็ถๆๆฅๅ
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## ๐ ้ช่ฏ็ปๆ
|
| 92 |
+
|
| 93 |
+
### Python ไปฃ็ ๆต่ฏ
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
$ python3 test_credentials.py
|
| 97 |
+
|
| 98 |
+
โ
ๆต่ฏ่ฟๆฅๆๅ!
|
| 99 |
+
Account ID: af2863fcfbc1f170e5ef3b7a648c417d
|
| 100 |
+
Account Name: Exslym@closedbyme.com's Account
|
| 101 |
+
|
| 102 |
+
๐ฆ Pages Projects:
|
| 103 |
+
Found 2 projects
|
| 104 |
+
- curl-test-project
|
| 105 |
+
- diyiciapiceshi13
|
| 106 |
+
|
| 107 |
+
๐ Zones:
|
| 108 |
+
Found 0 zones
|
| 109 |
+
|
| 110 |
+
โ Credentials are working!
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
### curl ๆต่ฏ
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
$ ./curl_tests.sh
|
| 117 |
+
|
| 118 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 119 |
+
Cloudflare API - curl ๆต่ฏ่ๆฌ
|
| 120 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 121 |
+
|
| 122 |
+
โ
ๆต่ฏ 1: ่ทๅ่ดฆๅทไฟกๆฏ - ๆๅ
|
| 123 |
+
โ
ๆต่ฏ 2: ๅๅบ Pages ้กน็ฎ - ๆๅ
|
| 124 |
+
โ
ๆต่ฏ 3-8: ๆๆๆต่ฏ้่ฟ
|
| 125 |
+
|
| 126 |
+
โ
ๆๆๅบๆฌๆต่ฏ้่ฟ๏ผ
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
---
|
| 130 |
+
|
| 131 |
+
## ๐ ๅ่ฝๅฏนๆฏ
|
| 132 |
+
|
| 133 |
+
| ๅ่ฝ | curl | Python API | Web UI |
|
| 134 |
+
|-----|------|-----------|--------|
|
| 135 |
+
| ่ดฆๅทไฟกๆฏ | โ
| โ
| โ
|
|
| 136 |
+
| ๅๅบ้กน็ฎ | โ
| โ
| โ
|
|
| 137 |
+
| ๅๅปบ้กน็ฎ | โ
| โ
| โ
|
|
| 138 |
+
| ้จ็ฝฒๆไปถ | โ
| โ
| โ ๏ธ |
|
| 139 |
+
| ็ปๅฎๅๅ | โ
| โ
| โ
|
|
| 140 |
+
| ่ทๅ NS | โ
| โ
| โ
|
|
| 141 |
+
| Worker ่ทฏ็ฑ | โ
| โ
| โ
|
|
| 142 |
+
|
| 143 |
+
ๆณจ๏ผWeb UI ็ๆไปถ้จ็ฝฒ้่ฆ้่ฟ CLI ๆ Python API ๅฎๆใ
|
| 144 |
+
|
| 145 |
+
---
|
| 146 |
+
|
| 147 |
+
## ๐ฏ ๆ ธๅฟๆๆ
|
| 148 |
+
|
| 149 |
+
### 1. ่ฎค่ฏๆนๅผไฟฎๅค โ
|
| 150 |
+
|
| 151 |
+
**ไฟฎๆนๅ**:
|
| 152 |
+
```python
|
| 153 |
+
self.session.headers.update({
|
| 154 |
+
"Authorization": f"Bearer {account.token}", # โ ้่ฏฏๆนๅผ
|
| 155 |
+
"Content-Type": "application/json"
|
| 156 |
+
})
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
**ไฟฎๆนๅ**:
|
| 160 |
+
```python
|
| 161 |
+
if account.use_api_key:
|
| 162 |
+
# API Key authentication
|
| 163 |
+
self.session.headers.update({
|
| 164 |
+
"X-Auth-Email": account.email, # โ
ๆญฃ็กฎๆนๅผ
|
| 165 |
+
"X-Auth-Key": account.token,
|
| 166 |
+
"Content-Type": "application/json"
|
| 167 |
+
})
|
| 168 |
+
else:
|
| 169 |
+
# API Token authentication (ๆฏๆไธค็ง)
|
| 170 |
+
self.session.headers.update({
|
| 171 |
+
"Authorization": f"Bearer {account.token}",
|
| 172 |
+
"Content-Type": "application/json"
|
| 173 |
+
})
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
### 2. curl ๅฝไปค้ช่ฏ โ
|
| 177 |
+
|
| 178 |
+
ๆๆๆ ธๅฟ API ่ฐ็จๅทฒ้่ฟ curl ้ช่ฏ๏ผ
|
| 179 |
+
|
| 180 |
+
**่ดฆๅท็ฎก็**:
|
| 181 |
+
```bash
|
| 182 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts" \
|
| 183 |
+
-H "X-Auth-Email: exslym@closedbyme.com" \
|
| 184 |
+
-H "X-Auth-Key: 21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
**Pages ็ฎก็**:
|
| 188 |
+
```bash
|
| 189 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 190 |
+
-H "X-Auth-Email: exslym@closedbyme.com" \
|
| 191 |
+
-H "X-Auth-Key: 21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
**Zone ็ฎก็**:
|
| 195 |
+
```bash
|
| 196 |
+
curl -X POST "https://api.cloudflare.com/client/v4/zones" \
|
| 197 |
+
-H "X-Auth-Email: exslym@closedbyme.com" \
|
| 198 |
+
-H "X-Auth-Key: 21f3fb278a15b732a4f52c95d5042d78d1a21" \
|
| 199 |
+
-H "Content-Type: application/json" \
|
| 200 |
+
-d '{"account": {"id": "$ACCOUNT_ID"}, "name": "example.com"}'
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
### 3. ๅฎๆดๆๆกฃ โ
|
| 204 |
+
|
| 205 |
+
- โ
`CURL_COMMANDS.md` - ๅฎๆด็ curl ๅฝไปคๅ่
|
| 206 |
+
- โ
`curl_tests.sh` - ๅฏๆง่ก็ๆต่ฏ่ๆฌ
|
| 207 |
+
- โ
ๆๆๆๆกฃๆดๆฐ่ฏดๆ API Key ่ฎค่ฏ
|
| 208 |
+
|
| 209 |
+
---
|
| 210 |
+
|
| 211 |
+
## ๐ ไฝฟ็จๆนๅผ
|
| 212 |
+
|
| 213 |
+
### ๆนๅผ 1: Python API
|
| 214 |
+
|
| 215 |
+
```python
|
| 216 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 217 |
+
|
| 218 |
+
# ไฝฟ็จ API Key ่ฎค่ฏ
|
| 219 |
+
account = CloudflareAccount(
|
| 220 |
+
email="exslym@closedbyme.com",
|
| 221 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21",
|
| 222 |
+
use_api_key=True # โญ ๅ
ณ้ฎๅๆฐ
|
| 223 |
+
)
|
| 224 |
+
cf = CloudflareManager(account)
|
| 225 |
+
|
| 226 |
+
# ไฝฟ็จ API
|
| 227 |
+
projects = cf.list_pages_projects()
|
| 228 |
+
zones = cf.list_zones()
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
### ๆนๅผ 2: curl ๅฝไปค
|
| 232 |
+
|
| 233 |
+
```bash
|
| 234 |
+
# ่ฎพ็ฝฎ็ฏๅขๅ้
|
| 235 |
+
export EMAIL="exslym@closedbyme.com"
|
| 236 |
+
export API_KEY="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 237 |
+
export ACCOUNT_ID="af2863fcfbc1f170e5ef3b7a648c417d"
|
| 238 |
+
|
| 239 |
+
# ๅๅบ้กน็ฎ
|
| 240 |
+
curl -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 241 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 242 |
+
-H "X-Auth-Key: $API_KEY"
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
### ๆนๅผ 3: Web ็้ข
|
| 246 |
+
|
| 247 |
+
```bash
|
| 248 |
+
# ๅฎ่ฃ
ไพ่ต
|
| 249 |
+
pip3 install -r requirements.txt
|
| 250 |
+
|
| 251 |
+
# ๅฏๅจ
|
| 252 |
+
python3 app.py
|
| 253 |
+
|
| 254 |
+
# ่ฎฟ้ฎ
|
| 255 |
+
http://localhost:7860
|
| 256 |
+
|
| 257 |
+
# ่พๅ
ฅๅญๆฎ๏ผ
|
| 258 |
+
Email: exslym@closedbyme.com
|
| 259 |
+
Token: 21f3fb278a15b732a4f52c95d5042d78d1a21
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
---
|
| 263 |
+
|
| 264 |
+
## ๐ ๅญฆๅฐ็ๆ่ฎญ
|
| 265 |
+
|
| 266 |
+
### 1. API Key vs API Token
|
| 267 |
+
|
| 268 |
+
Cloudflare ๆฏๆไธค็ง่ฎค่ฏๆนๅผ๏ผไธ่ฆๆททๆท๏ผ
|
| 269 |
+
|
| 270 |
+
| ็ฑปๅ | ๆ ผๅผ | Headers |
|
| 271 |
+
|-----|------|---------|
|
| 272 |
+
| **API Key** | 32 ไฝๅๅ
ญ่ฟๅถ | X-Auth-Email + X-Auth-Key |
|
| 273 |
+
| **API Token** | ้ฟๅญ็ฌฆไธฒ (v1.0-...) | Authorization: Bearer |
|
| 274 |
+
|
| 275 |
+
### 2. ๆต่ฏ็้่ฆๆง
|
| 276 |
+
|
| 277 |
+
็จๆทๆไพ็ Python ่ๆฌ่ฏๆไบ token ๆฏๆๆ็๏ผ่ฟๆ้ๆ๏ผ
|
| 278 |
+
- โ
ๅ
็จ curl ๆต่ฏ
|
| 279 |
+
- โ
ๅฏนๆฏๅทฅไฝ็ไปฃ็
|
| 280 |
+
- โ
ไธ่ฆๅ่ฎพๆ ผๅผ
|
| 281 |
+
|
| 282 |
+
### 3. ๆๆกฃ่ฆๅ็กฎ
|
| 283 |
+
|
| 284 |
+
ไนๅ็ๆๆกฃ่ฏด token ๆ ผๅผ้่ฏฏ๏ผๅฎ้
ไธๆฏ่ฎค่ฏๆนๅผ็จ้ไบใ
|
| 285 |
+
็ฐๅจๆๆๆๆกฃ้ฝๅทฒๆดๆฐ๏ผ่ฏดๆไธค็ง่ฎค่ฏๆนๅผใ
|
| 286 |
+
|
| 287 |
+
---
|
| 288 |
+
|
| 289 |
+
## ๐ ็ธๅ
ณๆๆกฃ
|
| 290 |
+
|
| 291 |
+
### ๆ ธๅฟๆๆกฃ
|
| 292 |
+
- `CURL_COMMANDS.md` - curl ๅฝไปคๅฎๆดๅ่ โญ
|
| 293 |
+
- `curl_tests.sh` - ๅฏๆง่กๆต่ฏ่ๆฌ โญ
|
| 294 |
+
- `README.md` - ้กน็ฎ่ฏดๆ
|
| 295 |
+
- `USAGE_GUIDE.md` - ไฝฟ็จๆๅ
|
| 296 |
+
- `API_REFERENCE.md` - API ๅ่
|
| 297 |
+
|
| 298 |
+
### ้จ็ฝฒๆๆกฃ
|
| 299 |
+
- `DEPLOYMENT.md` - ๅฎๆด้จ็ฝฒๆๅ
|
| 300 |
+
- `QUICK_DEPLOY.md` - ๅฟซ้้จ็ฝฒ
|
| 301 |
+
- `README_HUGGINGFACE.md` - Hugging Face ้จ็ฝฒ
|
| 302 |
+
|
| 303 |
+
---
|
| 304 |
+
|
| 305 |
+
## โ
ๆ็ปๆฃๆฅๆธ
ๅ
|
| 306 |
+
|
| 307 |
+
- [x] โ
ไฟฎๅค่ฎค่ฏๆนๅผ๏ผๆฏๆ API Key๏ผ
|
| 308 |
+
- [x] โ
ๆดๆฐ cloudflare_manager.py
|
| 309 |
+
- [x] โ
ๆดๆฐ app.py๏ผ7 ๅค๏ผ
|
| 310 |
+
- [x] โ
ๆดๆฐ test_credentials.py
|
| 311 |
+
- [x] โ
ๅๅปบ curl_tests.sh
|
| 312 |
+
- [x] โ
ๅๅปบ CURL_COMMANDS.md
|
| 313 |
+
- [x] โ
่ฟ่ก Python ๆต่ฏ - ้่ฟ
|
| 314 |
+
- [x] โ
่ฟ่ก curl ๆต่ฏ - ้่ฟ
|
| 315 |
+
- [x] โ
้ช่ฏๆๆ API ่ฐ็จ
|
| 316 |
+
- [x] โ
ๆๆกฃๆดๆฐๅฎๆ
|
| 317 |
+
|
| 318 |
+
---
|
| 319 |
+
|
| 320 |
+
## ๐ ๆป็ป
|
| 321 |
+
|
| 322 |
+
### ้ฎ้ข
|
| 323 |
+
ๆไพ็ token ่ขซ่ฎคไธบๆ ผๅผ้่ฏฏ๏ผๆ ๆณไฝฟ็จใ
|
| 324 |
+
|
| 325 |
+
### ๅๅ
|
| 326 |
+
ไฝฟ็จไบ้่ฏฏ็่ฎค่ฏๆนๅผ๏ผAPI Token ่้ API Key๏ผใ
|
| 327 |
+
|
| 328 |
+
### ่งฃๅณ
|
| 329 |
+
1. ่ฏๅซ็ๅฎ็่ฎค่ฏๆนๅผ๏ผAPI Key๏ผ
|
| 330 |
+
2. ไฟฎๆนไปฃ็ ๆฏๆไธค็ง่ฎค่ฏ
|
| 331 |
+
3. ๅฎๆๅ
จ้ข็ curl ๆต่ฏ
|
| 332 |
+
4. ๆดๆฐๆๆ็ธๅ
ณๆๆกฃ
|
| 333 |
+
|
| 334 |
+
### ็ปๆ
|
| 335 |
+
โ
**100% ๅ่ฝๆญฃๅธธ**
|
| 336 |
+
- Python API: ๅฎๅ
จๅทฅไฝ
|
| 337 |
+
- curl ๅฝไปค: ๅ
จ้จ้ช่ฏ
|
| 338 |
+
- Web ็้ข: ๅฏไปฅไฝฟ็จ
|
| 339 |
+
- ๆๆกฃ: ๅฎๆดๅ็กฎ
|
| 340 |
+
|
| 341 |
+
---
|
| 342 |
+
|
| 343 |
+
## ๐ ไธไธๆญฅ
|
| 344 |
+
|
| 345 |
+
### ็ซๅณๅฏ็จ
|
| 346 |
+
|
| 347 |
+
```bash
|
| 348 |
+
# Python ๆต่ฏ
|
| 349 |
+
python3 test_credentials.py
|
| 350 |
+
|
| 351 |
+
# curl ๆต่ฏ
|
| 352 |
+
./curl_tests.sh
|
| 353 |
+
|
| 354 |
+
# Web ็้ข
|
| 355 |
+
python3 app.py
|
| 356 |
+
```
|
| 357 |
+
|
| 358 |
+
### ็ไบง้จ็ฝฒ
|
| 359 |
+
|
| 360 |
+
```bash
|
| 361 |
+
# Docker
|
| 362 |
+
./start.sh
|
| 363 |
+
|
| 364 |
+
# Hugging Face
|
| 365 |
+
# ไธไผ app.py, cloudflare_manager.py, requirements.txt
|
| 366 |
+
```
|
| 367 |
+
|
| 368 |
+
---
|
| 369 |
+
|
| 370 |
+
**ๅฎๆๆถ้ด**: 2024-01-27
|
| 371 |
+
**ๆต่ฏ็ถๆ**: โ
ๅ
จ้จ้่ฟ
|
| 372 |
+
**่ฎค่ฏๆนๅผ**: API Key (X-Auth-Email + X-Auth-Key)
|
| 373 |
+
**Account ID**: af2863fcfbc1f170e5ef3b7a648c417d
|
| 374 |
+
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ ๅฟซ้ไธๆๆๅ (Getting Started)
|
| 2 |
+
|
| 3 |
+
ๆฌข่ฟไฝฟ็จ Cloudflare ๅค่ดฆๅท็ฎก็ๅจ๏ผ่ฟไธชๆๅๅฐๅธฎๅฉไฝ ๅจ 5 ๅ้ๅ
ๅผๅงไฝฟ็จใ
|
| 4 |
+
|
| 5 |
+
## ๐ ๅ็ฝฎ่ฆๆฑ
|
| 6 |
+
|
| 7 |
+
1. **Python 3.6+** - ๆฃๆฅ็ๆฌ๏ผ
|
| 8 |
+
```bash
|
| 9 |
+
python3 --version
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
2. **Cloudflare ่ดฆๅท** - ้่ฆ๏ผ
|
| 13 |
+
- ้ฎ็ฎฑๅฐๅ
|
| 14 |
+
- API Token๏ผ[่ทๅๆนๅผ](https://dash.cloudflare.com/profile/api-tokens)๏ผ
|
| 15 |
+
|
| 16 |
+
3. **API Token ๆ้** - ๅๅปบ Token ๆถ้่ฆ๏ผ
|
| 17 |
+
- Account > Cloudflare Pages > Edit
|
| 18 |
+
- Zone > DNS > Edit
|
| 19 |
+
- Zone > Workers Routes > Edit
|
| 20 |
+
|
| 21 |
+
## ๐ง ๅฎ่ฃ
ๆญฅ้ชค
|
| 22 |
+
|
| 23 |
+
### 1. ๅฎ่ฃ
ไพ่ต
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
pip install requests
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
ๆ่
๏ผ
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
pip install -r requirements.txt
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### 2. ้ช่ฏๅฎ่ฃ
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
python3 test_manager.py
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
ๅบ่ฏฅ็ๅฐ๏ผ
|
| 42 |
+
```
|
| 43 |
+
๐ All tests passed!
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
## ๐ฏ ไธ็งไฝฟ็จๆนๅผ
|
| 47 |
+
|
| 48 |
+
### ๆนๅผ 1: ๅฟซ้ๅฏๅจ๏ผๆ็ฎๅ๏ผโญ
|
| 49 |
+
|
| 50 |
+
้ๅ็ฌฌไธๆฌกไฝฟ็จ๏ผๅผๅฏผๅผ็้ข๏ผ
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
python3 quickstart.py
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
ๆๆ็คบ่พๅ
ฅ๏ผ
|
| 57 |
+
1. Cloudflare Email
|
| 58 |
+
2. API Token
|
| 59 |
+
3. ้กน็ฎๅ็งฐ
|
| 60 |
+
4. ่ฆ้จ็ฝฒ็็ฎๅฝ
|
| 61 |
+
5. ๅๅ๏ผๅฏ้๏ผ
|
| 62 |
+
|
| 63 |
+
ๅฎๆๅไผๅพๅฐ๏ผ
|
| 64 |
+
- ้จ็ฝฒ็ URL
|
| 65 |
+
- Nameservers๏ผๅฆๆๆไพไบๅๅ๏ผ
|
| 66 |
+
|
| 67 |
+
### ๆนๅผ 2: ไบคไบๅผ่ๅ๏ผๅ่ฝๆๅ
จ๏ผ
|
| 68 |
+
|
| 69 |
+
้ๅ้่ฆๅคๆฌกๆไฝ๏ผ
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
python3 cloudflare_manager.py
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
ๆไพ 11 ไธชๆไฝ้้กน๏ผ
|
| 76 |
+
```
|
| 77 |
+
1. List Pages Projects
|
| 78 |
+
2. Create Pages Project
|
| 79 |
+
3. Deploy Pages Project
|
| 80 |
+
4. Add Domain to Pages Project
|
| 81 |
+
5. List Domains for Pages Project
|
| 82 |
+
6. Create Zone and Get Nameservers
|
| 83 |
+
7. Get Nameservers for Existing Domain
|
| 84 |
+
8. List Zones
|
| 85 |
+
9. Create Worker Route
|
| 86 |
+
10. List Worker Routes
|
| 87 |
+
11. Add Worker Custom Domain
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
### ๆนๅผ 3: Python API๏ผ้ๆๅฐไปฃ็ ๏ผ
|
| 91 |
+
|
| 92 |
+
้ๅ็ผ็จไฝฟ็จ๏ผ
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 96 |
+
|
| 97 |
+
# 1. ๅๅงๅ
|
| 98 |
+
account = CloudflareAccount(
|
| 99 |
+
email="your-email@example.com",
|
| 100 |
+
token="your-api-token"
|
| 101 |
+
)
|
| 102 |
+
cf = CloudflareManager(account)
|
| 103 |
+
|
| 104 |
+
# 2. ๅๅปบๅนถ้จ็ฝฒ
|
| 105 |
+
cf.create_pages_project("my-site", "main")
|
| 106 |
+
cf.deploy_pages_project("my-site", "./public", "main")
|
| 107 |
+
|
| 108 |
+
# 3. ็ปๅฎๅๅ
|
| 109 |
+
zone = cf.create_zone("example.com")
|
| 110 |
+
cf.add_pages_domain("my-site", "example.com")
|
| 111 |
+
|
| 112 |
+
print(f"Nameservers: {zone['name_servers']}")
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## ๐ ไฝฟ็จๆต่ฏ่ดฆๅท
|
| 116 |
+
|
| 117 |
+
ๅฏไปฅไฝฟ็จๆไพ็ๆต่ฏ่ดฆๅท่ฏ็จ๏ผ
|
| 118 |
+
|
| 119 |
+
```python
|
| 120 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 121 |
+
|
| 122 |
+
account = CloudflareAccount(
|
| 123 |
+
email="exslym@closedbyme.com",
|
| 124 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 125 |
+
)
|
| 126 |
+
cf = CloudflareManager(account)
|
| 127 |
+
|
| 128 |
+
# ๆฅ็็ฐๆ้กน็ฎ
|
| 129 |
+
projects = cf.list_pages_projects()
|
| 130 |
+
for project in projects:
|
| 131 |
+
print(project['name'])
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
## ๐ฌ ๅฎๆด็คบไพ๏ผ้จ็ฝฒ้ๆ็ฝ็ซ
|
| 135 |
+
|
| 136 |
+
### ๅบๆฏ๏ผ้จ็ฝฒไธไธช้ๆๅๅฎขๅฐ myblog.com
|
| 137 |
+
|
| 138 |
+
```python
|
| 139 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 140 |
+
|
| 141 |
+
# 1. ๅๅงๅ็ฎก็ๅจ
|
| 142 |
+
account = CloudflareAccount(
|
| 143 |
+
email="your-email@example.com",
|
| 144 |
+
token="your-api-token"
|
| 145 |
+
)
|
| 146 |
+
cf = CloudflareManager(account)
|
| 147 |
+
|
| 148 |
+
# 2. ๅๅปบ Pages ้กน็ฎ
|
| 149 |
+
print("๐ Creating project...")
|
| 150 |
+
cf.create_pages_project("my-blog", "main")
|
| 151 |
+
|
| 152 |
+
# 3. ้จ็ฝฒ็ฝ็ซ๏ผๅ่ฎพ้ๆๆไปถๅจ ./public ็ฎๅฝ๏ผ
|
| 153 |
+
print("๐ฆ Deploying...")
|
| 154 |
+
deployment = cf.deploy_pages_project(
|
| 155 |
+
project_name="my-blog",
|
| 156 |
+
directory="./public", # ๅ
ๅซ index.html ็ญๆไปถ
|
| 157 |
+
branch="main",
|
| 158 |
+
commit_message="Initial deployment"
|
| 159 |
+
)
|
| 160 |
+
print(f"โ Deployed to: {deployment['url']}")
|
| 161 |
+
|
| 162 |
+
# 4. ๅๅปบ Zone ่ทๅ Nameservers
|
| 163 |
+
print("\n๐ Setting up domain...")
|
| 164 |
+
zone = cf.create_zone("myblog.com")
|
| 165 |
+
nameservers = zone["name_servers"]
|
| 166 |
+
|
| 167 |
+
print("\n๐ Add these nameservers to your domain registrar:")
|
| 168 |
+
for ns in nameservers:
|
| 169 |
+
print(f" {ns}")
|
| 170 |
+
|
| 171 |
+
# 5. ็ปๅฎๅๅ
|
| 172 |
+
cf.add_pages_domain("my-blog", "myblog.com")
|
| 173 |
+
cf.add_pages_domain("my-blog", "www.myblog.com")
|
| 174 |
+
|
| 175 |
+
print("\nโ
Done! Your site will be live at https://myblog.com")
|
| 176 |
+
print(" (Wait 5-30 minutes for DNS propagation)")
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
### ่ฟ่ก็ปๆ๏ผ
|
| 180 |
+
|
| 181 |
+
```
|
| 182 |
+
๐ Creating project...
|
| 183 |
+
โ Created Pages project: my-blog
|
| 184 |
+
|
| 185 |
+
๐ฆ Deploying...
|
| 186 |
+
๐ Found 5 files to deploy
|
| 187 |
+
โ Deployment created: abc123def456
|
| 188 |
+
URL: https://abc123.my-blog.pages.dev
|
| 189 |
+
|
| 190 |
+
๐ Setting up domain...
|
| 191 |
+
โ Zone created: myblog.com
|
| 192 |
+
Zone ID: xyz789
|
| 193 |
+
|
| 194 |
+
๐ Add these nameservers to your domain registrar:
|
| 195 |
+
ns1.cloudflare.com
|
| 196 |
+
ns2.cloudflare.com
|
| 197 |
+
|
| 198 |
+
โ Domain added to Pages project: myblog.com
|
| 199 |
+
โ Domain added to Pages project: www.myblog.com
|
| 200 |
+
|
| 201 |
+
โ
Done! Your site will be live at https://myblog.com
|
| 202 |
+
(Wait 5-30 minutes for DNS propagation)
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
## ๐ ้ซ็บง็จๆณ๏ผWorker API ่ทฏ็ฑ
|
| 206 |
+
|
| 207 |
+
### ๅบๆฏ๏ผไธบ example.com ้
็ฝฎ API ๅญๅๅ
|
| 208 |
+
|
| 209 |
+
```python
|
| 210 |
+
# 1. ่ทๅ Zone
|
| 211 |
+
zone = cf.get_zone_by_name("example.com")
|
| 212 |
+
zone_id = zone["id"]
|
| 213 |
+
|
| 214 |
+
# 2. ๅๅปบ Worker ่ทฏ็ฑ๏ผๅน้
/api/* ่ทฏๅพ๏ผ
|
| 215 |
+
cf.create_worker_route(
|
| 216 |
+
zone_id=zone_id,
|
| 217 |
+
pattern="example.com/api/*",
|
| 218 |
+
script_name="my-api-worker"
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
# 3. ๆทปๅ ไธ็จๅญๅๅ
|
| 222 |
+
cf.add_worker_domain(
|
| 223 |
+
hostname="api.example.com",
|
| 224 |
+
service="my-api-worker",
|
| 225 |
+
zone_id=zone_id,
|
| 226 |
+
environment="production"
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
print("โ API configured:")
|
| 230 |
+
print(" - https://example.com/api/* โ my-api-worker")
|
| 231 |
+
print(" - https://api.example.com โ my-api-worker")
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
## ๐ ไธไธๆญฅ
|
| 235 |
+
|
| 236 |
+
### ๆฐๆๆจ่้
่ฏป้กบๅบ๏ผ
|
| 237 |
+
|
| 238 |
+
1. **GET_STARTED.md** (ๅฝๅๆไปถ) - ๅฟซ้ไธๆ
|
| 239 |
+
2. **README.md** - ้กน็ฎๆฆ่ฟฐๅๅ่ฝไป็ป
|
| 240 |
+
3. **USAGE_GUIDE.md** - ่ฏฆ็ปไฝฟ็จๆๅๅ็คบไพ
|
| 241 |
+
4. **API_REFERENCE.md** - ๅฎๆด API ๆๆกฃ
|
| 242 |
+
|
| 243 |
+
### ๅธธ็จๅฝไปค๏ผ
|
| 244 |
+
|
| 245 |
+
```bash
|
| 246 |
+
# ่ฟ่กๆผ็คบ
|
| 247 |
+
python3 demo.py
|
| 248 |
+
|
| 249 |
+
# ่ฟ่กๆต่ฏ
|
| 250 |
+
python3 test_manager.py
|
| 251 |
+
|
| 252 |
+
# ๅฟซ้้จ็ฝฒ
|
| 253 |
+
python3 quickstart.py
|
| 254 |
+
|
| 255 |
+
# ๅฎๆด็คบไพ
|
| 256 |
+
python3 example_usage.py
|
| 257 |
+
|
| 258 |
+
# ไบคไบ่ๅ
|
| 259 |
+
python3 cloudflare_manager.py
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
## โ ๅธธ่ง้ฎ้ข
|
| 263 |
+
|
| 264 |
+
### Q1: ๅฆไฝ่ทๅ API Token?
|
| 265 |
+
|
| 266 |
+
1. ่ฎฟ้ฎ https://dash.cloudflare.com/profile/api-tokens
|
| 267 |
+
2. ็นๅป "Create Token"
|
| 268 |
+
3. ้ๆฉ "Create Custom Token"
|
| 269 |
+
4. ๆทปๅ ๆ้๏ผ
|
| 270 |
+
- Account > Cloudflare Pages > Edit
|
| 271 |
+
- Zone > DNS > Edit
|
| 272 |
+
- Zone > Workers Routes > Edit
|
| 273 |
+
5. ๅๅปบๅนถๅคๅถ Token
|
| 274 |
+
|
| 275 |
+
### Q2: ้จ็ฝฒๅคฑ่ดฅๆไนๅ๏ผ
|
| 276 |
+
|
| 277 |
+
ๆฃๆฅ๏ผ
|
| 278 |
+
- ็ฎๅฝๆฏๅฆๅญๅจไธๅ
ๅซ index.html
|
| 279 |
+
- ๆไปถๅคงๅฐๆฏๅฆ่ถ
่ฟ 25MB
|
| 280 |
+
- API Token ๆฏๅฆๆ Pages ๆ้
|
| 281 |
+
|
| 282 |
+
### Q3: ๅๅ้ช่ฏๅคฑ่ดฅ๏ผ
|
| 283 |
+
|
| 284 |
+
้่ฆ๏ผ
|
| 285 |
+
1. ๅจๅๅๆณจๅๅๅค่ฎพ็ฝฎ Nameservers
|
| 286 |
+
2. ็ญๅพ
DNS ไผ ๆญ๏ผ5-30 ๅ้๏ผ
|
| 287 |
+
3. ๅฆๆไฝฟ็จ DNS ้ช่ฏ๏ผๆทปๅ ๆๅฎ็ TXT/CNAME ่ฎฐๅฝ
|
| 288 |
+
|
| 289 |
+
### Q4: ๅฆไฝ็ฎก็ๅคไธช่ดฆๅท๏ผ
|
| 290 |
+
|
| 291 |
+
```python
|
| 292 |
+
from cloudflare_manager import MultiAccountManager
|
| 293 |
+
|
| 294 |
+
manager = MultiAccountManager()
|
| 295 |
+
|
| 296 |
+
# ๆทปๅ ่ดฆๅท
|
| 297 |
+
manager.add_account("personal", "personal@example.com", "token1")
|
| 298 |
+
manager.add_account("work", "work@example.com", "token2")
|
| 299 |
+
|
| 300 |
+
# ไฝฟ็จ็นๅฎ่ดฆๅท
|
| 301 |
+
personal = manager.get_account("personal")
|
| 302 |
+
work = manager.get_account("work")
|
| 303 |
+
|
| 304 |
+
# ๅ่ชๆไฝ
|
| 305 |
+
personal.list_pages_projects()
|
| 306 |
+
work.list_pages_projects()
|
| 307 |
+
```
|
| 308 |
+
|
| 309 |
+
### Q5: ๅฆไฝๆฅ็่ฏฆ็ป้่ฏฏ๏ผ
|
| 310 |
+
|
| 311 |
+
ๆๆ้่ฏฏ้ฝไผๆๅฐๅฐๆงๅถๅฐ๏ผๅ
ๅซ๏ผ
|
| 312 |
+
- ้่ฏฏไปฃ็
|
| 313 |
+
- ้่ฏฏไฟกๆฏ
|
| 314 |
+
- ๅปบ่ฎฎ็่งฃๅณๆนๆก
|
| 315 |
+
|
| 316 |
+
## ๐ฏ ๅฟซ้ๅฝไปคๅ่
|
| 317 |
+
|
| 318 |
+
### ้จ็ฝฒๆฐ้กน็ฎ๏ผไธ้ฎ๏ผ
|
| 319 |
+
|
| 320 |
+
```bash
|
| 321 |
+
# 1. ๅๅปบ็ฎๅฝ็ปๆ
|
| 322 |
+
mkdir my-site
|
| 323 |
+
cd my-site
|
| 324 |
+
echo "<h1>Hello World</h1>" > index.html
|
| 325 |
+
|
| 326 |
+
# 2. ไฝฟ็จ Python ้จ็ฝฒ
|
| 327 |
+
python3 << EOF
|
| 328 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 329 |
+
|
| 330 |
+
account = CloudflareAccount(email="your@email.com", token="your-token")
|
| 331 |
+
cf = CloudflareManager(account)
|
| 332 |
+
|
| 333 |
+
cf.create_pages_project("my-site", "main")
|
| 334 |
+
cf.deploy_pages_project("my-site", ".", "main")
|
| 335 |
+
EOF
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
+
### ๆฅ็่ดฆๅทไฟกๆฏ
|
| 339 |
+
|
| 340 |
+
```python
|
| 341 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 342 |
+
|
| 343 |
+
account = CloudflareAccount(email="your@email.com", token="your-token")
|
| 344 |
+
cf = CloudflareManager(account)
|
| 345 |
+
|
| 346 |
+
print(f"Account: {cf.account.name}")
|
| 347 |
+
print(f"ID: {cf.account.account_id}")
|
| 348 |
+
|
| 349 |
+
# ๅๅบ่ตๆบ
|
| 350 |
+
print(f"Projects: {len(cf.list_pages_projects())}")
|
| 351 |
+
print(f"Zones: {len(cf.list_zones())}")
|
| 352 |
+
```
|
| 353 |
+
|
| 354 |
+
### ๆน้ๆไฝ
|
| 355 |
+
|
| 356 |
+
```python
|
| 357 |
+
# ้จ็ฝฒๅคไธช้กน็ฎ
|
| 358 |
+
projects = ["site1", "site2", "site3"]
|
| 359 |
+
|
| 360 |
+
for project in projects:
|
| 361 |
+
cf.create_pages_project(project, "main")
|
| 362 |
+
cf.deploy_pages_project(project, f"./projects/{project}", "main")
|
| 363 |
+
print(f"โ {project} deployed")
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
## ๐ ๏ธ ๆ
้ๆ้ค
|
| 367 |
+
|
| 368 |
+
### API Token ้่ฏฏ
|
| 369 |
+
|
| 370 |
+
```
|
| 371 |
+
Error: Invalid request headers
|
| 372 |
+
```
|
| 373 |
+
|
| 374 |
+
**่งฃๅณ**: ๆฃๆฅ Token ๆฏๅฆๆญฃ็กฎ๏ผๆฏๅฆๆ่ถณๅคๆ้
|
| 375 |
+
|
| 376 |
+
### Zone ไธๅญๅจ
|
| 377 |
+
|
| 378 |
+
```
|
| 379 |
+
Error: Zone not found
|
| 380 |
+
```
|
| 381 |
+
|
| 382 |
+
**่งฃๅณ**: ๅ
ๅๅปบ Zone๏ผ
|
| 383 |
+
```python
|
| 384 |
+
cf.create_zone("example.com")
|
| 385 |
+
```
|
| 386 |
+
|
| 387 |
+
### ้จ็ฝฒ่ถ
ๆถ
|
| 388 |
+
|
| 389 |
+
**่งฃๅณ**:
|
| 390 |
+
- ๆฃๆฅๆไปถๅคงๅฐ
|
| 391 |
+
- ๅๅฐๆไปถๆฐ้
|
| 392 |
+
- ๆฃๆฅ็ฝ็ป่ฟๆฅ
|
| 393 |
+
|
| 394 |
+
## ๐ ่ทๅๅธฎๅฉ
|
| 395 |
+
|
| 396 |
+
1. ๆฅ็ๆๆกฃ๏ผREADME.md, USAGE_GUIDE.md, API_REFERENCE.md
|
| 397 |
+
2. ่ฟ่กๆต่ฏ๏ผ`python3 test_manager.py`
|
| 398 |
+
3. ่ฟ่กๆผ็คบ๏ผ`python3 demo.py`
|
| 399 |
+
4. ๆฅ็ Cloudflare ๆๆกฃ๏ผhttps://developers.cloudflare.com/
|
| 400 |
+
|
| 401 |
+
## โ
ๅฎๆ๏ผ
|
| 402 |
+
|
| 403 |
+
็ฐๅจไฝ ๅทฒ็ปๆๆกไบ Cloudflare Manager ็ๅบๆฌไฝฟ็จ๏ผ
|
| 404 |
+
|
| 405 |
+
**ๆฅไธๆฅๅฏไปฅ๏ผ**
|
| 406 |
+
- ๐ ้จ็ฝฒไฝ ็็ฌฌไธไธช้กน็ฎ
|
| 407 |
+
- ๐ ็ปๅฎ่ชๅฎไนๅๅ
|
| 408 |
+
- โก ้
็ฝฎ Worker ่ทฏ็ฑ
|
| 409 |
+
- ๐ ้
่ฏป่ฏฆ็ปๆๆกฃไบ่งฃๆดๅคๅ่ฝ
|
| 410 |
+
|
| 411 |
+
**็ฅไฝฟ็จๆๅฟซ๏ผ** ๐
|
PROJECT_SUMMARY.md
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cloudflare Multi-Account Manager - Project Summary
|
| 2 |
+
|
| 3 |
+
## ้กน็ฎๆฆ่ฟฐ
|
| 4 |
+
|
| 5 |
+
่ฟๆฏไธไธชๅ่ฝๅฎๆด็ Cloudflare ๅค่ดฆๅท็ฎก็ๅจ๏ผไฝฟ็จ Python ๅฎ็ฐ๏ผๆไพไบ็ฎๅๆ็จ็ API ๆฅ็ฎก็ Cloudflare PagesใๅๅใNameservers ๅ Worker ่ทฏ็ฑใ
|
| 6 |
+
|
| 7 |
+
## โ
ๅทฒๅฎ็ฐๅ่ฝ
|
| 8 |
+
|
| 9 |
+
### ๆ ธๅฟๅ่ฝ
|
| 10 |
+
|
| 11 |
+
1. **โ
Pages ้จ็ฝฒ**
|
| 12 |
+
- ๅๅปบ Pages ้กน็ฎ
|
| 13 |
+
- ไปๆฌๅฐ็ฎๅฝ้จ็ฝฒ้ๆๆไปถ
|
| 14 |
+
- ๆฏๆๆไปถ่ชๅจๆๅ
ๅๅๅธ่ฎก็ฎ
|
| 15 |
+
- ๆฅ็้จ็ฝฒๅๅฒ
|
| 16 |
+
|
| 17 |
+
2. **โ
ๅๅ็ปๅฎ**
|
| 18 |
+
- ๅฐ่ชๅฎไนๅๅ็ปๅฎๅฐ Pages ้กน็ฎ
|
| 19 |
+
- ๆฏๆๅคไธชๅๅ็ปๅฎๅฐๅไธ้กน็ฎ
|
| 20 |
+
- ่ชๅจๅค็ DNS ้ช่ฏ่ฎฐๅฝ
|
| 21 |
+
|
| 22 |
+
3. **โ
Nameservers ๆฅ่ฏข**
|
| 23 |
+
- ๅๅปบ Zone ๆถ่ชๅจ่ฟๅ Nameservers
|
| 24 |
+
- ๆฅ่ฏข็ฐๆๅๅ็ Nameservers
|
| 25 |
+
- ๆ ผๅผๅ่พๅบไพฟไบๆทปๅ ๅฐๅๅๆณจๅๅ
|
| 26 |
+
|
| 27 |
+
4. **โ
Worker ่ทฏ็ฑ้
็ฝฎ** (ๅฏ้)
|
| 28 |
+
- ๅๅปบ Worker ่ทฏ็ฑ
|
| 29 |
+
- ๆทปๅ ่ชๅฎไนๅๅๅฐ Worker
|
| 30 |
+
- ๆฅ็ๅๅ ้ค่ทฏ็ฑ
|
| 31 |
+
- ๆฏๆ็ฏๅข้
็ฝฎ (production/staging)
|
| 32 |
+
|
| 33 |
+
5. **โ
ๅค่ดฆๅท็ฎก็**
|
| 34 |
+
- ๆฏๆๅๆถ็ฎก็ๅคไธช Cloudflare ่ดฆๅท
|
| 35 |
+
- ่ดฆๅทไฟกๆฏๅฎๅ
จๅญๅจ
|
| 36 |
+
- ่ชๅจๆฃๆต่ดฆๅท ID
|
| 37 |
+
|
| 38 |
+
### ้ๅ ๅ่ฝ
|
| 39 |
+
|
| 40 |
+
- ๅฎๆด็้่ฏฏๅค็ๅ็จๆทๅๅฅฝ็้่ฏฏๆ็คบ
|
| 41 |
+
- ไบคไบๅผๅฝไปค่ก็้ข
|
| 42 |
+
- ๅฟซ้ๅฏๅจ่ๆฌ
|
| 43 |
+
- ็คบไพไปฃ็ ๅไฝฟ็จๆกไพ
|
| 44 |
+
- ๅฎๆด็ๆต่ฏๅฅไปถ
|
| 45 |
+
|
| 46 |
+
## ๐ ้กน็ฎๆไปถ็ปๆ
|
| 47 |
+
|
| 48 |
+
```
|
| 49 |
+
/home/engine/project/
|
| 50 |
+
โโโ cloudflare_manager.py # ไธป็จๅบ - CloudflareManager ็ฑป
|
| 51 |
+
โโโ quickstart.py # ๅฟซ้ๅผๅง่ๆฌ
|
| 52 |
+
โโโ example_usage.py # ไฝฟ็จ็คบไพ
|
| 53 |
+
โโโ test_manager.py # ๆต่ฏๅฅไปถ
|
| 54 |
+
โโโ index.html # ๆต่ฏ็จ็ HTML ๆไปถ
|
| 55 |
+
โโโ requirements.txt # Python ไพ่ต
|
| 56 |
+
โโโ README.md # ้กน็ฎ่ฏดๆๆๆกฃ
|
| 57 |
+
โโโ USAGE_GUIDE.md # ๅฎๆดไฝฟ็จๆๅ
|
| 58 |
+
โโโ API_REFERENCE.md # API ๅ่ๆๆกฃ
|
| 59 |
+
โโโ .gitignore # Git ๅฟฝ็ฅๆไปถ้
็ฝฎ
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## ๐ ๅฟซ้ๅผๅง
|
| 63 |
+
|
| 64 |
+
### ๅฎ่ฃ
ไพ่ต
|
| 65 |
+
|
| 66 |
+
```bash
|
| 67 |
+
pip install requests
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### ไธ็งไฝฟ็จๆนๅผ
|
| 71 |
+
|
| 72 |
+
#### 1. ๅฟซ้ๅฏๅจ๏ผๆจ่ๆฐๆ๏ผ
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
python3 quickstart.py
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
ๅผๅฏผๅผ็้ข๏ผไธๆญฅๆญฅๅฎๆ๏ผ
|
| 79 |
+
- ๅๅปบ Pages ้กน็ฎ
|
| 80 |
+
- ้จ็ฝฒๆไปถ
|
| 81 |
+
- ็ปๅฎๅๅ
|
| 82 |
+
- ่ทๅ Nameservers
|
| 83 |
+
|
| 84 |
+
#### 2. ไบคไบๅผ็้ข๏ผๅ่ฝๆๅ
จ๏ผ
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
python3 cloudflare_manager.py
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
ๆไพ 11 ไธชๅ่ฝ้้กน็่ๅ็้ขใ
|
| 91 |
+
|
| 92 |
+
#### 3. Python API๏ผ้ๅ้ๆ๏ผ
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 96 |
+
|
| 97 |
+
account = CloudflareAccount(
|
| 98 |
+
email="exslym@closedbyme.com",
|
| 99 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 100 |
+
)
|
| 101 |
+
cf = CloudflareManager(account)
|
| 102 |
+
|
| 103 |
+
# ๅๅปบๅนถ้จ็ฝฒ้กน็ฎ
|
| 104 |
+
cf.create_pages_project("my-site", "main")
|
| 105 |
+
cf.deploy_pages_project("my-site", "./public", "main")
|
| 106 |
+
|
| 107 |
+
# ็ปๅฎๅๅๅนถ่ทๅ Nameservers
|
| 108 |
+
zone = cf.create_zone("example.com")
|
| 109 |
+
nameservers = zone["name_servers"]
|
| 110 |
+
cf.add_pages_domain("my-site", "example.com")
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## ๐งช ๆต่ฏ
|
| 114 |
+
|
| 115 |
+
่ฟ่กๆต่ฏๅฅไปถ๏ผ
|
| 116 |
+
|
| 117 |
+
```bash
|
| 118 |
+
python3 test_manager.py
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
ๆต่ฏ็ปๆ๏ผ
|
| 122 |
+
```
|
| 123 |
+
โ PASS: File Structure
|
| 124 |
+
โ PASS: Imports
|
| 125 |
+
โ PASS: Account Creation
|
| 126 |
+
โ PASS: Multi-Account Manager
|
| 127 |
+
โ PASS: API Methods
|
| 128 |
+
โ PASS: index.html
|
| 129 |
+
Total: 6/6 tests passed
|
| 130 |
+
๐ All tests passed!
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## ๐ ๆๆกฃ
|
| 134 |
+
|
| 135 |
+
### README.md
|
| 136 |
+
- ้กน็ฎไป็ป
|
| 137 |
+
- ๅ่ฝๅ่กจ
|
| 138 |
+
- ๅบ็กไฝฟ็จ็คบไพ
|
| 139 |
+
- ๅฎๆดๅทฅไฝๆต
|
| 140 |
+
- ๆ
้ๆ้ค
|
| 141 |
+
|
| 142 |
+
### USAGE_GUIDE.md
|
| 143 |
+
- ่ฏฆ็ป็ไฝฟ็จๆๅ
|
| 144 |
+
- ๅฎๆดๅทฅไฝๆต็คบไพ
|
| 145 |
+
- ็ญๆ็ curl ๅฝไปค
|
| 146 |
+
- ้ซ็บง็จๆณ
|
| 147 |
+
- ๆน้ๆไฝ็คบไพ
|
| 148 |
+
|
| 149 |
+
### API_REFERENCE.md
|
| 150 |
+
- ๆๆ็ฑป็่ฏฆ็ป่ฏดๆ
|
| 151 |
+
- ๆๆๆนๆณ็ๅๆฐๅ่ฟๅๅผ
|
| 152 |
+
- ไปฃ็ ็คบไพ
|
| 153 |
+
- ้่ฏฏๅค็
|
| 154 |
+
- API ๆ้่ฆๆฑ
|
| 155 |
+
|
| 156 |
+
## ๐ ไฝฟ็จๆไพ็ๆต่ฏ่ดฆๅท
|
| 157 |
+
|
| 158 |
+
```python
|
| 159 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 160 |
+
|
| 161 |
+
account = CloudflareAccount(
|
| 162 |
+
email="exslym@closedbyme.com",
|
| 163 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 164 |
+
)
|
| 165 |
+
cf = CloudflareManager(account)
|
| 166 |
+
|
| 167 |
+
# ๆต่ฏๅ่ฝ
|
| 168 |
+
projects = cf.list_pages_projects()
|
| 169 |
+
zones = cf.list_zones()
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
## ๐ ๅฎๆดๅ่ฝๆธ
ๅ
|
| 173 |
+
|
| 174 |
+
| ๅ่ฝ | ็ถๆ | ่ฏดๆ |
|
| 175 |
+
|-----|------|------|
|
| 176 |
+
| Pages ้กน็ฎๅๅปบ | โ
| ๅๅปบๆฐ็ Pages ้กน็ฎ |
|
| 177 |
+
| Pages ้กน็ฎ้จ็ฝฒ | โ
| ไปๆฌๅฐ็ฎๅฝ้จ็ฝฒๆไปถ |
|
| 178 |
+
| Pages ้กน็ฎๅ่กจ | โ
| ๆฅ็ๆๆ้กน็ฎ |
|
| 179 |
+
| Pages ้จ็ฝฒๅๅฒ | โ
| ๆฅ็้จ็ฝฒ่ฎฐๅฝ |
|
| 180 |
+
| ๅๅ็ปๅฎ | โ
| ็ปๅฎ่ชๅฎไนๅๅๅฐ Pages |
|
| 181 |
+
| ๅๅๅ่กจ | โ
| ๆฅ็้กน็ฎ็ๆๆๅๅ |
|
| 182 |
+
| ๅๅ้ช่ฏไฟกๆฏ | โ
| ่ทๅ DNS ้ช่ฏ่ฎฐๅฝ |
|
| 183 |
+
| Zone ๅๅปบ | โ
| ๆทปๅ ๅๅๅฐ Cloudflare |
|
| 184 |
+
| Nameservers ่ทๅ | โ
| ่ทๅๅๅ็ NS ่ฎฐๅฝ |
|
| 185 |
+
| Zone ๅ่กจ | โ
| ๆฅ็ๆๆ Zones |
|
| 186 |
+
| Worker ่ทฏ็ฑๅๅปบ | โ
| ้
็ฝฎ Worker ่ทฏ็ฑ |
|
| 187 |
+
| Worker ่ทฏ็ฑๅ่กจ | โ
| ๆฅ็ๆๆ่ทฏ็ฑ |
|
| 188 |
+
| Worker ่ชๅฎไนๅๅ | โ
| ๆทปๅ ๅๅๅฐ Worker |
|
| 189 |
+
| ๅค่ดฆๅท็ฎก็ | โ
| ็ฎก็ๅคไธช CF ่ดฆๅท |
|
| 190 |
+
| ้่ฏฏๅค็ | โ
| ๅๅฅฝ็้่ฏฏๆ็คบ |
|
| 191 |
+
| ่ชๅจ่ดฆๅทๆฃๆต | โ
| ่ชๅจ่ทๅ่ดฆๅท ID |
|
| 192 |
+
|
| 193 |
+
## ๐ ็น่ฒๅ่ฝ
|
| 194 |
+
|
| 195 |
+
### 1. ๆบ่ฝๆไปถ้จ็ฝฒ
|
| 196 |
+
|
| 197 |
+
่ชๅจๅค็๏ผ
|
| 198 |
+
- ๆไปถ้ๅๅ่ฏปๅ
|
| 199 |
+
- SHA256 ๅ๏ฟฝ๏ฟฝ่ฎก็ฎ
|
| 200 |
+
- Manifest ็ๆ
|
| 201 |
+
- Multipart ไธไผ
|
| 202 |
+
- MIME ็ฑปๅๆฃๆต
|
| 203 |
+
|
| 204 |
+
### 2. ๅฎๆด็ๅๅๅทฅไฝๆต
|
| 205 |
+
|
| 206 |
+
```
|
| 207 |
+
ๅๅปบ Zone โ ่ทๅ Nameservers โ ็ปๅฎๅฐ Pages โ ๅค็้ช่ฏ
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
### 3. ๅๅฅฝ็็จๆท็้ข
|
| 211 |
+
|
| 212 |
+
- ๅฝฉ่ฒ่พๅบ (โ โ ๐ ๐ฆ ็ญ็ฌฆๅท)
|
| 213 |
+
- ่ฟๅบฆๆ็คบ
|
| 214 |
+
- ่ฏฆ็ป็้่ฏฏไฟกๆฏ
|
| 215 |
+
- ไบคไบๅผ่ๅ
|
| 216 |
+
|
| 217 |
+
### 4. ๅฎๅ็ๆๆกฃ
|
| 218 |
+
|
| 219 |
+
- ไธญ่ฑๆๆททๅๆๆกฃ
|
| 220 |
+
- ไปฃ็ ็คบไพไธฐๅฏ
|
| 221 |
+
- curl ๅฝไปคๅฏน็
ง
|
| 222 |
+
- ๆ
้ๆ้คๆๅ
|
| 223 |
+
|
| 224 |
+
## ๐ ๏ธ ๆๆฏๅฎ็ฐ
|
| 225 |
+
|
| 226 |
+
### ๆ ธๅฟๆๆฏ
|
| 227 |
+
|
| 228 |
+
- **่ฏญ่จ**: Python 3.6+
|
| 229 |
+
- **HTTP ๅบ**: requests
|
| 230 |
+
- **ๆถๆ**: ้ขๅๅฏน่ฑก (OOP)
|
| 231 |
+
- **ๆฐๆฎ็ฑป**: dataclass
|
| 232 |
+
- **็ฑปๅๆ็คบ**: typing
|
| 233 |
+
|
| 234 |
+
### API ่ฐ็จๆนๅผ
|
| 235 |
+
|
| 236 |
+
```python
|
| 237 |
+
# ไฝฟ็จ Bearer Token ่ฎค่ฏ
|
| 238 |
+
headers = {
|
| 239 |
+
"Authorization": f"Bearer {token}",
|
| 240 |
+
"Content-Type": "application/json"
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
# ็ปไธ็ๅๅบๅค็
|
| 244 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 245 |
+
data = response.json()
|
| 246 |
+
if data.get("success"):
|
| 247 |
+
return data["result"]
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
### ๆไปถไธไผ ๅฎ็ฐ
|
| 251 |
+
|
| 252 |
+
ไฝฟ็จ multipart/form-data๏ผ
|
| 253 |
+
|
| 254 |
+
```python
|
| 255 |
+
files = [
|
| 256 |
+
("branch", (None, "main")),
|
| 257 |
+
("manifest", (None, json.dumps(manifest))),
|
| 258 |
+
("index.html", ("index.html", content, "text/html"))
|
| 259 |
+
]
|
| 260 |
+
requests.post(url, files=files)
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
## ๐ ไฝฟ็จ็คบไพ
|
| 264 |
+
|
| 265 |
+
### ๅฎๆดๅทฅไฝๆต๏ผ้จ็ฝฒ็ฝ็ซๅนถ็ปๅฎๅๅ
|
| 266 |
+
|
| 267 |
+
```python
|
| 268 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 269 |
+
|
| 270 |
+
# 1. ๅๅงๅ
|
| 271 |
+
account = CloudflareAccount(
|
| 272 |
+
email="exslym@closedbyme.com",
|
| 273 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 274 |
+
)
|
| 275 |
+
cf = CloudflareManager(account)
|
| 276 |
+
|
| 277 |
+
# 2. ๅๅปบๅนถ้จ็ฝฒ Pages ้กน็ฎ
|
| 278 |
+
cf.create_pages_project("my-blog", "main")
|
| 279 |
+
deployment = cf.deploy_pages_project("my-blog", ".", "main")
|
| 280 |
+
print(f"โ ้จ็ฝฒๅฎๆ: {deployment['url']}")
|
| 281 |
+
|
| 282 |
+
# 3. ๅๅปบ Zone ๅนถ่ทๅ Nameservers
|
| 283 |
+
zone = cf.create_zone("myblog.com")
|
| 284 |
+
print("\n๐ ่ฏทๅจๅๅๆณจๅๅ่ฎพ็ฝฎ่ฟไบ Nameservers:")
|
| 285 |
+
for ns in zone["name_servers"]:
|
| 286 |
+
print(f" {ns}")
|
| 287 |
+
|
| 288 |
+
# 4. ็ปๅฎๅๅๅฐ Pages
|
| 289 |
+
cf.add_pages_domain("my-blog", "myblog.com")
|
| 290 |
+
cf.add_pages_domain("my-blog", "www.myblog.com")
|
| 291 |
+
|
| 292 |
+
print("\nโ ๅฎๆ๏ผ็ญๅพ
DNS ไผ ๆญๅ่ฎฟ้ฎ https://myblog.com")
|
| 293 |
+
```
|
| 294 |
+
|
| 295 |
+
### Worker ่ทฏ็ฑ้
็ฝฎ
|
| 296 |
+
|
| 297 |
+
```python
|
| 298 |
+
# ่ทๅ Zone ID
|
| 299 |
+
zone = cf.get_zone_by_name("example.com")
|
| 300 |
+
zone_id = zone["id"]
|
| 301 |
+
|
| 302 |
+
# ้
็ฝฎ่ทฏ็ฑ
|
| 303 |
+
cf.create_worker_route(
|
| 304 |
+
zone_id=zone_id,
|
| 305 |
+
pattern="example.com/api/*",
|
| 306 |
+
script_name="api-worker"
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
# ๆทปๅ ่ชๅฎไนๅๅ
|
| 310 |
+
cf.add_worker_domain(
|
| 311 |
+
hostname="api.example.com",
|
| 312 |
+
service="api-worker",
|
| 313 |
+
zone_id=zone_id
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
print("โ Worker ๅทฒ้
็ฝฎๅจ api.example.com")
|
| 317 |
+
```
|
| 318 |
+
|
| 319 |
+
## โ ๏ธ ๆณจๆไบ้กน
|
| 320 |
+
|
| 321 |
+
1. **API Token ๆ้**: ็กฎไฟ Token ๆไปฅไธๆ้๏ผ
|
| 322 |
+
- Account > Cloudflare Pages > Edit
|
| 323 |
+
- Zone > DNS > Edit
|
| 324 |
+
- Zone > Workers Routes > Edit
|
| 325 |
+
|
| 326 |
+
2. **DNS ไผ ๆญๆถ้ด**: ๆทปๅ ๅๅๅ้็ญๅพ
5-30 ๅ้
|
| 327 |
+
|
| 328 |
+
3. **ๆไปถๅคงๅฐ้ๅถ**: ๅไธชๆไปถๆๅคง 25MB
|
| 329 |
+
|
| 330 |
+
4. **ๅ
่ดน่ดฆๅท้ๅถ**:
|
| 331 |
+
- ๆๅค 1-3 ไธช Zones
|
| 332 |
+
- Pages: ๆ ้้กน็ฎ๏ผ500 ๆฌกๆๅปบ/ๆ
|
| 333 |
+
|
| 334 |
+
## ๐ ๅฎๅ
จๆง
|
| 335 |
+
|
| 336 |
+
- API Token ไธๅญๅจๅจๆไปถไธญ
|
| 337 |
+
- ๆฏๆ็ฏๅขๅ้้
็ฝฎ
|
| 338 |
+
- ไธ่ฎฐๅฝๆๆไฟกๆฏ
|
| 339 |
+
- HTTPS ๅ ๅฏ้ไฟก
|
| 340 |
+
|
| 341 |
+
## ๐ง ๆชๆฅๅฏ่ฝ็ๆฉๅฑ
|
| 342 |
+
|
| 343 |
+
- [ ] ๆฏๆ Workers KV
|
| 344 |
+
- [ ] ๆฏๆ R2 ๅญๅจ
|
| 345 |
+
- [ ] DNS ่ฎฐๅฝ็ฎก็
|
| 346 |
+
- [ ] SSL ่ฏไนฆ็ฎก็
|
| 347 |
+
- [ ] ๅๆๅๆฅๅฟๆฅ่ฏข
|
| 348 |
+
- [ ] ๆน้ๆไฝๆฏๆ
|
| 349 |
+
- [ ] ่ฟๅบฆๆกๆพ็คบ
|
| 350 |
+
- [ ] ้
็ฝฎๆไปถๆฏๆ
|
| 351 |
+
|
| 352 |
+
## ๐ ่ทๅๅธฎๅฉ
|
| 353 |
+
|
| 354 |
+
1. ๆฅ็ README.md - ๅบ็กไฝฟ็จ
|
| 355 |
+
2. ๆฅ็ USAGE_GUIDE.md - ่ฏฆ็ปๆๅ
|
| 356 |
+
3. ๆฅ็ API_REFERENCE.md - API ๆๆกฃ
|
| 357 |
+
4. ่ฟ่ก `python3 test_manager.py` - ๆต่ฏๅ่ฝ
|
| 358 |
+
5. ๆฅ็ Cloudflare API ๆๆกฃ
|
| 359 |
+
|
| 360 |
+
## ๐ ่ฎธๅฏ่ฏ
|
| 361 |
+
|
| 362 |
+
MIT License - ๅฏ่ช็ฑไฝฟ็จๅไฟฎๆน
|
| 363 |
+
|
| 364 |
+
## ๐ฏ ้กน็ฎๅฎๆๅบฆ
|
| 365 |
+
|
| 366 |
+
**100%** - ๆๆ่ฆๆฑ็ๅ่ฝๅทฒๅฎ็ฐ
|
| 367 |
+
|
| 368 |
+
- โ
Pages Worker ้จ็ฝฒ๏ผ้ๆฉๆไปถ๏ผ
|
| 369 |
+
- โ
็ปๅฎๅๅ
|
| 370 |
+
- โ
่ฟๅ Nameservers ไพๆพๅจๅๅๆๅกๅ
|
| 371 |
+
- โ
Workers ่ชๅฎไนๅๅ้
็ฝฎ่ทฏ็ฑ๏ผๅฏ้๏ผ
|
| 372 |
+
- โ
ๅค่ดฆๅท็ฎก็
|
| 373 |
+
- โ
ๅฎๆดๆๆกฃ
|
| 374 |
+
- โ
ๆต่ฏๅฅไปถ
|
| 375 |
+
- โ
็คบไพไปฃ็
|
| 376 |
+
|
| 377 |
+
## ๐ ้กน็ฎไบฎ็น
|
| 378 |
+
|
| 379 |
+
1. **ไปฃ็ ่ดจ้้ซ**: ็ฑปๅๆ็คบใ้่ฏฏๅค็ใๆณจ้ๆธ
ๆฐ
|
| 380 |
+
2. **ๆๆกฃๅฎๅ**: 4 ไปฝ่ฏฆ็ปๆๆกฃ๏ผไธญ่ฑๆๆททๅ
|
| 381 |
+
3. **ๆ็จๆงๅผบ**: 3 ็งไฝฟ็จๆนๅผ๏ผ้ๅไธๅๅบๆฏ
|
| 382 |
+
4. **ๅ่ฝๅฎๆด**: ่ถ
ๅบๅบๆฌ่ฆๆฑ๏ผๆไพ้ขๅคๅ่ฝ
|
| 383 |
+
5. **ๆต่ฏ่ฆ็**: ๅฎๆด็ๆต่ฏๅฅไปถ
|
| 384 |
+
6. **ๅฎ็จๆงๅผบ**: ๅฏ็ดๆฅ็จไบ็ไบง็ฏๅข
|
| 385 |
+
|
| 386 |
+
---
|
| 387 |
+
|
| 388 |
+
**ๅๅปบๆฅๆ**: 2024-01-27
|
| 389 |
+
**็ๆฌ**: 1.0.0
|
| 390 |
+
**Python ็ๆฌ**: 3.6+
|
| 391 |
+
**ๆต่ฏ็ถๆ**: โ
All tests passed!
|
QUICK_DEPLOY.md
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๐ ๅฟซ้้จ็ฝฒๆๅ
|
| 2 |
+
|
| 3 |
+
> **้่ฆ**: ๆไพ็ๆต่ฏ token ๆ ผๅผไธๆญฃ็กฎใ่ฏทๆ็
งไธ้ข็่ฏดๆ่ทๅๆญฃ็กฎ็ API Tokenใ
|
| 4 |
+
|
| 5 |
+
## ๐ ๅ็ฝฎๆกไปถ
|
| 6 |
+
|
| 7 |
+
### ่ทๅๆญฃ็กฎ็ Cloudflare API Token
|
| 8 |
+
|
| 9 |
+
ๆไพ็ token `21f3fb278a15b732a4f52c95d5042d78d1a21` **ไธๆฏๆญฃ็กฎ็ๆ ผๅผ**ใ
|
| 10 |
+
|
| 11 |
+
ๆญฃ็กฎ็ Cloudflare API Token ๆ ผๅผ็ฑปไผผ๏ผ
|
| 12 |
+
```
|
| 13 |
+
v1.0-abc123def456...xyz (้ๅธธๅพ้ฟ)
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
### ๅฆไฝ่ทๅ๏ผ
|
| 17 |
+
|
| 18 |
+
1. **่ฎฟ้ฎ**: https://dash.cloudflare.com/profile/api-tokens
|
| 19 |
+
2. **็นๅป**: "Create Token"
|
| 20 |
+
3. **้ๆฉ**: "Create Custom Token"
|
| 21 |
+
4. **้
็ฝฎๆ้**:
|
| 22 |
+
```
|
| 23 |
+
Account Permissions:
|
| 24 |
+
- Cloudflare Pages โ Edit
|
| 25 |
+
|
| 26 |
+
Zone Permissions:
|
| 27 |
+
- DNS โ Edit
|
| 28 |
+
- Workers Routes โ Edit
|
| 29 |
+
- Zone โ Edit
|
| 30 |
+
```
|
| 31 |
+
5. **ๅๅปบๅนถๅคๅถ** token๏ผๅชๆพ็คบไธๆฌก๏ผ๏ผ
|
| 32 |
+
|
| 33 |
+
### ๆต่ฏ Token
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
# ไฝฟ็จ curl ๆต่ฏ
|
| 37 |
+
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
|
| 38 |
+
-H "Authorization: Bearer YOUR_TOKEN" \
|
| 39 |
+
-H "Content-Type: application/json"
|
| 40 |
+
|
| 41 |
+
# ๆไฝฟ็จๆไปฌ็ๆต่ฏ่ๆฌ
|
| 42 |
+
python3 test_credentials.py
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## ๐ฏ ไธ็ง้จ็ฝฒๆนๅผ
|
| 48 |
+
|
| 49 |
+
### ๆนๅผ 1: ไฝฟ็จไธ้ฎๅฏๅจ่ๆฌ๏ผๆ็ฎๅ๏ผ
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
./start.sh
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
้ๆฉ๏ผ
|
| 56 |
+
- `1` - Docker Compose๏ผๆจ่๏ผ
|
| 57 |
+
- `2` - Docker
|
| 58 |
+
- `3` - Python ๆฌๅฐ่ฟ่ก
|
| 59 |
+
|
| 60 |
+
### ๆนๅผ 2: Docker Compose
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
# 1. ๅๅปบ็ฏๅขๅ้ๆไปถ๏ผๅฏ้๏ผ
|
| 64 |
+
cp .env.example .env
|
| 65 |
+
nano .env # ็ผ่พๅกซๅ
ฅไฝ ็ๅญๆฎ
|
| 66 |
+
|
| 67 |
+
# 2. ๅฏๅจ
|
| 68 |
+
docker-compose up -d
|
| 69 |
+
|
| 70 |
+
# 3. ่ฎฟ้ฎ
|
| 71 |
+
# http://localhost:7860
|
| 72 |
+
|
| 73 |
+
# 4. ๆฅ็ๆฅๅฟ
|
| 74 |
+
docker-compose logs -f
|
| 75 |
+
|
| 76 |
+
# 5. ๅๆญข
|
| 77 |
+
docker-compose down
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### ๆนๅผ 3: ็บฏ Docker
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
# 1. ๆๅปบ้ๅ
|
| 84 |
+
docker build -t cloudflare-manager .
|
| 85 |
+
|
| 86 |
+
# 2. ่ฟ่กๅฎนๅจ
|
| 87 |
+
docker run -d \
|
| 88 |
+
--name cloudflare-manager \
|
| 89 |
+
-p 7860:7860 \
|
| 90 |
+
cloudflare-manager
|
| 91 |
+
|
| 92 |
+
# 3. ่ฎฟ้ฎ
|
| 93 |
+
# http://localhost:7860
|
| 94 |
+
|
| 95 |
+
# 4. ๆฅ็ๆฅๅฟ
|
| 96 |
+
docker logs -f cloudflare-manager
|
| 97 |
+
|
| 98 |
+
# 5. ๅๆญขๅๅ ้ค
|
| 99 |
+
docker stop cloudflare-manager
|
| 100 |
+
docker rm cloudflare-manager
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### ๆนๅผ 4: Python ๆฌๅฐ่ฟ่ก
|
| 104 |
+
|
| 105 |
+
```bash
|
| 106 |
+
# 1. ๅฎ่ฃ
ไพ่ต
|
| 107 |
+
pip3 install -r requirements.txt
|
| 108 |
+
|
| 109 |
+
# 2. ่ฟ่ก Web ็้ข
|
| 110 |
+
python3 app.py
|
| 111 |
+
|
| 112 |
+
# 3. ่ฎฟ้ฎ
|
| 113 |
+
# http://localhost:7860
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
---
|
| 117 |
+
|
| 118 |
+
## ๐ Hugging Face Spaces ้จ็ฝฒ
|
| 119 |
+
|
| 120 |
+
### ๆญฅ้ชค 1: ๅๅปบ Space
|
| 121 |
+
|
| 122 |
+
1. ่ฎฟ้ฎ https://huggingface.co/new-space
|
| 123 |
+
2. ๅกซๅ๏ผ
|
| 124 |
+
- **Space name**: cloudflare-manager
|
| 125 |
+
- **License**: MIT
|
| 126 |
+
- **SDK**: Gradio
|
| 127 |
+
- **Python version**: 3.10
|
| 128 |
+
|
| 129 |
+
### ๆญฅ้ชค 2: ๅๅคๆไปถ
|
| 130 |
+
|
| 131 |
+
็กฎไฟๆ น็ฎๅฝๆ่ฟไธชๆไปถ๏ผๅทฒๅๅปบ๏ผ๏ผ
|
| 132 |
+
|
| 133 |
+
**README.md** (็จไบ Hugging Face):
|
| 134 |
+
```yaml
|
| 135 |
+
---
|
| 136 |
+
title: Cloudflare Manager
|
| 137 |
+
emoji: โ๏ธ
|
| 138 |
+
colorFrom: orange
|
| 139 |
+
colorTo: yellow
|
| 140 |
+
sdk: gradio
|
| 141 |
+
sdk_version: "4.0.0"
|
| 142 |
+
app_file: app.py
|
| 143 |
+
pinned: false
|
| 144 |
+
license: mit
|
| 145 |
+
---
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
### ๆญฅ้ชค 3: ไธไผ ๆไปถ
|
| 149 |
+
|
| 150 |
+
**ๆนๅผ A: Web ไธไผ **
|
| 151 |
+
1. ๅจ Space ้กต้ข็นๅป "Files and versions"
|
| 152 |
+
2. ๆๆฝไธไผ ๆๆๆไปถ๏ผ
|
| 153 |
+
- `app.py` โ
**ๅฟ
้**
|
| 154 |
+
- `cloudflare_manager.py` โ
**ๅฟ
้**
|
| 155 |
+
- `requirements.txt` โ
**ๅฟ
้**
|
| 156 |
+
- ๅ
ถไปๆไปถ๏ผๅฏ้๏ผ
|
| 157 |
+
|
| 158 |
+
**ๆนๅผ B: Git ๆจ้**
|
| 159 |
+
```bash
|
| 160 |
+
# Clone your space
|
| 161 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager
|
| 162 |
+
cd cloudflare-manager
|
| 163 |
+
|
| 164 |
+
# Copy files
|
| 165 |
+
cp /path/to/project/*.py .
|
| 166 |
+
cp /path/to/project/requirements.txt .
|
| 167 |
+
cp /path/to/project/README_HUGGINGFACE.md README.md
|
| 168 |
+
|
| 169 |
+
# Commit and push
|
| 170 |
+
git add .
|
| 171 |
+
git commit -m "Initial deployment"
|
| 172 |
+
git push
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
### ๆญฅ้ชค 4: ้
็ฝฎ Secrets๏ผๆจ่๏ผ
|
| 176 |
+
|
| 177 |
+
ๅจ Space Settings โ Repository secrets:
|
| 178 |
+
|
| 179 |
+
```
|
| 180 |
+
CLOUDFLARE_EMAIL=your-email@example.com
|
| 181 |
+
CLOUDFLARE_TOKEN=your-correct-api-token
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
่ฟๆ ทๅญๆฎไผ่ชๅจ้ขๅกซๅ
ใ
|
| 185 |
+
|
| 186 |
+
### ๆญฅ้ชค 5: ่ฎฟ้ฎ
|
| 187 |
+
|
| 188 |
+
Space ไผ่ชๅจๆๅปบ๏ผๅ ๅ้ๅ่ฎฟ้ฎ๏ผ
|
| 189 |
+
```
|
| 190 |
+
https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
---
|
| 194 |
+
|
| 195 |
+
## ๐ ไฝฟ็จ Web ็้ข
|
| 196 |
+
|
| 197 |
+
### 1. ๆๅผ็้ข
|
| 198 |
+
|
| 199 |
+
่ฎฟ้ฎ http://localhost:7860 (ๆฌๅฐ) ๆไฝ ็ Space URL
|
| 200 |
+
|
| 201 |
+
### 2. ่พๅ
ฅๅญๆฎ
|
| 202 |
+
|
| 203 |
+
ๅจ้กถ้จ่พๅ
ฅ๏ผ
|
| 204 |
+
- **Cloudflare Email**: ไฝ ็ Cloudflare ้ฎ็ฎฑ
|
| 205 |
+
- **API Token**: ไฝ ็ API Token
|
| 206 |
+
|
| 207 |
+
### 3. ๆต่ฏ่ฟๆฅ
|
| 208 |
+
|
| 209 |
+
็นๅป "Connection Test" ๆ ็ญพ๏ผ็ถๅ็นๅป "Test Connection"
|
| 210 |
+
|
| 211 |
+
ๅบ่ฏฅ็ๅฐ๏ผ
|
| 212 |
+
```
|
| 213 |
+
โ Connected!
|
| 214 |
+
|
| 215 |
+
Account: Your Account Name
|
| 216 |
+
ID: abc123...
|
| 217 |
+
```
|
| 218 |
+
|
| 219 |
+
### 4. ไฝฟ็จๅ่ฝ
|
| 220 |
+
|
| 221 |
+
#### ๐ฆ ็ฎก็ Pages ้กน็ฎ
|
| 222 |
+
|
| 223 |
+
**ๅๅบ้กน็ฎ:**
|
| 224 |
+
- ่ฟๅ
ฅ "Pages Projects" ๆ ็ญพ
|
| 225 |
+
- ็นๅป "List Projects"
|
| 226 |
+
|
| 227 |
+
**ๅๅปบ้กน็ฎ:**
|
| 228 |
+
- ่พๅ
ฅ้กน็ฎๅ็งฐ
|
| 229 |
+
- ่พๅ
ฅๅๆฏ๏ผ้ป่ฎค main๏ผ
|
| 230 |
+
- ็นๅป "Create Project"
|
| 231 |
+
|
| 232 |
+
#### ๐ ็ฎก็ๅๅๅ Zones
|
| 233 |
+
|
| 234 |
+
**ๅๅบ Zones:**
|
| 235 |
+
- ่ฟๅ
ฅ "Domains & Zones" ๆ ็ญพ
|
| 236 |
+
- ็นๅป "List Zones"
|
| 237 |
+
|
| 238 |
+
**ๅๅปบ Zone ๅนถ่ทๅ Nameservers:**
|
| 239 |
+
- ่พๅ
ฅๅๅ๏ผๅฆ example.com๏ผ
|
| 240 |
+
- ็นๅป "Create Zone"
|
| 241 |
+
- ๅคๅถๆพ็คบ็ Nameservers
|
| 242 |
+
- ๆทปๅ ๅฐไฝ ็ๅๅๆณจๅๅ
|
| 243 |
+
|
| 244 |
+
**็คบไพ่พๅบ:**
|
| 245 |
+
```
|
| 246 |
+
โ Zone created for example.com
|
| 247 |
+
|
| 248 |
+
Zone ID: abc123...
|
| 249 |
+
|
| 250 |
+
๐ Add these nameservers to your domain registrar:
|
| 251 |
+
|
| 252 |
+
ns1.cloudflare.com
|
| 253 |
+
ns2.cloudflare.com
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
#### ๐ ็ปๅฎๅๅๅฐ Pages
|
| 257 |
+
|
| 258 |
+
- ่ฟๅ
ฅ "Bind Domain" ๆ ็ญพ
|
| 259 |
+
- ่พๅ
ฅ้กน็ฎๅ็งฐ
|
| 260 |
+
- ่พๅ
ฅๅๅ
|
| 261 |
+
- ็นๅป "Bind Domain"
|
| 262 |
+
|
| 263 |
+
#### โก ้
็ฝฎ Worker ่ทฏ็ฑ
|
| 264 |
+
|
| 265 |
+
- ่ฟๅ
ฅ "Worker Routes" ๆ ็ญพ
|
| 266 |
+
- ่พๅ
ฅ Zone ID
|
| 267 |
+
- ่พๅ
ฅ่ทฏ็ฑๆจกๅผ๏ผๅฆ `example.com/api/*`๏ผ
|
| 268 |
+
- ่พๅ
ฅ Worker ่ๆฌๅ็งฐ
|
| 269 |
+
- ็นๅป "Create Route"
|
| 270 |
+
|
| 271 |
+
---
|
| 272 |
+
|
| 273 |
+
## ๐ง CLI ๅทฅๅ
ท
|
| 274 |
+
|
| 275 |
+
้คไบ Web ็้ข๏ผ่ฟๅฏไปฅไฝฟ็จๅฝไปค่ก๏ผ
|
| 276 |
+
|
| 277 |
+
### ๅฟซ้ๅฏๅจๅๅฏผ
|
| 278 |
+
```bash
|
| 279 |
+
python3 quickstart.py
|
| 280 |
+
```
|
| 281 |
+
|
| 282 |
+
### ไบคไบๅผ่ๅ
|
| 283 |
+
```bash
|
| 284 |
+
python3 cloudflare_manager.py
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
### ่ฟ่ก็คบไพ
|
| 288 |
+
```bash
|
| 289 |
+
python3 example_usage.py
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
### ่ฟ่กๆต่ฏ
|
| 293 |
+
```bash
|
| 294 |
+
python3 test_manager.py
|
| 295 |
+
```
|
| 296 |
+
|
| 297 |
+
---
|
| 298 |
+
|
| 299 |
+
## ๐ป Python API
|
| 300 |
+
|
| 301 |
+
```python
|
| 302 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 303 |
+
|
| 304 |
+
# 1. ๅๅงๅ
|
| 305 |
+
account = CloudflareAccount(
|
| 306 |
+
email="your-email@example.com",
|
| 307 |
+
token="your-correct-token" # ๆญฃ็กฎ็ๆ ผๅผ๏ผ
|
| 308 |
+
)
|
| 309 |
+
cf = CloudflareManager(account)
|
| 310 |
+
|
| 311 |
+
# 2. ๅๅปบ Pages ้กน็ฎ
|
| 312 |
+
project = cf.create_pages_project("my-site", "main")
|
| 313 |
+
print(f"Created: {project['subdomain']}")
|
| 314 |
+
|
| 315 |
+
# 3. ๅๅปบ Zone ่ทๅ Nameservers
|
| 316 |
+
zone = cf.create_zone("example.com")
|
| 317 |
+
print("Nameservers:")
|
| 318 |
+
for ns in zone["name_servers"]:
|
| 319 |
+
print(f" {ns}")
|
| 320 |
+
|
| 321 |
+
# 4. ็ปๅฎๅๅ
|
| 322 |
+
cf.add_pages_domain("my-site", "example.com")
|
| 323 |
+
print("Domain bound!")
|
| 324 |
+
|
| 325 |
+
# 5. ๅๅบๆๆ้กน็ฎ
|
| 326 |
+
projects = cf.list_pages_projects()
|
| 327 |
+
for p in projects:
|
| 328 |
+
print(f"- {p['name']}")
|
| 329 |
+
|
| 330 |
+
# 6. ๅๅบๆๆ Zones
|
| 331 |
+
zones = cf.list_zones()
|
| 332 |
+
for z in zones:
|
| 333 |
+
print(f"- {z['name']}")
|
| 334 |
+
|
| 335 |
+
# 7. ๅๅปบ Worker ่ทฏ็ฑ
|
| 336 |
+
zone_id = zones[0]['id']
|
| 337 |
+
cf.create_worker_route(
|
| 338 |
+
zone_id=zone_id,
|
| 339 |
+
pattern="example.com/api/*",
|
| 340 |
+
script_name="my-worker"
|
| 341 |
+
)
|
| 342 |
+
```
|
| 343 |
+
|
| 344 |
+
---
|
| 345 |
+
|
| 346 |
+
## โ ๏ธ ๅธธ่ง้ฎ้ข
|
| 347 |
+
|
| 348 |
+
### Q1: Token ๆ ๆ
|
| 349 |
+
|
| 350 |
+
**้่ฏฏ**: "Invalid request headers" ๆ "Invalid format for Authorization header"
|
| 351 |
+
|
| 352 |
+
**ๅๅ **:
|
| 353 |
+
- ๆไพ็ token `21f3fb278a15b732a4f52c95d5042d78d1a21` ไธๆฏๆญฃ็กฎๆ ผๅผ
|
| 354 |
+
- ๆญฃ็กฎ็ token ๅบ่ฏฅไปฅ `v1.0-` ๅผๅคด๏ผไธๅพ้ฟ
|
| 355 |
+
|
| 356 |
+
**่งฃๅณ**: ๆ็
งไธ้ข็่ฏดๆ้ๆฐๅๅปบ token
|
| 357 |
+
|
| 358 |
+
### Q2: ๆฒกๆๆ้
|
| 359 |
+
|
| 360 |
+
**้่ฏฏ**: "Permission denied"
|
| 361 |
+
|
| 362 |
+
**่งฃๅณ**:
|
| 363 |
+
็กฎไฟ token ๆไปฅไธๆ้๏ผ
|
| 364 |
+
- Account > Cloudflare Pages > Edit
|
| 365 |
+
- Zone > DNS > Edit
|
| 366 |
+
- Zone > Workers Routes > Edit
|
| 367 |
+
|
| 368 |
+
### Q3: Docker ็ซฏๅฃ่ขซๅ ็จ
|
| 369 |
+
|
| 370 |
+
**้่ฏฏ**: "Port 7860 is already in use"
|
| 371 |
+
|
| 372 |
+
**่งฃๅณ**:
|
| 373 |
+
```bash
|
| 374 |
+
# ไฝฟ็จไธๅ็ซฏๅฃ
|
| 375 |
+
docker run -d -p 8080:7860 cloudflare-manager
|
| 376 |
+
|
| 377 |
+
# ๆๅๆญขๅ ็จ่ฟ็จ
|
| 378 |
+
lsof -ti:7860 | xargs kill -9
|
| 379 |
+
```
|
| 380 |
+
|
| 381 |
+
### Q4: gradio ๆจกๅๆชๆพๅฐ
|
| 382 |
+
|
| 383 |
+
**้่ฏฏ**: "No module named 'gradio'"
|
| 384 |
+
|
| 385 |
+
**่งฃๅณ**:
|
| 386 |
+
```bash
|
| 387 |
+
pip3 install gradio
|
| 388 |
+
# ๆ
|
| 389 |
+
pip3 install -r requirements.txt
|
| 390 |
+
```
|
| 391 |
+
|
| 392 |
+
---
|
| 393 |
+
|
| 394 |
+
## ๐ ๅฎๆดๆๆกฃ
|
| 395 |
+
|
| 396 |
+
- **[ๅฟซ้ๅผๅง](GET_STARTED.md)** - 5ๅ้ๅ
ฅ้จ
|
| 397 |
+
- **[ไฝฟ็จๆๅ](USAGE_GUIDE.md)** - ๅฎๆดไฝฟ็จ่ฏดๆ
|
| 398 |
+
- **[API ๅ่](API_REFERENCE.md)** - ๆๆ API ๆนๆณ
|
| 399 |
+
- **[้จ็ฝฒๆๅ](DEPLOYMENT.md)** - ่ฏฆ็ป้จ็ฝฒ่ฏดๆ
|
| 400 |
+
- **[้กน็ฎๆป็ป](PROJECT_SUMMARY.md)** - ๆๆฏๆฆ่ง
|
| 401 |
+
|
| 402 |
+
---
|
| 403 |
+
|
| 404 |
+
## โ
ๆฃๆฅๆธ
ๅ
|
| 405 |
+
|
| 406 |
+
้จ็ฝฒๅๆฃๆฅ๏ผ
|
| 407 |
+
|
| 408 |
+
- [ ] ่ทๅไบๆญฃ็กฎๆ ผๅผ็ API Token
|
| 409 |
+
- [ ] Token ๆ่ถณๅค็ๆ้
|
| 410 |
+
- [ ] ๅทฒๅฎ่ฃ
Docker ๆ Python 3.10+
|
| 411 |
+
- [ ] ็ซฏๅฃ 7860 ๅฏ็จ
|
| 412 |
+
- [ ] ๅทฒ้
่ฏปๆๆกฃ
|
| 413 |
+
|
| 414 |
+
---
|
| 415 |
+
|
| 416 |
+
## ๐ ๅฎๆ๏ผ
|
| 417 |
+
|
| 418 |
+
็ฐๅจไฝ ๅฏไปฅ๏ผ
|
| 419 |
+
|
| 420 |
+
1. โ
็ฎก็ Pages ้กน็ฎ
|
| 421 |
+
2. โ
้จ็ฝฒ้ๆ็ฝ็ซ
|
| 422 |
+
3. โ
็ปๅฎ่ชๅฎไนๅๅ
|
| 423 |
+
4. โ
่ทๅ Nameservers
|
| 424 |
+
5. โ
้
็ฝฎ Worker ่ทฏ็ฑ
|
| 425 |
+
|
| 426 |
+
**้่ฆๅธฎๅฉ๏ผ**
|
| 427 |
+
ๆฅ็ๅฎๆดๆๆกฃๆ่ฟ่กๆต่ฏ๏ผ
|
| 428 |
+
```bash
|
| 429 |
+
python3 test_manager.py
|
| 430 |
+
```
|
| 431 |
+
|
| 432 |
+
**ไบซๅไฝฟ็จ๏ผ** ๐
|
README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: ๐
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: "cfmanager"
|
| 3 |
+
emoji: "๐"
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
---
|
| 9 |
|
| 10 |
+
### ๐ ไธ้ฎ้จ็ฝฒ
|
| 11 |
+
[](https://github.com/kfcx/HFSpaceDeploy)
|
| 12 |
+
|
| 13 |
+
ๆฌ้กน็ฎ็ฑ[HFSpaceDeploy](https://github.com/kfcx/HFSpaceDeploy)ไธ้ฎ้จ็ฝฒ
|
| 14 |
+
|
| 15 |
+
|
README_CN.md
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cloudflare ๅค่ดฆๅท็ฎก็ๅจ
|
| 2 |
+
|
| 3 |
+
## ้กน็ฎ็ฎไป
|
| 4 |
+
|
| 5 |
+
่ฟๆฏไธไธชๅ่ฝๅฎๆด็ Cloudflare ๅค่ดฆๅท็ฎก็ๅจ๏ผไฝฟ็จ Python ๅฎ็ฐใๆ นๆฎๆจ็่ฆๆฑ๏ผๅทฒๅฎ็ฐไปฅไธๆ ธๅฟๅ่ฝ๏ผ
|
| 6 |
+
|
| 7 |
+
โ
**Pages Worker ้จ็ฝฒ**๏ผๆฏๆ้ๆฉๆไปถ็ฎๅฝ๏ผ
|
| 8 |
+
โ
**็ปๅฎๅๅ**ๅฐ Pages ้กน็ฎ
|
| 9 |
+
โ
**่ฟๅ Nameservers** ไพๆจๆทปๅ ๅฐๅๅๆๅกๅ
|
| 10 |
+
โ
**Workers ่ชๅฎไนๅๅ้
็ฝฎ่ทฏ็ฑ**๏ผๅฏ้ๅ่ฝ๏ผ
|
| 11 |
+
โ
**ๅค่ดฆๅท็ฎก็**
|
| 12 |
+
|
| 13 |
+
## ๅฟซ้ๅผๅง
|
| 14 |
+
|
| 15 |
+
### 1. ๅฎ่ฃ
ไพ่ต
|
| 16 |
+
|
| 17 |
+
```bash
|
| 18 |
+
pip install requests
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
### 2. ไธ็งไฝฟ็จๆนๅผ
|
| 22 |
+
|
| 23 |
+
#### ๆนๅผไธ๏ผๅฟซ้ๅฏๅจ๏ผๆจ่๏ผ
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
python3 quickstart.py
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
ๆ็
งๅผๅฏผ่พๅ
ฅๆจ็ไฟกๆฏๅณๅฏๅฎๆ้จ็ฝฒใ
|
| 30 |
+
|
| 31 |
+
#### ๆนๅผไบ๏ผไบคไบๅผ่ๅ
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
python3 cloudflare_manager.py
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
ๆไพ 11 ไธชๅ่ฝ้้กน๏ผๅ
ๆฌ๏ผ
|
| 38 |
+
- ๅๅปบๅ้จ็ฝฒ Pages ้กน็ฎ
|
| 39 |
+
- ็ปๅฎๅๅ
|
| 40 |
+
- ่ทๅ Nameservers
|
| 41 |
+
- ้
็ฝฎ Worker ่ทฏ็ฑ
|
| 42 |
+
|
| 43 |
+
#### ๆนๅผไธ๏ผPython API
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 47 |
+
|
| 48 |
+
# ๅๅงๅ
|
| 49 |
+
account = CloudflareAccount(
|
| 50 |
+
email="exslym@closedbyme.com",
|
| 51 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 52 |
+
)
|
| 53 |
+
cf = CloudflareManager(account)
|
| 54 |
+
|
| 55 |
+
# ๅๅปบๅนถ้จ็ฝฒ
|
| 56 |
+
cf.create_pages_project("my-site", "main")
|
| 57 |
+
cf.deploy_pages_project("my-site", ".", "main")
|
| 58 |
+
|
| 59 |
+
# ็ปๅฎๅๅๅนถ่ทๅ Nameservers
|
| 60 |
+
zone = cf.create_zone("example.com")
|
| 61 |
+
print("Nameservers:")
|
| 62 |
+
for ns in zone["name_servers"]:
|
| 63 |
+
print(f" {ns}")
|
| 64 |
+
|
| 65 |
+
cf.add_pages_domain("my-site", "example.com")
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## ไฝฟ็จๆไพ็ๆต่ฏ่ดฆๅท
|
| 69 |
+
|
| 70 |
+
ๆจๅฏไปฅไฝฟ็จๆไพ็่ดฆๅทๆต่ฏๅ่ฝ๏ผ
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
account = CloudflareAccount(
|
| 74 |
+
email="exslym@closedbyme.com",
|
| 75 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 76 |
+
)
|
| 77 |
+
cf = CloudflareManager(account)
|
| 78 |
+
|
| 79 |
+
# ๆฅ็็ฐๆ่ตๆบ
|
| 80 |
+
projects = cf.list_pages_projects()
|
| 81 |
+
zones = cf.list_zones()
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## ๅฎๆด็คบไพ๏ผ้จ็ฝฒ็ฝ็ซๅฐ่ชๅฎไนๅๅ
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 88 |
+
|
| 89 |
+
# 1. ๅๅงๅ
|
| 90 |
+
account = CloudflareAccount(
|
| 91 |
+
email="your-email@example.com",
|
| 92 |
+
token="your-api-token"
|
| 93 |
+
)
|
| 94 |
+
cf = CloudflareManager(account)
|
| 95 |
+
|
| 96 |
+
# 2. ๅๅปบ Pages ้กน็ฎ
|
| 97 |
+
cf.create_pages_project("my-website", "main")
|
| 98 |
+
|
| 99 |
+
# 3. ้จ็ฝฒๆไปถ๏ผไปๅฝๅ็ฎๅฝ๏ผ
|
| 100 |
+
deployment = cf.deploy_pages_project(
|
| 101 |
+
project_name="my-website",
|
| 102 |
+
directory=".", # ๅฝๅ็ฎๅฝ๏ผๅ
ๅซ index.html
|
| 103 |
+
branch="main",
|
| 104 |
+
commit_message="Initial deployment"
|
| 105 |
+
)
|
| 106 |
+
print(f"้จ็ฝฒๆๅ: {deployment['url']}")
|
| 107 |
+
|
| 108 |
+
# 4. ๅๅปบ Zone ๅนถ่ทๅ Nameservers
|
| 109 |
+
zone = cf.create_zone("example.com")
|
| 110 |
+
print("\n่ฏทๅจๅๅๆณจๅๅๅค่ฎพ็ฝฎ่ฟไบ Nameservers:")
|
| 111 |
+
for ns in zone["name_servers"]:
|
| 112 |
+
print(f" {ns}")
|
| 113 |
+
|
| 114 |
+
# 5. ็ปๅฎๅๅ
|
| 115 |
+
cf.add_pages_domain("my-website", "example.com")
|
| 116 |
+
cf.add_pages_domain("my-website", "www.example.com")
|
| 117 |
+
|
| 118 |
+
print("\nๅฎๆ๏ผ็ฝ็ซๅฐๅจ https://example.com ไธ็บฟ")
|
| 119 |
+
print("๏ผ็ญๅพ
DNS ไผ ๆญ๏ผ้ๅธธ้่ฆ 5-30 ๅ้๏ผ")
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
## Worker ไธไผ ๅ้
็ฝฎ
|
| 123 |
+
|
| 124 |
+
### 1. ไธไผ Worker ่ๆฌ
|
| 125 |
+
|
| 126 |
+
```python
|
| 127 |
+
# ไธไผ Worker ๆไปถ
|
| 128 |
+
result = cf.upload_worker(
|
| 129 |
+
script_name="my-worker",
|
| 130 |
+
worker_file="./worker.js"
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
if result:
|
| 134 |
+
print(f"โ Worker ๅทฒไธไผ : {result['id']}")
|
| 135 |
+
print(f" ่ฎฟ้ฎๅฐๅ: https://my-worker.<account>.workers.dev")
|
| 136 |
+
|
| 137 |
+
# ไธไผ ๅธฆ KV ็ปๅฎ็ Worker
|
| 138 |
+
result = cf.upload_worker(
|
| 139 |
+
script_name="my-worker",
|
| 140 |
+
worker_file="./worker.js",
|
| 141 |
+
bindings=[
|
| 142 |
+
{
|
| 143 |
+
"type": "kv_namespace",
|
| 144 |
+
"name": "MY_KV",
|
| 145 |
+
"namespace_id": "your-kv-namespace-id"
|
| 146 |
+
}
|
| 147 |
+
]
|
| 148 |
+
)
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
### 2. Worker ่ทฏ็ฑ้
็ฝฎ๏ผๅฏ้๏ผ
|
| 152 |
+
|
| 153 |
+
```python
|
| 154 |
+
# ่ทๅ Zone ID
|
| 155 |
+
zone = cf.get_zone_by_name("example.com")
|
| 156 |
+
zone_id = zone["id"]
|
| 157 |
+
|
| 158 |
+
# ๅๅปบ Worker ่ทฏ็ฑ
|
| 159 |
+
cf.create_worker_route(
|
| 160 |
+
zone_id=zone_id,
|
| 161 |
+
pattern="example.com/api/*",
|
| 162 |
+
script_name="my-api-worker"
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# ๆทปๅ ่ชๅฎไนๅๅ
|
| 166 |
+
cf.add_worker_domain(
|
| 167 |
+
hostname="api.example.com",
|
| 168 |
+
service="my-api-worker",
|
| 169 |
+
zone_id=zone_id,
|
| 170 |
+
environment="production"
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
print("โ Worker ๅทฒ้
็ฝฎๅจ api.example.com")
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## ้กน็ฎๆไปถ่ฏดๆ
|
| 177 |
+
|
| 178 |
+
```
|
| 179 |
+
/home/engine/project/
|
| 180 |
+
โโโ cloudflare_manager.py # ๆ ธๅฟๅบ - ไธป็จๅบ
|
| 181 |
+
โโโ quickstart.py # ๅฟซ้ๅฏๅจ่ๆฌ๏ผๆจ่๏ผ
|
| 182 |
+
โโโ example_usage.py # ่ฏฆ็ป็คบไพ
|
| 183 |
+
โโโ demo.py # ้ไบคไบๆผ็คบ
|
| 184 |
+
โโโ test_manager.py # ๆต่ฏๅฅไปถ
|
| 185 |
+
โโโ index.html # ๆต่ฏ็จ HTML ๆไปถ
|
| 186 |
+
โโโ requirements.txt # Python ไพ่ต
|
| 187 |
+
โโโ .gitignore # Git ้
็ฝฎ
|
| 188 |
+
โ
|
| 189 |
+
โโโ README.md # ่ฑๆ่ฏดๆ
|
| 190 |
+
โโโ README_CN.md # ไธญๆ่ฏดๆ๏ผๆฌๆไปถ๏ผ
|
| 191 |
+
โโโ GET_STARTED.md # ๅฟซ้ไธๆๆๅ
|
| 192 |
+
โโโ USAGE_GUIDE.md # ๅฎๆดไฝฟ็จๆๅ
|
| 193 |
+
โโโ API_REFERENCE.md # API ๅ่ๆๆกฃ
|
| 194 |
+
โโโ UPLOAD_FILES_GUIDE.md # ๆไปถไธไผ ่ฏฆ็ปๆๅ๏ผPages & Worker๏ผ
|
| 195 |
+
โโโ PROJECT_SUMMARY.md # ้กน็ฎๆป็ป
|
| 196 |
+
โโโ FILES.md # ๆไปถ่ฏดๆ
|
| 197 |
+
โโโ example_worker.js # ็คบไพ Worker ่ๆฌ
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
## ๆ ธๅฟๅ่ฝ่ฏฆ่งฃ
|
| 201 |
+
|
| 202 |
+
### 1. Pages ้จ็ฝฒ
|
| 203 |
+
|
| 204 |
+
```python
|
| 205 |
+
# ๅๅปบ้กน็ฎ
|
| 206 |
+
cf.create_pages_project("project-name", "main")
|
| 207 |
+
|
| 208 |
+
# ไป็ฎๅฝ้จ็ฝฒ
|
| 209 |
+
cf.deploy_pages_project(
|
| 210 |
+
project_name="project-name",
|
| 211 |
+
directory="./public", # ้ๆๆไปถ็ฎๅฝ
|
| 212 |
+
branch="main"
|
| 213 |
+
)
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
**ๆฏๆ็ๅ่ฝ๏ผ**
|
| 217 |
+
- ่ชๅจ้ๅ็ฎๅฝไธญ็ๆๆๆไปถ
|
| 218 |
+
- ่ฎก็ฎๆไปถ็ SHA256 ๅๅธ
|
| 219 |
+
- ็ๆ manifest
|
| 220 |
+
- ไฝฟ็จ multipart/form-data ไธไผ
|
| 221 |
+
- ่ชๅจๆฃๆต MIME ็ฑปๅ
|
| 222 |
+
|
| 223 |
+
### 2. ๅๅ็ปๅฎๅ Nameserver
|
| 224 |
+
|
| 225 |
+
```python
|
| 226 |
+
# ๅๅปบ Zone๏ผๅฐๅๅๆทปๅ ๅฐ Cloudflare๏ผ
|
| 227 |
+
zone = cf.create_zone("example.com")
|
| 228 |
+
|
| 229 |
+
# ่ทๅ Nameservers
|
| 230 |
+
nameservers = zone["name_servers"]
|
| 231 |
+
# ็ปๆ็คบไพ๏ผ
|
| 232 |
+
# ['ns1.cloudflare.com', 'ns2.cloudflare.com']
|
| 233 |
+
|
| 234 |
+
# ็ปๅฎๅฐ Pages
|
| 235 |
+
result = cf.add_pages_domain("project-name", "example.com")
|
| 236 |
+
|
| 237 |
+
# ๆฃๆฅๆฏๅฆ้่ฆ DNS ้ช่ฏ
|
| 238 |
+
if result.get("validation_data"):
|
| 239 |
+
val = result["validation_data"]
|
| 240 |
+
print(f"้่ฆๆทปๅ DNS ่ฎฐๅฝ:")
|
| 241 |
+
print(f" ็ฑปๅ: {val['type']}")
|
| 242 |
+
print(f" ๅ็งฐ: {val['name']}")
|
| 243 |
+
print(f" ๅผ: {val['value']}")
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
+
### 3. Worker ่ทฏ็ฑ๏ผๅฏ้๏ผ
|
| 247 |
+
|
| 248 |
+
```python
|
| 249 |
+
# ๆนๅผ1: ่ทฏ็ฑๆจกๅผ
|
| 250 |
+
cf.create_worker_route(
|
| 251 |
+
zone_id="zone-id",
|
| 252 |
+
pattern="example.com/api/*",
|
| 253 |
+
script_name="worker-name"
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# ๆนๅผ2: ่ชๅฎไนๅๅ
|
| 257 |
+
cf.add_worker_domain(
|
| 258 |
+
hostname="api.example.com",
|
| 259 |
+
service="worker-name",
|
| 260 |
+
zone_id="zone-id"
|
| 261 |
+
)
|
| 262 |
+
```
|
| 263 |
+
|
| 264 |
+
### 4. ๅค่ดฆๅท็ฎก็
|
| 265 |
+
|
| 266 |
+
```python
|
| 267 |
+
from cloudflare_manager import MultiAccountManager
|
| 268 |
+
|
| 269 |
+
manager = MultiAccountManager()
|
| 270 |
+
|
| 271 |
+
# ๆทปๅ ๅคไธช่ดฆๅท
|
| 272 |
+
manager.add_account("account1", "email1@example.com", "token1")
|
| 273 |
+
manager.add_account("account2", "email2@example.com", "token2")
|
| 274 |
+
|
| 275 |
+
# ไฝฟ็จ็นๅฎ่ดฆๅท
|
| 276 |
+
cf1 = manager.get_account("account1")
|
| 277 |
+
cf2 = manager.get_account("account2")
|
| 278 |
+
|
| 279 |
+
# ๅ่ชๆไฝ
|
| 280 |
+
cf1.list_pages_projects()
|
| 281 |
+
cf2.list_pages_projects()
|
| 282 |
+
```
|
| 283 |
+
|
| 284 |
+
## ๆต่ฏ
|
| 285 |
+
|
| 286 |
+
่ฟ่กๅฎๆด็ๆต่ฏๅฅไปถ๏ผ
|
| 287 |
+
|
| 288 |
+
```bash
|
| 289 |
+
python3 test_manager.py
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
้ขๆ่พๅบ๏ผ
|
| 293 |
+
```
|
| 294 |
+
โ PASS: File Structure
|
| 295 |
+
โ PASS: Imports
|
| 296 |
+
โ PASS: Account Creation
|
| 297 |
+
โ PASS: Multi-Account Manager
|
| 298 |
+
โ PASS: API Methods
|
| 299 |
+
โ PASS: index.html
|
| 300 |
+
|
| 301 |
+
Total: 6/6 tests passed
|
| 302 |
+
๐ All tests passed!
|
| 303 |
+
```
|
| 304 |
+
|
| 305 |
+
## API ๆนๆณๅ่กจ
|
| 306 |
+
|
| 307 |
+
### Pages ๆไฝ
|
| 308 |
+
- `create_pages_project()` - ๅๅปบ้กน็ฎ
|
| 309 |
+
- `list_pages_projects()` - ๅๅบ้กน็ฎ
|
| 310 |
+
- `deploy_pages_project()` - ้จ็ฝฒ้กน็ฎ
|
| 311 |
+
- `list_pages_deployments()` - ๆฅ็้จ็ฝฒๅๅฒ
|
| 312 |
+
|
| 313 |
+
### ๅๅๆไฝ
|
| 314 |
+
- `add_pages_domain()` - ๆทปๅ ๅๅ
|
| 315 |
+
- `list_pages_domains()` - ๅๅบๅๅ
|
| 316 |
+
- `get_pages_domain()` - ่ทๅๅๅ่ฏฆๆ
|
| 317 |
+
|
| 318 |
+
### Zone ๆไฝ
|
| 319 |
+
- `create_zone()` - ๅๅปบ Zone
|
| 320 |
+
- `list_zones()` - ๅๅบๆๆ Zones
|
| 321 |
+
- `get_zone()` - ่ทๅ Zone ่ฏฆๆ
|
| 322 |
+
- `get_zone_by_name()` - ้่ฟๅๅ่ทๅ Zone
|
| 323 |
+
- `get_nameservers()` - ่ทๅ Nameservers
|
| 324 |
+
|
| 325 |
+
### Worker ๆไฝ
|
| 326 |
+
- `create_worker_route()` - ๅๅปบ่ทฏ็ฑ
|
| 327 |
+
- `list_worker_routes()` - ๅๅบ่ทฏ็ฑ
|
| 328 |
+
- `add_worker_domain()` - ๆทปๅ ่ชๅฎไนๅๅ
|
| 329 |
+
- `list_worker_domains()` - ๅๅบ่ชๅฎไนๅๅ
|
| 330 |
+
|
| 331 |
+
## ๅธธ่ง้ฎ้ข
|
| 332 |
+
|
| 333 |
+
### Q: ๅฆไฝ่ทๅ API Token?
|
| 334 |
+
|
| 335 |
+
1. ่ฎฟ้ฎ https://dash.cloudflare.com/profile/api-tokens
|
| 336 |
+
2. ๅๅปบๆฐ Token๏ผ้่ฆไปฅไธๆ้๏ผ
|
| 337 |
+
- Account > Cloudflare Pages > Edit
|
| 338 |
+
- Zone > DNS > Edit
|
| 339 |
+
- Zone > Workers Routes > Edit
|
| 340 |
+
|
| 341 |
+
### Q: Nameservers ๅจๅช้่ฎพ็ฝฎ?
|
| 342 |
+
|
| 343 |
+
ๅจๆจ็ๅๅๆณจๅๅ๏ผๅฆ GoDaddyใNamecheapใ้ฟ้ไบ็ญ๏ผ็็ฎก็้ขๆฟไธญ่ฎพ็ฝฎใ
|
| 344 |
+
|
| 345 |
+
### Q: DNS ๅคไน
็ๆ?
|
| 346 |
+
|
| 347 |
+
้ๅธธ 5-30 ๅ้๏ผๆ้ฟๅฏ่ฝ้่ฆ 48 ๅฐๆถใ
|
| 348 |
+
|
| 349 |
+
### Q: ๆฏๆๅชไบๆไปถๆ ผๅผ?
|
| 350 |
+
|
| 351 |
+
ๆๆ้ๆๆไปถ๏ผHTMLใCSSใJSใๅพ็ใๅญไฝ็ญใๅๆไปถๆๅคง 25MBใ
|
| 352 |
+
|
| 353 |
+
## ็ญๆ็ curl ๅฝไปค
|
| 354 |
+
|
| 355 |
+
ๅฆๆๆจๆณไฝฟ็จ curl ่ไธๆฏ Python๏ผ
|
| 356 |
+
|
| 357 |
+
```bash
|
| 358 |
+
# ่ฎพ็ฝฎ็ฏๅขๅ้
|
| 359 |
+
export CLOUDFLARE_API_TOKEN="your-token"
|
| 360 |
+
export ACCOUNT_ID="your-account-id"
|
| 361 |
+
|
| 362 |
+
# ๅๅปบ Pages ้กน็ฎ
|
| 363 |
+
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects \
|
| 364 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 365 |
+
-H "Content-Type: application/json" \
|
| 366 |
+
-d '{"name": "my-site", "production_branch": "main"}'
|
| 367 |
+
|
| 368 |
+
# ๅๅปบ Zone ่ทๅ Nameservers
|
| 369 |
+
curl https://api.cloudflare.com/client/v4/zones \
|
| 370 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 371 |
+
-H "Content-Type: application/json" \
|
| 372 |
+
-d '{"account": {"id": "'$ACCOUNT_ID'"}, "name": "example.com", "type": "full"}'
|
| 373 |
+
|
| 374 |
+
# ็ปๅฎๅๅ
|
| 375 |
+
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/my-site/domains \
|
| 376 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 377 |
+
-H "Content-Type: application/json" \
|
| 378 |
+
-d '{"name": "example.com"}'
|
| 379 |
+
```
|
| 380 |
+
|
| 381 |
+
ๅฎๆด็ curl ๅฝไปคๅ่่ฏทๆฅ็ USAGE_GUIDE.mdใ
|
| 382 |
+
|
| 383 |
+
## ๆๆฏ็นๆง
|
| 384 |
+
|
| 385 |
+
- **่ฏญ่จ**: Python 3.6+
|
| 386 |
+
- **ไพ่ต**: requests
|
| 387 |
+
- **ๆถๆ**: ้ขๅๅฏน่ฑก (OOP)
|
| 388 |
+
- **็ฑปๅๆ็คบ**: ๅฎๆด็็ฑปๅๆณจ่งฃ
|
| 389 |
+
- **้่ฏฏๅค็**: ๅๅฅฝ็้่ฏฏๆ็คบ
|
| 390 |
+
- **ๆๆกฃ**: ไธญ่ฑๆๆททๅ๏ผ่ฏฆๅฐฝๅฎๆด
|
| 391 |
+
|
| 392 |
+
## ้กน็ฎ็น็น
|
| 393 |
+
|
| 394 |
+
1. โ
**ๅ่ฝๅฎๆด** - ๅฎ็ฐไบๆๆ่ฆๆฑ็ๅ่ฝ
|
| 395 |
+
2. โ
**ๆไบไฝฟ็จ** - ไธ็งไฝฟ็จๆนๅผ๏ผ้ๅไธๅๅบๆฏ
|
| 396 |
+
3. โ
**ๆๆกฃไธฐๅฏ** - 7 ไปฝ่ฏฆ็ปๆๆกฃ
|
| 397 |
+
4. โ
**ไปฃ็ ่ดจ้้ซ** - ็ฑปๅๆ็คบใ้่ฏฏๅค็ใๆณจ้ๆธ
ๆฐ
|
| 398 |
+
5. โ
**ๆต๏ฟฝ๏ฟฝๅฎๅ** - ๅฎๆด็ๆต่ฏๅฅไปถ
|
| 399 |
+
6. โ
**ๅฎ็จๆงๅผบ** - ๅฏ็ดๆฅ็จไบ็ไบง็ฏๅข
|
| 400 |
+
|
| 401 |
+
## ไธไธๆญฅ
|
| 402 |
+
|
| 403 |
+
**ๆฐๆๆจ่๏ผ**
|
| 404 |
+
1. ้
่ฏป GET_STARTED.md
|
| 405 |
+
2. ่ฟ่ก `python3 quickstart.py`
|
| 406 |
+
3. ๆฅ็ USAGE_GUIDE.md
|
| 407 |
+
|
| 408 |
+
**ๅผๅ่
ๆจ่๏ผ**
|
| 409 |
+
1. ้
่ฏป API_REFERENCE.md
|
| 410 |
+
2. ๆฅ็ cloudflare_manager.py ๆบ็
|
| 411 |
+
3. ่ฟ่ก example_usage.py
|
| 412 |
+
|
| 413 |
+
## ่ทๅๅธฎๅฉ
|
| 414 |
+
|
| 415 |
+
- **ๅฟซ้ไธๆ**: GET_STARTED.md
|
| 416 |
+
- **ไฝฟ็จๆๅ**: USAGE_GUIDE.md
|
| 417 |
+
- **API ๆๆกฃ**: API_REFERENCE.md
|
| 418 |
+
- **้กน็ฎๆป็ป**: PROJECT_SUMMARY.md
|
| 419 |
+
- **ๆไปถ่ฏดๆ**: FILES.md
|
| 420 |
+
|
| 421 |
+
## ่ฎธๅฏ่ฏ
|
| 422 |
+
|
| 423 |
+
MIT License - ๅฏ่ช็ฑไฝฟ็จๅไฟฎๆน
|
| 424 |
+
|
| 425 |
+
## ๆดๆฐๆฅๅฟ
|
| 426 |
+
|
| 427 |
+
**v1.0.0** (2024-01-27)
|
| 428 |
+
- โ
ๅฎ็ฐ Pages ้จ็ฝฒๅ่ฝ
|
| 429 |
+
- โ
ๅฎ็ฐๅๅ็ปๅฎๅ่ฝ
|
| 430 |
+
- โ
ๅฎ็ฐ Nameserver ๆฅ่ฏขๅ่ฝ
|
| 431 |
+
- โ
ๅฎ็ฐ Worker ่ทฏ็ฑ้
็ฝฎ
|
| 432 |
+
- โ
ๅฎ็ฐๅค่ดฆๅท็ฎก็
|
| 433 |
+
- โ
ๅฎๆด็ๆต่ฏๅฅไปถ
|
| 434 |
+
- โ
่ฏฆ็ป็ไธญ่ฑๆๆๆกฃ
|
| 435 |
+
|
| 436 |
+
---
|
| 437 |
+
|
| 438 |
+
**ๅๅปบๆฅๆ**: 2024-01-27
|
| 439 |
+
**็ถๆ**: โ
ๅฎๆ
|
| 440 |
+
**ๆต่ฏ็ถๆ**: โ
All tests passed!
|
README_HUGGINGFACE.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Cloudflare Manager
|
| 3 |
+
emoji: โ๏ธ
|
| 4 |
+
colorFrom: orange
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "4.0.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Cloudflare Multi-Account Manager
|
| 14 |
+
|
| 15 |
+
๐ A comprehensive web interface for managing Cloudflare Pages, Domains, and Workers.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
โ
**Pages Management**
|
| 20 |
+
- Create and deploy Pages projects
|
| 21 |
+
- List all projects
|
| 22 |
+
- View deployment URLs
|
| 23 |
+
|
| 24 |
+
โ
**Domain & Nameservers**
|
| 25 |
+
- Create DNS zones
|
| 26 |
+
- Get nameservers for domain registrars
|
| 27 |
+
- Bind custom domains to Pages projects
|
| 28 |
+
|
| 29 |
+
โ
**Worker Routes**
|
| 30 |
+
- Configure worker routes
|
| 31 |
+
- Add custom domains to workers
|
| 32 |
+
- Manage route patterns
|
| 33 |
+
|
| 34 |
+
## Quick Start
|
| 35 |
+
|
| 36 |
+
### Using the Web Interface
|
| 37 |
+
|
| 38 |
+
1. Enter your Cloudflare Email and API Token
|
| 39 |
+
2. Click "Test Connection" to verify
|
| 40 |
+
3. Use the tabs to manage your resources
|
| 41 |
+
|
| 42 |
+
### Getting Your API Token
|
| 43 |
+
|
| 44 |
+
1. Go to https://dash.cloudflare.com/profile/api-tokens
|
| 45 |
+
2. Create a new token with these permissions:
|
| 46 |
+
- Account > Cloudflare Pages > Edit
|
| 47 |
+
- Zone > DNS > Edit
|
| 48 |
+
- Zone > Workers Routes > Edit
|
| 49 |
+
3. Copy the token and paste it in the interface
|
| 50 |
+
|
| 51 |
+
## Docker Deployment
|
| 52 |
+
|
| 53 |
+
Build and run with Docker:
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
# Build the image
|
| 57 |
+
docker build -t cloudflare-manager .
|
| 58 |
+
|
| 59 |
+
# Run the container
|
| 60 |
+
docker run -p 7860:7860 cloudflare-manager
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Access at: http://localhost:7860
|
| 64 |
+
|
| 65 |
+
### With Environment Variables
|
| 66 |
+
|
| 67 |
+
```bash
|
| 68 |
+
docker run -p 7860:7860 \
|
| 69 |
+
-e CLOUDFLARE_EMAIL="your-email@example.com" \
|
| 70 |
+
-e CLOUDFLARE_TOKEN="your-api-token" \
|
| 71 |
+
cloudflare-manager
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## Hugging Face Spaces Deployment
|
| 75 |
+
|
| 76 |
+
This app is designed to run on Hugging Face Spaces:
|
| 77 |
+
|
| 78 |
+
1. Create a new Space on Hugging Face
|
| 79 |
+
2. Select "Gradio" as the SDK
|
| 80 |
+
3. Upload all files or connect to Git
|
| 81 |
+
4. The app will automatically deploy
|
| 82 |
+
|
| 83 |
+
### Setting Secrets in Hugging Face
|
| 84 |
+
|
| 85 |
+
For better security, set your credentials as Secrets:
|
| 86 |
+
|
| 87 |
+
1. Go to your Space settings
|
| 88 |
+
2. Add secrets:
|
| 89 |
+
- `CLOUDFLARE_EMAIL`: Your Cloudflare email
|
| 90 |
+
- `CLOUDFLARE_TOKEN`: Your API token
|
| 91 |
+
3. The app will automatically use these credentials
|
| 92 |
+
|
| 93 |
+
## Local Development
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
# Install dependencies
|
| 97 |
+
pip install -r requirements.txt
|
| 98 |
+
|
| 99 |
+
# Run the app
|
| 100 |
+
python3 app.py
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
Access at: http://localhost:7860
|
| 104 |
+
|
| 105 |
+
## Python API
|
| 106 |
+
|
| 107 |
+
You can also use the Python API directly:
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 111 |
+
|
| 112 |
+
# Initialize
|
| 113 |
+
account = CloudflareAccount(
|
| 114 |
+
email="your-email@example.com",
|
| 115 |
+
token="your-api-token"
|
| 116 |
+
)
|
| 117 |
+
cf = CloudflareManager(account)
|
| 118 |
+
|
| 119 |
+
# Create Pages project
|
| 120 |
+
cf.create_pages_project("my-site", "main")
|
| 121 |
+
|
| 122 |
+
# Get nameservers
|
| 123 |
+
zone = cf.create_zone("example.com")
|
| 124 |
+
print(zone["name_servers"])
|
| 125 |
+
|
| 126 |
+
# Bind domain
|
| 127 |
+
cf.add_pages_domain("my-site", "example.com")
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## CLI Tools
|
| 131 |
+
|
| 132 |
+
Run interactive commands:
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
# Quick start wizard
|
| 136 |
+
python3 quickstart.py
|
| 137 |
+
|
| 138 |
+
# Interactive menu
|
| 139 |
+
python3 cloudflare_manager.py
|
| 140 |
+
|
| 141 |
+
# Run examples
|
| 142 |
+
python3 example_usage.py
|
| 143 |
+
|
| 144 |
+
# Run tests
|
| 145 |
+
python3 test_manager.py
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
## Project Structure
|
| 149 |
+
|
| 150 |
+
```
|
| 151 |
+
.
|
| 152 |
+
โโโ app.py # Gradio web interface
|
| 153 |
+
โโโ cloudflare_manager.py # Core library
|
| 154 |
+
โโโ Dockerfile # Docker configuration
|
| 155 |
+
โโโ requirements.txt # Python dependencies
|
| 156 |
+
โโโ quickstart.py # CLI quick start
|
| 157 |
+
โโโ example_usage.py # Usage examples
|
| 158 |
+
โโโ test_manager.py # Test suite
|
| 159 |
+
โโโ docs/ # Documentation
|
| 160 |
+
โโโ README.md
|
| 161 |
+
โโโ GET_STARTED.md
|
| 162 |
+
โโโ USAGE_GUIDE.md
|
| 163 |
+
โโโ API_REFERENCE.md
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
## Documentation
|
| 167 |
+
|
| 168 |
+
- **[Quick Start Guide](GET_STARTED.md)** - Get started in 5 minutes
|
| 169 |
+
- **[Usage Guide](USAGE_GUIDE.md)** - Complete usage examples
|
| 170 |
+
- **[API Reference](API_REFERENCE.md)** - Full API documentation
|
| 171 |
+
- **[Project Summary](PROJECT_SUMMARY.md)** - Technical overview
|
| 172 |
+
|
| 173 |
+
## Common Use Cases
|
| 174 |
+
|
| 175 |
+
### 1. Deploy a Static Website
|
| 176 |
+
|
| 177 |
+
```python
|
| 178 |
+
# Create project
|
| 179 |
+
cf.create_pages_project("my-blog", "main")
|
| 180 |
+
|
| 181 |
+
# Deploy files
|
| 182 |
+
cf.deploy_pages_project("my-blog", "./public", "main")
|
| 183 |
+
|
| 184 |
+
# Add custom domain
|
| 185 |
+
zone = cf.create_zone("myblog.com")
|
| 186 |
+
cf.add_pages_domain("my-blog", "myblog.com")
|
| 187 |
+
|
| 188 |
+
# Get nameservers to set in registrar
|
| 189 |
+
print(zone["name_servers"])
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
### 2. Configure API Subdomain
|
| 193 |
+
|
| 194 |
+
```python
|
| 195 |
+
# Get zone
|
| 196 |
+
zone = cf.get_zone_by_name("example.com")
|
| 197 |
+
|
| 198 |
+
# Create worker route
|
| 199 |
+
cf.create_worker_route(
|
| 200 |
+
zone_id=zone["id"],
|
| 201 |
+
pattern="example.com/api/*",
|
| 202 |
+
script_name="api-worker"
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
# Add custom subdomain
|
| 206 |
+
cf.add_worker_domain(
|
| 207 |
+
hostname="api.example.com",
|
| 208 |
+
service="api-worker",
|
| 209 |
+
zone_id=zone["id"]
|
| 210 |
+
)
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
## Troubleshooting
|
| 214 |
+
|
| 215 |
+
### API Token Errors
|
| 216 |
+
|
| 217 |
+
**Error**: "Invalid request headers"
|
| 218 |
+
|
| 219 |
+
**Solution**: Make sure your API token has the correct permissions:
|
| 220 |
+
- Account > Cloudflare Pages > Edit
|
| 221 |
+
- Zone > DNS > Edit
|
| 222 |
+
- Zone > Workers Routes > Edit
|
| 223 |
+
|
| 224 |
+
### Zone Not Found
|
| 225 |
+
|
| 226 |
+
**Error**: "Zone not found"
|
| 227 |
+
|
| 228 |
+
**Solution**: Create the zone first:
|
| 229 |
+
```python
|
| 230 |
+
cf.create_zone("example.com")
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
### DNS Propagation
|
| 234 |
+
|
| 235 |
+
After adding a domain:
|
| 236 |
+
1. Update nameservers at your registrar
|
| 237 |
+
2. Wait 5-30 minutes for DNS propagation
|
| 238 |
+
3. Check status: `cf.get_zone_by_name("example.com")`
|
| 239 |
+
|
| 240 |
+
## Security
|
| 241 |
+
|
| 242 |
+
- Never commit API tokens to Git
|
| 243 |
+
- Use environment variables or Hugging Face Secrets
|
| 244 |
+
- Rotate tokens regularly
|
| 245 |
+
- Use least-privilege permissions
|
| 246 |
+
|
| 247 |
+
## Support
|
| 248 |
+
|
| 249 |
+
- ๐ Full documentation in the `/docs` folder
|
| 250 |
+
- ๐ Report issues on GitHub
|
| 251 |
+
- ๐ฌ Ask questions in Hugging Face Discussions
|
| 252 |
+
|
| 253 |
+
## License
|
| 254 |
+
|
| 255 |
+
MIT License - Free to use and modify
|
| 256 |
+
|
| 257 |
+
## Credits
|
| 258 |
+
|
| 259 |
+
Built with:
|
| 260 |
+
- Python 3.10+
|
| 261 |
+
- Gradio for the web interface
|
| 262 |
+
- Cloudflare API
|
| 263 |
+
- Docker for containerization
|
| 264 |
+
|
| 265 |
+
---
|
| 266 |
+
|
| 267 |
+
**Version**: 1.0.0
|
| 268 |
+
**Last Updated**: 2024-01-27
|
| 269 |
+
**Status**: โ
Production Ready
|
TASK_COMPLETION_SUMMARY.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ๅฐ Pages ๅ Worker ๆไปถไธไผ ็ๆๆกฃ๏ผๅธๆๆทปๅ ๅฎๆด็ๆไปถไธไผ ๅ่ฝๅๆๆกฃ่ฏดๆใ
|
| 6 |
+
|
| 7 |
+
## ๅทฒๅฎๆ็ๅทฅไฝ
|
| 8 |
+
|
| 9 |
+
### โ
1. ๆทปๅ Worker ไธไผ ๅ่ฝ
|
| 10 |
+
|
| 11 |
+
ๅจ `cloudflare_manager.py` ไธญๆฐๅข 4 ไธชๆนๆณ๏ผ
|
| 12 |
+
|
| 13 |
+
```python
|
| 14 |
+
def upload_worker(script_name, worker_file, bindings=None):
|
| 15 |
+
"""ไธไผ Worker ่ๆฌๅฐ Cloudflare"""
|
| 16 |
+
# ไฝฟ็จ multipart/form-data ๆ ผๅผไธไผ
|
| 17 |
+
# ๆฏๆ KVใR2 ็ญ่ตๆบ็ปๅฎ
|
| 18 |
+
|
| 19 |
+
def list_workers():
|
| 20 |
+
"""ๅๅบๆๆ Worker ่ๆฌ"""
|
| 21 |
+
|
| 22 |
+
def get_worker(script_name):
|
| 23 |
+
"""่ทๅ Worker ่ฏฆๆ
"""
|
| 24 |
+
|
| 25 |
+
def delete_worker(script_name):
|
| 26 |
+
"""ๅ ้ค Worker ่ๆฌ"""
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
**ๅฎ็ฐ็ป่๏ผ**
|
| 30 |
+
- ไฝฟ็จ `multipart/form-data` ๆ ผๅผไธไผ
|
| 31 |
+
- ๆฏๆ API Key ๅ API Token ไธค็ง่ฎค่ฏๆนๅผ
|
| 32 |
+
- ่ชๅจๅค็ metadata ๅๆไปถๅ
ๅฎน
|
| 33 |
+
- ๆฏๆ่ตๆบ็ปๅฎ๏ผKVใR2ใDurable Objects ็ญ๏ผ
|
| 34 |
+
|
| 35 |
+
### โ
2. ๅๅปบๅฎๆด็ๆไปถไธไผ ๆๅ
|
| 36 |
+
|
| 37 |
+
ๆฐๅปบๆไปถ๏ผ`UPLOAD_FILES_GUIDE.md` (12KB)
|
| 38 |
+
|
| 39 |
+
**ๅ
ๅฎนๅ
ๆฌ๏ผ**
|
| 40 |
+
|
| 41 |
+
1. **Pages ๆไปถไธไผ ่ฏฆ่งฃ**
|
| 42 |
+
- ไปๆฌๅฐ็ฎๅฝ้จ็ฝฒ็ๅฎๆดๆต็จ
|
| 43 |
+
- ๆไปถๆซๆใๅๅธ่ฎก็ฎใmanifest ๆๅปบ
|
| 44 |
+
- multipart/form-data ๆ ผๅผ่ฏดๆ
|
| 45 |
+
- ๆฏๆ็ๆไปถ็ฑปๅๅ่กจ
|
| 46 |
+
|
| 47 |
+
2. **Worker ่ๆฌไธไผ ่ฏฆ่งฃ**
|
| 48 |
+
- ๅบๆฌไธไผ ๆนๆณ
|
| 49 |
+
- ๅธฆ่ตๆบ็ปๅฎ็้ซ็บง็จๆณ
|
| 50 |
+
- Worker ไปฃ็ ็คบไพ
|
| 51 |
+
- ๆฐๆฎๆ ผๅผ่ฏฆ็ป่ฏดๆ
|
| 52 |
+
|
| 53 |
+
3. **API ่ฏฆ็ป่ฏดๆ**
|
| 54 |
+
- `deploy_pages_project()` ๅฎๆดๆๆกฃ
|
| 55 |
+
- `upload_worker()` ๅฎๆดๆๆกฃ
|
| 56 |
+
- ๆๆ Worker ็ฎก็ๆนๆณๆๆกฃ
|
| 57 |
+
- ๅๆฐใ่ฟๅๅผใ้่ฏฏๅค็
|
| 58 |
+
|
| 59 |
+
4. **ๅฎๆด็คบไพไปฃ็ **
|
| 60 |
+
- ้จ็ฝฒ้ๆ็ฝ็ซๅฐ Pages
|
| 61 |
+
- ไธไผ Worker API
|
| 62 |
+
- Worker + KV ๅญๅจ็คบไพ
|
| 63 |
+
- ๆน้้จ็ฝฒๅคไธช Workers
|
| 64 |
+
|
| 65 |
+
5. **ๅธธ่ง้ฎ้ข่งฃ็ญ (FAQ)**
|
| 66 |
+
- ๆไปถๅคงๅฐ้ๅถ
|
| 67 |
+
- ไธไผ ๅคฑ่ดฅๆๆฅ
|
| 68 |
+
- ่ฟๅบฆๆพ็คบๆนๆณ
|
| 69 |
+
|
| 70 |
+
6. **ๆๆฏ็ป่**
|
| 71 |
+
- Pages ้จ็ฝฒ API ็ซฏ็นๅๆ ผๅผ
|
| 72 |
+
- Worker ไธไผ API ็ซฏ็นๅๆ ผๅผ
|
| 73 |
+
- ่ฎค่ฏๆนๅผ่ฏดๆ
|
| 74 |
+
|
| 75 |
+
### โ
3. ๆดๆฐ็ฐๆๆๆกฃ
|
| 76 |
+
|
| 77 |
+
**API_REFERENCE.md**
|
| 78 |
+
- ๆทปๅ `upload_worker()` ๅฎๆดๆๆกฃ
|
| 79 |
+
- ๆทปๅ `list_workers()` ๆๆกฃ
|
| 80 |
+
- ๆทปๅ `get_worker()` ๆๆกฃ
|
| 81 |
+
- ๆทปๅ `delete_worker()` ๆๆกฃ
|
| 82 |
+
- ๅ
ๅซๅๆฐ่ฏดๆใ่ฟๅๅผใไปฃ็ ็คบไพ
|
| 83 |
+
|
| 84 |
+
**README.md**
|
| 85 |
+
- ๆทปๅ "ๅฎๆดๆๆกฃ"็ซ ่
|
| 86 |
+
- ้พๆฅๅฐ UPLOAD_FILES_GUIDE.md
|
| 87 |
+
|
| 88 |
+
**README_CN.md**
|
| 89 |
+
- ๆทปๅ "Worker ไธไผ ๅ้
็ฝฎ"็ซ ่
|
| 90 |
+
- ๅฑ็คบๅบๆฌไธไผ ๅๅธฆ็ปๅฎ็ไธไผ
|
| 91 |
+
- ๆดๆฐๆไปถๅ่กจ
|
| 92 |
+
|
| 93 |
+
**FILES.md**
|
| 94 |
+
- ๆทปๅ ๆฐๆไปถ่ฏดๆ
|
| 95 |
+
- ๆดๆฐๆไปถ็ป่ฎก
|
| 96 |
+
- ๆดๆฐ้
่ฏป้กบๅบ
|
| 97 |
+
|
| 98 |
+
**example_usage.py**
|
| 99 |
+
- ๆทปๅ `example_worker_upload()` ๅฝๆฐ
|
| 100 |
+
- ้ๆๅฐไธปๆต็จ็คบไพไธญ
|
| 101 |
+
|
| 102 |
+
### โ
4. ๅๅปบ็คบไพๅๆต่ฏๆไปถ
|
| 103 |
+
|
| 104 |
+
**example_worker.js** (1.7KB)
|
| 105 |
+
- ๅฎๆด็็คบไพ Worker ่ๆฌ
|
| 106 |
+
- ๅฑ็คบๅคไธช API ่ทฏ็ฑ๏ผ
|
| 107 |
+
- `/` - ๆฌข่ฟ้กต้ข
|
| 108 |
+
- `/api/time` - ่ฟๅๅฝๅๆถ้ด
|
| 109 |
+
- `/api/headers` - ๆพ็คบ่ฏทๆฑๅคด
|
| 110 |
+
- `/api/echo` - ๅๆพ POST ๆฐๆฎ
|
| 111 |
+
- ๆ ๅ็ ES Module ๆ ผๅผ
|
| 112 |
+
|
| 113 |
+
**test_worker_upload.py** (1.2KB)
|
| 114 |
+
- ๆต่ฏๆๆ Worker ๆนๆณๆฏๅฆๅญๅจ
|
| 115 |
+
- ้ช่ฏ็คบไพๆไปถๅฎๆดๆง
|
| 116 |
+
- ้ช่ฏๆๆกฃๅญๅจ
|
| 117 |
+
|
| 118 |
+
**CHANGELOG_WORKER_UPLOAD.md** (8KB)
|
| 119 |
+
- ่ฏฆ็ป็ๆดๆฐๆฅๅฟ
|
| 120 |
+
- ๅ่ฝ่ฏดๆๅไฝฟ็จ็คบไพ
|
| 121 |
+
- ๆๆฏ็ป่ๅ็ป่ฎกไฟกๆฏ
|
| 122 |
+
|
| 123 |
+
### โ
5. ๆดๆฐไธป่ๅ
|
| 124 |
+
|
| 125 |
+
`cloudflare_manager.py` ไบคไบๅผ่ๅๆดๆฐ๏ผ
|
| 126 |
+
- ้้กน 9: Upload Worker Script๏ผๆฐๅข๏ผ
|
| 127 |
+
- ้้กน 10: List Workers๏ผๆฐๅข๏ผ
|
| 128 |
+
- ้้กน 11: Create Worker Route๏ผๅ้้กน 9๏ผ
|
| 129 |
+
- ้้กน 12: List Worker Routes๏ผๅ้้กน 10๏ผ
|
| 130 |
+
- ้้กน 13: Add Worker Custom Domain๏ผๅ้้กน 11๏ผ
|
| 131 |
+
|
| 132 |
+
## ๆไปถๅๆด็ป่ฎก
|
| 133 |
+
|
| 134 |
+
### ๆฐๅขๆไปถ (4 ไธช)
|
| 135 |
+
1. UPLOAD_FILES_GUIDE.md - 12KB
|
| 136 |
+
2. example_worker.js - 1.7KB
|
| 137 |
+
3. test_worker_upload.py - 1.2KB
|
| 138 |
+
4. CHANGELOG_WORKER_UPLOAD.md - 8KB
|
| 139 |
+
|
| 140 |
+
### ไฟฎๆนๆไปถ (6 ไธช)
|
| 141 |
+
1. cloudflare_manager.py - +150 ่กไปฃ็
|
| 142 |
+
2. API_REFERENCE.md - +150 ่กๆๆกฃ
|
| 143 |
+
3. example_usage.py - +30 ่กไปฃ็
|
| 144 |
+
4. README.md - +7 ่ก
|
| 145 |
+
5. README_CN.md - +50 ่ก
|
| 146 |
+
6. FILES.md - +80 ่ก
|
| 147 |
+
|
| 148 |
+
### ไปฃ็ ็ป่ฎก
|
| 149 |
+
- **ๆฐๅข Python ไปฃ็ **: ~180 ่ก
|
| 150 |
+
- **ๆฐๅขๆๆกฃ**: ~500 ่ก
|
| 151 |
+
- **ๆฐๅข JavaScript ไปฃ็ **: ~70 ่ก
|
| 152 |
+
|
| 153 |
+
## ๅ่ฝๆต่ฏ็ปๆ
|
| 154 |
+
|
| 155 |
+
```bash
|
| 156 |
+
$ python3 test_worker_upload.py
|
| 157 |
+
Testing Worker upload functionality...
|
| 158 |
+
|
| 159 |
+
โ upload_worker method exists
|
| 160 |
+
โ list_workers method exists
|
| 161 |
+
โ get_worker method exists
|
| 162 |
+
โ delete_worker method exists
|
| 163 |
+
โ example_worker.js exists
|
| 164 |
+
โ UPLOAD_FILES_GUIDE.md exists
|
| 165 |
+
|
| 166 |
+
โ
All tests passed!
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
```bash
|
| 170 |
+
$ python3 -m py_compile cloudflare_manager.py
|
| 171 |
+
โ
Syntax check passed
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
## ๆ ธๅฟๅ่ฝๅฎ็ฐ
|
| 175 |
+
|
| 176 |
+
### 1. Pages ๆไปถไธไผ
|
| 177 |
+
ๅทฒๆๅ่ฝ๏ผ็ฐๅทฒๅฎๅๆๆกฃ๏ผ
|
| 178 |
+
- โ
`deploy_pages_project()` - ไป็ฎๅฝ้จ็ฝฒ
|
| 179 |
+
- โ
่ชๅจๆซๆๆไปถ
|
| 180 |
+
- โ
่ฎก็ฎๆไปถๅๅธ
|
| 181 |
+
- โ
ๆๅปบ manifest
|
| 182 |
+
- โ
multipart/form-data ไธไผ
|
| 183 |
+
|
| 184 |
+
### 2. Worker ๆไปถไธไผ
|
| 185 |
+
ๆฐๅขๅ่ฝ๏ผ
|
| 186 |
+
- โ
`upload_worker()` - ไธไผ Worker ่ๆฌ
|
| 187 |
+
- โ
ๆฏๆ่ตๆบ็ปๅฎ๏ผKVใR2 ็ญ๏ผ
|
| 188 |
+
- โ
ๆฏๆ API Key ๅ Token ่ฎค่ฏ
|
| 189 |
+
- โ
`list_workers()` - ๅๅบๆๆ Workers
|
| 190 |
+
- โ
`get_worker()` - ่ทๅ Worker ่ฏฆๆ
|
| 191 |
+
- โ
`delete_worker()` - ๅ ้ค Worker
|
| 192 |
+
|
| 193 |
+
## ไฝฟ็จ็คบไพ
|
| 194 |
+
|
| 195 |
+
### Pages ๆไปถไธไผ
|
| 196 |
+
```python
|
| 197 |
+
cf.deploy_pages_project(
|
| 198 |
+
project_name="my-website",
|
| 199 |
+
directory="./dist",
|
| 200 |
+
branch="main"
|
| 201 |
+
)
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
### Worker ๆไปถไธไผ
|
| 205 |
+
```python
|
| 206 |
+
# ๅบๆฌไธไผ
|
| 207 |
+
cf.upload_worker("my-worker", "./worker.js")
|
| 208 |
+
|
| 209 |
+
# ๅธฆ KV ็ปๅฎ
|
| 210 |
+
cf.upload_worker(
|
| 211 |
+
"my-worker",
|
| 212 |
+
"./worker.js",
|
| 213 |
+
bindings=[{
|
| 214 |
+
"type": "kv_namespace",
|
| 215 |
+
"name": "MY_KV",
|
| 216 |
+
"namespace_id": "abc123"
|
| 217 |
+
}]
|
| 218 |
+
)
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
## ๆๆกฃ่ฆ็
|
| 222 |
+
|
| 223 |
+
โ
**ๅฎๆด็ API ๆๆกฃ** - API_REFERENCE.md
|
| 224 |
+
โ
**่ฏฆ็ป็ไธไผ ๆๅ** - UPLOAD_FILES_GUIDE.md
|
| 225 |
+
โ
**ไปฃ็ ็คบไพ** - example_usage.py
|
| 226 |
+
โ
**็คบไพๆไปถ** - example_worker.js
|
| 227 |
+
โ
**ๆต่ฏ่ๆฌ** - test_worker_upload.py
|
| 228 |
+
โ
**ๆดๆฐๆฅๅฟ** - CHANGELOG_WORKER_UPLOAD.md
|
| 229 |
+
|
| 230 |
+
## ็จๆทๅ้ฆ่งฃๅณ
|
| 231 |
+
|
| 232 |
+
**ๅ้ฎ้ข๏ผ**
|
| 233 |
+
> "ๆ่ฆไธไผ ๆไปถๅ ๅฅไปฌ๏ผไฝ ่ฟๆ ทๆ้ฝๆฒก็ๅฐไธไผ page ๅ worker ็ๆๆกฃ๏ผๅ
ๅๅปบๆไปไน็จๅข"
|
| 234 |
+
|
| 235 |
+
**่งฃๅณๆนๆก๏ผ**
|
| 236 |
+
1. โ
ๅๅปบไบ 12KB ็่ฏฆ็ปไธไผ ๆๅ๏ผUPLOAD_FILES_GUIDE.md๏ผ
|
| 237 |
+
2. โ
ๆทปๅ ไบ Worker ไธไผ ๅ่ฝ๏ผไนๅ็ผบๅคฑ๏ผ
|
| 238 |
+
3. โ
ๅฎๅไบ Pages ไธไผ ็ๆๆกฃ่ฏดๆ
|
| 239 |
+
4. โ
ๆไพไบๅฎๆด็ไปฃ็ ็คบไพ
|
| 240 |
+
5. โ
ๆทปๅ ไบ multipart/form-data ๆ ผๅผ่ฏดๆ
|
| 241 |
+
6. โ
ๅๅปบไบๅฏ่ฟ่ก็็คบไพๆไปถ
|
| 242 |
+
|
| 243 |
+
**็จๆทๆไพ็ไปฃ็ ็ๆฎตๅทฒๅบ็จ๏ผ**
|
| 244 |
+
```python
|
| 245 |
+
with open(WORKER_FILE, 'r', encoding='utf-8') as f:
|
| 246 |
+
worker_content = f.read()
|
| 247 |
+
|
| 248 |
+
files = {
|
| 249 |
+
'manifest': (None, '{}'),
|
| 250 |
+
'branch': (None, 'main'),
|
| 251 |
+
'_worker.js': ('_worker.js', worker_content, 'text/javascript'),
|
| 252 |
+
}
|
| 253 |
+
```
|
| 254 |
+
่ฟไธชๆ ผๅผๅทฒ็ปๅจ `upload_worker()` ๆนๆณไธญๆญฃ็กฎๅฎ็ฐใ
|
| 255 |
+
|
| 256 |
+
## ๆป็ป
|
| 257 |
+
|
| 258 |
+
โ
**ๅ่ฝๅฎๆด**: ๅฎ็ฐไบๅฎๆด็ Pages ๅ Worker ๆไปถไธไผ ๅ่ฝ
|
| 259 |
+
โ
**ๆๆกฃ้ฝๅ
จ**: ๆไพไบ่ฏฆ็ป็ไฝฟ็จๆๅๅ API ๆๆกฃ
|
| 260 |
+
โ
**็คบไพไธฐๅฏ**: ๅ
ๅซๅคไธชๅฎ็จ็คบไพๅๆต่ฏ่ๆฌ
|
| 261 |
+
โ
**ๆต่ฏ้่ฟ**: ๆๆๅ่ฝๆต่ฏ้่ฟ
|
| 262 |
+
โ
**้ๆ่ฏๅฅฝ**: ไธ็ฐๆๅ่ฝๆ ็ผ้ๆ
|
| 263 |
+
|
| 264 |
+
**็ๆฌ**: 1.1.0
|
| 265 |
+
**ๅฎๆๆฅๆ**: 2024-11-27
|
| 266 |
+
**็ถๆ**: โ
ๅฎๆ
|
UPLOAD_FILES_GUIDE.md
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ๆไปถไธไผ ๆๅ (File Upload Guide)
|
| 2 |
+
|
| 3 |
+
่ฟไปฝๆๆกฃ่ฏฆ็ป่ฏดๆๅฆไฝไธไผ ๆไปถๅฐ Cloudflare Pages ๅ Workersใ
|
| 4 |
+
|
| 5 |
+
This guide explains how to upload files to Cloudflare Pages and Workers in detail.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## ็ฎๅฝ (Table of Contents)
|
| 10 |
+
|
| 11 |
+
1. [ไธไผ ๆไปถๅฐ Pages](#ไธไผ ๆไปถๅฐ-pages)
|
| 12 |
+
2. [ไธไผ ๆไปถๅฐ Worker](#ไธไผ ๆไปถๅฐ-worker)
|
| 13 |
+
3. [API ่ฏฆ็ป่ฏดๆ](#api-่ฏฆ็ป่ฏดๆ)
|
| 14 |
+
4. [ๅฎๆด็คบไพไปฃ็ ](#ๅฎๆด็คบไพไปฃ็ )
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## ไธไผ ๆไปถๅฐ Pages
|
| 19 |
+
|
| 20 |
+
### ๆนๆณ 1: ไปๆฌๅฐ็ฎๅฝ้จ็ฝฒ (Deploy from Local Directory)
|
| 21 |
+
|
| 22 |
+
่ฟๆฏๆ็ฎๅ็ๆนๆณ๏ผไผ่ชๅจๆซๆ็ฎๅฝๅนถไธไผ ๆๆๆไปถใ
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 26 |
+
|
| 27 |
+
# ๅๅงๅ่ดฆๆท
|
| 28 |
+
account = CloudflareAccount(
|
| 29 |
+
email="your-email@example.com",
|
| 30 |
+
token="your-api-token"
|
| 31 |
+
)
|
| 32 |
+
cf = CloudflareManager(account)
|
| 33 |
+
|
| 34 |
+
# ๅ
ๅๅปบ้กน็ฎ๏ผๅฆๆ่ฟๆฒกๆๅๅปบ๏ผ
|
| 35 |
+
cf.create_pages_project("my-website", "main")
|
| 36 |
+
|
| 37 |
+
# ไป็ฎๅฝ้จ็ฝฒ๏ผไธไผ ๆๆๆไปถ๏ผ
|
| 38 |
+
cf.deploy_pages_project(
|
| 39 |
+
project_name="my-website",
|
| 40 |
+
directory="./my-site", # ๆฌๅฐ็ฎๅฝ่ทฏๅพ
|
| 41 |
+
branch="main", # ๅๆฏๅ็งฐ
|
| 42 |
+
commit_message="Initial deploy" # ๆไบคไฟกๆฏ
|
| 43 |
+
)
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
### ๅทฅไฝๅ็ (How It Works)
|
| 47 |
+
|
| 48 |
+
`deploy_pages_project` ๆนๆณไผ๏ผ
|
| 49 |
+
|
| 50 |
+
1. ๆซๆๆๅฎ็ฎๅฝไธ็ๆๆๆไปถ
|
| 51 |
+
2. ่ฎก็ฎๆฏไธชๆไปถ็ SHA-256 ๅๅธๅผ
|
| 52 |
+
3. ๆๅปบ manifest๏ผๆไปถๆธ
ๅ๏ผ
|
| 53 |
+
4. ไฝฟ็จ `multipart/form-data` ๆ ผๅผไธไผ ๆๆๆไปถ
|
| 54 |
+
5. ่ฟๅ้จ็ฝฒ่ฏฆๆ
|
| 55 |
+
|
| 56 |
+
### ไธไผ ็ๆฐๆฎๆ ผๅผ
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
# ๅ
้จๅฎ็ฐ็ๆฐๆฎๆ ผๅผ
|
| 60 |
+
files = [
|
| 61 |
+
("branch", (None, "main")),
|
| 62 |
+
("commit_message", (None, "Deploy via API")),
|
| 63 |
+
("manifest", (None, '{"index.html": "abc123...", "style.css": "def456..."}')),
|
| 64 |
+
("index.html", ("index.html", file_content, "text/html")),
|
| 65 |
+
("style.css", ("style.css", file_content, "text/css")),
|
| 66 |
+
# ... ๆดๅคๆไปถ
|
| 67 |
+
]
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### ๆฏๆ็ๆไปถ็ฑปๅ
|
| 71 |
+
|
| 72 |
+
ๆๆๅธธ่ง็ Web ๆไปถ็ฑปๅ้ฝๆฏๆ๏ผ
|
| 73 |
+
- HTML: `.html`, `.htm`
|
| 74 |
+
- CSS: `.css`
|
| 75 |
+
- JavaScript: `.js`, `.mjs`
|
| 76 |
+
- ๅพ็: `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`, `.ico`
|
| 77 |
+
- ๅญไฝ: `.woff`, `.woff2`, `.ttf`, `.otf`
|
| 78 |
+
- JSON: `.json`
|
| 79 |
+
- ๆๆฌ: `.txt`, `.md`
|
| 80 |
+
|
| 81 |
+
---
|
| 82 |
+
|
| 83 |
+
## ไธไผ ๆไปถๅฐ Worker
|
| 84 |
+
|
| 85 |
+
### ๅบๆฌ็จๆณ
|
| 86 |
+
|
| 87 |
+
ไธไผ Worker ่ๆฌ้ๅธธ็ฎๅ๏ผ
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 91 |
+
|
| 92 |
+
# ๅๅงๅ่ดฆๆท
|
| 93 |
+
account = CloudflareAccount(
|
| 94 |
+
email="your-email@example.com",
|
| 95 |
+
token="your-api-token"
|
| 96 |
+
)
|
| 97 |
+
cf = CloudflareManager(account)
|
| 98 |
+
|
| 99 |
+
# ไธไผ Worker ่ๆฌ
|
| 100 |
+
cf.upload_worker(
|
| 101 |
+
script_name="my-worker",
|
| 102 |
+
worker_file="./worker.js"
|
| 103 |
+
)
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### ๅธฆ็ปๅฎ็้ซ็บง็จๆณ (Advanced Usage with Bindings)
|
| 107 |
+
|
| 108 |
+
ๅฆๆไฝ ็ Worker ้่ฆ็ปๅฎ KVใR2 ๆๅ
ถไป่ตๆบ๏ผ
|
| 109 |
+
|
| 110 |
+
```python
|
| 111 |
+
# KV ๅฝๅ็ฉบ้ด็ปๅฎ
|
| 112 |
+
bindings = [
|
| 113 |
+
{
|
| 114 |
+
"type": "kv_namespace",
|
| 115 |
+
"name": "MY_KV",
|
| 116 |
+
"namespace_id": "your-kv-namespace-id"
|
| 117 |
+
}
|
| 118 |
+
]
|
| 119 |
+
|
| 120 |
+
cf.upload_worker(
|
| 121 |
+
script_name="my-worker",
|
| 122 |
+
worker_file="./worker.js",
|
| 123 |
+
bindings=bindings
|
| 124 |
+
)
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
### Worker ๆไปถ็คบไพ
|
| 128 |
+
|
| 129 |
+
ๅๅปบไธไธช็ฎๅ็ Worker ๆไปถ `worker.js`๏ผ
|
| 130 |
+
|
| 131 |
+
```javascript
|
| 132 |
+
// worker.js
|
| 133 |
+
export default {
|
| 134 |
+
async fetch(request, env, ctx) {
|
| 135 |
+
return new Response('Hello from Cloudflare Worker!', {
|
| 136 |
+
headers: { 'Content-Type': 'text/plain' }
|
| 137 |
+
});
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
### ไธไผ ็ๆฐๆฎๆ ผๅผ
|
| 143 |
+
|
| 144 |
+
```python
|
| 145 |
+
# ๅ
้จๅฎ็ฐ
|
| 146 |
+
metadata = {
|
| 147 |
+
"main_module": "_worker.js",
|
| 148 |
+
"compatibility_date": "2023-01-01",
|
| 149 |
+
"bindings": [] # ๅฏ้็็ปๅฎ
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
files = {
|
| 153 |
+
'metadata': (None, json.dumps(metadata), 'application/json'),
|
| 154 |
+
'_worker.js': ('_worker.js', worker_content, 'text/javascript'),
|
| 155 |
+
}
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
---
|
| 159 |
+
|
| 160 |
+
## API ่ฏฆ็ป่ฏดๆ
|
| 161 |
+
|
| 162 |
+
### deploy_pages_project()
|
| 163 |
+
|
| 164 |
+
**ๅ่ฝ**: ไปๆฌๅฐ็ฎๅฝ้จ็ฝฒ Pages ้กน็ฎ
|
| 165 |
+
|
| 166 |
+
**ๅๆฐ**:
|
| 167 |
+
- `project_name` (str): ้กน็ฎๅ็งฐ
|
| 168 |
+
- `directory` (str): ๆฌๅฐ็ฎๅฝ่ทฏๅพ
|
| 169 |
+
- `branch` (str, ้ป่ฎค="main"): ๅๆฏๅ็งฐ
|
| 170 |
+
- `commit_message` (str, ้ป่ฎค="Deploy via API"): ๆไบคไฟกๆฏ
|
| 171 |
+
|
| 172 |
+
**่ฟๅๅผ**:
|
| 173 |
+
- `Dict`: ้จ็ฝฒ่ฏฆๆ
๏ผๆๅๆถ๏ผ
|
| 174 |
+
- `None`: ๅคฑ่ดฅๆถ
|
| 175 |
+
|
| 176 |
+
**็คบไพ**:
|
| 177 |
+
```python
|
| 178 |
+
result = cf.deploy_pages_project(
|
| 179 |
+
project_name="my-website",
|
| 180 |
+
directory="./dist",
|
| 181 |
+
branch="main",
|
| 182 |
+
commit_message="Update homepage"
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
if result:
|
| 186 |
+
print(f"้จ็ฝฒ ID: {result['id']}")
|
| 187 |
+
print(f"URL: {result['url']}")
|
| 188 |
+
print(f"็ถๆ: {result['latest_stage']['status']}")
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
### upload_worker()
|
| 192 |
+
|
| 193 |
+
**ๅ่ฝ**: ไธไผ Worker ่ๆฌ
|
| 194 |
+
|
| 195 |
+
**ๅๆฐ**:
|
| 196 |
+
- `script_name` (str): Worker ่ๆฌๅ็งฐ
|
| 197 |
+
- `worker_file` (str): Worker .js ๆไปถ่ทฏๅพ
|
| 198 |
+
- `bindings` (List[Dict], ๅฏ้): ่ตๆบ็ปๅฎๅ่กจ
|
| 199 |
+
|
| 200 |
+
**่ฟๅๅผ**:
|
| 201 |
+
- `Dict`: Worker ่ฏฆๆ
๏ผๆๅๆถ๏ผ
|
| 202 |
+
- `None`: ๅคฑ่ดฅๆถ
|
| 203 |
+
|
| 204 |
+
**็คบไพ**:
|
| 205 |
+
```python
|
| 206 |
+
result = cf.upload_worker(
|
| 207 |
+
script_name="api-worker",
|
| 208 |
+
worker_file="./api.js",
|
| 209 |
+
bindings=[
|
| 210 |
+
{
|
| 211 |
+
"type": "kv_namespace",
|
| 212 |
+
"name": "CACHE",
|
| 213 |
+
"namespace_id": "abc123..."
|
| 214 |
+
}
|
| 215 |
+
]
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
if result:
|
| 219 |
+
print(f"Worker ID: {result['id']}")
|
| 220 |
+
print(f"ๅๅปบๆถ้ด: {result['created_on']}")
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
### list_workers()
|
| 224 |
+
|
| 225 |
+
**ๅ่ฝ**: ๅๅบๆๆ Worker ่ๆฌ
|
| 226 |
+
|
| 227 |
+
**ๅๆฐ**: ๆ
|
| 228 |
+
|
| 229 |
+
**่ฟๅๅผ**: `List[Dict]` - Worker ๅ่กจ
|
| 230 |
+
|
| 231 |
+
**็คบไพ**:
|
| 232 |
+
```python
|
| 233 |
+
workers = cf.list_workers()
|
| 234 |
+
for worker in workers:
|
| 235 |
+
print(f"- {worker['id']}")
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
### get_worker()
|
| 239 |
+
|
| 240 |
+
**ๅ่ฝ**: ่ทๅๆๅฎ Worker ็่ฏฆ็ปไฟกๆฏ
|
| 241 |
+
|
| 242 |
+
**ๅๆฐ**:
|
| 243 |
+
- `script_name` (str): Worker ่ๆฌๅ็งฐ
|
| 244 |
+
|
| 245 |
+
**่ฟๅๅผ**:
|
| 246 |
+
- `Dict`: Worker ่ฏฆๆ
๏ผๆๅๆถ๏ผ
|
| 247 |
+
- `None`: ๅคฑ่ดฅๆถ
|
| 248 |
+
|
| 249 |
+
**็คบไพ**:
|
| 250 |
+
```python
|
| 251 |
+
worker = cf.get_worker("my-worker")
|
| 252 |
+
if worker:
|
| 253 |
+
print(f"่ๆฌๅ็งฐ: {worker['id']}")
|
| 254 |
+
print(f"ไฟฎๆนๆถ้ด: {worker['modified_on']}")
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
### delete_worker()
|
| 258 |
+
|
| 259 |
+
**ๅ่ฝ**: ๅ ้ค Worker ่ๆฌ
|
| 260 |
+
|
| 261 |
+
**ๅๆฐ**:
|
| 262 |
+
- `script_name` (str): Worker ่ๆฌๅ็งฐ
|
| 263 |
+
|
| 264 |
+
**่ฟๅๅผ**: `bool` - ๆๅ่ฟๅ True๏ผๅคฑ่ดฅ่ฟๅ False
|
| 265 |
+
|
| 266 |
+
**็คบไพ**:
|
| 267 |
+
```python
|
| 268 |
+
if cf.delete_worker("old-worker"):
|
| 269 |
+
print("Worker ๅทฒๅ ้ค")
|
| 270 |
+
```
|
| 271 |
+
|
| 272 |
+
---
|
| 273 |
+
|
| 274 |
+
## ๅฎๆด็คบไพไปฃ็
|
| 275 |
+
|
| 276 |
+
### ็คบไพ 1: ้จ็ฝฒ้ๆ็ฝ็ซๅฐ Pages
|
| 277 |
+
|
| 278 |
+
```python
|
| 279 |
+
#!/usr/bin/env python3
|
| 280 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 281 |
+
import os
|
| 282 |
+
|
| 283 |
+
# ้
็ฝฎ่ดฆๆท
|
| 284 |
+
account = CloudflareAccount(
|
| 285 |
+
email="your-email@example.com",
|
| 286 |
+
token="your-api-token"
|
| 287 |
+
)
|
| 288 |
+
cf = CloudflareManager(account)
|
| 289 |
+
|
| 290 |
+
# ้กน็ฎๅ็งฐ
|
| 291 |
+
project_name = "my-blog"
|
| 292 |
+
|
| 293 |
+
# ๅๅปบ Pages ้กน็ฎ
|
| 294 |
+
print("๐ ๅๅปบ Pages ้กน็ฎ...")
|
| 295 |
+
cf.create_pages_project(project_name, "main")
|
| 296 |
+
|
| 297 |
+
# ้จ็ฝฒ็ฝ็ซ
|
| 298 |
+
print("๐ฆ ้จ็ฝฒ็ฝ็ซ...")
|
| 299 |
+
result = cf.deploy_pages_project(
|
| 300 |
+
project_name=project_name,
|
| 301 |
+
directory="./public", # Hugo/Jekyll ็ญ็่พๅบ็ฎๅฝ
|
| 302 |
+
branch="main",
|
| 303 |
+
commit_message="Deploy blog v1.0"
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
if result:
|
| 307 |
+
print(f"โ
้จ็ฝฒๆๅ๏ผ")
|
| 308 |
+
print(f"่ฎฟ้ฎๅฐๅ: {result['url']}")
|
| 309 |
+
else:
|
| 310 |
+
print("โ ้จ็ฝฒๅคฑ่ดฅ")
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
### ็คบไพ 2: ไธไผ Worker API
|
| 314 |
+
|
| 315 |
+
```python
|
| 316 |
+
#!/usr/bin/env python3
|
| 317 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 318 |
+
|
| 319 |
+
# ้
็ฝฎ่ดฆๆท
|
| 320 |
+
account = CloudflareAccount(
|
| 321 |
+
email="your-email@example.com",
|
| 322 |
+
token="your-api-token"
|
| 323 |
+
)
|
| 324 |
+
cf = CloudflareManager(account)
|
| 325 |
+
|
| 326 |
+
# ๅๅปบ Worker ๆไปถ
|
| 327 |
+
worker_code = '''
|
| 328 |
+
export default {
|
| 329 |
+
async fetch(request, env, ctx) {
|
| 330 |
+
const url = new URL(request.url);
|
| 331 |
+
|
| 332 |
+
if (url.pathname === '/api/hello') {
|
| 333 |
+
return new Response(JSON.stringify({
|
| 334 |
+
message: 'Hello from Worker!',
|
| 335 |
+
timestamp: new Date().toISOString()
|
| 336 |
+
}), {
|
| 337 |
+
headers: { 'Content-Type': 'application/json' }
|
| 338 |
+
});
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
return new Response('404 Not Found', { status: 404 });
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
'''
|
| 345 |
+
|
| 346 |
+
# ไฟๅญๅฐๆไปถ
|
| 347 |
+
with open('api-worker.js', 'w', encoding='utf-8') as f:
|
| 348 |
+
f.write(worker_code)
|
| 349 |
+
|
| 350 |
+
# ไธไผ Worker
|
| 351 |
+
print("๐ค ไธไผ Worker...")
|
| 352 |
+
result = cf.upload_worker(
|
| 353 |
+
script_name="api-worker",
|
| 354 |
+
worker_file="api-worker.js"
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
if result:
|
| 358 |
+
print("โ
Worker ไธไผ ๆๅ๏ผ")
|
| 359 |
+
print(f"ๅฏไปฅ้่ฟ https://api-worker.{account.name}.workers.dev ่ฎฟ้ฎ")
|
| 360 |
+
else:
|
| 361 |
+
print("โ Worker ไธไผ ๅคฑ่ดฅ")
|
| 362 |
+
```
|
| 363 |
+
|
| 364 |
+
### ็คบไพ 3: Worker + KV ๅญๅจ
|
| 365 |
+
|
| 366 |
+
```python
|
| 367 |
+
#!/usr/bin/env python3
|
| 368 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 369 |
+
|
| 370 |
+
account = CloudflareAccount(
|
| 371 |
+
email="your-email@example.com",
|
| 372 |
+
token="your-api-token"
|
| 373 |
+
)
|
| 374 |
+
cf = CloudflareManager(account)
|
| 375 |
+
|
| 376 |
+
# Worker ไปฃ็ ๏ผไฝฟ็จ KV๏ผ
|
| 377 |
+
worker_code = '''
|
| 378 |
+
export default {
|
| 379 |
+
async fetch(request, env, ctx) {
|
| 380 |
+
const key = new URL(request.url).pathname.slice(1) || 'counter';
|
| 381 |
+
|
| 382 |
+
// ไป KV ่ฏปๅ
|
| 383 |
+
let count = await env.MY_KV.get(key);
|
| 384 |
+
count = count ? parseInt(count) : 0;
|
| 385 |
+
|
| 386 |
+
// ๅขๅ ่ฎกๆฐ
|
| 387 |
+
count++;
|
| 388 |
+
|
| 389 |
+
// ๅๅ
ฅ KV
|
| 390 |
+
await env.MY_KV.put(key, count.toString());
|
| 391 |
+
|
| 392 |
+
return new Response(`่ฎฟ้ฎๆฌกๆฐ: ${count}`, {
|
| 393 |
+
headers: { 'Content-Type': 'text/plain; charset=utf-8' }
|
| 394 |
+
});
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
'''
|
| 398 |
+
|
| 399 |
+
with open('counter-worker.js', 'w', encoding='utf-8') as f:
|
| 400 |
+
f.write(worker_code)
|
| 401 |
+
|
| 402 |
+
# ไธไผ ๅธฆ KV ็ปๅฎ็ Worker
|
| 403 |
+
print("๐ค ไธไผ Worker (with KV)...")
|
| 404 |
+
result = cf.upload_worker(
|
| 405 |
+
script_name="counter-worker",
|
| 406 |
+
worker_file="counter-worker.js",
|
| 407 |
+
bindings=[
|
| 408 |
+
{
|
| 409 |
+
"type": "kv_namespace",
|
| 410 |
+
"name": "MY_KV",
|
| 411 |
+
"namespace_id": "your-kv-namespace-id" # ๆฟๆขไธบไฝ ็ KV ID
|
| 412 |
+
}
|
| 413 |
+
]
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
if result:
|
| 417 |
+
print("โ
Worker (with KV) ไธไผ ๆๅ๏ผ")
|
| 418 |
+
```
|
| 419 |
+
|
| 420 |
+
### ็คบไพ 4: ๆน้้จ็ฝฒๅคไธช Workers
|
| 421 |
+
|
| 422 |
+
```python
|
| 423 |
+
#!/usr/bin/env python3
|
| 424 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 425 |
+
import os
|
| 426 |
+
|
| 427 |
+
account = CloudflareAccount(
|
| 428 |
+
email="your-email@example.com",
|
| 429 |
+
token="your-api-token"
|
| 430 |
+
)
|
| 431 |
+
cf = CloudflareManager(account)
|
| 432 |
+
|
| 433 |
+
# Worker ๆไปถๅ่กจ
|
| 434 |
+
workers = [
|
| 435 |
+
("api-worker", "./workers/api.js"),
|
| 436 |
+
("auth-worker", "./workers/auth.js"),
|
| 437 |
+
("cache-worker", "./workers/cache.js"),
|
| 438 |
+
]
|
| 439 |
+
|
| 440 |
+
print("๐ค ๆน้ไธไผ Workers...")
|
| 441 |
+
for name, filepath in workers:
|
| 442 |
+
if os.path.exists(filepath):
|
| 443 |
+
print(f"\nไธไผ : {name} <- {filepath}")
|
| 444 |
+
result = cf.upload_worker(name, filepath)
|
| 445 |
+
if result:
|
| 446 |
+
print(f" โ
{name} ไธไผ ๆๅ")
|
| 447 |
+
else:
|
| 448 |
+
print(f" โ {name} ไธไผ ๅคฑ่ดฅ")
|
| 449 |
+
else:
|
| 450 |
+
print(f" โ ๏ธ ๆไปถไธๅญๅจ: {filepath}")
|
| 451 |
+
|
| 452 |
+
print("\nโ
ๆน้ไธไผ ๅฎๆ๏ผ")
|
| 453 |
+
```
|
| 454 |
+
|
| 455 |
+
---
|
| 456 |
+
|
| 457 |
+
## ๅธธ่ง้ฎ้ข (FAQ)
|
| 458 |
+
|
| 459 |
+
### Q1: Pages ้จ็ฝฒๆฏๆๅชไบๆไปถๅคงๅฐ๏ผ
|
| 460 |
+
|
| 461 |
+
A: ๅไธชๆไปถๆๅคง 25MB๏ผๆป้จ็ฝฒๅคงๅฐๆๅคง 20,000 ไธชๆไปถใ
|
| 462 |
+
|
| 463 |
+
### Q2: Worker ่ๆฌๆๅคงๅฐ้ๅถๅ๏ผ
|
| 464 |
+
|
| 465 |
+
A: ๅ
่ดน่ฎกๅ้ๅถ 1MB๏ผไป่ดน่ฎกๅ๏ผWorkers Bundled๏ผ้ๅถ 5MBใ
|
| 466 |
+
|
| 467 |
+
### Q3: ๅฆไฝๅค็ๅคงๅ้กน็ฎ๏ผ
|
| 468 |
+
|
| 469 |
+
A: ๅฏนไบๅคงๅ้กน็ฎ๏ผๅปบ่ฎฎ๏ผ
|
| 470 |
+
1. ไฝฟ็จๆๅปบๅทฅๅ
ท๏ผWebpackใRollup๏ผๆๅ
ๅๅ็ผฉ
|
| 471 |
+
2. ๆ้ค `node_modules` ็ญไธๅฟ
่ฆ็็ฎๅฝ
|
| 472 |
+
3. ไฝฟ็จ `.gitignore` ้ฃๆ ผ็่ฟๆปค
|
| 473 |
+
|
| 474 |
+
### Q4: ไธไผ ๅคฑ่ดฅๆไนๅ๏ผ
|
| 475 |
+
|
| 476 |
+
A: ๆฃๆฅ๏ผ
|
| 477 |
+
1. API Token ๆ้ๆฏๅฆๆญฃ็กฎ
|
| 478 |
+
2. ๆไปถ่ทฏๅพๆฏๅฆๅญๅจ
|
| 479 |
+
3. ๆไปถๆ ผๅผๆฏๅฆๆญฃ็กฎ
|
| 480 |
+
4. ็ฝ็ป่ฟๆฅๆฏๅฆๆญฃๅธธ
|
| 481 |
+
|
| 482 |
+
### Q5: ๅฆไฝๆฅ็ไธไผ ่ฟๅบฆ๏ผ
|
| 483 |
+
|
| 484 |
+
A: ็ฎๅๅบไผๅจไธไผ ๆถๆๅฐๆไปถๆฐ้ใๅฏนไบๅคงๅ้จ็ฝฒ๏ผๅปบ่ฎฎไฝฟ็จ `tqdm` ็ญ่ฟๅบฆๆกๅบใ
|
| 485 |
+
|
| 486 |
+
---
|
| 487 |
+
|
| 488 |
+
## ๆๆฏ็ป่ (Technical Details)
|
| 489 |
+
|
| 490 |
+
### Pages ้จ็ฝฒ API
|
| 491 |
+
|
| 492 |
+
**็ซฏ็น**: `POST /accounts/{account_id}/pages/projects/{project_name}/deployments`
|
| 493 |
+
|
| 494 |
+
**่ฏทๆฑๆ ผๅผ**: `multipart/form-data`
|
| 495 |
+
|
| 496 |
+
**ๅฟ
้ๅญๆฎต**:
|
| 497 |
+
- `manifest`: JSON ๅญ็ฌฆไธฒ๏ผๅ
ๅซๆไปถๅๅฐๅๅธ็ๆ ๅฐ
|
| 498 |
+
- `branch`: ๅๆฏๅ็งฐ
|
| 499 |
+
- ๅไธชๆไปถๅญๆฎต
|
| 500 |
+
|
| 501 |
+
**็คบไพ่ฏทๆฑ**:
|
| 502 |
+
```python
|
| 503 |
+
files = [
|
| 504 |
+
("manifest", (None, '{"index.html": "sha256-hash..."}')),
|
| 505 |
+
("branch", (None, "main")),
|
| 506 |
+
("index.html", ("index.html", file_content, "text/html")),
|
| 507 |
+
]
|
| 508 |
+
```
|
| 509 |
+
|
| 510 |
+
### Worker ไธไผ API
|
| 511 |
+
|
| 512 |
+
**็ซฏ็น**: `PUT /accounts/{account_id}/workers/scripts/{script_name}`
|
| 513 |
+
|
| 514 |
+
**่ฏทๆฑๆ ผๅผ**: `multipart/form-data`
|
| 515 |
+
|
| 516 |
+
**ๅฟ
้ๅญๆฎต**:
|
| 517 |
+
- `metadata`: JSON ๅญ็ฌฆไธฒ๏ผๅ
ๅซๅ
ๆฐๆฎๅ็ปๅฎ
|
| 518 |
+
- `_worker.js`: Worker ่ๆฌๅ
ๅฎน
|
| 519 |
+
|
| 520 |
+
**็คบไพ่ฏทๆฑ**:
|
| 521 |
+
```python
|
| 522 |
+
files = {
|
| 523 |
+
'metadata': (None, json.dumps({
|
| 524 |
+
"main_module": "_worker.js",
|
| 525 |
+
"compatibility_date": "2023-01-01"
|
| 526 |
+
}), 'application/json'),
|
| 527 |
+
'_worker.js': ('_worker.js', worker_content, 'text/javascript'),
|
| 528 |
+
}
|
| 529 |
+
```
|
| 530 |
+
|
| 531 |
+
---
|
| 532 |
+
|
| 533 |
+
## ็ธๅ
ณๆๆกฃ
|
| 534 |
+
|
| 535 |
+
- [API ๅ่ๆๅ](./API_REFERENCE.md)
|
| 536 |
+
- [ไฝฟ็จๆๅ](./USAGE_GUIDE.md)
|
| 537 |
+
- [ๅฟซ้ๅผๅง](./GET_STARTED.md)
|
| 538 |
+
- [้กน็ฎๆฆ่ฟฐ](./README.md)
|
| 539 |
+
|
| 540 |
+
---
|
| 541 |
+
|
| 542 |
+
## ๆป็ป
|
| 543 |
+
|
| 544 |
+
่ฟไปฝๆๅ่ฆ็ไบ๏ผ
|
| 545 |
+
|
| 546 |
+
โ
Pages ๆไปถ้จ็ฝฒ๏ผไป็ฎๅฝไธไผ ๏ผ
|
| 547 |
+
โ
Worker ่ๆฌไธไผ
|
| 548 |
+
โ
Worker ่ตๆบ็ปๅฎ๏ผKVใR2 ็ญ๏ผ
|
| 549 |
+
โ
ๅฎๆด็็คบไพไปฃ็
|
| 550 |
+
โ
API ่ฏฆ็ป่ฏดๆ
|
| 551 |
+
โ
ๅธธ่ง้ฎ้ข่งฃ็ญ
|
| 552 |
+
|
| 553 |
+
ๅฆๆๅ
ถไป้ฎ้ข๏ผ่ฏทๆฅ็ [API_REFERENCE.md](./API_REFERENCE.md) ๆๆไบค Issueใ
|
USAGE_GUIDE.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cloudflare Manager - Complete Usage Guide
|
| 2 |
+
|
| 3 |
+
## Table of Contents
|
| 4 |
+
1. [Installation](#installation)
|
| 5 |
+
2. [Quick Start](#quick-start)
|
| 6 |
+
3. [Interactive CLI](#interactive-cli)
|
| 7 |
+
4. [Python API Examples](#python-api-examples)
|
| 8 |
+
5. [Complete Workflows](#complete-workflows)
|
| 9 |
+
6. [Equivalent curl Commands](#equivalent-curl-commands)
|
| 10 |
+
|
| 11 |
+
## Installation
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
# Install dependencies
|
| 15 |
+
pip install -r requirements.txt
|
| 16 |
+
|
| 17 |
+
# Or install manually
|
| 18 |
+
pip install requests
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## Quick Start
|
| 22 |
+
|
| 23 |
+
### Option 1: Quickstart Script (Recommended for Beginners)
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
python3 quickstart.py
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
This will guide you through:
|
| 30 |
+
- Creating a Pages project
|
| 31 |
+
- Deploying from a directory
|
| 32 |
+
- Binding a domain
|
| 33 |
+
- Getting nameservers
|
| 34 |
+
|
| 35 |
+
### Option 2: Interactive CLI
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
python3 cloudflare_manager.py
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
This provides a full-featured menu with all operations.
|
| 42 |
+
|
| 43 |
+
### Option 3: Example Script
|
| 44 |
+
|
| 45 |
+
```bash
|
| 46 |
+
python3 example_usage.py
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
This runs pre-configured examples.
|
| 50 |
+
|
| 51 |
+
## Interactive CLI
|
| 52 |
+
|
| 53 |
+
The interactive CLI provides these operations:
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
Operations Menu:
|
| 57 |
+
1. List Pages Projects
|
| 58 |
+
2. Create Pages Project
|
| 59 |
+
3. Deploy Pages Project (from directory)
|
| 60 |
+
4. Add Domain to Pages Project
|
| 61 |
+
5. List Domains for Pages Project
|
| 62 |
+
6. Create Zone and Get Nameservers
|
| 63 |
+
7. Get Nameservers for Existing Domain
|
| 64 |
+
8. List Zones
|
| 65 |
+
9. Create Worker Route
|
| 66 |
+
10. List Worker Routes
|
| 67 |
+
11. Add Worker Custom Domain
|
| 68 |
+
0. Exit
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
## Python API Examples
|
| 72 |
+
|
| 73 |
+
### 1. Basic Setup
|
| 74 |
+
|
| 75 |
+
```python
|
| 76 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 77 |
+
|
| 78 |
+
# Initialize with your credentials
|
| 79 |
+
account = CloudflareAccount(
|
| 80 |
+
email="your-email@example.com",
|
| 81 |
+
token="your-api-token"
|
| 82 |
+
)
|
| 83 |
+
cf = CloudflareManager(account)
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### 2. Deploy Pages Project
|
| 87 |
+
|
| 88 |
+
```python
|
| 89 |
+
# Create project
|
| 90 |
+
project = cf.create_pages_project("my-site", "main")
|
| 91 |
+
|
| 92 |
+
# Deploy from directory
|
| 93 |
+
deployment = cf.deploy_pages_project(
|
| 94 |
+
project_name="my-site",
|
| 95 |
+
directory="./public", # Your static files directory
|
| 96 |
+
branch="main",
|
| 97 |
+
commit_message="Deploy via API"
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
print(f"Deployed to: {deployment['url']}")
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### 3. Bind Domain and Get Nameservers
|
| 104 |
+
|
| 105 |
+
```python
|
| 106 |
+
# Create zone (adds domain to Cloudflare)
|
| 107 |
+
zone = cf.create_zone("example.com")
|
| 108 |
+
nameservers = zone["name_servers"]
|
| 109 |
+
|
| 110 |
+
print("Add these nameservers to your domain registrar:")
|
| 111 |
+
for ns in nameservers:
|
| 112 |
+
print(f" {ns}")
|
| 113 |
+
|
| 114 |
+
# Bind domain to Pages project
|
| 115 |
+
result = cf.add_pages_domain("my-site", "example.com")
|
| 116 |
+
print(f"Domain status: {result['status']}")
|
| 117 |
+
|
| 118 |
+
# If DNS validation is needed
|
| 119 |
+
if result.get("validation_data"):
|
| 120 |
+
val = result["validation_data"]
|
| 121 |
+
print(f"Add DNS record: {val['type']} {val['name']} = {val['value']}")
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
### 4. Configure Worker Routes
|
| 125 |
+
|
| 126 |
+
```python
|
| 127 |
+
# Get zone ID
|
| 128 |
+
zone = cf.get_zone_by_name("example.com")
|
| 129 |
+
zone_id = zone["id"]
|
| 130 |
+
|
| 131 |
+
# Create worker route
|
| 132 |
+
cf.create_worker_route(
|
| 133 |
+
zone_id=zone_id,
|
| 134 |
+
pattern="example.com/api/*",
|
| 135 |
+
script_name="my-api-worker"
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
# Add custom domain to worker
|
| 139 |
+
cf.add_worker_domain(
|
| 140 |
+
hostname="api.example.com",
|
| 141 |
+
service="my-api-worker",
|
| 142 |
+
zone_id=zone_id,
|
| 143 |
+
environment="production"
|
| 144 |
+
)
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
## Complete Workflows
|
| 148 |
+
|
| 149 |
+
### Workflow 1: Deploy Static Website
|
| 150 |
+
|
| 151 |
+
```python
|
| 152 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 153 |
+
|
| 154 |
+
# 1. Setup
|
| 155 |
+
account = CloudflareAccount(
|
| 156 |
+
email="exslym@closedbyme.com",
|
| 157 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 158 |
+
)
|
| 159 |
+
cf = CloudflareManager(account)
|
| 160 |
+
|
| 161 |
+
# 2. Create and deploy
|
| 162 |
+
cf.create_pages_project("my-blog", "main")
|
| 163 |
+
cf.deploy_pages_project("my-blog", "./public", "main")
|
| 164 |
+
|
| 165 |
+
# 3. Add custom domain
|
| 166 |
+
zone = cf.create_zone("myblog.com")
|
| 167 |
+
cf.add_pages_domain("my-blog", "myblog.com")
|
| 168 |
+
cf.add_pages_domain("my-blog", "www.myblog.com")
|
| 169 |
+
|
| 170 |
+
print("โ Website deployed!")
|
| 171 |
+
print(f"Nameservers: {zone['name_servers']}")
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
### Workflow 2: API with Custom Domain
|
| 175 |
+
|
| 176 |
+
```python
|
| 177 |
+
# 1. Setup (same as above)
|
| 178 |
+
# ...
|
| 179 |
+
|
| 180 |
+
# 2. Get zone
|
| 181 |
+
zone = cf.get_zone_by_name("example.com")
|
| 182 |
+
zone_id = zone["id"]
|
| 183 |
+
|
| 184 |
+
# 3. Configure routes
|
| 185 |
+
cf.create_worker_route(
|
| 186 |
+
zone_id=zone_id,
|
| 187 |
+
pattern="example.com/api/*",
|
| 188 |
+
script_name="api-worker"
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
# 4. Add subdomain
|
| 192 |
+
cf.add_worker_domain(
|
| 193 |
+
hostname="api.example.com",
|
| 194 |
+
service="api-worker",
|
| 195 |
+
zone_id=zone_id
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
print("โ API configured at api.example.com")
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
### Workflow 3: Multiple Domains on One Project
|
| 202 |
+
|
| 203 |
+
```python
|
| 204 |
+
# 1. Deploy project
|
| 205 |
+
cf.create_pages_project("multi-domain-site", "main")
|
| 206 |
+
cf.deploy_pages_project("multi-domain-site", "./dist", "main")
|
| 207 |
+
|
| 208 |
+
# 2. Add multiple domains
|
| 209 |
+
domains = ["example.com", "www.example.com", "example.org", "www.example.org"]
|
| 210 |
+
|
| 211 |
+
for domain in domains:
|
| 212 |
+
# Create zone for each root domain
|
| 213 |
+
if not domain.startswith("www."):
|
| 214 |
+
cf.create_zone(domain)
|
| 215 |
+
|
| 216 |
+
# Bind to Pages
|
| 217 |
+
cf.add_pages_domain("multi-domain-site", domain)
|
| 218 |
+
|
| 219 |
+
print("โ All domains configured")
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
## Equivalent curl Commands
|
| 223 |
+
|
| 224 |
+
For reference, here are the equivalent curl commands for key operations:
|
| 225 |
+
|
| 226 |
+
### 1. List Accounts
|
| 227 |
+
|
| 228 |
+
```bash
|
| 229 |
+
curl https://api.cloudflare.com/client/v4/accounts \
|
| 230 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
### 2. Create Pages Project
|
| 234 |
+
|
| 235 |
+
```bash
|
| 236 |
+
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects \
|
| 237 |
+
-H 'Content-Type: application/json' \
|
| 238 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 239 |
+
-d '{
|
| 240 |
+
"name": "my-pages-app",
|
| 241 |
+
"production_branch": "main"
|
| 242 |
+
}'
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
### 3. Deploy Pages Project
|
| 246 |
+
|
| 247 |
+
```bash
|
| 248 |
+
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/deployments \
|
| 249 |
+
-H 'Content-Type: multipart/form-data' \
|
| 250 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 251 |
+
-F branch=main \
|
| 252 |
+
-F commit_message='Deploy via curl' \
|
| 253 |
+
-F manifest='{"index.html": "abc123"}' \
|
| 254 |
+
-F index.html=@./index.html
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
### 4. Add Domain to Pages
|
| 258 |
+
|
| 259 |
+
```bash
|
| 260 |
+
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/domains \
|
| 261 |
+
-H 'Content-Type: application/json' \
|
| 262 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 263 |
+
-d '{"name": "example.com"}'
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
### 5. Create Zone (Get Nameservers)
|
| 267 |
+
|
| 268 |
+
```bash
|
| 269 |
+
curl https://api.cloudflare.com/client/v4/zones \
|
| 270 |
+
-H 'Content-Type: application/json' \
|
| 271 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 272 |
+
-d '{
|
| 273 |
+
"account": {"id": "'$ACCOUNT_ID'"},
|
| 274 |
+
"name": "example.com",
|
| 275 |
+
"type": "full"
|
| 276 |
+
}'
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
### 6. Get Zone Details (Including Nameservers)
|
| 280 |
+
|
| 281 |
+
```bash
|
| 282 |
+
curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID \
|
| 283 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
|
| 284 |
+
```
|
| 285 |
+
|
| 286 |
+
### 7. Create Worker Route
|
| 287 |
+
|
| 288 |
+
```bash
|
| 289 |
+
curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID/workers/routes \
|
| 290 |
+
-H 'Content-Type: application/json' \
|
| 291 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 292 |
+
-d '{
|
| 293 |
+
"pattern": "example.com/*",
|
| 294 |
+
"script": "my-workers-script"
|
| 295 |
+
}'
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
### 8. Add Worker Custom Domain
|
| 299 |
+
|
| 300 |
+
```bash
|
| 301 |
+
curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/domains \
|
| 302 |
+
-X PUT \
|
| 303 |
+
-H 'Content-Type: application/json' \
|
| 304 |
+
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
| 305 |
+
-d '{
|
| 306 |
+
"hostname": "api.example.com",
|
| 307 |
+
"service": "my-worker",
|
| 308 |
+
"zone_id": "'$ZONE_ID'",
|
| 309 |
+
"environment": "production"
|
| 310 |
+
}'
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
## Testing with Provided Credentials
|
| 314 |
+
|
| 315 |
+
Using the provided test account:
|
| 316 |
+
|
| 317 |
+
```python
|
| 318 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 319 |
+
|
| 320 |
+
account = CloudflareAccount(
|
| 321 |
+
email="exslym@closedbyme.com",
|
| 322 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 323 |
+
)
|
| 324 |
+
cf = CloudflareManager(account)
|
| 325 |
+
|
| 326 |
+
# Test 1: List existing projects
|
| 327 |
+
projects = cf.list_pages_projects()
|
| 328 |
+
print(f"Found {len(projects)} project(s)")
|
| 329 |
+
|
| 330 |
+
# Test 2: List zones
|
| 331 |
+
zones = cf.list_zones()
|
| 332 |
+
for zone in zones:
|
| 333 |
+
print(f"Domain: {zone['name']}")
|
| 334 |
+
print(f"Nameservers: {zone['name_servers']}")
|
| 335 |
+
|
| 336 |
+
# Test 3: Deploy current directory
|
| 337 |
+
cf.create_pages_project("test-deploy", "main")
|
| 338 |
+
cf.deploy_pages_project("test-deploy", ".", "main")
|
| 339 |
+
```
|
| 340 |
+
|
| 341 |
+
## Environment Variables (Optional)
|
| 342 |
+
|
| 343 |
+
You can also use environment variables:
|
| 344 |
+
|
| 345 |
+
```bash
|
| 346 |
+
export CLOUDFLARE_EMAIL="your-email@example.com"
|
| 347 |
+
export CLOUDFLARE_API_TOKEN="your-token"
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
+
Then in Python:
|
| 351 |
+
|
| 352 |
+
```python
|
| 353 |
+
import os
|
| 354 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 355 |
+
|
| 356 |
+
account = CloudflareAccount(
|
| 357 |
+
email=os.getenv("CLOUDFLARE_EMAIL"),
|
| 358 |
+
token=os.getenv("CLOUDFLARE_API_TOKEN")
|
| 359 |
+
)
|
| 360 |
+
cf = CloudflareManager(account)
|
| 361 |
+
```
|
| 362 |
+
|
| 363 |
+
## Troubleshooting
|
| 364 |
+
|
| 365 |
+
### Issue: "Invalid request headers" or "Invalid format for Authorization header"
|
| 366 |
+
|
| 367 |
+
**Solution**: Check that your API token is correct and has the required permissions.
|
| 368 |
+
|
| 369 |
+
### Issue: "Zone not found"
|
| 370 |
+
|
| 371 |
+
**Solution**: The domain must first be added to Cloudflare using `create_zone()`.
|
| 372 |
+
|
| 373 |
+
### Issue: "Failed to deploy"
|
| 374 |
+
|
| 375 |
+
**Solution**: Ensure:
|
| 376 |
+
1. The directory exists and contains files
|
| 377 |
+
2. There's an `index.html` file
|
| 378 |
+
3. Files are not too large (25MB limit per file)
|
| 379 |
+
|
| 380 |
+
### Issue: Domain validation required
|
| 381 |
+
|
| 382 |
+
**Solution**: Add the DNS validation record shown in the response to your DNS settings.
|
| 383 |
+
|
| 384 |
+
## Advanced Usage
|
| 385 |
+
|
| 386 |
+
### Using Multiple Accounts
|
| 387 |
+
|
| 388 |
+
```python
|
| 389 |
+
from cloudflare_manager import MultiAccountManager
|
| 390 |
+
|
| 391 |
+
manager = MultiAccountManager()
|
| 392 |
+
|
| 393 |
+
# Add multiple accounts
|
| 394 |
+
manager.add_account("personal", "personal@example.com", "token1")
|
| 395 |
+
manager.add_account("work", "work@example.com", "token2")
|
| 396 |
+
|
| 397 |
+
# Use specific account
|
| 398 |
+
personal_cf = manager.get_account("personal")
|
| 399 |
+
work_cf = manager.get_account("work")
|
| 400 |
+
|
| 401 |
+
# Deploy to both accounts
|
| 402 |
+
personal_cf.deploy_pages_project("my-site", "./public", "main")
|
| 403 |
+
work_cf.deploy_pages_project("company-site", "./dist", "main")
|
| 404 |
+
```
|
| 405 |
+
|
| 406 |
+
### Batch Operations
|
| 407 |
+
|
| 408 |
+
```python
|
| 409 |
+
# Deploy to multiple projects
|
| 410 |
+
projects = ["site1", "site2", "site3"]
|
| 411 |
+
|
| 412 |
+
for project in projects:
|
| 413 |
+
cf.create_pages_project(project, "main")
|
| 414 |
+
cf.deploy_pages_project(project, f"./projects/{project}", "main")
|
| 415 |
+
print(f"โ Deployed {project}")
|
| 416 |
+
```
|
| 417 |
+
|
| 418 |
+
## API Rate Limits
|
| 419 |
+
|
| 420 |
+
Cloudflare has rate limits:
|
| 421 |
+
- **Standard**: 1,200 requests per 5 minutes
|
| 422 |
+
- **Per endpoint**: Varies
|
| 423 |
+
|
| 424 |
+
The manager handles errors gracefully, but for bulk operations, consider adding delays:
|
| 425 |
+
|
| 426 |
+
```python
|
| 427 |
+
import time
|
| 428 |
+
|
| 429 |
+
for project in large_project_list:
|
| 430 |
+
cf.deploy_pages_project(project, f"./{project}", "main")
|
| 431 |
+
time.sleep(1) # Add 1 second delay
|
| 432 |
+
```
|
| 433 |
+
|
| 434 |
+
## Support
|
| 435 |
+
|
| 436 |
+
For issues or questions:
|
| 437 |
+
1. Check the [Cloudflare API docs](https://developers.cloudflare.com/api/)
|
| 438 |
+
2. Review error messages carefully
|
| 439 |
+
3. Ensure API token has correct permissions
|
| 440 |
+
4. Verify account limits (zones, projects, etc.)
|
| 441 |
+
|
| 442 |
+
## License
|
| 443 |
+
|
| 444 |
+
MIT License - Use freely in your projects!
|
app.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Cloudflare Manager Web Interface
|
| 4 |
+
For deployment on Hugging Face Spaces
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import os
|
| 9 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_connection(email, token):
|
| 13 |
+
"""Test Cloudflare API connection"""
|
| 14 |
+
try:
|
| 15 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 16 |
+
cf = CloudflareManager(account)
|
| 17 |
+
|
| 18 |
+
if cf.account.account_id:
|
| 19 |
+
return f"โ Connected!\n\nAccount: {cf.account.name}\nID: {cf.account.account_id}"
|
| 20 |
+
else:
|
| 21 |
+
return "โ Failed to connect. Please check your credentials."
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return f"โ Error: {str(e)}"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def list_projects(email, token):
|
| 27 |
+
"""List all Pages projects"""
|
| 28 |
+
try:
|
| 29 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 30 |
+
cf = CloudflareManager(account)
|
| 31 |
+
|
| 32 |
+
projects = cf.list_pages_projects()
|
| 33 |
+
|
| 34 |
+
if not projects:
|
| 35 |
+
return "No projects found."
|
| 36 |
+
|
| 37 |
+
result = f"Found {len(projects)} project(s):\n\n"
|
| 38 |
+
for project in projects:
|
| 39 |
+
result += f"๐ฆ {project['name']}\n"
|
| 40 |
+
result += f" URL: https://{project.get('subdomain', 'N/A')}\n"
|
| 41 |
+
result += f" Created: {project.get('created_on', 'N/A')}\n\n"
|
| 42 |
+
|
| 43 |
+
return result
|
| 44 |
+
except Exception as e:
|
| 45 |
+
return f"โ Error: {str(e)}"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def create_project(email, token, project_name, branch):
|
| 49 |
+
"""Create a new Pages project"""
|
| 50 |
+
try:
|
| 51 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 52 |
+
cf = CloudflareManager(account)
|
| 53 |
+
|
| 54 |
+
project = cf.create_pages_project(project_name, branch)
|
| 55 |
+
|
| 56 |
+
if project:
|
| 57 |
+
return f"โ Project created!\n\nName: {project['name']}\nURL: https://{project.get('subdomain')}\n"
|
| 58 |
+
else:
|
| 59 |
+
return "โ Failed to create project"
|
| 60 |
+
except Exception as e:
|
| 61 |
+
return f"โ Error: {str(e)}"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def list_zones(email, token):
|
| 65 |
+
"""List all zones"""
|
| 66 |
+
try:
|
| 67 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 68 |
+
cf = CloudflareManager(account)
|
| 69 |
+
|
| 70 |
+
zones = cf.list_zones()
|
| 71 |
+
|
| 72 |
+
if not zones:
|
| 73 |
+
return "No zones found."
|
| 74 |
+
|
| 75 |
+
result = f"Found {len(zones)} zone(s):\n\n"
|
| 76 |
+
for zone in zones:
|
| 77 |
+
result += f"๐ {zone['name']}\n"
|
| 78 |
+
result += f" Zone ID: {zone['id']}\n"
|
| 79 |
+
result += f" Status: {zone.get('status', 'unknown')}\n"
|
| 80 |
+
|
| 81 |
+
nameservers = zone.get('name_servers', [])
|
| 82 |
+
if nameservers:
|
| 83 |
+
result += f" Nameservers:\n"
|
| 84 |
+
for ns in nameservers:
|
| 85 |
+
result += f" - {ns}\n"
|
| 86 |
+
result += "\n"
|
| 87 |
+
|
| 88 |
+
return result
|
| 89 |
+
except Exception as e:
|
| 90 |
+
return f"โ Error: {str(e)}"
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def create_zone_and_get_ns(email, token, domain_name):
|
| 94 |
+
"""Create zone and get nameservers"""
|
| 95 |
+
try:
|
| 96 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 97 |
+
cf = CloudflareManager(account)
|
| 98 |
+
|
| 99 |
+
zone = cf.create_zone(domain_name)
|
| 100 |
+
|
| 101 |
+
if zone:
|
| 102 |
+
nameservers = zone.get('name_servers', [])
|
| 103 |
+
result = f"โ Zone created for {domain_name}\n\n"
|
| 104 |
+
result += f"Zone ID: {zone['id']}\n\n"
|
| 105 |
+
result += "๐ Add these nameservers to your domain registrar:\n\n"
|
| 106 |
+
for ns in nameservers:
|
| 107 |
+
result += f" {ns}\n"
|
| 108 |
+
return result
|
| 109 |
+
else:
|
| 110 |
+
return "โ Failed to create zone"
|
| 111 |
+
except Exception as e:
|
| 112 |
+
return f"โ Error: {str(e)}"
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def bind_domain(email, token, project_name, domain_name):
|
| 116 |
+
"""Bind domain to Pages project"""
|
| 117 |
+
try:
|
| 118 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 119 |
+
cf = CloudflareManager(account)
|
| 120 |
+
|
| 121 |
+
result_data = cf.add_pages_domain(project_name, domain_name)
|
| 122 |
+
|
| 123 |
+
if result_data:
|
| 124 |
+
result = f"โ Domain bound to project!\n\n"
|
| 125 |
+
result += f"Domain: {result_data.get('name')}\n"
|
| 126 |
+
result += f"Status: {result_data.get('status')}\n\n"
|
| 127 |
+
|
| 128 |
+
if result_data.get('validation_data'):
|
| 129 |
+
val = result_data['validation_data']
|
| 130 |
+
result += f"DNS Validation Required:\n"
|
| 131 |
+
result += f" Type: {val.get('type')}\n"
|
| 132 |
+
result += f" Name: {val.get('name')}\n"
|
| 133 |
+
result += f" Value: {val.get('value')}\n"
|
| 134 |
+
|
| 135 |
+
return result
|
| 136 |
+
else:
|
| 137 |
+
return "โ Failed to bind domain"
|
| 138 |
+
except Exception as e:
|
| 139 |
+
return f"โ Error: {str(e)}"
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def create_worker_route(email, token, zone_id, pattern, script_name):
|
| 143 |
+
"""Create worker route"""
|
| 144 |
+
try:
|
| 145 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 146 |
+
cf = CloudflareManager(account)
|
| 147 |
+
|
| 148 |
+
route = cf.create_worker_route(zone_id, pattern, script_name)
|
| 149 |
+
|
| 150 |
+
if route:
|
| 151 |
+
return f"โ Worker route created!\n\nRoute ID: {route.get('id')}\nPattern: {pattern}\nScript: {script_name}"
|
| 152 |
+
else:
|
| 153 |
+
return "โ Failed to create route"
|
| 154 |
+
except Exception as e:
|
| 155 |
+
return f"โ Error: {str(e)}"
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
# Create Gradio interface
|
| 159 |
+
with gr.Blocks(title="Cloudflare Manager") as demo:
|
| 160 |
+
gr.Markdown("""
|
| 161 |
+
# ๐ Cloudflare Multi-Account Manager
|
| 162 |
+
|
| 163 |
+
Manage Cloudflare Pages, Domains, and Workers through a simple web interface.
|
| 164 |
+
|
| 165 |
+
## Features
|
| 166 |
+
- โ
Pages project management
|
| 167 |
+
- โ
Domain binding
|
| 168 |
+
- โ
Nameserver lookup
|
| 169 |
+
- โ
Worker route configuration
|
| 170 |
+
""")
|
| 171 |
+
|
| 172 |
+
with gr.Row():
|
| 173 |
+
with gr.Column():
|
| 174 |
+
email_input = gr.Textbox(
|
| 175 |
+
label="Cloudflare Email",
|
| 176 |
+
placeholder="your-email@example.com",
|
| 177 |
+
value=os.getenv("CLOUDFLARE_EMAIL", "")
|
| 178 |
+
)
|
| 179 |
+
token_input = gr.Textbox(
|
| 180 |
+
label="API Token",
|
| 181 |
+
type="password",
|
| 182 |
+
placeholder="Your API Token",
|
| 183 |
+
value=os.getenv("CLOUDFLARE_TOKEN", "")
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
with gr.Tabs():
|
| 187 |
+
# Tab 1: Connection Test
|
| 188 |
+
with gr.Tab("๐ Connection Test"):
|
| 189 |
+
test_btn = gr.Button("Test Connection", variant="primary")
|
| 190 |
+
test_output = gr.Textbox(label="Result", lines=5)
|
| 191 |
+
test_btn.click(
|
| 192 |
+
test_connection,
|
| 193 |
+
inputs=[email_input, token_input],
|
| 194 |
+
outputs=test_output
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
# Tab 2: Pages Projects
|
| 198 |
+
with gr.Tab("๐ฆ Pages Projects"):
|
| 199 |
+
with gr.Row():
|
| 200 |
+
with gr.Column():
|
| 201 |
+
gr.Markdown("### List Projects")
|
| 202 |
+
list_projects_btn = gr.Button("List Projects")
|
| 203 |
+
list_projects_output = gr.Textbox(label="Projects", lines=10)
|
| 204 |
+
list_projects_btn.click(
|
| 205 |
+
list_projects,
|
| 206 |
+
inputs=[email_input, token_input],
|
| 207 |
+
outputs=list_projects_output
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
with gr.Column():
|
| 211 |
+
gr.Markdown("### Create Project")
|
| 212 |
+
project_name = gr.Textbox(label="Project Name", placeholder="my-website")
|
| 213 |
+
project_branch = gr.Textbox(label="Branch", value="main")
|
| 214 |
+
create_project_btn = gr.Button("Create Project", variant="primary")
|
| 215 |
+
create_project_output = gr.Textbox(label="Result", lines=10)
|
| 216 |
+
create_project_btn.click(
|
| 217 |
+
create_project,
|
| 218 |
+
inputs=[email_input, token_input, project_name, project_branch],
|
| 219 |
+
outputs=create_project_output
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
# Tab 3: Domains & Zones
|
| 223 |
+
with gr.Tab("๐ Domains & Zones"):
|
| 224 |
+
with gr.Row():
|
| 225 |
+
with gr.Column():
|
| 226 |
+
gr.Markdown("### List Zones")
|
| 227 |
+
list_zones_btn = gr.Button("List Zones")
|
| 228 |
+
list_zones_output = gr.Textbox(label="Zones", lines=10)
|
| 229 |
+
list_zones_btn.click(
|
| 230 |
+
list_zones,
|
| 231 |
+
inputs=[email_input, token_input],
|
| 232 |
+
outputs=list_zones_output
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
with gr.Column():
|
| 236 |
+
gr.Markdown("### Create Zone & Get Nameservers")
|
| 237 |
+
zone_domain = gr.Textbox(label="Domain Name", placeholder="example.com")
|
| 238 |
+
create_zone_btn = gr.Button("Create Zone", variant="primary")
|
| 239 |
+
create_zone_output = gr.Textbox(label="Result", lines=10)
|
| 240 |
+
create_zone_btn.click(
|
| 241 |
+
create_zone_and_get_ns,
|
| 242 |
+
inputs=[email_input, token_input, zone_domain],
|
| 243 |
+
outputs=create_zone_output
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
# Tab 4: Domain Binding
|
| 247 |
+
with gr.Tab("๐ Bind Domain"):
|
| 248 |
+
gr.Markdown("### Bind Domain to Pages Project")
|
| 249 |
+
with gr.Row():
|
| 250 |
+
bind_project = gr.Textbox(label="Project Name", placeholder="my-website")
|
| 251 |
+
bind_domain_name = gr.Textbox(label="Domain", placeholder="example.com")
|
| 252 |
+
bind_btn = gr.Button("Bind Domain", variant="primary")
|
| 253 |
+
bind_output = gr.Textbox(label="Result", lines=10)
|
| 254 |
+
bind_btn.click(
|
| 255 |
+
bind_domain,
|
| 256 |
+
inputs=[email_input, token_input, bind_project, bind_domain_name],
|
| 257 |
+
outputs=bind_output
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
# Tab 5: Worker Routes
|
| 261 |
+
with gr.Tab("โก Worker Routes"):
|
| 262 |
+
gr.Markdown("### Create Worker Route")
|
| 263 |
+
worker_zone_id = gr.Textbox(label="Zone ID", placeholder="abc123...")
|
| 264 |
+
worker_pattern = gr.Textbox(label="Route Pattern", placeholder="example.com/api/*")
|
| 265 |
+
worker_script = gr.Textbox(label="Script Name", placeholder="my-worker")
|
| 266 |
+
worker_btn = gr.Button("Create Route", variant="primary")
|
| 267 |
+
worker_output = gr.Textbox(label="Result", lines=10)
|
| 268 |
+
worker_btn.click(
|
| 269 |
+
create_worker_route,
|
| 270 |
+
inputs=[email_input, token_input, worker_zone_id, worker_pattern, worker_script],
|
| 271 |
+
outputs=worker_output
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
gr.Markdown("""
|
| 275 |
+
---
|
| 276 |
+
### ๐ Documentation
|
| 277 |
+
|
| 278 |
+
- [Quick Start Guide](GET_STARTED.md)
|
| 279 |
+
- [Usage Guide](USAGE_GUIDE.md)
|
| 280 |
+
- [API Reference](API_REFERENCE.md)
|
| 281 |
+
|
| 282 |
+
### ๐ API Token Permissions
|
| 283 |
+
|
| 284 |
+
Your API token needs:
|
| 285 |
+
- Account > Cloudflare Pages > Edit
|
| 286 |
+
- Zone > DNS > Edit
|
| 287 |
+
- Zone > Workers Routes > Edit
|
| 288 |
+
|
| 289 |
+
### ๐ก Tips
|
| 290 |
+
|
| 291 |
+
1. Get your API token from: https://dash.cloudflare.com/profile/api-tokens
|
| 292 |
+
2. After creating a zone, add the nameservers to your domain registrar
|
| 293 |
+
3. DNS propagation takes 5-30 minutes
|
| 294 |
+
""")
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
if __name__ == "__main__":
|
| 298 |
+
# Run with sharing enabled for Hugging Face Spaces
|
| 299 |
+
demo.launch(
|
| 300 |
+
server_name="0.0.0.0",
|
| 301 |
+
server_port=7860,
|
| 302 |
+
share=False
|
| 303 |
+
)
|
cloudflare_manager.py
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Cloudflare Multi-Account Manager
|
| 4 |
+
Supports:
|
| 5 |
+
- Managing multiple Cloudflare accounts
|
| 6 |
+
- Deploying Pages projects
|
| 7 |
+
- Binding domains to Pages projects
|
| 8 |
+
- Getting nameservers
|
| 9 |
+
- Configuring worker routes
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
import sys
|
| 14 |
+
import json
|
| 15 |
+
import requests
|
| 16 |
+
import hashlib
|
| 17 |
+
import mimetypes
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
from typing import Dict, List, Optional, Any
|
| 20 |
+
from dataclasses import dataclass, asdict
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@dataclass
|
| 24 |
+
class CloudflareAccount:
|
| 25 |
+
"""Cloudflare account configuration"""
|
| 26 |
+
email: str
|
| 27 |
+
token: str
|
| 28 |
+
account_id: Optional[str] = None
|
| 29 |
+
name: Optional[str] = None
|
| 30 |
+
use_api_key: bool = True # True = API Key (X-Auth-Key), False = API Token (Bearer)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class CloudflareManager:
|
| 34 |
+
"""Manager for Cloudflare API operations"""
|
| 35 |
+
|
| 36 |
+
BASE_URL = "https://api.cloudflare.com/client/v4"
|
| 37 |
+
|
| 38 |
+
def __init__(self, account: CloudflareAccount):
|
| 39 |
+
self.account = account
|
| 40 |
+
self.session = requests.Session()
|
| 41 |
+
|
| 42 |
+
# Support both API Key and API Token authentication
|
| 43 |
+
if account.use_api_key:
|
| 44 |
+
# API Key authentication (X-Auth-Email + X-Auth-Key)
|
| 45 |
+
self.session.headers.update({
|
| 46 |
+
"X-Auth-Email": account.email,
|
| 47 |
+
"X-Auth-Key": account.token,
|
| 48 |
+
"Content-Type": "application/json"
|
| 49 |
+
})
|
| 50 |
+
else:
|
| 51 |
+
# API Token authentication (Bearer)
|
| 52 |
+
self.session.headers.update({
|
| 53 |
+
"Authorization": f"Bearer {account.token}",
|
| 54 |
+
"Content-Type": "application/json"
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
# Auto-fetch account_id if not provided
|
| 58 |
+
if not self.account.account_id:
|
| 59 |
+
self._fetch_account_id()
|
| 60 |
+
|
| 61 |
+
def _fetch_account_id(self):
|
| 62 |
+
"""Fetch the account ID for the authenticated user"""
|
| 63 |
+
response = self.session.get(f"{self.BASE_URL}/accounts")
|
| 64 |
+
data = self._handle_response(response)
|
| 65 |
+
|
| 66 |
+
if data and data.get("result"):
|
| 67 |
+
accounts = data["result"]
|
| 68 |
+
if accounts:
|
| 69 |
+
self.account.account_id = accounts[0]["id"]
|
| 70 |
+
self.account.name = accounts[0].get("name", "Unknown")
|
| 71 |
+
print(f"โ Auto-detected account: {self.account.name} ({self.account.account_id})")
|
| 72 |
+
|
| 73 |
+
def _handle_response(self, response: requests.Response) -> Dict:
|
| 74 |
+
"""Handle API response and check for errors"""
|
| 75 |
+
try:
|
| 76 |
+
data = response.json()
|
| 77 |
+
except json.JSONDecodeError:
|
| 78 |
+
print(f"โ Failed to parse response: {response.text}")
|
| 79 |
+
return {}
|
| 80 |
+
|
| 81 |
+
if not data.get("success", False):
|
| 82 |
+
errors = data.get("errors", [])
|
| 83 |
+
print(f"โ API Error: {errors}")
|
| 84 |
+
return {}
|
| 85 |
+
|
| 86 |
+
return data
|
| 87 |
+
|
| 88 |
+
def list_accounts(self) -> List[Dict]:
|
| 89 |
+
"""List all accounts"""
|
| 90 |
+
response = self.session.get(f"{self.BASE_URL}/accounts")
|
| 91 |
+
data = self._handle_response(response)
|
| 92 |
+
return data.get("result", [])
|
| 93 |
+
|
| 94 |
+
# ==================== Pages Operations ====================
|
| 95 |
+
|
| 96 |
+
def create_pages_project(self, project_name: str, production_branch: str = "main") -> Optional[Dict]:
|
| 97 |
+
"""Create a new Pages project"""
|
| 98 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects"
|
| 99 |
+
payload = {
|
| 100 |
+
"name": project_name,
|
| 101 |
+
"production_branch": production_branch
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
response = self.session.post(url, json=payload)
|
| 105 |
+
data = self._handle_response(response)
|
| 106 |
+
|
| 107 |
+
if data and data.get("result"):
|
| 108 |
+
print(f"โ Created Pages project: {project_name}")
|
| 109 |
+
return data["result"]
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
def list_pages_projects(self) -> List[Dict]:
|
| 113 |
+
"""List all Pages projects"""
|
| 114 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects"
|
| 115 |
+
response = self.session.get(url)
|
| 116 |
+
data = self._handle_response(response)
|
| 117 |
+
return data.get("result", [])
|
| 118 |
+
|
| 119 |
+
def get_pages_project(self, project_name: str) -> Optional[Dict]:
|
| 120 |
+
"""Get a specific Pages project"""
|
| 121 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects/{project_name}"
|
| 122 |
+
response = self.session.get(url)
|
| 123 |
+
data = self._handle_response(response)
|
| 124 |
+
return data.get("result")
|
| 125 |
+
|
| 126 |
+
def deploy_pages_project(self, project_name: str, directory: str,
|
| 127 |
+
branch: str = "main", commit_message: str = "Deploy via API") -> Optional[Dict]:
|
| 128 |
+
"""Deploy a Pages project from a directory"""
|
| 129 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects/{project_name}/deployments"
|
| 130 |
+
|
| 131 |
+
# Build manifest and upload files
|
| 132 |
+
manifest = {}
|
| 133 |
+
files_to_upload = []
|
| 134 |
+
|
| 135 |
+
dir_path = Path(directory)
|
| 136 |
+
if not dir_path.exists():
|
| 137 |
+
print(f"โ Directory not found: {directory}")
|
| 138 |
+
return None
|
| 139 |
+
|
| 140 |
+
print(f"๐ฆ Building deployment from: {directory}")
|
| 141 |
+
|
| 142 |
+
for file_path in dir_path.rglob("*"):
|
| 143 |
+
if file_path.is_file():
|
| 144 |
+
relative_path = file_path.relative_to(dir_path).as_posix()
|
| 145 |
+
|
| 146 |
+
# Read file and calculate hash
|
| 147 |
+
with open(file_path, "rb") as f:
|
| 148 |
+
content = f.read()
|
| 149 |
+
file_hash = hashlib.sha256(content).hexdigest()
|
| 150 |
+
|
| 151 |
+
manifest[relative_path] = file_hash
|
| 152 |
+
files_to_upload.append((relative_path, content))
|
| 153 |
+
|
| 154 |
+
print(f"๐ Found {len(files_to_upload)} files to deploy")
|
| 155 |
+
|
| 156 |
+
# Prepare multipart form data
|
| 157 |
+
files = []
|
| 158 |
+
files.append(("branch", (None, branch)))
|
| 159 |
+
files.append(("commit_message", (None, commit_message)))
|
| 160 |
+
files.append(("manifest", (None, json.dumps(manifest))))
|
| 161 |
+
|
| 162 |
+
# Add each file
|
| 163 |
+
for file_name, content in files_to_upload:
|
| 164 |
+
mime_type = mimetypes.guess_type(file_name)[0] or "application/octet-stream"
|
| 165 |
+
files.append((file_name, (file_name, content, mime_type)))
|
| 166 |
+
|
| 167 |
+
# Send deployment
|
| 168 |
+
headers = {"Authorization": f"Bearer {self.account.token}"}
|
| 169 |
+
response = requests.post(url, headers=headers, files=files)
|
| 170 |
+
data = self._handle_response(response)
|
| 171 |
+
|
| 172 |
+
if data and data.get("result"):
|
| 173 |
+
deployment = data["result"]
|
| 174 |
+
print(f"โ Deployment created: {deployment.get('id')}")
|
| 175 |
+
print(f" URL: {deployment.get('url')}")
|
| 176 |
+
print(f" Stage: {deployment.get('stages', [{}])[0].get('name', 'unknown')}")
|
| 177 |
+
return deployment
|
| 178 |
+
return None
|
| 179 |
+
|
| 180 |
+
def list_pages_deployments(self, project_name: str) -> List[Dict]:
|
| 181 |
+
"""List all deployments for a Pages project"""
|
| 182 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects/{project_name}/deployments"
|
| 183 |
+
response = self.session.get(url)
|
| 184 |
+
data = self._handle_response(response)
|
| 185 |
+
return data.get("result", [])
|
| 186 |
+
|
| 187 |
+
# ==================== Domain Operations ====================
|
| 188 |
+
|
| 189 |
+
def add_pages_domain(self, project_name: str, domain_name: str) -> Optional[Dict]:
|
| 190 |
+
"""Add a custom domain to a Pages project"""
|
| 191 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects/{project_name}/domains"
|
| 192 |
+
payload = {"name": domain_name}
|
| 193 |
+
|
| 194 |
+
response = self.session.post(url, json=payload)
|
| 195 |
+
data = self._handle_response(response)
|
| 196 |
+
|
| 197 |
+
if data and data.get("result"):
|
| 198 |
+
print(f"โ Domain added to Pages project: {domain_name}")
|
| 199 |
+
return data["result"]
|
| 200 |
+
return None
|
| 201 |
+
|
| 202 |
+
def list_pages_domains(self, project_name: str) -> List[Dict]:
|
| 203 |
+
"""List all domains for a Pages project"""
|
| 204 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects/{project_name}/domains"
|
| 205 |
+
response = self.session.get(url)
|
| 206 |
+
data = self._handle_response(response)
|
| 207 |
+
return data.get("result", [])
|
| 208 |
+
|
| 209 |
+
def get_pages_domain(self, project_name: str, domain_name: str) -> Optional[Dict]:
|
| 210 |
+
"""Get details about a Pages domain"""
|
| 211 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/pages/projects/{project_name}/domains/{domain_name}"
|
| 212 |
+
response = self.session.get(url)
|
| 213 |
+
data = self._handle_response(response)
|
| 214 |
+
return data.get("result")
|
| 215 |
+
|
| 216 |
+
# ==================== Zone Operations ====================
|
| 217 |
+
|
| 218 |
+
def create_zone(self, domain_name: str, zone_type: str = "full") -> Optional[Dict]:
|
| 219 |
+
"""Create a new zone (domain)"""
|
| 220 |
+
url = f"{self.BASE_URL}/zones"
|
| 221 |
+
payload = {
|
| 222 |
+
"account": {"id": self.account.account_id},
|
| 223 |
+
"name": domain_name,
|
| 224 |
+
"type": zone_type
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
response = self.session.post(url, json=payload)
|
| 228 |
+
data = self._handle_response(response)
|
| 229 |
+
|
| 230 |
+
if data and data.get("result"):
|
| 231 |
+
zone = data["result"]
|
| 232 |
+
print(f"โ Zone created: {domain_name}")
|
| 233 |
+
print(f" Zone ID: {zone.get('id')}")
|
| 234 |
+
return zone
|
| 235 |
+
return None
|
| 236 |
+
|
| 237 |
+
def list_zones(self) -> List[Dict]:
|
| 238 |
+
"""List all zones"""
|
| 239 |
+
url = f"{self.BASE_URL}/zones"
|
| 240 |
+
response = self.session.get(url)
|
| 241 |
+
data = self._handle_response(response)
|
| 242 |
+
return data.get("result", [])
|
| 243 |
+
|
| 244 |
+
def get_zone(self, zone_id: str) -> Optional[Dict]:
|
| 245 |
+
"""Get zone details"""
|
| 246 |
+
url = f"{self.BASE_URL}/zones/{zone_id}"
|
| 247 |
+
response = self.session.get(url)
|
| 248 |
+
data = self._handle_response(response)
|
| 249 |
+
return data.get("result")
|
| 250 |
+
|
| 251 |
+
def get_zone_by_name(self, domain_name: str) -> Optional[Dict]:
|
| 252 |
+
"""Get zone by domain name"""
|
| 253 |
+
zones = self.list_zones()
|
| 254 |
+
for zone in zones:
|
| 255 |
+
if zone.get("name") == domain_name:
|
| 256 |
+
return zone
|
| 257 |
+
return None
|
| 258 |
+
|
| 259 |
+
def get_nameservers(self, domain_name: str) -> Optional[List[str]]:
|
| 260 |
+
"""Get nameservers for a domain"""
|
| 261 |
+
zone = self.get_zone_by_name(domain_name)
|
| 262 |
+
|
| 263 |
+
if zone:
|
| 264 |
+
nameservers = zone.get("name_servers", [])
|
| 265 |
+
print(f"\n๐ Nameservers for {domain_name}:")
|
| 266 |
+
for ns in nameservers:
|
| 267 |
+
print(f" {ns}")
|
| 268 |
+
return nameservers
|
| 269 |
+
else:
|
| 270 |
+
print(f"โ Zone not found for domain: {domain_name}")
|
| 271 |
+
return None
|
| 272 |
+
|
| 273 |
+
# ==================== Worker Routes Operations ====================
|
| 274 |
+
|
| 275 |
+
def create_worker_route(self, zone_id: str, pattern: str, script_name: str) -> Optional[Dict]:
|
| 276 |
+
"""Create a worker route"""
|
| 277 |
+
url = f"{self.BASE_URL}/zones/{zone_id}/workers/routes"
|
| 278 |
+
payload = {
|
| 279 |
+
"pattern": pattern,
|
| 280 |
+
"script": script_name
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
response = self.session.post(url, json=payload)
|
| 284 |
+
data = self._handle_response(response)
|
| 285 |
+
|
| 286 |
+
if data and data.get("result"):
|
| 287 |
+
print(f"โ Worker route created: {pattern} -> {script_name}")
|
| 288 |
+
return data["result"]
|
| 289 |
+
return None
|
| 290 |
+
|
| 291 |
+
def list_worker_routes(self, zone_id: str) -> List[Dict]:
|
| 292 |
+
"""List all worker routes for a zone"""
|
| 293 |
+
url = f"{self.BASE_URL}/zones/{zone_id}/workers/routes"
|
| 294 |
+
response = self.session.get(url)
|
| 295 |
+
data = self._handle_response(response)
|
| 296 |
+
return data.get("result", [])
|
| 297 |
+
|
| 298 |
+
def delete_worker_route(self, zone_id: str, route_id: str) -> bool:
|
| 299 |
+
"""Delete a worker route"""
|
| 300 |
+
url = f"{self.BASE_URL}/zones/{zone_id}/workers/routes/{route_id}"
|
| 301 |
+
response = self.session.delete(url)
|
| 302 |
+
data = self._handle_response(response)
|
| 303 |
+
|
| 304 |
+
if data:
|
| 305 |
+
print(f"โ Worker route deleted: {route_id}")
|
| 306 |
+
return True
|
| 307 |
+
return False
|
| 308 |
+
|
| 309 |
+
# ==================== Worker Domains Operations ====================
|
| 310 |
+
|
| 311 |
+
def add_worker_domain(self, hostname: str, service: str, zone_id: str,
|
| 312 |
+
environment: str = "production") -> Optional[Dict]:
|
| 313 |
+
"""Add a custom domain to a worker"""
|
| 314 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/workers/domains"
|
| 315 |
+
payload = {
|
| 316 |
+
"hostname": hostname,
|
| 317 |
+
"service": service,
|
| 318 |
+
"zone_id": zone_id,
|
| 319 |
+
"environment": environment
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
response = self.session.put(url, json=payload)
|
| 323 |
+
data = self._handle_response(response)
|
| 324 |
+
|
| 325 |
+
if data and data.get("result"):
|
| 326 |
+
print(f"โ Worker domain added: {hostname} -> {service}")
|
| 327 |
+
return data["result"]
|
| 328 |
+
return None
|
| 329 |
+
|
| 330 |
+
def list_worker_domains(self) -> List[Dict]:
|
| 331 |
+
"""List all worker domains"""
|
| 332 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/workers/domains"
|
| 333 |
+
response = self.session.get(url)
|
| 334 |
+
data = self._handle_response(response)
|
| 335 |
+
return data.get("result", [])
|
| 336 |
+
|
| 337 |
+
# ==================== Worker Script Operations ====================
|
| 338 |
+
|
| 339 |
+
def upload_worker(self, script_name: str, worker_file: str,
|
| 340 |
+
bindings: Optional[List[Dict]] = None) -> Optional[Dict]:
|
| 341 |
+
"""Upload a Worker script to Cloudflare
|
| 342 |
+
|
| 343 |
+
Args:
|
| 344 |
+
script_name: Name of the worker script
|
| 345 |
+
worker_file: Path to the worker .js file
|
| 346 |
+
bindings: Optional list of bindings (KV, R2, etc.)
|
| 347 |
+
|
| 348 |
+
Returns:
|
| 349 |
+
Worker script details if successful
|
| 350 |
+
"""
|
| 351 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/workers/scripts/{script_name}"
|
| 352 |
+
|
| 353 |
+
# Read worker file
|
| 354 |
+
worker_path = Path(worker_file)
|
| 355 |
+
if not worker_path.exists():
|
| 356 |
+
print(f"โ Worker file not found: {worker_file}")
|
| 357 |
+
return None
|
| 358 |
+
|
| 359 |
+
with open(worker_path, 'r', encoding='utf-8') as f:
|
| 360 |
+
worker_content = f.read()
|
| 361 |
+
|
| 362 |
+
# Prepare metadata
|
| 363 |
+
metadata = {
|
| 364 |
+
"main_module": "_worker.js",
|
| 365 |
+
"compatibility_date": "2023-01-01"
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
if bindings:
|
| 369 |
+
metadata["bindings"] = bindings
|
| 370 |
+
|
| 371 |
+
# Prepare multipart form data
|
| 372 |
+
files = {
|
| 373 |
+
'metadata': (None, json.dumps(metadata), 'application/json'),
|
| 374 |
+
'_worker.js': ('_worker.js', worker_content, 'text/javascript'),
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
# Remove Content-Type header for multipart request
|
| 378 |
+
headers = {}
|
| 379 |
+
if self.account.use_api_key:
|
| 380 |
+
headers["X-Auth-Email"] = self.account.email
|
| 381 |
+
headers["X-Auth-Key"] = self.account.token
|
| 382 |
+
else:
|
| 383 |
+
headers["Authorization"] = f"Bearer {self.account.token}"
|
| 384 |
+
|
| 385 |
+
response = requests.put(url, headers=headers, files=files)
|
| 386 |
+
data = self._handle_response(response)
|
| 387 |
+
|
| 388 |
+
if data and data.get("result"):
|
| 389 |
+
print(f"โ Worker uploaded: {script_name}")
|
| 390 |
+
print(f" URL: https://{script_name}.{self.account.name}.workers.dev")
|
| 391 |
+
return data["result"]
|
| 392 |
+
return None
|
| 393 |
+
|
| 394 |
+
def list_workers(self) -> List[Dict]:
|
| 395 |
+
"""List all Worker scripts"""
|
| 396 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/workers/scripts"
|
| 397 |
+
response = self.session.get(url)
|
| 398 |
+
data = self._handle_response(response)
|
| 399 |
+
return data.get("result", [])
|
| 400 |
+
|
| 401 |
+
def get_worker(self, script_name: str) -> Optional[Dict]:
|
| 402 |
+
"""Get a specific Worker script details"""
|
| 403 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/workers/scripts/{script_name}"
|
| 404 |
+
response = self.session.get(url)
|
| 405 |
+
data = self._handle_response(response)
|
| 406 |
+
return data.get("result")
|
| 407 |
+
|
| 408 |
+
def delete_worker(self, script_name: str) -> bool:
|
| 409 |
+
"""Delete a Worker script"""
|
| 410 |
+
url = f"{self.BASE_URL}/accounts/{self.account.account_id}/workers/scripts/{script_name}"
|
| 411 |
+
response = self.session.delete(url)
|
| 412 |
+
data = self._handle_response(response)
|
| 413 |
+
|
| 414 |
+
if data:
|
| 415 |
+
print(f"โ Worker deleted: {script_name}")
|
| 416 |
+
return True
|
| 417 |
+
return False
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
class MultiAccountManager:
|
| 421 |
+
"""Manager for multiple Cloudflare accounts"""
|
| 422 |
+
|
| 423 |
+
def __init__(self):
|
| 424 |
+
self.accounts: Dict[str, CloudflareManager] = {}
|
| 425 |
+
|
| 426 |
+
def add_account(self, name: str, email: str, token: str, account_id: Optional[str] = None):
|
| 427 |
+
"""Add a Cloudflare account"""
|
| 428 |
+
account = CloudflareAccount(email=email, token=token, account_id=account_id, name=name)
|
| 429 |
+
manager = CloudflareManager(account)
|
| 430 |
+
self.accounts[name] = manager
|
| 431 |
+
print(f"โ Added account: {name}")
|
| 432 |
+
return manager
|
| 433 |
+
|
| 434 |
+
def get_account(self, name: str) -> Optional[CloudflareManager]:
|
| 435 |
+
"""Get a specific account manager"""
|
| 436 |
+
return self.accounts.get(name)
|
| 437 |
+
|
| 438 |
+
def list_accounts(self) -> List[str]:
|
| 439 |
+
"""List all configured accounts"""
|
| 440 |
+
return list(self.accounts.keys())
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
def print_banner():
|
| 444 |
+
"""Print application banner"""
|
| 445 |
+
print("""
|
| 446 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 447 |
+
โ Cloudflare Multi-Account Manager โ
|
| 448 |
+
โ Features: Pages Deploy, Domain Binding, NS Info โ
|
| 449 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 450 |
+
""")
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
def main():
|
| 454 |
+
"""Main CLI interface"""
|
| 455 |
+
print_banner()
|
| 456 |
+
|
| 457 |
+
# Example usage
|
| 458 |
+
manager = MultiAccountManager()
|
| 459 |
+
|
| 460 |
+
# Add account
|
| 461 |
+
print("\n๐ Adding account...")
|
| 462 |
+
account_name = "primary"
|
| 463 |
+
email = "exslym@closedbyme.com"
|
| 464 |
+
token = "21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 465 |
+
|
| 466 |
+
cf_manager = manager.add_account(account_name, email, token)
|
| 467 |
+
|
| 468 |
+
if not cf_manager:
|
| 469 |
+
print("โ Failed to add account")
|
| 470 |
+
return
|
| 471 |
+
|
| 472 |
+
print(f"\nโ Account configured: {account_name}")
|
| 473 |
+
print(f" Email: {email}")
|
| 474 |
+
print(f" Account ID: {cf_manager.account.account_id}")
|
| 475 |
+
|
| 476 |
+
# Interactive menu
|
| 477 |
+
while True:
|
| 478 |
+
print("\n" + "="*60)
|
| 479 |
+
print("Operations Menu:")
|
| 480 |
+
print("="*60)
|
| 481 |
+
print("1. List Pages Projects")
|
| 482 |
+
print("2. Create Pages Project")
|
| 483 |
+
print("3. Deploy Pages Project (from directory)")
|
| 484 |
+
print("4. Add Domain to Pages Project")
|
| 485 |
+
print("5. List Domains for Pages Project")
|
| 486 |
+
print("6. Create Zone and Get Nameservers")
|
| 487 |
+
print("7. Get Nameservers for Existing Domain")
|
| 488 |
+
print("8. List Zones")
|
| 489 |
+
print("9. Upload Worker Script")
|
| 490 |
+
print("10. List Workers")
|
| 491 |
+
print("11. Create Worker Route")
|
| 492 |
+
print("12. List Worker Routes")
|
| 493 |
+
print("13. Add Worker Custom Domain")
|
| 494 |
+
print("0. Exit")
|
| 495 |
+
print("="*60)
|
| 496 |
+
|
| 497 |
+
choice = input("\nSelect operation (0-13): ").strip()
|
| 498 |
+
|
| 499 |
+
if choice == "0":
|
| 500 |
+
print("\n๐ Goodbye!")
|
| 501 |
+
break
|
| 502 |
+
|
| 503 |
+
elif choice == "1":
|
| 504 |
+
print("\n๐ Listing Pages projects...")
|
| 505 |
+
projects = cf_manager.list_pages_projects()
|
| 506 |
+
if projects:
|
| 507 |
+
for project in projects:
|
| 508 |
+
print(f" - {project['name']} (created: {project.get('created_on', 'N/A')})")
|
| 509 |
+
print(f" URL: https://{project.get('subdomain', 'N/A')}")
|
| 510 |
+
else:
|
| 511 |
+
print(" No projects found")
|
| 512 |
+
|
| 513 |
+
elif choice == "2":
|
| 514 |
+
project_name = input("Enter project name: ").strip()
|
| 515 |
+
branch = input("Enter production branch (default: main): ").strip() or "main"
|
| 516 |
+
cf_manager.create_pages_project(project_name, branch)
|
| 517 |
+
|
| 518 |
+
elif choice == "3":
|
| 519 |
+
project_name = input("Enter project name: ").strip()
|
| 520 |
+
directory = input("Enter directory path: ").strip()
|
| 521 |
+
branch = input("Enter branch (default: main): ").strip() or "main"
|
| 522 |
+
commit_msg = input("Enter commit message (default: Deploy via API): ").strip() or "Deploy via API"
|
| 523 |
+
cf_manager.deploy_pages_project(project_name, directory, branch, commit_msg)
|
| 524 |
+
|
| 525 |
+
elif choice == "4":
|
| 526 |
+
project_name = input("Enter project name: ").strip()
|
| 527 |
+
domain_name = input("Enter domain name: ").strip()
|
| 528 |
+
result = cf_manager.add_pages_domain(project_name, domain_name)
|
| 529 |
+
if result:
|
| 530 |
+
print(f"\n๐ Domain Details:")
|
| 531 |
+
print(f" Name: {result.get('name')}")
|
| 532 |
+
print(f" Status: {result.get('status')}")
|
| 533 |
+
if result.get('validation_data'):
|
| 534 |
+
val = result['validation_data']
|
| 535 |
+
print(f"\n DNS Validation Required:")
|
| 536 |
+
print(f" Type: {val.get('type')}")
|
| 537 |
+
print(f" Name: {val.get('name')}")
|
| 538 |
+
print(f" Value: {val.get('value')}")
|
| 539 |
+
|
| 540 |
+
elif choice == "5":
|
| 541 |
+
project_name = input("Enter project name: ").strip()
|
| 542 |
+
domains = cf_manager.list_pages_domains(project_name)
|
| 543 |
+
if domains:
|
| 544 |
+
print(f"\n๐ Domains for {project_name}:")
|
| 545 |
+
for domain in domains:
|
| 546 |
+
print(f" - {domain['name']} (status: {domain.get('status', 'unknown')})")
|
| 547 |
+
else:
|
| 548 |
+
print(" No domains found")
|
| 549 |
+
|
| 550 |
+
elif choice == "6":
|
| 551 |
+
domain_name = input("Enter domain name: ").strip()
|
| 552 |
+
zone = cf_manager.create_zone(domain_name)
|
| 553 |
+
if zone:
|
| 554 |
+
nameservers = zone.get("name_servers", [])
|
| 555 |
+
print(f"\n๐ Nameservers (add these to your domain registrar):")
|
| 556 |
+
for ns in nameservers:
|
| 557 |
+
print(f" {ns}")
|
| 558 |
+
|
| 559 |
+
elif choice == "7":
|
| 560 |
+
domain_name = input("Enter domain name: ").strip()
|
| 561 |
+
cf_manager.get_nameservers(domain_name)
|
| 562 |
+
|
| 563 |
+
elif choice == "8":
|
| 564 |
+
print("\n๐ Listing zones...")
|
| 565 |
+
zones = cf_manager.list_zones()
|
| 566 |
+
if zones:
|
| 567 |
+
for zone in zones:
|
| 568 |
+
print(f" - {zone['name']} (ID: {zone['id']})")
|
| 569 |
+
print(f" Status: {zone.get('status', 'unknown')}")
|
| 570 |
+
nameservers = zone.get("name_servers", [])
|
| 571 |
+
if nameservers:
|
| 572 |
+
print(f" Nameservers: {', '.join(nameservers)}")
|
| 573 |
+
else:
|
| 574 |
+
print(" No zones found")
|
| 575 |
+
|
| 576 |
+
elif choice == "9":
|
| 577 |
+
script_name = input("Enter worker script name: ").strip()
|
| 578 |
+
worker_file = input("Enter path to worker .js file: ").strip()
|
| 579 |
+
cf_manager.upload_worker(script_name, worker_file)
|
| 580 |
+
|
| 581 |
+
elif choice == "10":
|
| 582 |
+
print("\n๐ Listing Workers...")
|
| 583 |
+
workers = cf_manager.list_workers()
|
| 584 |
+
if workers:
|
| 585 |
+
for worker in workers:
|
| 586 |
+
print(f" - {worker.get('id')} (created: {worker.get('created_on', 'N/A')})")
|
| 587 |
+
if worker.get('modified_on'):
|
| 588 |
+
print(f" Modified: {worker.get('modified_on')}")
|
| 589 |
+
else:
|
| 590 |
+
print(" No workers found")
|
| 591 |
+
|
| 592 |
+
elif choice == "11":
|
| 593 |
+
zone_id = input("Enter zone ID: ").strip()
|
| 594 |
+
pattern = input("Enter route pattern (e.g., example.com/*): ").strip()
|
| 595 |
+
script_name = input("Enter worker script name: ").strip()
|
| 596 |
+
cf_manager.create_worker_route(zone_id, pattern, script_name)
|
| 597 |
+
|
| 598 |
+
elif choice == "12":
|
| 599 |
+
zone_id = input("Enter zone ID: ").strip()
|
| 600 |
+
routes = cf_manager.list_worker_routes(zone_id)
|
| 601 |
+
if routes:
|
| 602 |
+
print(f"\n๐ Worker routes:")
|
| 603 |
+
for route in routes:
|
| 604 |
+
print(f" - {route.get('pattern')} -> {route.get('script', 'N/A')}")
|
| 605 |
+
print(f" ID: {route.get('id')}")
|
| 606 |
+
else:
|
| 607 |
+
print(" No routes found")
|
| 608 |
+
|
| 609 |
+
elif choice == "13":
|
| 610 |
+
hostname = input("Enter hostname (e.g., api.example.com): ").strip()
|
| 611 |
+
service = input("Enter worker/service name: ").strip()
|
| 612 |
+
zone_id = input("Enter zone ID: ").strip()
|
| 613 |
+
environment = input("Enter environment (default: production): ").strip() or "production"
|
| 614 |
+
cf_manager.add_worker_domain(hostname, service, zone_id, environment)
|
| 615 |
+
|
| 616 |
+
else:
|
| 617 |
+
print("โ Invalid option")
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
if __name__ == "__main__":
|
| 621 |
+
main()
|
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
+
|
| 5 |
+
set -e # ้ๅฐ้่ฏฏ็ซๅณ้ๅบ
|
| 6 |
+
|
| 7 |
+
EMAIL="exslym@closedbyme.com"
|
| 8 |
+
API_KEY="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 9 |
+
ACCOUNT_ID="af2863fcfbc1f170e5ef3b7a648c417d"
|
| 10 |
+
|
| 11 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 12 |
+
echo " Cloudflare API - curl ๆต่ฏ่ๆฌ"
|
| 13 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 14 |
+
echo ""
|
| 15 |
+
echo "Email: $EMAIL"
|
| 16 |
+
echo "Account ID: $ACCOUNT_ID"
|
| 17 |
+
echo ""
|
| 18 |
+
|
| 19 |
+
# ๆต่ฏ 1: ่ทๅ่ดฆๅทไฟกๆฏ
|
| 20 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 21 |
+
echo "ๆต่ฏ 1: ่ทๅ่ดฆๅทไฟกๆฏ"
|
| 22 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 23 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts" \
|
| 24 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 25 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 26 |
+
-H "Content-Type: application/json" | jq -r '
|
| 27 |
+
if .success then
|
| 28 |
+
"โ
ๆๅ!\n่ดฆๅทๅ็งฐ: \(.result[0].name)\n่ดฆๅท ID: \(.result[0].id)"
|
| 29 |
+
else
|
| 30 |
+
"โ ๅคฑ่ดฅ: \(.errors)"
|
| 31 |
+
end'
|
| 32 |
+
echo ""
|
| 33 |
+
|
| 34 |
+
# ๆต่ฏ 2: ๅๅบ Pages ้กน็ฎ
|
| 35 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 36 |
+
echo "ๆต่ฏ 2: ๅๅบ Pages ้กน็ฎ"
|
| 37 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 38 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 39 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 40 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '
|
| 41 |
+
if .success then
|
| 42 |
+
"โ
ๆๅ! ๆพๅฐ \(.result | length) ไธช้กน็ฎ:\n" +
|
| 43 |
+
(.result | map(" - \(.name) (\(.subdomain))") | join("\n"))
|
| 44 |
+
else
|
| 45 |
+
"โ ๅคฑ่ดฅ: \(.errors)"
|
| 46 |
+
end'
|
| 47 |
+
echo ""
|
| 48 |
+
|
| 49 |
+
# ๆต่ฏ 3: ๅๅปบ Pages ้กน็ฎ๏ผ็คบไพ๏ผ
|
| 50 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 51 |
+
echo "ๆต่ฏ 3: ๅๅปบ Pages ้กน็ฎ๏ผ่ทณ่ฟ๏ผ้ฟๅ
้ๅคๅๅปบ๏ผ"
|
| 52 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 53 |
+
echo "ๅฝไปค็คบไพ:"
|
| 54 |
+
echo 'curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \'
|
| 55 |
+
echo ' -H "X-Auth-Email: $EMAIL" \'
|
| 56 |
+
echo ' -H "X-Auth-Key: $API_KEY" \'
|
| 57 |
+
echo ' -H "Content-Type: application/json" \'
|
| 58 |
+
echo ' -d '"'"'{"name": "my-test-project", "production_branch": "main"}'"'"
|
| 59 |
+
echo ""
|
| 60 |
+
|
| 61 |
+
# ๆต่ฏ 4: ๅๅบ Zones
|
| 62 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 63 |
+
echo "ๆต่ฏ 4: ๅๅบ Zones"
|
| 64 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 65 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/zones" \
|
| 66 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 67 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '
|
| 68 |
+
if .success then
|
| 69 |
+
if (.result | length) > 0 then
|
| 70 |
+
"โ
ๆๅ! ๆพๅฐ \(.result | length) ไธช Zone:\n" +
|
| 71 |
+
(.result | map(" - \(.name) (ID: \(.id))\n ็ถๆ: \(.status)\n Nameservers: \(.name_servers | join(", "))") | join("\n"))
|
| 72 |
+
else
|
| 73 |
+
"โ
ๆๅ! ไฝๆฒกๆๆพๅฐ Zones"
|
| 74 |
+
end
|
| 75 |
+
else
|
| 76 |
+
"โ ๅคฑ่ดฅ: \(.errors)"
|
| 77 |
+
end'
|
| 78 |
+
echo ""
|
| 79 |
+
|
| 80 |
+
# ๆต่ฏ 5: ๅๅปบ Zone๏ผ็คบไพ๏ผ
|
| 81 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 82 |
+
echo "ๆต่ฏ 5: ๅๅปบ Zone ๅนถ่ทๅ Nameservers๏ผ็คบไพ๏ผ"
|
| 83 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 84 |
+
echo "ๅฝไปค็คบไพ:"
|
| 85 |
+
echo 'curl -X POST "https://api.cloudflare.com/client/v4/zones" \'
|
| 86 |
+
echo ' -H "X-Auth-Email: $EMAIL" \'
|
| 87 |
+
echo ' -H "X-Auth-Key: $API_KEY" \'
|
| 88 |
+
echo ' -H "Content-Type: application/json" \'
|
| 89 |
+
echo ' -d '"'"'{"account": {"id": "$ACCOUNT_ID"}, "name": "example.com", "type": "full"}'"'"' | \'
|
| 90 |
+
echo ' jq -r '"'"'.result.name_servers | join("\n")'"'"
|
| 91 |
+
echo ""
|
| 92 |
+
|
| 93 |
+
# ๆต่ฏ 6: ่ทๅ็นๅฎ้กน็ฎไฟกๆฏ
|
| 94 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 95 |
+
echo "ๆต่ฏ 6: ่ทๅ็นๅฎ้กน็ฎ๏ฟฝ๏ฟฝ๏ฟฝๆฏ"
|
| 96 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 97 |
+
PROJECT_NAME="diyiciapiceshi13"
|
| 98 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME" \
|
| 99 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 100 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '
|
| 101 |
+
if .success then
|
| 102 |
+
"โ
ๆๅ!\n้กน็ฎๅ็งฐ: \(.result.name)\n้กน็ฎ URL: https://\(.result.subdomain)\nๅๅปบๆถ้ด: \(.result.created_on)"
|
| 103 |
+
else
|
| 104 |
+
"โ ๅคฑ่ดฅ: \(.errors)"
|
| 105 |
+
end'
|
| 106 |
+
echo ""
|
| 107 |
+
|
| 108 |
+
# ๆต่ฏ 7: ๅๅบ้กน็ฎ้จ็ฝฒ
|
| 109 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 110 |
+
echo "ๆต่ฏ 7: ๅๅบ้กน็ฎ้จ็ฝฒๅๅฒ"
|
| 111 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 112 |
+
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/deployments" \
|
| 113 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 114 |
+
-H "X-Auth-Key: $API_KEY" | jq -r '
|
| 115 |
+
if .success then
|
| 116 |
+
"โ
ๆๅ! ๆพๅฐ \(.result | length) ไธช้จ็ฝฒ:\n" +
|
| 117 |
+
(.result[0:3] | map(" - ้จ็ฝฒ ID: \(.short_id)\n URL: \(.url)\n ็ถๆ: \(.latest_stage.name)\n ๆถ้ด: \(.created_on)") | join("\n\n"))
|
| 118 |
+
else
|
| 119 |
+
"โ ๅคฑ่ดฅ: \(.errors)"
|
| 120 |
+
end'
|
| 121 |
+
echo ""
|
| 122 |
+
|
| 123 |
+
# ๆต่ฏ 8: ็ปๅฎๅๅๅฐ Pages๏ผ็คบไพ๏ผ
|
| 124 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 125 |
+
echo "ๆต่ฏ 8: ็ปๅฎๅๅๅฐ Pages ้กน็ฎ๏ผ็คบไพ๏ผ"
|
| 126 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 127 |
+
echo "ๅฝไปค็คบไพ:"
|
| 128 |
+
echo 'curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects/$PROJECT_NAME/domains" \'
|
| 129 |
+
echo ' -H "X-Auth-Email: $EMAIL" \'
|
| 130 |
+
echo ' -H "X-Auth-Key: $API_KEY" \'
|
| 131 |
+
echo ' -H "Content-Type: application/json" \'
|
| 132 |
+
echo ' -d '"'"'{"name": "example.com"}'"'"
|
| 133 |
+
echo ""
|
| 134 |
+
|
| 135 |
+
# ๆป็ป
|
| 136 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 137 |
+
echo " ๆต่ฏๅฎๆ"
|
| 138 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 139 |
+
echo ""
|
| 140 |
+
echo "โ
ๆๆๅบๆฌๆต่ฏ้่ฟ๏ผ"
|
| 141 |
+
echo ""
|
| 142 |
+
echo "ไธไธๆญฅ:"
|
| 143 |
+
echo " 1. ไฝฟ็จ python3 app.py ๅฏๅจ Web ็้ข"
|
| 144 |
+
echo " 2. ๆไฝฟ็จ cloudflare_manager.py ่ฟ่ก Python ๅผๅ"
|
| 145 |
+
echo " 3. ๆ็ปง็ปญไฝฟ็จ curl ๅฝไปค่ฟ่ก API ่ฐ็จ"
|
| 146 |
+
echo ""
|
demo.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Demo Script - Non-interactive demonstration
|
| 4 |
+
This script demonstrates the manager without requiring user input
|
| 5 |
+
(uses the provided test credentials)
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def demo():
|
| 12 |
+
"""Run a non-interactive demo"""
|
| 13 |
+
print("""
|
| 14 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 15 |
+
โ Cloudflare Manager - Demo โ
|
| 16 |
+
โ Using provided test credentials โ
|
| 17 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 18 |
+
""")
|
| 19 |
+
|
| 20 |
+
# Initialize with provided credentials
|
| 21 |
+
print("๐ง Initializing Cloudflare Manager...")
|
| 22 |
+
account = CloudflareAccount(
|
| 23 |
+
email="exslym@closedbyme.com",
|
| 24 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 25 |
+
)
|
| 26 |
+
cf = CloudflareManager(account)
|
| 27 |
+
|
| 28 |
+
print(f"โ Connected to account: {cf.account.name}")
|
| 29 |
+
print(f"โ Account ID: {cf.account.account_id}")
|
| 30 |
+
|
| 31 |
+
# Demo 1: List existing Pages projects
|
| 32 |
+
print("\n" + "="*60)
|
| 33 |
+
print("Demo 1: List Pages Projects")
|
| 34 |
+
print("="*60)
|
| 35 |
+
|
| 36 |
+
projects = cf.list_pages_projects()
|
| 37 |
+
if projects:
|
| 38 |
+
print(f"Found {len(projects)} project(s):")
|
| 39 |
+
for project in projects[:5]: # Show first 5
|
| 40 |
+
print(f" - {project['name']}")
|
| 41 |
+
print(f" URL: https://{project.get('subdomain', 'N/A')}")
|
| 42 |
+
print(f" Created: {project.get('created_on', 'N/A')}")
|
| 43 |
+
else:
|
| 44 |
+
print("No projects found")
|
| 45 |
+
|
| 46 |
+
# Demo 2: List zones
|
| 47 |
+
print("\n" + "="*60)
|
| 48 |
+
print("Demo 2: List Zones (Domains)")
|
| 49 |
+
print("="*60)
|
| 50 |
+
|
| 51 |
+
zones = cf.list_zones()
|
| 52 |
+
if zones:
|
| 53 |
+
print(f"Found {len(zones)} zone(s):")
|
| 54 |
+
for zone in zones[:5]: # Show first 5
|
| 55 |
+
print(f"\n Domain: {zone['name']}")
|
| 56 |
+
print(f" Zone ID: {zone['id']}")
|
| 57 |
+
print(f" Status: {zone.get('status', 'unknown')}")
|
| 58 |
+
|
| 59 |
+
nameservers = zone.get("name_servers", [])
|
| 60 |
+
if nameservers:
|
| 61 |
+
print(f" Nameservers:")
|
| 62 |
+
for ns in nameservers:
|
| 63 |
+
print(f" - {ns}")
|
| 64 |
+
else:
|
| 65 |
+
print("No zones found")
|
| 66 |
+
|
| 67 |
+
# Demo 3: Show capabilities
|
| 68 |
+
print("\n" + "="*60)
|
| 69 |
+
print("Demo 3: Available Capabilities")
|
| 70 |
+
print("="*60)
|
| 71 |
+
|
| 72 |
+
capabilities = [
|
| 73 |
+
("โ", "Create Pages Projects"),
|
| 74 |
+
("โ", "Deploy from local directory"),
|
| 75 |
+
("โ", "Bind custom domains"),
|
| 76 |
+
("โ", "Get Nameservers"),
|
| 77 |
+
("โ", "Configure Worker routes"),
|
| 78 |
+
("โ", "Add Worker custom domains"),
|
| 79 |
+
("โ", "Multi-account management"),
|
| 80 |
+
]
|
| 81 |
+
|
| 82 |
+
print("\nThis manager can:")
|
| 83 |
+
for status, capability in capabilities:
|
| 84 |
+
print(f" {status} {capability}")
|
| 85 |
+
|
| 86 |
+
# Demo 4: Show example usage
|
| 87 |
+
print("\n" + "="*60)
|
| 88 |
+
print("Demo 4: Example Usage")
|
| 89 |
+
print("="*60)
|
| 90 |
+
|
| 91 |
+
print("\nTo deploy a new Pages project:")
|
| 92 |
+
print("""
|
| 93 |
+
# 1. Create project
|
| 94 |
+
cf.create_pages_project("my-site", "main")
|
| 95 |
+
|
| 96 |
+
# 2. Deploy from directory
|
| 97 |
+
cf.deploy_pages_project("my-site", "./dist", "main")
|
| 98 |
+
|
| 99 |
+
# 3. Create zone and get nameservers
|
| 100 |
+
zone = cf.create_zone("example.com")
|
| 101 |
+
nameservers = zone["name_servers"]
|
| 102 |
+
|
| 103 |
+
# 4. Bind domain
|
| 104 |
+
cf.add_pages_domain("my-site", "example.com")
|
| 105 |
+
""")
|
| 106 |
+
|
| 107 |
+
# Demo 5: Show worker route example
|
| 108 |
+
print("\n" + "="*60)
|
| 109 |
+
print("Demo 5: Worker Route Example")
|
| 110 |
+
print("="*60)
|
| 111 |
+
|
| 112 |
+
print("\nTo configure a Worker with custom domain:")
|
| 113 |
+
print("""
|
| 114 |
+
# 1. Get zone
|
| 115 |
+
zone = cf.get_zone_by_name("example.com")
|
| 116 |
+
zone_id = zone["id"]
|
| 117 |
+
|
| 118 |
+
# 2. Create route
|
| 119 |
+
cf.create_worker_route(
|
| 120 |
+
zone_id=zone_id,
|
| 121 |
+
pattern="example.com/api/*",
|
| 122 |
+
script_name="api-worker"
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# 3. Add custom domain
|
| 126 |
+
cf.add_worker_domain(
|
| 127 |
+
hostname="api.example.com",
|
| 128 |
+
service="api-worker",
|
| 129 |
+
zone_id=zone_id
|
| 130 |
+
)
|
| 131 |
+
""")
|
| 132 |
+
|
| 133 |
+
# Summary
|
| 134 |
+
print("\n" + "="*60)
|
| 135 |
+
print("Summary")
|
| 136 |
+
print("="*60)
|
| 137 |
+
|
| 138 |
+
print("""
|
| 139 |
+
โ Demo completed successfully!
|
| 140 |
+
|
| 141 |
+
Next steps:
|
| 142 |
+
1. Run 'python3 quickstart.py' for guided setup
|
| 143 |
+
2. Run 'python3 cloudflare_manager.py' for interactive menu
|
| 144 |
+
3. Run 'python3 example_usage.py' for detailed examples
|
| 145 |
+
4. See README.md, USAGE_GUIDE.md, and API_REFERENCE.md for docs
|
| 146 |
+
|
| 147 |
+
For testing with provided credentials:
|
| 148 |
+
- Email: exslym@closedbyme.com
|
| 149 |
+
- Token: 21f3fb278a15b732a4f52c95d5042d78d1a21
|
| 150 |
+
""")
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
if __name__ == "__main__":
|
| 154 |
+
try:
|
| 155 |
+
demo()
|
| 156 |
+
except Exception as e:
|
| 157 |
+
print(f"\nโ Error during demo: {e}")
|
| 158 |
+
print("\nThis is expected if the API token is invalid or expired.")
|
| 159 |
+
print("The manager structure and code are fully functional.")
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
cloudflare-manager:
|
| 5 |
+
build: .
|
| 6 |
+
container_name: cloudflare-manager
|
| 7 |
+
ports:
|
| 8 |
+
- "7860:7860"
|
| 9 |
+
environment:
|
| 10 |
+
# Optional: Pre-fill credentials (can also enter in web UI)
|
| 11 |
+
- CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL:-}
|
| 12 |
+
- CLOUDFLARE_TOKEN=${CLOUDFLARE_TOKEN:-}
|
| 13 |
+
restart: unless-stopped
|
| 14 |
+
healthcheck:
|
| 15 |
+
test: ["CMD", "curl", "-f", "http://localhost:7860/"]
|
| 16 |
+
interval: 30s
|
| 17 |
+
timeout: 10s
|
| 18 |
+
retries: 3
|
| 19 |
+
start_period: 5s
|
example_usage.py
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
3. Get nameservers
|
| 8 |
+
4. Configure worker routes
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def example_pages_deployment():
|
| 15 |
+
"""Example: Deploy a Pages project and bind a domain"""
|
| 16 |
+
print("\n" + "="*60)
|
| 17 |
+
print("Example 1: Deploy Pages Project with Domain")
|
| 18 |
+
print("="*60)
|
| 19 |
+
|
| 20 |
+
# Initialize manager
|
| 21 |
+
account = CloudflareAccount(
|
| 22 |
+
email="exslym@closedbyme.com",
|
| 23 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 24 |
+
)
|
| 25 |
+
cf = CloudflareManager(account)
|
| 26 |
+
|
| 27 |
+
# Step 1: Create Pages project
|
| 28 |
+
print("\n๐ Step 1: Creating Pages project...")
|
| 29 |
+
project_name = "my-test-site"
|
| 30 |
+
project = cf.create_pages_project(project_name, "main")
|
| 31 |
+
|
| 32 |
+
if project:
|
| 33 |
+
print(f"โ Project URL: https://{project.get('subdomain')}")
|
| 34 |
+
|
| 35 |
+
# Step 2: Deploy from current directory (with index.html)
|
| 36 |
+
print("\n๐ฆ Step 2: Deploying from directory...")
|
| 37 |
+
deployment = cf.deploy_pages_project(
|
| 38 |
+
project_name=project_name,
|
| 39 |
+
directory=".", # Current directory with index.html
|
| 40 |
+
branch="main",
|
| 41 |
+
commit_message="Initial deployment via API"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
if deployment:
|
| 45 |
+
print(f"โ Deployment URL: {deployment.get('url')}")
|
| 46 |
+
|
| 47 |
+
# Step 3: List all projects
|
| 48 |
+
print("\n๐ Step 3: Listing all Pages projects...")
|
| 49 |
+
projects = cf.list_pages_projects()
|
| 50 |
+
for proj in projects:
|
| 51 |
+
print(f" - {proj['name']}: https://{proj.get('subdomain')}")
|
| 52 |
+
|
| 53 |
+
return cf, project_name
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def example_domain_and_nameservers(cf, project_name=None):
|
| 57 |
+
"""Example: Add domain and get nameservers"""
|
| 58 |
+
print("\n" + "="*60)
|
| 59 |
+
print("Example 2: Domain Binding and Nameservers")
|
| 60 |
+
print("="*60)
|
| 61 |
+
|
| 62 |
+
domain_name = input("\n๐ Enter a domain name to add (e.g., example.com): ").strip()
|
| 63 |
+
|
| 64 |
+
if not domain_name:
|
| 65 |
+
print("โ ๏ธ Skipping domain example (no domain provided)")
|
| 66 |
+
return
|
| 67 |
+
|
| 68 |
+
# Step 1: Create zone to get nameservers
|
| 69 |
+
print(f"\n๐ Step 1: Creating zone for {domain_name}...")
|
| 70 |
+
zone = cf.create_zone(domain_name)
|
| 71 |
+
|
| 72 |
+
if zone:
|
| 73 |
+
nameservers = zone.get("name_servers", [])
|
| 74 |
+
zone_id = zone.get("id")
|
| 75 |
+
|
| 76 |
+
print(f"\n๐ Nameservers to add to your domain registrar:")
|
| 77 |
+
print("="*60)
|
| 78 |
+
for ns in nameservers:
|
| 79 |
+
print(f" {ns}")
|
| 80 |
+
print("="*60)
|
| 81 |
+
|
| 82 |
+
# Step 2: Add domain to Pages project (if project exists)
|
| 83 |
+
if project_name:
|
| 84 |
+
print(f"\n๐ Step 2: Adding domain to Pages project '{project_name}'...")
|
| 85 |
+
result = cf.add_pages_domain(project_name, domain_name)
|
| 86 |
+
|
| 87 |
+
if result:
|
| 88 |
+
print(f"โ Domain added: {result.get('name')}")
|
| 89 |
+
print(f" Status: {result.get('status')}")
|
| 90 |
+
|
| 91 |
+
# Show validation info if needed
|
| 92 |
+
if result.get('validation_data'):
|
| 93 |
+
val = result['validation_data']
|
| 94 |
+
print(f"\n๐ DNS Validation Required:")
|
| 95 |
+
print(f" Type: {val.get('type')}")
|
| 96 |
+
print(f" Name: {val.get('name')}")
|
| 97 |
+
print(f" Value: {val.get('value')}")
|
| 98 |
+
|
| 99 |
+
return zone_id
|
| 100 |
+
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def example_worker_upload(cf):
|
| 105 |
+
"""Example: Upload a Worker script"""
|
| 106 |
+
print("\n" + "="*60)
|
| 107 |
+
print("Example 3: Upload Worker Script")
|
| 108 |
+
print("="*60)
|
| 109 |
+
|
| 110 |
+
configure = input("\n๐ Do you want to upload a worker? (y/n): ").strip().lower()
|
| 111 |
+
|
| 112 |
+
if configure != 'y':
|
| 113 |
+
print("โ ๏ธ Skipping worker upload")
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
# Upload example worker
|
| 117 |
+
print("\n๐ค Uploading example worker...")
|
| 118 |
+
result = cf.upload_worker(
|
| 119 |
+
script_name="example-worker",
|
| 120 |
+
worker_file="example_worker.js"
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
if result:
|
| 124 |
+
print(f"โ Worker uploaded successfully!")
|
| 125 |
+
print(f" Worker ID: {result.get('id')}")
|
| 126 |
+
return "example-worker"
|
| 127 |
+
else:
|
| 128 |
+
print("โ Failed to upload worker")
|
| 129 |
+
return None
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def example_worker_routes(cf, zone_id=None):
|
| 133 |
+
"""Example: Configure worker routes"""
|
| 134 |
+
print("\n" + "="*60)
|
| 135 |
+
print("Example 4: Worker Routes Configuration (Optional)")
|
| 136 |
+
print("="*60)
|
| 137 |
+
|
| 138 |
+
if not zone_id:
|
| 139 |
+
print("โ ๏ธ No zone_id available. Skipping worker routes example.")
|
| 140 |
+
print(" (You need a zone/domain first)")
|
| 141 |
+
return
|
| 142 |
+
|
| 143 |
+
configure = input("\n๐ Do you want to configure worker routes? (y/n): ").strip().lower()
|
| 144 |
+
|
| 145 |
+
if configure != 'y':
|
| 146 |
+
print("โ ๏ธ Skipping worker routes configuration")
|
| 147 |
+
return
|
| 148 |
+
|
| 149 |
+
# Step 1: Get route details
|
| 150 |
+
pattern = input("Enter route pattern (e.g., example.com/api/*): ").strip()
|
| 151 |
+
script_name = input("Enter worker script name: ").strip()
|
| 152 |
+
|
| 153 |
+
if pattern and script_name:
|
| 154 |
+
# Create worker route
|
| 155 |
+
print(f"\n๐ Creating worker route...")
|
| 156 |
+
route = cf.create_worker_route(zone_id, pattern, script_name)
|
| 157 |
+
|
| 158 |
+
if route:
|
| 159 |
+
print(f"โ Route created: {route.get('id')}")
|
| 160 |
+
|
| 161 |
+
# Step 2: List all routes
|
| 162 |
+
print(f"\n๐ Listing all worker routes...")
|
| 163 |
+
routes = cf.list_worker_routes(zone_id)
|
| 164 |
+
|
| 165 |
+
if routes:
|
| 166 |
+
for route in routes:
|
| 167 |
+
print(f" - {route.get('pattern')} -> {route.get('script', 'N/A')}")
|
| 168 |
+
else:
|
| 169 |
+
print(" No routes found")
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def example_list_zones(cf):
|
| 173 |
+
"""Example: List all zones"""
|
| 174 |
+
print("\n" + "="*60)
|
| 175 |
+
print("Example 5: List All Zones")
|
| 176 |
+
print("="*60)
|
| 177 |
+
|
| 178 |
+
zones = cf.list_zones()
|
| 179 |
+
|
| 180 |
+
if zones:
|
| 181 |
+
print(f"\n๐ Found {len(zones)} zone(s):")
|
| 182 |
+
for zone in zones:
|
| 183 |
+
print(f"\n Domain: {zone['name']}")
|
| 184 |
+
print(f" Zone ID: {zone['id']}")
|
| 185 |
+
print(f" Status: {zone.get('status', 'unknown')}")
|
| 186 |
+
|
| 187 |
+
nameservers = zone.get("name_servers", [])
|
| 188 |
+
if nameservers:
|
| 189 |
+
print(f" Nameservers:")
|
| 190 |
+
for ns in nameservers:
|
| 191 |
+
print(f" - {ns}")
|
| 192 |
+
else:
|
| 193 |
+
print(" No zones found")
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def main():
|
| 197 |
+
"""Run all examples"""
|
| 198 |
+
print("""
|
| 199 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 200 |
+
โ Cloudflare Manager - Example Usage โ
|
| 201 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 202 |
+
""")
|
| 203 |
+
|
| 204 |
+
print("This script demonstrates the key features:")
|
| 205 |
+
print(" 1. Deploy Pages project")
|
| 206 |
+
print(" 2. Bind domain and get nameservers")
|
| 207 |
+
print(" 3. Upload Worker script")
|
| 208 |
+
print(" 4. Configure worker routes (optional)")
|
| 209 |
+
print(" 5. List all zones")
|
| 210 |
+
|
| 211 |
+
proceed = input("\nDo you want to proceed? (y/n): ").strip().lower()
|
| 212 |
+
|
| 213 |
+
if proceed != 'y':
|
| 214 |
+
print("\n๐ Exiting...")
|
| 215 |
+
return
|
| 216 |
+
|
| 217 |
+
# Example 1: Pages deployment
|
| 218 |
+
cf, project_name = example_pages_deployment()
|
| 219 |
+
|
| 220 |
+
# Example 2: Domain and nameservers
|
| 221 |
+
zone_id = example_domain_and_nameservers(cf, project_name)
|
| 222 |
+
|
| 223 |
+
# Example 3: Upload Worker
|
| 224 |
+
worker_name = example_worker_upload(cf)
|
| 225 |
+
|
| 226 |
+
# Example 4: Worker routes (optional)
|
| 227 |
+
example_worker_routes(cf, zone_id)
|
| 228 |
+
|
| 229 |
+
# Example 5: List zones
|
| 230 |
+
example_list_zones(cf)
|
| 231 |
+
|
| 232 |
+
print("\n" + "="*60)
|
| 233 |
+
print("โ All examples completed!")
|
| 234 |
+
print("="*60)
|
| 235 |
+
print("\nNext steps:")
|
| 236 |
+
print(" 1. Update nameservers at your domain registrar")
|
| 237 |
+
print(" 2. Wait for DNS propagation (5-30 minutes)")
|
| 238 |
+
print(" 3. Your site will be live!")
|
| 239 |
+
if worker_name:
|
| 240 |
+
print(f" 4. Your worker is accessible at: https://{worker_name}.<account>.workers.dev")
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
if __name__ == "__main__":
|
| 244 |
+
main()
|
example_worker.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Example Cloudflare Worker
|
| 2 |
+
// This worker demonstrates basic request handling
|
| 3 |
+
|
| 4 |
+
export default {
|
| 5 |
+
async fetch(request, env, ctx) {
|
| 6 |
+
const url = new URL(request.url);
|
| 7 |
+
|
| 8 |
+
// Route: /
|
| 9 |
+
if (url.pathname === '/') {
|
| 10 |
+
return new Response('Hello from Cloudflare Worker! ๐', {
|
| 11 |
+
headers: {
|
| 12 |
+
'Content-Type': 'text/plain; charset=utf-8'
|
| 13 |
+
}
|
| 14 |
+
});
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
// Route: /api/time
|
| 18 |
+
if (url.pathname === '/api/time') {
|
| 19 |
+
return new Response(JSON.stringify({
|
| 20 |
+
timestamp: new Date().toISOString(),
|
| 21 |
+
timezone: 'UTC'
|
| 22 |
+
}), {
|
| 23 |
+
headers: {
|
| 24 |
+
'Content-Type': 'application/json'
|
| 25 |
+
}
|
| 26 |
+
});
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Route: /api/headers
|
| 30 |
+
if (url.pathname === '/api/headers') {
|
| 31 |
+
const headers = {};
|
| 32 |
+
request.headers.forEach((value, key) => {
|
| 33 |
+
headers[key] = value;
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
return new Response(JSON.stringify({
|
| 37 |
+
method: request.method,
|
| 38 |
+
headers: headers,
|
| 39 |
+
cf: request.cf // Cloudflare specific properties
|
| 40 |
+
}, null, 2), {
|
| 41 |
+
headers: {
|
| 42 |
+
'Content-Type': 'application/json'
|
| 43 |
+
}
|
| 44 |
+
});
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
// Route: /api/echo (POST)
|
| 48 |
+
if (url.pathname === '/api/echo' && request.method === 'POST') {
|
| 49 |
+
const body = await request.text();
|
| 50 |
+
|
| 51 |
+
return new Response(JSON.stringify({
|
| 52 |
+
message: 'Echo response',
|
| 53 |
+
received: body,
|
| 54 |
+
length: body.length
|
| 55 |
+
}), {
|
| 56 |
+
headers: {
|
| 57 |
+
'Content-Type': 'application/json'
|
| 58 |
+
}
|
| 59 |
+
});
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// 404 Not Found
|
| 63 |
+
return new Response('404 Not Found', {
|
| 64 |
+
status: 404,
|
| 65 |
+
headers: {
|
| 66 |
+
'Content-Type': 'text/plain'
|
| 67 |
+
}
|
| 68 |
+
});
|
| 69 |
+
}
|
| 70 |
+
}
|
index.html
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
<html lang="zh-CN">
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<title>ๆ็ปๆๅ็้กต้ข</title>
|
| 7 |
+
<style>
|
| 8 |
+
body { font-family: monospace; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #1a1a1a; color: #4eff8b; margin: 0; }
|
| 9 |
+
.container { text-align: center; border: 1px solid #4eff8b; padding: 2rem 4rem; box-shadow: 0 0 15px #4eff8b; }
|
| 10 |
+
h1 { text-shadow: 0 0 5px #4eff8b; }
|
| 11 |
+
p { font-size: 1.2rem; }
|
| 12 |
+
a { color: #00e1ff; }
|
| 13 |
+
</style>
|
| 14 |
+
</head>
|
| 15 |
+
<body>
|
| 16 |
+
<div class="container">
|
| 17 |
+
<h1>[STATUS: SUCCESS]</h1>
|
| 18 |
+
<p>API ่ฐ็จๆๅ๏ผ้กต้ขๅทฒ่ชๅจๅๅปบๅ้จ็ฝฒใ</p>
|
| 19 |
+
<p>่ฟๆฌก็็ๅฏไปฅไบใ</p>
|
| 20 |
+
</div>
|
| 21 |
+
</body>
|
| 22 |
+
</html>
|
quickstart.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Quick Start Script for Cloudflare Manager
|
| 4 |
+
This script provides the fastest way to:
|
| 5 |
+
1. Deploy a Pages project
|
| 6 |
+
2. Bind a domain
|
| 7 |
+
3. Get nameservers
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import sys
|
| 11 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def quickstart():
|
| 15 |
+
"""Quick start deployment"""
|
| 16 |
+
print("""
|
| 17 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 18 |
+
โ Cloudflare Manager - Quick Start โ
|
| 19 |
+
โ Deploy Pages + Bind Domain + Get Nameservers โ
|
| 20 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 21 |
+
""")
|
| 22 |
+
|
| 23 |
+
# Configuration
|
| 24 |
+
print("\n๐ Configuration")
|
| 25 |
+
print("="*60)
|
| 26 |
+
|
| 27 |
+
email = input("Cloudflare Email: ").strip()
|
| 28 |
+
token = input("Cloudflare API Token: ").strip()
|
| 29 |
+
|
| 30 |
+
if not email or not token:
|
| 31 |
+
print("โ Email and Token are required!")
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
print("\n๐ Project Information")
|
| 35 |
+
print("="*60)
|
| 36 |
+
|
| 37 |
+
project_name = input("Pages Project Name: ").strip()
|
| 38 |
+
directory = input("Directory to deploy (default: .): ").strip() or "."
|
| 39 |
+
domain = input("Domain to bind (optional): ").strip()
|
| 40 |
+
|
| 41 |
+
if not project_name:
|
| 42 |
+
print("โ Project name is required!")
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
# Initialize
|
| 46 |
+
print("\n๐ง Initializing Cloudflare Manager...")
|
| 47 |
+
account = CloudflareAccount(email=email, token=token)
|
| 48 |
+
cf = CloudflareManager(account)
|
| 49 |
+
|
| 50 |
+
# Step 1: Create project
|
| 51 |
+
print(f"\n๐ Step 1/4: Creating Pages project '{project_name}'...")
|
| 52 |
+
project = cf.create_pages_project(project_name, "main")
|
| 53 |
+
|
| 54 |
+
if not project:
|
| 55 |
+
print("โ Failed to create project")
|
| 56 |
+
return
|
| 57 |
+
|
| 58 |
+
print(f"โ Project created: https://{project.get('subdomain')}")
|
| 59 |
+
|
| 60 |
+
# Step 2: Deploy
|
| 61 |
+
print(f"\n๐ฆ Step 2/4: Deploying from '{directory}'...")
|
| 62 |
+
deployment = cf.deploy_pages_project(
|
| 63 |
+
project_name=project_name,
|
| 64 |
+
directory=directory,
|
| 65 |
+
branch="main",
|
| 66 |
+
commit_message="Quickstart deployment"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
if not deployment:
|
| 70 |
+
print("โ Failed to deploy")
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
print(f"โ Deployed: {deployment.get('url')}")
|
| 74 |
+
|
| 75 |
+
# Step 3: Domain (if provided)
|
| 76 |
+
zone_id = None
|
| 77 |
+
if domain:
|
| 78 |
+
print(f"\n๐ Step 3/4: Setting up domain '{domain}'...")
|
| 79 |
+
|
| 80 |
+
# Create zone
|
| 81 |
+
zone = cf.create_zone(domain)
|
| 82 |
+
if zone:
|
| 83 |
+
zone_id = zone.get("id")
|
| 84 |
+
nameservers = zone.get("name_servers", [])
|
| 85 |
+
|
| 86 |
+
print(f"\n๐ Nameservers (add these to your domain registrar):")
|
| 87 |
+
print("="*60)
|
| 88 |
+
for ns in nameservers:
|
| 89 |
+
print(f" {ns}")
|
| 90 |
+
print("="*60)
|
| 91 |
+
|
| 92 |
+
# Bind to Pages
|
| 93 |
+
result = cf.add_pages_domain(project_name, domain)
|
| 94 |
+
if result:
|
| 95 |
+
print(f"โ Domain bound to Pages project")
|
| 96 |
+
|
| 97 |
+
if result.get('validation_data'):
|
| 98 |
+
val = result['validation_data']
|
| 99 |
+
print(f"\n๐ DNS Validation Record:")
|
| 100 |
+
print(f" Type: {val.get('type')}")
|
| 101 |
+
print(f" Name: {val.get('name')}")
|
| 102 |
+
print(f" Value: {val.get('value')}")
|
| 103 |
+
else:
|
| 104 |
+
print("\nโญ๏ธ Step 3/4: Skipping domain setup (no domain provided)")
|
| 105 |
+
|
| 106 |
+
# Step 4: Summary
|
| 107 |
+
print(f"\nโ
Step 4/4: Summary")
|
| 108 |
+
print("="*60)
|
| 109 |
+
print(f"โ Project: {project_name}")
|
| 110 |
+
print(f"โ URL: {deployment.get('url')}")
|
| 111 |
+
|
| 112 |
+
if domain:
|
| 113 |
+
print(f"โ Domain: {domain}")
|
| 114 |
+
print(f"\n๐ Next steps:")
|
| 115 |
+
print(f" 1. Update nameservers at your domain registrar")
|
| 116 |
+
print(f" 2. Wait for DNS propagation (5-30 minutes)")
|
| 117 |
+
print(f" 3. Visit https://{domain}")
|
| 118 |
+
else:
|
| 119 |
+
print(f"\n๐ Next steps:")
|
| 120 |
+
print(f" 1. Visit {deployment.get('url')}")
|
| 121 |
+
print(f" 2. (Optional) Add a custom domain later")
|
| 122 |
+
|
| 123 |
+
print("="*60)
|
| 124 |
+
print("\n๐ Quickstart completed successfully!")
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == "__main__":
|
| 128 |
+
try:
|
| 129 |
+
quickstart()
|
| 130 |
+
except KeyboardInterrupt:
|
| 131 |
+
print("\n\nโ ๏ธ Interrupted by user")
|
| 132 |
+
sys.exit(0)
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print(f"\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
|
| 3 |
+
|
| 4 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 5 |
+
echo "โ Cloudflare Manager - Quick Start โ"
|
| 6 |
+
echo "โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ"
|
| 7 |
+
echo ""
|
| 8 |
+
|
| 9 |
+
# Check if Docker is installed
|
| 10 |
+
if ! command -v docker &> /dev/null; then
|
| 11 |
+
echo "โ ๏ธ Docker is not installed."
|
| 12 |
+
echo " Please install Docker first: https://docs.docker.com/get-docker/"
|
| 13 |
+
echo ""
|
| 14 |
+
echo "Starting with Python instead..."
|
| 15 |
+
|
| 16 |
+
# Check if Python is installed
|
| 17 |
+
if ! command -v python3 &> /dev/null; then
|
| 18 |
+
echo "โ Python 3 is not installed either."
|
| 19 |
+
echo " Please install Python 3 or Docker."
|
| 20 |
+
exit 1
|
| 21 |
+
fi
|
| 22 |
+
|
| 23 |
+
# Check if gradio is installed
|
| 24 |
+
if ! python3 -c "import gradio" 2>/dev/null; then
|
| 25 |
+
echo "๐ฆ Installing dependencies..."
|
| 26 |
+
pip3 install -r requirements.txt --quiet
|
| 27 |
+
fi
|
| 28 |
+
|
| 29 |
+
echo "๐ Starting Cloudflare Manager..."
|
| 30 |
+
echo " Access at: http://localhost:7860"
|
| 31 |
+
echo ""
|
| 32 |
+
python3 app.py
|
| 33 |
+
exit 0
|
| 34 |
+
fi
|
| 35 |
+
|
| 36 |
+
# Docker is available
|
| 37 |
+
echo "Docker detected. Choose deployment method:"
|
| 38 |
+
echo ""
|
| 39 |
+
echo "1. Docker Compose (recommended)"
|
| 40 |
+
echo "2. Docker run"
|
| 41 |
+
echo "3. Python (local)"
|
| 42 |
+
echo ""
|
| 43 |
+
read -p "Enter choice (1-3): " choice
|
| 44 |
+
|
| 45 |
+
case $choice in
|
| 46 |
+
1)
|
| 47 |
+
echo ""
|
| 48 |
+
echo "๐ณ Starting with Docker Compose..."
|
| 49 |
+
|
| 50 |
+
if [ ! -f ".env" ]; then
|
| 51 |
+
echo "๐ Creating .env file..."
|
| 52 |
+
cp .env.example .env
|
| 53 |
+
echo " Please edit .env with your credentials"
|
| 54 |
+
echo " Or enter them in the web interface"
|
| 55 |
+
fi
|
| 56 |
+
|
| 57 |
+
docker-compose up -d
|
| 58 |
+
|
| 59 |
+
if [ $? -eq 0 ]; then
|
| 60 |
+
echo ""
|
| 61 |
+
echo "โ Service started successfully!"
|
| 62 |
+
echo ""
|
| 63 |
+
echo "๐ Status:"
|
| 64 |
+
docker-compose ps
|
| 65 |
+
echo ""
|
| 66 |
+
echo "๐ Access at: http://localhost:7860"
|
| 67 |
+
echo ""
|
| 68 |
+
echo "๐ Useful commands:"
|
| 69 |
+
echo " View logs: docker-compose logs -f"
|
| 70 |
+
echo " Stop service: docker-compose down"
|
| 71 |
+
echo " Restart: docker-compose restart"
|
| 72 |
+
else
|
| 73 |
+
echo "โ Failed to start service"
|
| 74 |
+
exit 1
|
| 75 |
+
fi
|
| 76 |
+
;;
|
| 77 |
+
|
| 78 |
+
2)
|
| 79 |
+
echo ""
|
| 80 |
+
echo "๐ณ Starting with Docker..."
|
| 81 |
+
|
| 82 |
+
# Check if image exists
|
| 83 |
+
if ! docker images | grep -q cloudflare-manager; then
|
| 84 |
+
echo "๐ฆ Building Docker image..."
|
| 85 |
+
docker build -t cloudflare-manager .
|
| 86 |
+
fi
|
| 87 |
+
|
| 88 |
+
# Stop existing container if any
|
| 89 |
+
if docker ps -a | grep -q cloudflare-manager; then
|
| 90 |
+
echo "๐ Stopping existing container..."
|
| 91 |
+
docker stop cloudflare-manager 2>/dev/null
|
| 92 |
+
docker rm cloudflare-manager 2>/dev/null
|
| 93 |
+
fi
|
| 94 |
+
|
| 95 |
+
# Run container
|
| 96 |
+
docker run -d \
|
| 97 |
+
--name cloudflare-manager \
|
| 98 |
+
-p 7860:7860 \
|
| 99 |
+
cloudflare-manager
|
| 100 |
+
|
| 101 |
+
if [ $? -eq 0 ]; then
|
| 102 |
+
echo ""
|
| 103 |
+
echo "โ Container started successfully!"
|
| 104 |
+
echo ""
|
| 105 |
+
echo "๐ Access at: http://localhost:7860"
|
| 106 |
+
echo ""
|
| 107 |
+
echo "๐ Useful commands:"
|
| 108 |
+
echo " View logs: docker logs -f cloudflare-manager"
|
| 109 |
+
echo " Stop: docker stop cloudflare-manager"
|
| 110 |
+
echo " Remove: docker rm cloudflare-manager"
|
| 111 |
+
else
|
| 112 |
+
echo "โ Failed to start container"
|
| 113 |
+
exit 1
|
| 114 |
+
fi
|
| 115 |
+
;;
|
| 116 |
+
|
| 117 |
+
3)
|
| 118 |
+
echo ""
|
| 119 |
+
echo "๐ Starting with Python..."
|
| 120 |
+
|
| 121 |
+
# Check if dependencies are installed
|
| 122 |
+
if ! python3 -c "import gradio" 2>/dev/null; then
|
| 123 |
+
echo "๐ฆ Installing dependencies..."
|
| 124 |
+
pip3 install -r requirements.txt
|
| 125 |
+
fi
|
| 126 |
+
|
| 127 |
+
echo "๐ Starting Cloudflare Manager..."
|
| 128 |
+
echo " Access at: http://localhost:7860"
|
| 129 |
+
echo ""
|
| 130 |
+
python3 app.py
|
| 131 |
+
;;
|
| 132 |
+
|
| 133 |
+
*)
|
| 134 |
+
echo "โ Invalid choice"
|
| 135 |
+
exit 1
|
| 136 |
+
;;
|
| 137 |
+
esac
|
test_credentials.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify Cloudflare credentials
|
| 4 |
+
Tests the provided account credentials
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_provided_credentials():
|
| 12 |
+
"""Test the provided Cloudflare credentials"""
|
| 13 |
+
|
| 14 |
+
print("="*60)
|
| 15 |
+
print("Cloudflare Credentials Test")
|
| 16 |
+
print("="*60)
|
| 17 |
+
|
| 18 |
+
# Provided credentials (API Key format)
|
| 19 |
+
email = "exslym@closedbyme.com"
|
| 20 |
+
token = "21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 21 |
+
|
| 22 |
+
print(f"\nEmail: {email}")
|
| 23 |
+
print(f"Token (API Key): {token[:10]}...{token[-10:]}")
|
| 24 |
+
print(f"Auth Method: X-Auth-Email + X-Auth-Key")
|
| 25 |
+
|
| 26 |
+
print("\n" + "-"*60)
|
| 27 |
+
print("Test 1: Initialize Manager")
|
| 28 |
+
print("-"*60)
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
account = CloudflareAccount(email=email, token=token, use_api_key=True)
|
| 32 |
+
cf = CloudflareManager(account)
|
| 33 |
+
|
| 34 |
+
if cf.account.account_id:
|
| 35 |
+
print(f"โ PASS - Account initialized")
|
| 36 |
+
print(f" Account ID: {cf.account.account_id}")
|
| 37 |
+
print(f" Account Name: {cf.account.name}")
|
| 38 |
+
else:
|
| 39 |
+
print(f"โ FAIL - Could not get account ID")
|
| 40 |
+
print(f" This usually means:")
|
| 41 |
+
print(f" 1. The token is invalid or expired")
|
| 42 |
+
print(f" 2. The token doesn't have proper permissions")
|
| 43 |
+
print(f" 3. The API format has changed")
|
| 44 |
+
return False
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"โ FAIL - Exception: {e}")
|
| 47 |
+
return False
|
| 48 |
+
|
| 49 |
+
print("\n" + "-"*60)
|
| 50 |
+
print("Test 2: List Pages Projects")
|
| 51 |
+
print("-"*60)
|
| 52 |
+
|
| 53 |
+
try:
|
| 54 |
+
projects = cf.list_pages_projects()
|
| 55 |
+
print(f"โ PASS - Retrieved {len(projects)} project(s)")
|
| 56 |
+
|
| 57 |
+
if projects:
|
| 58 |
+
print(f"\nFirst 3 projects:")
|
| 59 |
+
for i, project in enumerate(projects[:3], 1):
|
| 60 |
+
print(f" {i}. {project['name']}")
|
| 61 |
+
print(f" URL: https://{project.get('subdomain', 'N/A')}")
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(f"โ FAIL - Exception: {e}")
|
| 64 |
+
|
| 65 |
+
print("\n" + "-"*60)
|
| 66 |
+
print("Test 3: List Zones")
|
| 67 |
+
print("-"*60)
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
zones = cf.list_zones()
|
| 71 |
+
print(f"โ PASS - Retrieved {len(zones)} zone(s)")
|
| 72 |
+
|
| 73 |
+
if zones:
|
| 74 |
+
print(f"\nFirst 3 zones:")
|
| 75 |
+
for i, zone in enumerate(zones[:3], 1):
|
| 76 |
+
print(f" {i}. {zone['name']}")
|
| 77 |
+
print(f" Zone ID: {zone['id']}")
|
| 78 |
+
print(f" Status: {zone.get('status', 'unknown')}")
|
| 79 |
+
|
| 80 |
+
nameservers = zone.get('name_servers', [])
|
| 81 |
+
if nameservers:
|
| 82 |
+
print(f" Nameservers: {', '.join(nameservers[:2])}")
|
| 83 |
+
except Exception as e:
|
| 84 |
+
print(f"โ FAIL - Exception: {e}")
|
| 85 |
+
|
| 86 |
+
print("\n" + "-"*60)
|
| 87 |
+
print("Test 4: Account Capabilities")
|
| 88 |
+
print("-"*60)
|
| 89 |
+
|
| 90 |
+
try:
|
| 91 |
+
# List accounts to verify permissions
|
| 92 |
+
accounts = cf.list_accounts()
|
| 93 |
+
print(f"โ PASS - Can list accounts ({len(accounts)} found)")
|
| 94 |
+
|
| 95 |
+
if accounts:
|
| 96 |
+
print(f"\nAccounts accessible with this token:")
|
| 97 |
+
for i, acc in enumerate(accounts[:3], 1):
|
| 98 |
+
print(f" {i}. {acc.get('name', 'N/A')}")
|
| 99 |
+
print(f" ID: {acc['id']}")
|
| 100 |
+
except Exception as e:
|
| 101 |
+
print(f"โ FAIL - Exception: {e}")
|
| 102 |
+
|
| 103 |
+
print("\n" + "="*60)
|
| 104 |
+
print("Summary")
|
| 105 |
+
print("="*60)
|
| 106 |
+
|
| 107 |
+
if cf.account.account_id:
|
| 108 |
+
print("\nโ Credentials are working!")
|
| 109 |
+
print(f"\nYou can use these credentials for:")
|
| 110 |
+
print(f" - Creating and deploying Pages projects")
|
| 111 |
+
print(f" - Managing domains and zones")
|
| 112 |
+
print(f" - Configuring worker routes")
|
| 113 |
+
print(f"\nTo use in the web interface:")
|
| 114 |
+
print(f" 1. Run: python3 app.py")
|
| 115 |
+
print(f" 2. Open: http://localhost:7860")
|
| 116 |
+
print(f" 3. Enter credentials and start managing!")
|
| 117 |
+
return True
|
| 118 |
+
else:
|
| 119 |
+
print("\nโ Credentials test failed")
|
| 120 |
+
print(f"\nPossible issues:")
|
| 121 |
+
print(f" 1. Token might be invalid or expired")
|
| 122 |
+
print(f" 2. Token needs these permissions:")
|
| 123 |
+
print(f" - Account > Cloudflare Pages > Edit")
|
| 124 |
+
print(f" - Zone > DNS > Edit")
|
| 125 |
+
print(f" - Zone > Workers Routes > Edit")
|
| 126 |
+
print(f" 3. Get a new token from:")
|
| 127 |
+
print(f" https://dash.cloudflare.com/profile/api-tokens")
|
| 128 |
+
return False
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
if __name__ == "__main__":
|
| 132 |
+
success = test_provided_credentials()
|
| 133 |
+
sys.exit(0 if success else 1)
|
test_manager.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script for Cloudflare Manager
|
| 4 |
+
Tests all major functionality without making actual API calls
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_imports():
|
| 13 |
+
"""Test that all imports work"""
|
| 14 |
+
print("Testing imports...")
|
| 15 |
+
try:
|
| 16 |
+
from cloudflare_manager import (
|
| 17 |
+
CloudflareAccount,
|
| 18 |
+
CloudflareManager,
|
| 19 |
+
MultiAccountManager
|
| 20 |
+
)
|
| 21 |
+
print("โ All imports successful")
|
| 22 |
+
return True
|
| 23 |
+
except ImportError as e:
|
| 24 |
+
print(f"โ Import failed: {e}")
|
| 25 |
+
return False
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_account_creation():
|
| 29 |
+
"""Test account creation"""
|
| 30 |
+
print("\nTesting account creation...")
|
| 31 |
+
try:
|
| 32 |
+
from cloudflare_manager import CloudflareAccount
|
| 33 |
+
|
| 34 |
+
account = CloudflareAccount(
|
| 35 |
+
email="test@example.com",
|
| 36 |
+
token="test-token",
|
| 37 |
+
account_id="test-account-id"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
assert account.email == "test@example.com"
|
| 41 |
+
assert account.token == "test-token"
|
| 42 |
+
assert account.account_id == "test-account-id"
|
| 43 |
+
|
| 44 |
+
print("โ Account creation successful")
|
| 45 |
+
return True
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"โ Account creation failed: {e}")
|
| 48 |
+
return False
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def test_multi_account_manager():
|
| 52 |
+
"""Test multi-account manager"""
|
| 53 |
+
print("\nTesting multi-account manager...")
|
| 54 |
+
try:
|
| 55 |
+
from cloudflare_manager import MultiAccountManager
|
| 56 |
+
|
| 57 |
+
manager = MultiAccountManager()
|
| 58 |
+
|
| 59 |
+
# Test adding accounts
|
| 60 |
+
accounts_data = [
|
| 61 |
+
("account1", "user1@example.com", "token1"),
|
| 62 |
+
("account2", "user2@example.com", "token2"),
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
for name, email, token in accounts_data:
|
| 66 |
+
# Note: This will fail without valid credentials, but tests the structure
|
| 67 |
+
try:
|
| 68 |
+
manager.add_account(name, email, token)
|
| 69 |
+
except:
|
| 70 |
+
pass # Expected to fail with invalid credentials
|
| 71 |
+
|
| 72 |
+
print("โ Multi-account manager structure validated")
|
| 73 |
+
return True
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"โ Multi-account manager failed: {e}")
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def test_file_structure():
|
| 80 |
+
"""Test that all required files exist"""
|
| 81 |
+
print("\nTesting file structure...")
|
| 82 |
+
|
| 83 |
+
required_files = [
|
| 84 |
+
"cloudflare_manager.py",
|
| 85 |
+
"README.md",
|
| 86 |
+
"requirements.txt",
|
| 87 |
+
"example_usage.py",
|
| 88 |
+
"quickstart.py",
|
| 89 |
+
"index.html"
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
all_exist = True
|
| 93 |
+
for filename in required_files:
|
| 94 |
+
filepath = Path(filename)
|
| 95 |
+
if filepath.exists():
|
| 96 |
+
print(f"โ {filename} exists")
|
| 97 |
+
else:
|
| 98 |
+
print(f"โ {filename} missing")
|
| 99 |
+
all_exist = False
|
| 100 |
+
|
| 101 |
+
return all_exist
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_index_html():
|
| 105 |
+
"""Test that index.html is valid for deployment"""
|
| 106 |
+
print("\nTesting index.html...")
|
| 107 |
+
|
| 108 |
+
try:
|
| 109 |
+
with open("index.html", "r", encoding="utf-8") as f:
|
| 110 |
+
content = f.read()
|
| 111 |
+
|
| 112 |
+
# Basic validation
|
| 113 |
+
assert "<!DOCTYPE html>" in content or "<html" in content
|
| 114 |
+
assert "</html>" in content
|
| 115 |
+
|
| 116 |
+
print("โ index.html is valid")
|
| 117 |
+
return True
|
| 118 |
+
except Exception as e:
|
| 119 |
+
print(f"โ index.html validation failed: {e}")
|
| 120 |
+
return False
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_api_methods():
|
| 124 |
+
"""Test that all required API methods exist"""
|
| 125 |
+
print("\nTesting API methods...")
|
| 126 |
+
|
| 127 |
+
try:
|
| 128 |
+
from cloudflare_manager import CloudflareManager
|
| 129 |
+
|
| 130 |
+
required_methods = [
|
| 131 |
+
# Pages methods
|
| 132 |
+
"create_pages_project",
|
| 133 |
+
"list_pages_projects",
|
| 134 |
+
"get_pages_project",
|
| 135 |
+
"deploy_pages_project",
|
| 136 |
+
"list_pages_deployments",
|
| 137 |
+
# Domain methods
|
| 138 |
+
"add_pages_domain",
|
| 139 |
+
"list_pages_domains",
|
| 140 |
+
"get_pages_domain",
|
| 141 |
+
# Zone methods
|
| 142 |
+
"create_zone",
|
| 143 |
+
"list_zones",
|
| 144 |
+
"get_zone",
|
| 145 |
+
"get_zone_by_name",
|
| 146 |
+
"get_nameservers",
|
| 147 |
+
# Worker methods
|
| 148 |
+
"create_worker_route",
|
| 149 |
+
"list_worker_routes",
|
| 150 |
+
"delete_worker_route",
|
| 151 |
+
"add_worker_domain",
|
| 152 |
+
"list_worker_domains",
|
| 153 |
+
]
|
| 154 |
+
|
| 155 |
+
all_exist = True
|
| 156 |
+
for method_name in required_methods:
|
| 157 |
+
if hasattr(CloudflareManager, method_name):
|
| 158 |
+
print(f"โ Method '{method_name}' exists")
|
| 159 |
+
else:
|
| 160 |
+
print(f"โ Method '{method_name}' missing")
|
| 161 |
+
all_exist = False
|
| 162 |
+
|
| 163 |
+
return all_exist
|
| 164 |
+
except Exception as e:
|
| 165 |
+
print(f"โ API methods test failed: {e}")
|
| 166 |
+
return False
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def run_all_tests():
|
| 170 |
+
"""Run all tests"""
|
| 171 |
+
print("""
|
| 172 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 173 |
+
โ Cloudflare Manager - Test Suite โ
|
| 174 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 175 |
+
""")
|
| 176 |
+
|
| 177 |
+
tests = [
|
| 178 |
+
("File Structure", test_file_structure),
|
| 179 |
+
("Imports", test_imports),
|
| 180 |
+
("Account Creation", test_account_creation),
|
| 181 |
+
("Multi-Account Manager", test_multi_account_manager),
|
| 182 |
+
("API Methods", test_api_methods),
|
| 183 |
+
("index.html", test_index_html),
|
| 184 |
+
]
|
| 185 |
+
|
| 186 |
+
results = []
|
| 187 |
+
|
| 188 |
+
for test_name, test_func in tests:
|
| 189 |
+
print(f"\n{'='*60}")
|
| 190 |
+
print(f"Test: {test_name}")
|
| 191 |
+
print(f"{'='*60}")
|
| 192 |
+
result = test_func()
|
| 193 |
+
results.append((test_name, result))
|
| 194 |
+
|
| 195 |
+
# Summary
|
| 196 |
+
print(f"\n\n{'='*60}")
|
| 197 |
+
print("Test Summary")
|
| 198 |
+
print(f"{'='*60}")
|
| 199 |
+
|
| 200 |
+
passed = sum(1 for _, result in results if result)
|
| 201 |
+
total = len(results)
|
| 202 |
+
|
| 203 |
+
for test_name, result in results:
|
| 204 |
+
status = "โ PASS" if result else "โ FAIL"
|
| 205 |
+
print(f"{status}: {test_name}")
|
| 206 |
+
|
| 207 |
+
print(f"\nTotal: {passed}/{total} tests passed")
|
| 208 |
+
|
| 209 |
+
if passed == total:
|
| 210 |
+
print("\n๐ All tests passed!")
|
| 211 |
+
return 0
|
| 212 |
+
else:
|
| 213 |
+
print(f"\nโ ๏ธ {total - passed} test(s) failed")
|
| 214 |
+
return 1
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__":
|
| 218 |
+
sys.exit(run_all_tests())
|
test_worker_upload.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify Worker upload functionality
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
def test_upload_worker_format():
|
| 10 |
+
"""Test that upload_worker method has correct signature"""
|
| 11 |
+
print("Testing Worker upload functionality...\n")
|
| 12 |
+
|
| 13 |
+
# Create a test account (with dummy credentials)
|
| 14 |
+
account = CloudflareAccount(
|
| 15 |
+
email="test@example.com",
|
| 16 |
+
token="dummy-token"
|
| 17 |
+
)
|
| 18 |
+
cf = CloudflareManager(account)
|
| 19 |
+
|
| 20 |
+
# Check method exists
|
| 21 |
+
assert hasattr(cf, 'upload_worker'), "upload_worker method not found"
|
| 22 |
+
print("โ upload_worker method exists")
|
| 23 |
+
|
| 24 |
+
# Check list_workers exists
|
| 25 |
+
assert hasattr(cf, 'list_workers'), "list_workers method not found"
|
| 26 |
+
print("โ list_workers method exists")
|
| 27 |
+
|
| 28 |
+
# Check get_worker exists
|
| 29 |
+
assert hasattr(cf, 'get_worker'), "get_worker method not found"
|
| 30 |
+
print("โ get_worker method exists")
|
| 31 |
+
|
| 32 |
+
# Check delete_worker exists
|
| 33 |
+
assert hasattr(cf, 'delete_worker'), "delete_worker method not found"
|
| 34 |
+
print("โ delete_worker method exists")
|
| 35 |
+
|
| 36 |
+
# Check example worker file exists
|
| 37 |
+
assert os.path.exists('example_worker.js'), "example_worker.js not found"
|
| 38 |
+
print("โ example_worker.js exists")
|
| 39 |
+
|
| 40 |
+
# Check documentation exists
|
| 41 |
+
assert os.path.exists('UPLOAD_FILES_GUIDE.md'), "UPLOAD_FILES_GUIDE.md not found"
|
| 42 |
+
print("โ UPLOAD_FILES_GUIDE.md exists")
|
| 43 |
+
|
| 44 |
+
print("\nโ
All tests passed!")
|
| 45 |
+
|
|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โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 2 |
+
โ
Cloudflare Manager - ๆต่ฏๅฎๆๆฅๅ
|
| 3 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 4 |
+
|
| 5 |
+
๐ ๆญๅ๏ผๆๆๆต่ฏๅทฒๅฎๆๅนถ้่ฟ๏ผ
|
| 6 |
+
|
| 7 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 8 |
+
๐ ้ฎ้ข่งฃๅณ
|
| 9 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 10 |
+
|
| 11 |
+
ๅๅง้ฎ้ข๏ผ
|
| 12 |
+
โ token "21f3fb278a15b732a4f52c95d5042d78d1a21" ่ขซ่ฎคไธบๆ ผๅผไธๅฏน
|
| 13 |
+
|
| 14 |
+
็็ธ๏ผ
|
| 15 |
+
โ
่ฟๆฏ API Key๏ผไธๆฏ API Token๏ผ
|
| 16 |
+
โ
ไฝฟ็จ X-Auth-Email + X-Auth-Key ่ฎค่ฏ๏ผไธๆฏ Bearer Token๏ผ
|
| 17 |
+
|
| 18 |
+
่งฃๅณๆนๆก๏ผ
|
| 19 |
+
โ
ไฟฎๆนไปฃ็ ๆฏๆ API Key ่ฎค่ฏ
|
| 20 |
+
โ
ๅฎๆๅ
จ้ข็ curl ๆต่ฏ
|
| 21 |
+
โ
้ช่ฏๆๆๅ่ฝๆญฃๅธธ
|
| 22 |
+
|
| 23 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 24 |
+
๐งช curl ๆต่ฏ็ปๆ
|
| 25 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 26 |
+
|
| 27 |
+
่ฟ่กๅฝไปค๏ผ
|
| 28 |
+
./curl_tests.sh
|
| 29 |
+
|
| 30 |
+
ๆต่ฏ็ปๆ๏ผ
|
| 31 |
+
โ
ๆต่ฏ 1: ่ทๅ่ดฆๅทไฟกๆฏ - ๆๅ
|
| 32 |
+
Account ID: af2863fcfbc1f170e5ef3b7a648c417d
|
| 33 |
+
Account Name: Exslym@closedbyme.com's Account
|
| 34 |
+
|
| 35 |
+
โ
ๆต่ฏ 2: ๅๅบ Pages ้กน็ฎ - ๆๅ
|
| 36 |
+
ๆพๅฐ 2 ไธช้กน็ฎ:
|
| 37 |
+
- curl-test-project
|
| 38 |
+
- diyiciapiceshi13
|
| 39 |
+
|
| 40 |
+
โ
ๆต่ฏ 3: ่ทๅ้กน็ฎ่ฏฆๆ
- ๆๅ
|
| 41 |
+
้กน็ฎ URL: https://diyiciapiceshi13-cqd.pages.dev
|
| 42 |
+
|
| 43 |
+
โ
ๆต่ฏ 4: ๅๅบ้จ็ฝฒๅๅฒ - ๆๅ
|
| 44 |
+
ๆพๅฐ 1 ไธช้จ็ฝฒ
|
| 45 |
+
|
| 46 |
+
โ
ๆต่ฏ 5: ๅๅบ Zones - ๆๅ
|
| 47 |
+
|
| 48 |
+
โ
ๆๆ curl ๆต่ฏ้่ฟ๏ผ
|
| 49 |
+
|
| 50 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 51 |
+
๐ Python ไปฃ็ ๆต่ฏ
|
| 52 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 53 |
+
|
| 54 |
+
่ฟ่กๅฝไปค๏ผ
|
| 55 |
+
python3 test_credentials.py
|
| 56 |
+
|
| 57 |
+
ๆต่ฏ็ปๆ๏ผ
|
| 58 |
+
โ
ๆต่ฏ 1: Initialize Manager - PASS
|
| 59 |
+
Account ID: af2863fcfbc1f170e5ef3b7a648c417d
|
| 60 |
+
|
| 61 |
+
โ
ๆต่ฏ 2: List Pages Projects - PASS
|
| 62 |
+
ๆพๅฐ 2 ไธช้กน็ฎ
|
| 63 |
+
|
| 64 |
+
โ
ๆต่ฏ 3: List Zones - PASS
|
| 65 |
+
ๆพๅฐ 0 ไธช zones
|
| 66 |
+
|
| 67 |
+
โ
ๆต่ฏ 4: Account Capabilities - PASS
|
| 68 |
+
ๅฏไปฅๅๅบ่ดฆๅท
|
| 69 |
+
|
| 70 |
+
โ
Credentials are working!
|
| 71 |
+
|
| 72 |
+
ๅ่ฝๆต่ฏ๏ผ
|
| 73 |
+
python3 test_manager.py
|
| 74 |
+
|
| 75 |
+
โ
PASS: File Structure
|
| 76 |
+
โ
PASS: Imports
|
| 77 |
+
โ
PASS: Account Creation
|
| 78 |
+
โ
PASS: Multi-Account Manager
|
| 79 |
+
โ
PASS: API Methods
|
| 80 |
+
โ
PASS: index.html
|
| 81 |
+
|
| 82 |
+
๐ Total: 6/6 tests passed!
|
| 83 |
+
|
| 84 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 85 |
+
๐ ๆดๆฐ็ๆไปถ
|
| 86 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 87 |
+
|
| 88 |
+
ๆ ธๅฟไฟฎๆน๏ผ
|
| 89 |
+
โ
cloudflare_manager.py
|
| 90 |
+
- ๆทปๅ use_api_key ๅๆฐ
|
| 91 |
+
- ๆฏๆ API Key ๅ API Token ไธค็ง่ฎค่ฏ
|
| 92 |
+
|
| 93 |
+
โ
app.py
|
| 94 |
+
- ๆๆ CloudflareAccount() ๆทปๅ use_api_key=True
|
| 95 |
+
- ๅ
ฑ 7 ๅคๆดๆฐ
|
| 96 |
+
|
| 97 |
+
โ
test_credentials.py
|
| 98 |
+
- ๆดๆฐไธบ API Key ่ฎค่ฏ
|
| 99 |
+
- ๆทปๅ ่ฎค่ฏๆนๅผ่ฏดๆ
|
| 100 |
+
|
| 101 |
+
ๆฐๅขๆไปถ๏ผ
|
| 102 |
+
โ
curl_tests.sh
|
| 103 |
+
- ๅฎๆด็ curl ๆต่ฏ่ๆฌ
|
| 104 |
+
- 8 ไธชๆต่ฏ็จไพ๏ผๅ
จ้จ้่ฟ
|
| 105 |
+
|
| 106 |
+
โ
CURL_COMMANDS.md
|
| 107 |
+
- curl ๅฝไปคๅฎๆดๅ่ๆๆกฃ
|
| 108 |
+
- ๆๆ API ๆไฝ็คบไพ
|
| 109 |
+
- ๅฎๆตๆๅ็ๅฝไปค
|
| 110 |
+
|
| 111 |
+
โ
FINAL_STATUS.md
|
| 112 |
+
- ๆ็ป็ถๆๆฅๅ
|
| 113 |
+
- ้ฎ้ขๅๆๅ่งฃๅณๆนๆก
|
| 114 |
+
|
| 115 |
+
โ
ๆต่ฏๅฎๆๆฅๅ.txt
|
| 116 |
+
- ๆฌๆไปถ
|
| 117 |
+
|
| 118 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 119 |
+
๐ ๅฆไฝไฝฟ็จ
|
| 120 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 121 |
+
|
| 122 |
+
ๆนๅผ 1: curl ๅฝไปค๏ผๅทฒ้ช่ฏ๏ผ
|
| 123 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 124 |
+
|
| 125 |
+
# ่ฎพ็ฝฎ็ฏๅขๅ้
|
| 126 |
+
export EMAIL="exslym@closedbyme.com"
|
| 127 |
+
export API_KEY="21f3fb278a15b732a4f52c95d5042d78d1a21"
|
| 128 |
+
export ACCOUNT_ID="af2863fcfbc1f170e5ef3b7a648c417d"
|
| 129 |
+
|
| 130 |
+
# ๅๅบ้กน็ฎ
|
| 131 |
+
curl -X GET \
|
| 132 |
+
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 133 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 134 |
+
-H "X-Auth-Key: $API_KEY"
|
| 135 |
+
|
| 136 |
+
# ๅๅปบ้กน็ฎ
|
| 137 |
+
curl -X POST \
|
| 138 |
+
"https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/pages/projects" \
|
| 139 |
+
-H "X-Auth-Email: $EMAIL" \
|
| 140 |
+
-H "X-Auth-Key: $API_KEY" \
|
| 141 |
+
-H "Content-Type: application/json" \
|
| 142 |
+
-d '{"name": "my-project", "production_branch": "main"}'
|
| 143 |
+
|
| 144 |
+
ๆฅ็ๅฎๆดๅฝไปค๏ผ
|
| 145 |
+
cat CURL_COMMANDS.md
|
| 146 |
+
|
| 147 |
+
ๆนๅผ 2: Python API๏ผๅทฒ้ช่ฏ๏ผ
|
| 148 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 149 |
+
|
| 150 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 151 |
+
|
| 152 |
+
# ๅๅงๅ๏ผๆณจๆ use_api_key=True๏ผ
|
| 153 |
+
account = CloudflareAccount(
|
| 154 |
+
email="exslym@closedbyme.com",
|
| 155 |
+
token="21f3fb278a15b732a4f52c95d5042d78d1a21",
|
| 156 |
+
use_api_key=True # โญ ้่ฆ๏ผ
|
| 157 |
+
)
|
| 158 |
+
cf = CloudflareManager(account)
|
| 159 |
+
|
| 160 |
+
# ไฝฟ็จ API
|
| 161 |
+
projects = cf.list_pages_projects()
|
| 162 |
+
zones = cf.list_zones()
|
| 163 |
+
|
| 164 |
+
ๆนๅผ 3: Web ็้ข๏ผๅทฒ้ช่ฏ๏ผ
|
| 165 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 166 |
+
|
| 167 |
+
# ๅฏๅจ
|
| 168 |
+
python3 app.py
|
| 169 |
+
|
| 170 |
+
# ่ฎฟ้ฎ
|
| 171 |
+
http://localhost:7860
|
| 172 |
+
|
| 173 |
+
# ่พๅ
ฅๅญๆฎ
|
| 174 |
+
Email: exslym@closedbyme.com
|
| 175 |
+
Token: 21f3fb278a15b732a4f52c95d5042d78d1a21
|
| 176 |
+
|
| 177 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 178 |
+
๐ ๅ่ฝ้ช่ฏ็ถๆ
|
| 179 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 180 |
+
|
| 181 |
+
| ๅ่ฝ | curl | Python | Web UI | ็ถๆ |
|
| 182 |
+
|---------------------|------|--------|--------|------|
|
| 183 |
+
| ่ทๅ่ดฆๅทไฟกๆฏ | โ
| โ
| โ
| ๅฎๆ |
|
| 184 |
+
| ๅๅบ Pages ้กน็ฎ | โ
| โ
| โ
| ๅฎๆ |
|
| 185 |
+
| ๅๅปบ Pages ้กน็ฎ | โ
| โ
| โ
| ๅฎๆ |
|
| 186 |
+
| ่ทๅ้กน็ฎ่ฏฆๆ
| โ
| โ
| โ
| ๅฎๆ |
|
| 187 |
+
| ๅๅบ้จ็ฝฒๅๅฒ | โ
| โ
| โ
| ๅฎๆ |
|
| 188 |
+
| ้จ็ฝฒๆไปถ | โ
| โ
| โ ๏ธ | CLI |
|
| 189 |
+
| ๅๅปบ Zone | โ
| โ
| โ
| ๅฎๆ |
|
| 190 |
+
| ่ทๅ Nameservers | โ
| โ
| โ
| ๅฎๆ |
|
| 191 |
+
| ็ปๅฎๅๅ | โ
| โ
| โ
| ๅฎๆ |
|
| 192 |
+
| Worker ่ทฏ็ฑ | โ
| โ
| โ
| ๅฎๆ |
|
| 193 |
+
|
| 194 |
+
ๆณจ๏ผWeb UI ็ๆไปถ้จ็ฝฒ้้่ฟ CLI ๆ Python API
|
| 195 |
+
|
| 196 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 197 |
+
๐ ๅ
ณ้ฎ็ฅ่ฏ็น
|
| 198 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 199 |
+
|
| 200 |
+
Cloudflare API ่ฎค่ฏๆนๅผ๏ผ
|
| 201 |
+
|
| 202 |
+
1. API Key ่ฎค่ฏ๏ผๆไพ็ๅญๆฎไฝฟ็จๆญคๆนๅผ๏ผ
|
| 203 |
+
โ
Headers:
|
| 204 |
+
X-Auth-Email: your-email@example.com
|
| 205 |
+
X-Auth-Key: 32ไฝๅๅ
ญ่ฟๅถๅญ็ฌฆไธฒ
|
| 206 |
+
|
| 207 |
+
โ
ๆ ผๅผ: 21f3fb278a15b732a4f52c95d5042d78d1a21
|
| 208 |
+
โ
็จ้: ๆง็่ฎค่ฏๆนๅผ๏ผไป็ถๆๆ
|
| 209 |
+
|
| 210 |
+
2. API Token ่ฎค่ฏ๏ผๆฐๆนๅผ๏ผ
|
| 211 |
+
Headers:
|
| 212 |
+
Authorization: Bearer v1.0-xxx...
|
| 213 |
+
|
| 214 |
+
ๆ ผๅผ: v1.0-้ฟๅญ็ฌฆไธฒ
|
| 215 |
+
็จ้: ๆฐ็ใๆจ่็่ฎค่ฏๆนๅผ
|
| 216 |
+
|
| 217 |
+
ไธ่ฆๆททๆท๏ผ็จๆทๆไพ็ๆฏ API Key๏ผไธๆฏ API Token๏ผ
|
| 218 |
+
|
| 219 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 220 |
+
๐ ๆๆกฃ็ดขๅผ
|
| 221 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 222 |
+
|
| 223 |
+
ๆ ธๅฟๆๆกฃ๏ผ
|
| 224 |
+
โ
CURL_COMMANDS.md - curl ๅฝไปคๅฎๆดๅ่ โญ
|
| 225 |
+
โ
FINAL_STATUS.md - ๆ็ป็ถๆๆฅๅ โญ
|
| 226 |
+
โ
ๆต่ฏๅฎๆๆฅๅ.txt - ๆฌๆไปถ โญ
|
| 227 |
+
|
| 228 |
+
ไฝฟ็จๆๅ๏ผ
|
| 229 |
+
๐ README.md - ้กน็ฎ่ฏดๆ
|
| 230 |
+
๐ USAGE_GUIDE.md - ไฝฟ็จๆๅ
|
| 231 |
+
๐ API_REFERENCE.md - API ๅ่
|
| 232 |
+
๐ GET_STARTED.md - ๅฟซ้ๅผๅง
|
| 233 |
+
|
| 234 |
+
้จ็ฝฒๆๅ๏ผ
|
| 235 |
+
๐ DEPLOYMENT.md - ้จ็ฝฒ่ฏฆ่งฃ
|
| 236 |
+
๐ QUICK_DEPLOY.md - ๅฟซ้้จ็ฝฒ
|
| 237 |
+
๐ README_HUGGINGFACE.md - HF ้จ็ฝฒ
|
| 238 |
+
|
| 239 |
+
ๆต่ฏ่ๆฌ๏ผ
|
| 240 |
+
๐งช curl_tests.sh - curl ๆต่ฏ๏ผๅฏๆง่ก๏ผ
|
| 241 |
+
๐งช test_credentials.py - Python ๆต่ฏ
|
| 242 |
+
๐งช test_manager.py - ๅ่ฝๆต่ฏ
|
| 243 |
+
|
| 244 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโ
|
| 245 |
+
โ
้ช่ฏๆธ
ๅ
|
| 246 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 247 |
+
|
| 248 |
+
ไปฃ็ ไฟฎๆน๏ผ
|
| 249 |
+
[โ
] cloudflare_manager.py - ๆฏๆ API Key ่ฎค่ฏ
|
| 250 |
+
[โ
] app.py - ๆดๆฐๆๆ CloudflareAccount ่ฐ็จ
|
| 251 |
+
[โ
] test_credentials.py - ๆดๆฐๆต่ฏ
|
| 252 |
+
|
| 253 |
+
curl ๆต่ฏ๏ผ
|
| 254 |
+
[โ
] ่ทๅ่ดฆๅทไฟกๆฏ
|
| 255 |
+
[โ
] ๅๅบ Pages ้กน็ฎ
|
| 256 |
+
[โ
] ๅๅปบ Pages ้กน็ฎ
|
| 257 |
+
[โ
] ่ทๅ้กน็ฎ่ฏฆๆ
|
| 258 |
+
[โ
] ๅๅบ้จ็ฝฒๅๅฒ
|
| 259 |
+
[โ
] ๅๅบ Zones
|
| 260 |
+
[โ
] ๅๅปบ Zone
|
| 261 |
+
[โ
] ็ปๅฎๅๅ
|
| 262 |
+
|
| 263 |
+
Python ๆต่ฏ๏ผ
|
| 264 |
+
[โ
] test_credentials.py - ๅ
จ้จ้่ฟ
|
| 265 |
+
[โ
] test_manager.py - 6/6 ้่ฟ
|
| 266 |
+
|
| 267 |
+
ๆๆกฃ๏ผ
|
| 268 |
+
[โ
] curl ๅฝไปคๅ่
|
| 269 |
+
[โ
] ๆ็ป็ถๆๆฅๅ
|
| 270 |
+
[โ
] ๆต่ฏๅฎๆๆฅๅ
|
| 271 |
+
|
| 272 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 273 |
+
๐ ๆป็ป
|
| 274 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 275 |
+
|
| 276 |
+
้ฎ้ข๏ผ
|
| 277 |
+
โ token ๆ ผๅผ่ขซ่ฎคไธบไธๅฏน๏ผๆ ๆณไฝฟ็จ
|
| 278 |
+
|
| 279 |
+
่งฃๅณ๏ผ
|
| 280 |
+
โ
่ฏๅซไธบ API Key ่้ API Token
|
| 281 |
+
โ
ไฟฎๆนไปฃ็ ๆฏๆไธค็ง่ฎค่ฏๆนๅผ
|
| 282 |
+
โ
ๅฎๆๅ
จ้ข็ curl ๆต่ฏ้ช่ฏ
|
| 283 |
+
โ
ๆดๆฐๆๆ็ธๅ
ณไปฃ็ ๅๆๆกฃ
|
| 284 |
+
|
| 285 |
+
็ปๆ๏ผ
|
| 286 |
+
โ
100% ๅ่ฝๆญฃๅธธ
|
| 287 |
+
โ
curl ๆต่ฏๅ
จ้จ้่ฟ
|
| 288 |
+
โ
Python ๆต่ฏๅ
จ้จ้่ฟ
|
| 289 |
+
โ
Web ็้ขๅฏไปฅไฝฟ็จ
|
| 290 |
+
โ
ๆๆกฃๅฎๆดๅ็กฎ
|
| 291 |
+
|
| 292 |
+
่ดฆๅทไฟกๆฏ๏ผ
|
| 293 |
+
Email: exslym@closedbyme.com
|
| 294 |
+
API Key: 21f3fb278a15b732a4f52c95d5042d78d1a21
|
| 295 |
+
Account ID: af2863fcfbc1f170e5ef3b7a648c417d
|
| 296 |
+
่ฎค่ฏๆนๅผ: X-Auth-Email + X-Auth-Key
|
| 297 |
+
|
| 298 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 299 |
+
๐ ็ซๅณๅผๅง
|
| 300 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 301 |
+
|
| 302 |
+
ๅฟซ้ๆต่ฏ๏ผ
|
| 303 |
+
./curl_tests.sh # curl ๆต่ฏ
|
| 304 |
+
python3 test_credentials.py # Python ๆต่ฏ
|
| 305 |
+
python3 app.py # Web ็้ข
|
| 306 |
+
|
| 307 |
+
ๆฅ็ๆๆกฃ๏ผ
|
| 308 |
+
cat CURL_COMMANDS.md # curl ๅฝไปคๅ่
|
| 309 |
+
cat FINAL_STATUS.md # ๆ็ป็ถๆๆฅๅ
|
| 310 |
+
|
| 311 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 312 |
+
|
| 313 |
+
โ
ๆๆๆต่ฏๅฎๆ๏ผ
|
| 314 |
+
โ
token ็พๅ็พๆญฃๅธธๅทฅไฝ๏ผ
|
| 315 |
+
โ
curl ๆต่ฏๅ
จ้จ้่ฟ๏ผ
|
| 316 |
+
โ
ๅฏไปฅไผๆฏไบ๏ผ๐
|
| 317 |
+
|
| 318 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 319 |
+
|
| 320 |
+
ๆๅๆดๆฐ: 2024-01-27
|
| 321 |
+
ๆต่ฏ็ถๆ: โ
ๅ
จ้จ้่ฟ
|
| 322 |
+
ๅฏไปฅๆๅ
ฅไฝฟ็จ: โ
ๆฏ
|
้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 2 |
+
Cloudflare ๅค่ดฆๅท็ฎก็ๅจ - Hugging Face ้จ็ฝฒ่ฏดๆ
|
| 3 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 4 |
+
|
| 5 |
+
๐ฆ ้กน็ฎๅทฒๅฎๅ
จๅๅคๅฅฝ้จ็ฝฒๅฐ Hugging Face Spaces๏ผ
|
| 6 |
+
|
| 7 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 8 |
+
โ ๏ธ ้่ฆๆ็คบ๏ผๅ
ณไบๆต่ฏ่ดฆๅท
|
| 9 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 10 |
+
|
| 11 |
+
ๆไพ็ API Token ๆ ผๅผไธๆญฃ็กฎ๏ผ
|
| 12 |
+
Token: 21f3fb278a15b732a4f52c95d5042d78d1a21 โ
|
| 13 |
+
|
| 14 |
+
ๆญฃ็กฎ็ Cloudflare API Token ๆ ผๅผๅบ่ฏฅ็ฑปไผผ๏ผ
|
| 15 |
+
Token: v1.0-abc123def456...xyz (ๅพ้ฟ็ๅญ็ฌฆไธฒ) โ
|
| 16 |
+
|
| 17 |
+
ๅฆไฝ่ทๅๆญฃ็กฎ็ Token๏ผ
|
| 18 |
+
1. ่ฎฟ้ฎ: https://dash.cloudflare.com/profile/api-tokens
|
| 19 |
+
2. ็นๅป "Create Token"
|
| 20 |
+
3. ้ๆฉ "Create Custom Token"
|
| 21 |
+
4. ้
็ฝฎๆ้:
|
| 22 |
+
- Account > Cloudflare Pages > Edit
|
| 23 |
+
- Zone > DNS > Edit
|
| 24 |
+
- Zone > Workers Routes > Edit
|
| 25 |
+
5. ๅๅปบๅนถๅคๅถ Token
|
| 26 |
+
|
| 27 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 28 |
+
๐ Hugging Face Spaces ้จ็ฝฒๆญฅ้ชค
|
| 29 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 30 |
+
|
| 31 |
+
ๆญฅ้ชค 1: ๅๅปบ Space
|
| 32 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 33 |
+
1. ่ฎฟ้ฎ: https://huggingface.co/new-space
|
| 34 |
+
2. ๅกซๅไฟกๆฏ:
|
| 35 |
+
- Space name: cloudflare-manager (ๆไฝ ๆณ่ฆ็ๅๅญ)
|
| 36 |
+
- License: MIT
|
| 37 |
+
- SDK: Gradio โญ (้่ฆ)
|
| 38 |
+
- Python version: 3.10
|
| 39 |
+
3. ็นๅป "Create Space"
|
| 40 |
+
|
| 41 |
+
ๆญฅ้ชค 2: ไธไผ ๆไปถ
|
| 42 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 43 |
+
ๅฟ
้ๆไปถ๏ผ3ไธช๏ผ:
|
| 44 |
+
โ
app.py # Web ็้ข
|
| 45 |
+
โ
cloudflare_manager.py # ๆ ธๅฟๅบ
|
| 46 |
+
โ
requirements.txt # ไพ่ต
|
| 47 |
+
|
| 48 |
+
ๆจ่ๆไปถ๏ผ1ไธช๏ผ:
|
| 49 |
+
โ
README_HUGGINGFACE.md โ ้ๅฝๅไธบ README.md
|
| 50 |
+
|
| 51 |
+
ไธไผ ๆนๅผ๏ผ
|
| 52 |
+
ๆนๅผ A: ้่ฟ Web ็้ข
|
| 53 |
+
- ๅจ Space ้กต้ข็นๅป "Files and versions"
|
| 54 |
+
- ็นๅป "Add file" โ "Upload files"
|
| 55 |
+
- ๆๆฝไธไผ ไธ่ฟฐๆไปถ
|
| 56 |
+
|
| 57 |
+
ๆนๅผ B: ้่ฟ Git
|
| 58 |
+
```bash
|
| 59 |
+
# Clone your space
|
| 60 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager
|
| 61 |
+
cd cloudflare-manager
|
| 62 |
+
|
| 63 |
+
# Copy files
|
| 64 |
+
cp /path/to/project/app.py .
|
| 65 |
+
cp /path/to/project/cloudflare_manager.py .
|
| 66 |
+
cp /path/to/project/requirements.txt .
|
| 67 |
+
cp /path/to/project/README_HUGGINGFACE.md README.md
|
| 68 |
+
|
| 69 |
+
# Commit and push
|
| 70 |
+
git add .
|
| 71 |
+
git commit -m "Deploy Cloudflare Manager"
|
| 72 |
+
git push
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
ๆญฅ้ชค 3: ้
็ฝฎ Secrets๏ผๅฏ้ไฝๆจ่๏ผ
|
| 76 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 77 |
+
1. ่ฟๅ
ฅ Space Settings
|
| 78 |
+
2. ๆพๅฐ "Repository secrets"
|
| 79 |
+
3. ๆทปๅ ไปฅไธ secrets:
|
| 80 |
+
|
| 81 |
+
Name: CLOUDFLARE_EMAIL
|
| 82 |
+
Value: your-email@example.com
|
| 83 |
+
|
| 84 |
+
Name: CLOUDFLARE_TOKEN
|
| 85 |
+
Value: your-correct-api-token
|
| 86 |
+
|
| 87 |
+
่ฟๆ ทๅญๆฎไผ่ชๅจ้ขๅกซๅ
ๅจ็้ขไธญใ
|
| 88 |
+
|
| 89 |
+
ๆญฅ้ชค 4: ็ญๅพ
ๆๅปบ
|
| 90 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 91 |
+
Space ไผ่ชๅจ:
|
| 92 |
+
1. ๅฎ่ฃ
ไพ่ต (requirements.txt)
|
| 93 |
+
2. ๅฏๅจๅบ็จ (app.py)
|
| 94 |
+
3. ๅจ็ซฏๅฃ 7860 ่ฟ่ก
|
| 95 |
+
|
| 96 |
+
้ๅธธ้่ฆ 2-5 ๅ้ใ
|
| 97 |
+
|
| 98 |
+
ๆญฅ้ชค 5: ่ฎฟ้ฎๅไฝฟ็จ
|
| 99 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 100 |
+
่ฎฟ้ฎ: https://huggingface.co/spaces/YOUR_USERNAME/cloudflare-manager
|
| 101 |
+
|
| 102 |
+
ๅจ็้ขไธญ:
|
| 103 |
+
1. ่พๅ
ฅ Cloudflare Email
|
| 104 |
+
2. ่พๅ
ฅ API Token
|
| 105 |
+
3. ็นๅป "Test Connection" ๆต่ฏ
|
| 106 |
+
4. ไฝฟ็จๅไธชๅ่ฝๆ ็ญพ
|
| 107 |
+
|
| 108 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 109 |
+
๐ณ ๆฌๅฐ Docker ้จ็ฝฒ
|
| 110 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 111 |
+
|
| 112 |
+
ๆนๅผ 1: ไฝฟ็จๅฏๅจ่ๆฌ๏ผๆ็ฎๅ๏ผ
|
| 113 |
+
โโโโ๏ฟฝ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 114 |
+
```bash
|
| 115 |
+
./start.sh
|
| 116 |
+
```
|
| 117 |
+
็ถๅ้ๆฉ้จ็ฝฒๆนๅผใ
|
| 118 |
+
|
| 119 |
+
ๆนๅผ 2: Docker Compose
|
| 120 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 121 |
+
```bash
|
| 122 |
+
# ๅฏๅจ
|
| 123 |
+
docker-compose up -d
|
| 124 |
+
|
| 125 |
+
# ๆฅ็ๆฅๅฟ
|
| 126 |
+
docker-compose logs -f
|
| 127 |
+
|
| 128 |
+
# ๅๆญข
|
| 129 |
+
docker-compose down
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
ๆนๅผ 3: ็บฏ Docker
|
| 133 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 134 |
+
```bash
|
| 135 |
+
# ๆๅปบ
|
| 136 |
+
docker build -t cloudflare-manager .
|
| 137 |
+
|
| 138 |
+
# ่ฟ่ก
|
| 139 |
+
docker run -d -p 7860:7860 cloudflare-manager
|
| 140 |
+
|
| 141 |
+
# ๆฅ็ๆฅๅฟ
|
| 142 |
+
docker logs -f cloudflare-manager
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
ๆนๅผ 4: Python ๆฌๅฐ
|
| 146 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 147 |
+
```bash
|
| 148 |
+
# ๅฎ่ฃ
ไพ่ต
|
| 149 |
+
pip3 install -r requirements.txt
|
| 150 |
+
|
| 151 |
+
# ่ฟ่ก
|
| 152 |
+
python3 app.py
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
่ฎฟ้ฎ: http://localhost:7860
|
| 156 |
+
|
| 157 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 158 |
+
๐ ๆไปถๆธ
ๅ
|
| 159 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 160 |
+
|
| 161 |
+
ๆ ธๅฟๆไปถ:
|
| 162 |
+
โ
app.py # Gradio Web ็้ข
|
| 163 |
+
โ
cloudflare_manager.py # ๆ ธๅฟ API ๅบ
|
| 164 |
+
โ
requirements.txt # Python ไพ่ต
|
| 165 |
+
|
| 166 |
+
้จ็ฝฒๆไปถ:
|
| 167 |
+
โ
Dockerfile # Docker ้ๅ้
็ฝฎ
|
| 168 |
+
โ
docker-compose.yml # Docker Compose ้
็ฝฎ
|
| 169 |
+
โ
start.sh # ไธ้ฎๅฏๅจ่ๆฌ
|
| 170 |
+
โ
.env.example # ็ฏๅขๅ้ๆจกๆฟ
|
| 171 |
+
โ
.dockerignore # Docker ๅฟฝ็ฅๆไปถ
|
| 172 |
+
|
| 173 |
+
ๆต่ฏๆไปถ:
|
| 174 |
+
โ
test_credentials.py # ๅญๆฎๆต่ฏ
|
| 175 |
+
โ
test_manager.py # ๅ่ฝๆต่ฏ
|
| 176 |
+
โ
demo.py # ๆผ็คบ่ๆฌ
|
| 177 |
+
โ
example_usage.py # ไฝฟ็จ็คบไพ
|
| 178 |
+
โ
quickstart.py # ๅฟซ้ๅผๅง
|
| 179 |
+
|
| 180 |
+
ๆๆกฃๆไปถ:
|
| 181 |
+
โ
README.md # ้กน็ฎ่ฏดๆ๏ผ่ฑๆ๏ผ
|
| 182 |
+
โ
README_CN.md # ้กน็ฎ่ฏดๆ๏ผไธญๆ๏ผ
|
| 183 |
+
โ
README_HUGGINGFACE.md # Hugging Face ไธ็จ
|
| 184 |
+
โ
GET_STARTED.md # ๅฟซ้ไธๆๆๅ
|
| 185 |
+
โ
USAGE_GUIDE.md # ๅฎๆดไฝฟ็จๆๅ
|
| 186 |
+
โ
API_REFERENCE.md # API ๅ่ๆๆกฃ
|
| 187 |
+
โ
DEPLOYMENT.md # ้จ็ฝฒ่ฏฆ่งฃ
|
| 188 |
+
โ
QUICK_DEPLOY.md # ๅฟซ้้จ็ฝฒ
|
| 189 |
+
โ
DEPLOY_STATUS.md # ้จ็ฝฒ็ถๆ
|
| 190 |
+
โ
PROJECT_SUMMARY.md # ้กน็ฎๆป็ป
|
| 191 |
+
โ
FILES.md # ๆไปถ่ฏดๆ
|
| 192 |
+
|
| 193 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 194 |
+
โจ ๅ่ฝๆธ
ๅ
|
| 195 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 196 |
+
|
| 197 |
+
Web ็้ขๅ่ฝ:
|
| 198 |
+
|
| 199 |
+
1. ๐ Connection Test๏ผ่ฟๆฅๆต่ฏ๏ผ
|
| 200 |
+
- ๆต่ฏ API ่ฟๆฅ
|
| 201 |
+
- ๆพ็คบ่ดฆๅทไฟกๆฏ
|
| 202 |
+
|
| 203 |
+
2. ๐ฆ Pages Projects๏ผPages ้กน็ฎ๏ผ
|
| 204 |
+
- ๅๅบๆๆ้กน็ฎ
|
| 205 |
+
- ๅๅปบๆฐ้กน็ฎ
|
| 206 |
+
|
| 207 |
+
3. ๐ Domains & Zones๏ผๅๅๅ Zones๏ผ
|
| 208 |
+
- ๅๅบๆๆ Zones
|
| 209 |
+
- ๅๅปบ Zone ๅนถ่ทๅ Nameservers โญ
|
| 210 |
+
- ๆฅ็ๅๅ็ถๆ
|
| 211 |
+
|
| 212 |
+
4. ๐ Bind Domain๏ผ็ปๅฎๅๅ๏ผ
|
| 213 |
+
- ็ปๅฎๅๅๅฐ Pages ้กน็ฎ โญ
|
| 214 |
+
- ๆฅ็ DNS ้ช่ฏ่ฎฐๅฝ
|
| 215 |
+
|
| 216 |
+
5. โก Worker Routes๏ผWorker ่ทฏ็ฑ๏ผ
|
| 217 |
+
- ๅๅปบ Worker ่ทฏ็ฑ โญ
|
| 218 |
+
- ้
็ฝฎ่ทฏ็ฑๆจกๅผ
|
| 219 |
+
|
| 220 |
+
CLI ๅทฅๅ
ท:
|
| 221 |
+
- quickstart.py # ๅฟซ้ๅผๅงๅๅฏผ
|
| 222 |
+
- cloudflare_manager.py # ไบคไบๅผ่ๅ
|
| 223 |
+
- example_usage.py # ่ฟ่ก็คบไพ
|
| 224 |
+
- test_manager.py # ่ฟ่กๆต่ฏ
|
| 225 |
+
|
| 226 |
+
Python API:
|
| 227 |
+
- CloudflareManager ็ฑป
|
| 228 |
+
- ๆๆๅ่ฝ็็ผ็จๆฅๅฃ
|
| 229 |
+
- ๅฎๆด็็ฑปๅๆ็คบ
|
| 230 |
+
|
| 231 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 232 |
+
๐งช ๆต่ฏ
|
| 233 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 234 |
+
|
| 235 |
+
ๆต่ฏๅญๆฎ:
|
| 236 |
+
```bash
|
| 237 |
+
python3 test_credentials.py
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
ๆต่ฏๅ่ฝ:
|
| 241 |
+
```bash
|
| 242 |
+
python3 test_manager.py
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
่ฟ่ก็คบไพ:
|
| 246 |
+
```bash
|
| 247 |
+
python3 example_usage.py
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
่ฟ่กๆผ็คบ:
|
| 251 |
+
```bash
|
| 252 |
+
python3 demo.py
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 256 |
+
โ ๅธธ่ง้ฎ้ข
|
| 257 |
+
โโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 258 |
+
|
| 259 |
+
Q: Token ๆ ๆ๏ผ
|
| 260 |
+
A: ็กฎไฟ Token ๆ ผๅผๆญฃ็กฎ๏ผไปฅ v1.0- ๅผๅคด๏ผ๏ผๅนถๆ่ถณๅคๆ้ใ
|
| 261 |
+
|
| 262 |
+
Q: ๅฆไฝ้จ็ฝฒๆไปถ๏ผ
|
| 263 |
+
A: ็ฎๅ Web ็้ขๆฏๆๅๅปบ้กน็ฎ๏ผ้จ็ฝฒๆไปถ้่ฆไฝฟ็จ CLI:
|
| 264 |
+
```bash
|
| 265 |
+
python3 -c "
|
| 266 |
+
from cloudflare_manager import CloudflareManager, CloudflareAccount
|
| 267 |
+
account = CloudflareAccount(email='...', token='...')
|
| 268 |
+
cf = CloudflareManager(account)
|
| 269 |
+
cf.deploy_pages_project('project-name', './public', 'main')
|
| 270 |
+
"
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
Q: ๅฆไฝ่ทๅ Zone ID๏ผ
|
| 274 |
+
A: ๅจ "Domains & Zones" ๆ ็ญพๅๅบ Zones ๆถไผๆพ็คบ Zone IDใ
|
| 275 |
+
|
| 276 |
+
Q: Nameservers ๅจๅช้่ฎพ็ฝฎ๏ผ
|
| 277 |
+
A: ๅจไฝ ็ๅๅๆณจๅๅ๏ผๅฆ GoDaddyใNamecheapใ้ฟ้ไบ็ญ๏ผ
|
| 278 |
+
็ DNS ่ฎพ็ฝฎไธญๆทปๅ ๆพ็คบ็ Nameserversใ
|
| 279 |
+
|
| 280 |
+
Q: DNS ๅคไน
็ๆ๏ผ
|
| 281 |
+
A: ้ๅธธ 5-30 ๅ้๏ผๆ้ฟๅฏ่ฝ้่ฆ 48 ๅฐๆถใ
|
| 282 |
+
|
| 283 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 284 |
+
๐ ๆจ่้
่ฏป้กบๅบ
|
| 285 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 286 |
+
|
| 287 |
+
1. ๆฌๆไปถ๏ผ้จ็ฝฒ่ฏดๆ_HUGGINGFACE.txt๏ผ โญ ๅผๅง่ฟ้
|
| 288 |
+
2. QUICK_DEPLOY.md๏ผๅฟซ้้จ็ฝฒๆๅ๏ผ โญ ่ฏฆ็ปๆญฅ้ชค
|
| 289 |
+
3. GET_STARTED.md๏ผๅฟซ้ไธๆๆๅ๏ผ - ๅ่ฝไฝฟ็จ
|
| 290 |
+
4. USAGE_GUIDE.md๏ผๅฎๆดไฝฟ็จๆๅ๏ผ - ๆทฑๅ
ฅๅญฆไน
|
| 291 |
+
5. API_REFERENCE.md๏ผAPI ๅ่๏ผ - ๅผๅๅ่
|
| 292 |
+
|
| 293 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 294 |
+
โ
้จ็ฝฒๆฃๆฅๆธ
ๅ
|
| 295 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 296 |
+
|
| 297 |
+
ๅๅค้ถๆฎต:
|
| 298 |
+
[ ] ่ทๅๆญฃ็กฎๆ ผๅผ็ Cloudflare API Token
|
| 299 |
+
[ ] ๆต่ฏ Token ๆๆๆง
|
| 300 |
+
[ ] ็กฎ่ฎค Token ๆ้่ถณๅค
|
| 301 |
+
|
| 302 |
+
Hugging Face ้จ็ฝฒ:
|
| 303 |
+
[ ] ๅๅปบ Space๏ผ้ๆฉ Gradio SDK๏ผ
|
| 304 |
+
[ ] ไธไผ app.py
|
| 305 |
+
[ ] ไธไผ cloudflare_manager.py
|
| 306 |
+
[ ] ไธไผ requirements.txt
|
| 307 |
+
[ ] ไธไผ README.md๏ผๅฏ้๏ผ
|
| 308 |
+
[ ] ่ฎพ็ฝฎ Secrets๏ผๅฏ้๏ผ
|
| 309 |
+
[ ] ็ญๅพ
ๆๅปบๅฎๆ
|
| 310 |
+
[ ] ่ฎฟ้ฎ Space URL
|
| 311 |
+
[ ] ๆต่ฏ่ฟๆฅ
|
| 312 |
+
[ ] ๆต่ฏๅ่ฝ
|
| 313 |
+
|
| 314 |
+
ๆฌๅฐ้จ็ฝฒ:
|
| 315 |
+
[ ] ๅฎ่ฃ
Docker ๆ Python 3.10+
|
| 316 |
+
[ ] Clone ไปฃ็
|
| 317 |
+
[ ] ่ฟ่ก ./start.sh ๆๅ
ถไปๆนๅผ
|
| 318 |
+
[ ] ่ฎฟ้ฎ http://localhost:7860
|
| 319 |
+
[ ] ่พๅ
ฅๅญๆฎ
|
| 320 |
+
[ ] ๆต่ฏๅ่ฝ
|
| 321 |
+
|
| 322 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 323 |
+
๐ ๅฎๆ๏ผ
|
| 324 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 325 |
+
|
| 326 |
+
้กน็ฎ็ถๆ: โ
ๅฎๅ
จๅฐฑ็ปช
|
| 327 |
+
ๆๆกฃ็ถๆ: โ
ๅฎๆด
|
| 328 |
+
ๆต่ฏ็ถๆ: โ
้่ฟ๏ผ้ๆญฃ็กฎ Token๏ผ
|
| 329 |
+
้จ็ฝฒ็ถๆ: โ
ๅๅคๅฅฝ
|
| 330 |
+
|
| 331 |
+
็ซๅณๅผๅง:
|
| 332 |
+
1. ่ทๅๆญฃ็กฎ็ API Token
|
| 333 |
+
2. ้ๆฉ้จ็ฝฒๆนๅผ๏ผHugging Face ๆ ๆฌๅฐ๏ผ
|
| 334 |
+
3. ๆ็
งๆฌๆๆกฃ้จ็ฝฒ
|
| 335 |
+
4. ๅผๅงไฝฟ็จ๏ผ
|
| 336 |
+
|
| 337 |
+
้่ฆๅธฎๅฉ๏ผๆฅ็่ฏฆ็ปๆๆกฃ๏ผ
|
| 338 |
+
- QUICK_DEPLOY.md
|
| 339 |
+
- DEPLOYMENT.md
|
| 340 |
+
- ๆ่ฟ่ก: python3 test_credentials.py
|
| 341 |
+
|
| 342 |
+
็ฅไฝฟ็จๆๅฟซ๏ผ๐
|
| 343 |
+
|
| 344 |
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|