5.9 KiB
5.9 KiB
GitHub Gists Auto-Backup Feature
🎉 Implementation Complete!
Writingway 2 now has automatic cloud backup using GitHub Gists.
✨ Features
What's Included
-
Manual Backup
- Click "Backup Now" to save immediately
- Creates/updates a private GitHub Gist
-
Auto-Backup
- Automatic backup every 5 minutes when enabled
- Runs silently in the background
- Shows status in sidebar when active
-
Version History
- GitHub keeps unlimited versions of your backups
- View all backup timestamps
- Restore from any previous version
-
Restore Functionality
- Browse all backup versions
- One-click restore
- Full project recovery (chapters, scenes, content, compendium, prompts)
-
Simple Setup
- Clear step-by-step instructions in the UI
- Just paste your GitHub token
- Works immediately
-
Security & Privacy
- All Gists are private by default
- Token stored locally in browser
- No storage limits
- You control your data
🚀 How to Use
Initial Setup
- Start Writingway 2 with
start.bat - Open the main menu (☰)
- Click "☁️ Cloud Backup"
- Follow the instructions to create a GitHub token
- Paste your token and click "Save Settings"
- Enable "Enable automatic backup"
- Done! Your project will backup every 5 minutes
Backup Now
- Open main menu → "☁️ Cloud Backup"
- Click "Backup Now"
- Wait for confirmation
Restore from Backup
- Open main menu → "☁️ Cloud Backup"
- Click "📥 Restore from Backup"
- Select a backup version
- Click "Restore"
- Confirm the warning
- Your project is restored!
📁 Files Modified/Created
New Files
src/modules/github-backup.js- Backup moduleBACKUP_TESTING.md- Testing guide
Modified Files
src/app.js- Added backup state variables and methodsmain.html- Added backup UI (settings panel, restore modal, menu button, status indicator)
🔧 Technical Details
Backup Contents
Each backup includes:
- Project metadata (name, dates, etc.)
- All chapters with their order
- All scenes with their order
- Scene content (text and word counts)
- Compendium entries (characters, places, items, lore, notes)
- Custom prompts
Storage
- Each project gets its own GitHub Gist
- Gists are private by default
- No storage limits
- Unlimited version history
- Accessible from https://gist.github.com/
API Usage
- Uses GitHub REST API v3
- Only requires
gistpermission - Token stored in localStorage
- Auto-backup timer: 5 minutes
Key Functions
github-backup.js:
validateToken()- Validates GitHub tokenexportProjectData()- Exports all project databackupToGist()- Creates or updates GistlistBackups()- Fetches version historyrestoreFromBackup()- Restores from specific versionrestoreProjectData()- Writes backup data to databasestartAutoBackup()- Starts 5-minute timerstopAutoBackup()- Stops timersaveBackupSettings()- Saves to localStorageloadBackupSettings()- Loads from localStorage
app.js methods:
openBackupSettings()- Opens settings panelcloseBackupSettings()- Closes settings panelsaveBackupSettings()- Validates and saves settingsbackupNow()- Triggers immediate backupopenRestoreModal()- Opens restore UIcloseRestoreModal()- Closes restore UIrestoreBackup(versionUrl)- Restores from URL
📝 Testing
See BACKUP_TESTING.md for comprehensive testing guide.
Quick test:
- Create a test project with some content
- Setup backup (follow UI instructions)
- Click "Backup Now"
- Go to https://gist.github.com/ and verify the backup
- Make changes and wait 5 minutes (or backup manually)
- Try restoring from backup
🎯 User Experience
UI Location
- Main Menu: "☁️ Cloud Backup" button
- Sidebar: Small status indicator when auto-backup is enabled
- Settings Panel: Slide-in from right with full controls
- Restore Modal: Centered overlay with version list
Status Messages
- "Backing up..." - In progress
- "Backed up" - Success
- "Backup failed" - Error occurred
- "Auto-backup active" - Timer running
- "✓ Connected as: [username]" - Token validated
Error Handling
- Invalid token: Clear error message
- No project: Helpful alert
- No backup: Informative message
- Network errors: Shows error text
🔐 Security Notes
- Token requires only
gistpermission (minimal access) - All Gists are private by default
- Token stored only in browser localStorage
- No server-side storage
- Token sent only to api.github.com via HTTPS
- Can be revoked anytime from GitHub settings
🌟 Benefits Over Google Drive
- Simpler - No OAuth flow, just paste token
- No storage limits - Unlimited Gist storage
- Better versioning - GitHub tracks all changes automatically
- No quotas - No API rate limits for personal use
- Developer-friendly - Clean API, good documentation
- Always accessible - View/edit from GitHub web interface
💡 Future Enhancements (Optional)
Possible improvements:
- Configurable backup interval
- Backup multiple projects to one Gist
- Compress backup data
- Export backup as downloadable ZIP
- Backup conflict detection
- Manual backup notes/tags
- Email notifications on backup
✅ Testing Checklist
- Token validation works
- Manual backup creates Gist
- Manual backup updates existing Gist
- Auto-backup timer runs every 5 minutes
- Settings persist across sessions
- Restore lists all versions
- Restore recovers all data correctly
- Each project has separate Gist
- Error messages are clear
- UI is intuitive
- Status indicator shows in sidebar
- No console errors
📚 Resources
- GitHub Gists API: https://docs.github.com/en/rest/gists
- Token creation: https://github.com/settings/tokens
- Your Gists: https://gist.github.com/
Ready to test! Follow BACKUP_TESTING.md for detailed testing steps.