Database Settings Controller Documentation
The DatabaseController
exposes Melon's database settings, such as performing backups,
restoring from backups, resetting the database, importing/exporting playlists, and configuring queue cleanup
frequency.
This is apart of the Settings Endpoints, which are scattered across a couple of controllers that group them by similarity.
Controller Route: /api/settings/db/
All routes within the DatabaseController
are prefixed by /api/settings/db/
.
Summary of Endpoints
Endpoint | Method | Description | Authorization |
---|---|---|---|
/api/settings/db/backup |
POST | Backup the database. | Admin |
/api/settings/db/view-backups |
GET | View all available database backups. | Admin |
/api/settings/db/load-backup |
POST | Load the database from a specific backup. | Admin |
/api/settings/db/reset |
POST | Reset the entire database. | Admin |
/api/settings/db/export-playlist |
GET | Export a playlist in a specified format. | Admin, User |
/api/settings/db/import-playlist |
POST | Import a playlist from a file. | Admin, User |
/api/settings/db/queue-cleanup-frequency |
GET | Get the queue cleanup frequency. | Admin |
/api/settings/db/queue-cleanup-frequency |
POST | Set the queue cleanup frequency. | Admin |
Backup Database
This endpoint performs a full backup of the database, backup is saved to a folder in Melon/Exports/DbBackups as a collection of JSON files representing the Collection from MongoDb.
Details:
- Endpoint:
/api/settings/db/backup
- Method:
POST
- Authorization: JWT with Admin role
Responses:
- 200 OK: Database backup completed successfully.
- 400 Bad Request: Failed to backup the database.
Example Request (using curl
):
curl -X POST "https://your-melon-server.com/api/settings/db/backup" \
-H "Authorization: Bearer <Admin-JWT>"
View Backups
This endpoint returns a list of available database backups, taken from Melon/Exports/DbBackups.
Details:
- Endpoint:
/api/settings/db/view-backups
- Method:
GET
- Authorization: JWT with Admin role
Responses:
- 200 OK: List of backup files returned.
Example Request (using curl
):
curl -X GET "https://your-melon-server.com/api/settings/db/view-backups" \
-H "Authorization: Bearer <Admin-JWT>"
Load Database from Backup
This endpoint loads the database from a specified backup folder.
Details:
- Endpoint:
/api/settings/db/load-backup
- Method:
POST
- Authorization: JWT with Admin role
Parameters:
- backupFileName (string, required): The name of the backup folder to restore from.
Responses:
- 200 OK: Database successfully loaded from the backup.
- 404 Not Found: Backup file not found.
Example Request (using curl
):
curl -X POST "https://your-melon-server.com/api/settings/db/load-backup" \
-H "Authorization: Bearer <Admin-JWT>" \
-d "backupFileName=140924-013709AM"
Reset Database
This endpoint resets the entire database.
Details:
- Endpoint:
/api/settings/db/reset
- Method:
POST
- Authorization: JWT with Admin role
Responses:
- 200 OK: Database reset successfully.
Example Request (using curl
):
curl -X POST "https://your-melon-server.com/api/settings/db/reset" \
-H "Authorization: Bearer <Admin-JWT>"
Export Playlist
This endpoint exports a playlist in a specified format.
Details:
- Endpoint:
/api/settings/db/export-playlist
- Method:
GET
- Authorization: JWT with Admin or User role
Parameters:
- format (string, required): The format for exporting the playlist, supports m3u, pls, and xml.
- playlistId (string, required): The ID of the playlist to export.
Responses:
- 200 OK: The playlist file is returned for download.
- 404 Not Found: Playlist not found.
- 400 Bad Request: Failed to export the playlist.
Example Request (using curl
):
curl -X GET "https://your-melon-server.com/api/settings/db/export-playlist?format=json&playlistId=12345" \
-H "Authorization: Bearer <User-JWT>"
Import Playlist
This endpoint imports a playlist from an uploaded file. Supports m3u, pls, and xml
Details:
- Endpoint:
/api/settings/db/import-playlist
- Method:
POST
- Authorization: JWT with Admin or User role
Parameters:
- plstFile (IFormFile, required): The playlist file to be uploaded and imported.
Responses:
- 200 OK: Playlist imported successfully.
- 400 Bad Request: No file uploaded or file format not supported.
Example Request (using curl
):
curl -X POST "https://your-melon-server.com/api/settings/db/import-playlist" \
-H "Authorization: Bearer <User-JWT>" \
-F "plstFile=@path_to_playlist_file"
Get Queue Cleanup Frequency
This endpoint returns the current queue cleanup frequency.
Details:
- Endpoint:
/api/settings/db/queue-cleanup-frequency
- Method:
GET
- Authorization: JWT with Admin role
Responses:
- 200 OK: The current queue cleanup frequency is returned.
Example Request (using curl
):
curl -X GET "https://your-melon-server.com/api/settings/db/queue-cleanup-frequency" \
-H "Authorization: Bearer <Admin-JWT>"
Set Queue Cleanup Frequency
This endpoint sets a new queue cleanup frequency.
Details:
- Endpoint:
/api/settings/db/queue-cleanup-frequency
- Method:
POST
- Authorization: JWT with Admin role
Parameters:
- frequencyInHours (double, required): The new frequency in hours for queue cleanup.
Responses:
- 200 OK: Queue cleanup frequency updated successfully.
Example Request (using curl
):
curl -X POST "https://your-melon-server.com/api/settings/db/queue-cleanup-frequency" \
-H "Authorization: Bearer <Admin-JWT>" \
-d "frequencyInHours=24"