/** * Global Profile Plugin - Docs Routes * * Handles API documentation endpoints */ const sdk = require('../../../includes/plugins/sdk'); /** * Handle docs-related routes */ async function handleDocsRoutes(req, res, path, query, method) { // GET /api/docs - Interactive API documentation if (path === 'api/docs' && method === 'GET') { const baseUrl = `https://${process.env.PLUGIN_DOMAIN || 'global.profile'}`; const html = ` Global Profile API Documentation

Global Profile API Documentation

Complete REST API reference for the Global Profile plugin

Table of Contents

GET /api/profile

Get your local profile. Returns default profile if none exists.
200 OK Profile retrieved successfully
500 Local peer ID not available
Example Request
curl -X GET ${baseUrl}/api/profile
Example Response
{ "peerId": "abc123...", "displayName": "John Doe", "bio": "Software developer", "website": "https://example.com", "email": "john@example.com", "xUsername": "johndoe", "github": "johndoe", "discord": "johndoe#1234", "location": "San Francisco, CA", "avatarHash": "abc123...", "customFields": {}, "tags": ["developer", "opensource"], "lastUpdated": 1703123456789 }

PUT /api/profile

Update your profile (full update). All fields must be provided.

Request Body

displayNamestring (optional)
Display name for the profile
biostring (optional)
Biography or description
websitestring (optional)
Website URL
emailstring (optional)
Email address
xUsernamestring (optional)
X (Twitter) username
tagsarray (optional)
Array of tag strings
customFieldsobject (optional)
Custom fields object
200 OK Profile updated successfully
500 Error updating profile
503 Database not ready
Example Request
curl -X PUT ${baseUrl}/api/profile \\ -H "Content-Type: application/json" \\ -d '{ "displayName": "John Doe", "bio": "Software developer", "website": "https://example.com", "email": "john@example.com", "tags": ["developer"], "customFields": {} }'

PATCH /api/profile

Partially update your profile. Only provided fields will be updated.

Request Body

Any profile fieldmixed (optional)
Any combination of profile fields to update
200 OK Profile updated successfully
400 Invalid JSON
404 Profile not found
500 Error updating profile
Example Request
curl -X PATCH ${baseUrl}/api/profile \\ -H "Content-Type: application/json" \\ -d '{ "displayName": "Jane Doe", "bio": "Updated bio" }'

DELETE /api/profile

Delete your local profile.
200 OK Profile deleted successfully
404 Profile not found
500 Error deleting profile
Example Request
curl -X DELETE ${baseUrl}/api/profile

GET /api/profile/:peerId

Get a specific peer's profile by their peer ID.

Path Parameters

peerIdstring (required)
The peer ID to get the profile for
200 OK Profile retrieved successfully
404 Profile not found
Example Request
curl -X GET ${baseUrl}/api/profile/abc123...

GET /api/profiles

List all profiles with optional search, filtering, pagination, and sorting.

Query Parameters

searchstring (optional)
Search in displayName and bio fields
tagstring (optional)
Filter by tag
limitnumber (optional, default: 100)
Maximum number of results (1-1000)
offsetnumber (optional, default: 0)
Number of results to skip
sortstring (optional, default: "lastUpdated")
Sort field: "lastUpdated" or "displayName"
200 OK Profiles retrieved successfully
400 Invalid query parameters
Example Request
curl -X GET "${baseUrl}/api/profiles?search=developer&limit=10&offset=0&sort=lastUpdated"
Example Response
{ "profiles": [...], "pagination": { "total": 50, "limit": 10, "offset": 0, "hasMore": true } }

POST /api/profile/avatar

Upload a new avatar image. Image will be resized to multiple sizes (16, 32, 64, 128, 256, 512px).

Request Body

avatarfile (required)
Image file (multipart/form-data)
200 OK Avatar uploaded successfully
400 No avatar file provided or file is empty
500 Error uploading avatar
Example Request
curl -X POST ${baseUrl}/api/profile/avatar \\ -F "avatar=@/path/to/image.jpg"

DELETE /api/profile/avatar

Delete your avatar image.
200 OK Avatar deleted successfully
500 Error deleting avatar
Example Request
curl -X DELETE ${baseUrl}/api/profile/avatar

GET /api/profile/avatar/:peerId

Get default avatar (64px) for a peer. Redirects to size-specific endpoint.

Path Parameters

peerIdstring (required)
The peer ID to get the avatar for
302 Redirects to /api/profile/avatar/:peerId/64
Example Request
curl -X GET ${baseUrl}/api/profile/avatar/abc123...

GET /api/profile/avatar/:peerId/:size

Get avatar image for a peer at a specific size. Returns default SVG if no avatar exists.

Path Parameters

peerIdstring (required)
The peer ID to get the avatar for
sizenumber (required)
Avatar size: 16, 32, 64, 128, 256, or 512
200 OK Avatar image (PNG or SVG)
400 Invalid avatar size
Example Request
curl -X GET ${baseUrl}/api/profile/avatar/abc123.../128

GET /api/fields

Get all registered custom fields.
200 OK Fields retrieved successfully
Example Request
curl -X GET ${baseUrl}/api/fields
Example Response
{ "fields": [ { "fieldKey": "favoriteColor", "registeredBy": "example.plugin", "label": "Favorite Color", "type": "string", "description": "User's favorite color", "defaultValue": "" } ] }

POST /api/fields

Register a new custom field. Fields can only be registered by the plugin that created them.

Request Body

fieldKeystring (required)
Unique key for the field
labelstring (required)
Human-readable label
typestring (required)
Field type (string, number, boolean, etc.)
descriptionstring (optional)
Field description
defaultValueany (optional)
Default value for the field
200 OK Field registered successfully
400 Missing required fields or invalid JSON
409 Field already registered by another plugin
500 Error registering field
Example Request
curl -X POST ${baseUrl}/api/fields \\ -H "Content-Type: application/json" \\ -d '{ "fieldKey": "favoriteColor", "label": "Favorite Color", "type": "string", "description": "User'\''s favorite color", "defaultValue": "blue" }'

GET /api/stats

Get profile statistics including total counts, online/offline status, and recent activity.
200 OK Statistics retrieved successfully
500 Error getting stats
Example Request
curl -X GET ${baseUrl}/api/stats
Example Response
{ "total": 50, "online": 12, "offline": 38, "recentActivity": [ { "peerId": "abc123...", "displayName": "John Doe", "hoursAgo": 2.5 } ], "timestamp": 1703123456789 }

Base URL: ${baseUrl}

Note: All endpoints return JSON unless otherwise specified. Error responses include an error field with a descriptive message.

`; res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'public, max-age=3600' }); res.end(html); return true; } return false; // Not handled by this module } module.exports = { handleDocsRoutes };