Google Drive Integration β
TuneCamp allows administrators to link a Google Drive account to stream, import, and localize music files directly from the cloud.
1. OAuth2 Workflow β
The integration uses the Google OAuth2 protocol to securely access user files.
- Service:
src/server/modules/storage/google-drive.service.ts - Scopes:
drive.readonly: To list and download files.drive.file: To upload files (if needed).userinfo.email: To identify the connected account.
Authentication Steps: β
- Admin clicks "Connect Google Drive" in the Storage tab.
- Redirected to Google Consent screen via
GET /api/storage/gdrive/auth. - After approval, Google redirects back to
/api/storage/gdrive/callback?code=.... - Backend exchanges the code for an
access_tokenandrefresh_token. - Tokens are encrypted and stored in the
storage_accountstable.
2. Cloud Streaming β
TuneCamp supports streaming directly from Google Drive without downloading the file to the local server first.
- Protocol: Tracks with a
file_pathstarting withgdrive://are treated as cloud tracks. - Mechanism:
- When a stream is requested,
GoogleDriveService.getFileStreamis called. - It uses the
alt=mediaGoogle Drive API parameter. - Supports Range Requests (seeking) by passing the HTTP Range header directly to the Google API.
- When a stream is requested,
3. Importing & Localization β
Importing β
- Admins can browse their Drive folders (
GET /api/storage/gdrive/files). - Selecting a file creates a track record in the database with
file_path: gdrive://{fileId}. - Metadata (Title/Artist) is tentatively parsed from the filename.
Localization β
- Purpose: Converts a cloud track (
gdrive://) into a local file on the TuneCamp server. - Mechanism: The backend downloads the file from Drive, saves it to the local
music/tracks/folder, and updates the database record to point to the local path.
4. Configuration β
Credentials can be set either via environment variables or in the Admin UI (Storage tab β google_drive_client_id / google_drive_client_secret settings, which take precedence over the env vars).
Environment variables:
TUNECAMP_GDRIVE_CLIENT_ID: From Google Cloud Console.TUNECAMP_GDRIVE_CLIENT_SECRET: From Google Cloud Console.
The OAuth redirect URI is derived from the instance public URL: https://your-domain.com/api/storage/gdrive/callback.