Shareify

API Documentation

This document provides an overview of all the API endpoints available in the main.py file, including their parameters and responses.

Authentication: Most endpoints require JWT authentication via the Authorization: Bearer <token> header (except login, is_up, root, serve_static, serve_assets, auth, and preview endpoints). Tokens are obtained via the /api/user/login endpoint and are valid for 24 hours.


General Endpoints

/api/is_up [GET]

Description: Check if the server is running.
Authentication: None required
Rate Limiting: 1 request per second Response:


/api/shutdown [POST]

Description: Shutdown the system (requires admin privileges).
Authentication: JWT token required
Response:


/api/restart [POST]

Description: Restart the system (requires admin privileges).
Authentication: JWT token required
Response:


File Management Endpoints

/api/finder [GET]

Description: List files and directories at a given path.
Authentication: JWT token required
Parameters:


/api/new_file [POST]

Description: Create a new file.
Authentication: JWT token required
Request Body:


/api/delete_file [POST]

Description: Delete a file.
Authentication: JWT token required
Request Body:


/api/edit_file [POST]

Description: Edit a file’s content.
Authentication: JWT token required
Request Body:


/api/get_file [GET]

Description: Retrieve the content of a file.
Authentication: JWT token required
Parameters:


/api/rename_file [POST]

Description: Rename a file.
Authentication: JWT token required
Request Body:


/api/upload [POST]

Description: Upload a file.
Authentication: JWT token required
Request Body (multipart/form-data):


/api/download [GET]

Description: Download a file or folder (as zip).
Authentication: JWT token required
Parameters:


Folder Management Endpoints

/api/create_folder [POST]

Description: Create a new folder.
Authentication: JWT token required
Request Body:


/api/delete_folder [POST]

Description: Delete a folder.
Authentication: JWT token required
Request Body:


/api/rename_folder [POST]

Description: Rename a folder.
Authentication: JWT token required
Request Body:


Command Execution Endpoints

/api/command [POST]

Description: Execute a system command.
Authentication: JWT token required
Request Body:


System Information Endpoints

/api/resources [GET]

Description: Get system resource usage (CPU, memory, disk).
Authentication: JWT token required
Response:


User Management Endpoints

/api/user/create [POST]

Description: Create a new user.
Authentication: JWT token required
Request Body:


/api/user/delete [POST]

Description: Delete a user and automatically remove their role from the roles configuration.
Authentication: JWT token required
Request Body:

Note: When a user is deleted, their role will be automatically removed from all endpoints in the roles configuration file (except for admin roles). The system also updates the roles.json file and reloads configurations automatically.


/api/user/edit [POST]

Description: Edit a user’s details.
Authentication: JWT token required
Request Body:


/api/user/login [POST]

Description: Login a user and receive a JWT token.
Authentication: None required
Rate Limiting: 1 request per second Request Body:

Note: The returned JWT token should be used in the Authorization: Bearer <token> header for subsequent API calls.


/api/user/get_self [GET]

Description: Retrieve the current user’s details.
Authentication: JWT token required
Response:


/api/user/get_all [GET]

Description: Retrieve all users.
Authentication: JWT token required
Response:


/api/user/edit_self [POST]

Description: Edit the current user’s details.
Authentication: JWT token required
Request Body: JSON object with optional fields to update:


FTP Management Endpoints

/api/ftp/create_user [POST]

Description: Create an FTP user.
Authentication: JWT token required
Request Body:


/api/ftp/delete_user [POST]

Description: Delete an FTP user.
Authentication: JWT token required
Request Body:


/api/ftp/get_users [GET]

Description: Retrieve all FTP users.
Authentication: JWT token required
Response:


/api/ftp/edit_user [POST]

Description: Edit an FTP user’s details.
Authentication: JWT token required
Request Body:


/api/ftp/start [POST]

Description: Start the FTP server.
Authentication: JWT token required
Response:


/api/ftp/stop [POST]

Description: Stop the FTP server.
Authentication: JWT token required
Response:


Server Management Endpoints

/api/get_logs [GET]

Description: Retrieve server logs.
Authentication: JWT token required
Response:


/api/get_settings [GET]

Description: Retrieve server settings.
Authentication: JWT token required
Response:


/api/update_settings [POST]

Description: Update server settings.
Authentication: JWT token required
Request Body: JSON object with updated settings.
Response:


/api/get_version [GET]

Description: Get the server version.
Authentication: JWT token required
Response:


/api/update [POST]

Description: Trigger a server update (runs update.py in background).
Authentication: JWT token required
Response:


/update_start_exit_program [POST]

Description: Exit program for update process (calls stop_completely()).
Authentication: JWT token required
Response:


Cloud Management Endpoints

/api/cloud/manage [POST]

Description: Manage cloud integration settings and operations.
Authentication: JWT token required
Request Body: JSON object with action and additional parameters:

Enable/Disable Cloud

Delete Authentication Data

Cloud Signup

Response:

Note: The signup action requires an existing auth token in cloud settings and communicates with the cloud bridge server.


Role Management Endpoints

/api/role/get [GET]

Description: Retrieve all roles from roles.json.
Authentication: JWT token required
Response:


/api/role/edit [POST]

Description: Edit roles configuration.
Authentication: JWT token required
Request Body: JSON object with updated roles.
Response:


Static File Serving

/ [GET]

Description: Serve the main index.html page.
Authentication: None required


/auth [GET]

Description: Serve the login.html page.
Authentication: None required


/preview [GET]

Description: Serve the preview.html page for file previews.
Authentication: None required


/web/<path:filename> [GET]

Description: Serve static files from the web directory.
Authentication: None required
Parameters:


/web/assets/<path:filename> [GET]

Description: Serve asset files from the web/assets directory.
Authentication: None required
Parameters:


JWT Authentication

The API uses JSON Web Tokens (JWT) for authentication. Here’s how it works:

Getting a Token

  1. Send a POST request to /api/user/login with username and password
  2. Receive a JWT token that’s valid for 24 hours
  3. Use this token in the Authorization: Bearer <token> header for all subsequent requests

Token Structure

Using the Token

Include the token in the Authorization header:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Token Validation

The server validates tokens before processing requests:

Error Handling

Migration Notes


Access Control

The API implements a JWT-based role access control system:

  1. Authentication: Most endpoints require JWT authentication via Authorization: Bearer <token> header
  2. Path Access Control: Users have specific read/write permissions for different paths
  3. Role-based Permissions: Different endpoints are accessible based on user roles defined in roles.json
  4. Token Expiration: JWT tokens are valid for 24 hours and must be refreshed via login

Access Functions:

JWT Token Errors:


Database Schema

Users Table:

Logs Table:


Error Handling

All endpoints return consistent error responses:


For more details, refer to the source code in main.py.


GET /api/role/self

Description: Get the current user’s role permissions for all endpoints

Headers:

Response:

Notes: