Hawk

File System

Everything you need to know about the file system

File System

Mounting

Each container has its own directory at:

/var/lib/hawk/services/${UUID}/

This directory is used for easy accessibility and control over the file system, where ${UUID} is a unique identifier for each container instance.

API Access

The file system can be accessed through the following API endpoints, which are split into different routes for convenience.


Endpoints

1. GET /:uuid/files/contains

  • Purpose: Retrieve a list of all files and folders in a specified directory.

  • Query Parameter:

    • dir (optional): The subdirectory to search within. If not provided, defaults to the root directory.
  • Example:

    GET /abc123/files/contains?dir=plugins/MyPlugin
  • Response:

    • A list of objects representing files and directories, each with a name and type (either "file" or "directory").
    [
      { "name": "pluginA.js", "type": "file" },
      { "name": "subfolder", "type": "directory" }
    ]

2. GET /:uuid/files/content

  • Purpose: This route is intentionally left invalid with a 404 response as a method to restrict unauthorized access.

  • Response:

    • 404 Not Found

3. POST /:uuid/files/content

  • Purpose: Retrieve the content of a specific file.

  • Request Body:

    • file: Path to the file to retrieve content from.
  • Example:

    Retrieve File Content
    {
      "file": "path/to/file.txt"
    }
  • Response:

    • The content of the specified file in UTF-8 encoding.
    {
      "content": "This is the content of the file."
    }

4. POST /:uuid/files/content/save

  • Purpose: Save content to a specific file.

  • Request Body:

    • file: Path to the file to save.
    • content: The content to save in the file.
  • Example:

    Save File Content
    {
      "file": "path/to/file.txt",
      "content": "This is the new content of the file."
    }
  • Response:

    • A confirmation message indicating the file was saved successfully.
    {
      "message": "File saved successfully."
    }

5. POST /:uuid/files/create

  • Purpose: Create a new file with content.

  • Request Body:

    • file: Path for the new file.
    • content: The content to save in the new file.
  • Example:

    Create New File
    {
      "file": "newFile.txt",
      "content": "This is a new file."
    }
  • Response:

    • A confirmation message indicating the file was created successfully.
    {
      "message": "File created successfully."
    }

6. POST /:uuid/folders/create

  • Purpose: Create a new folder.

  • Request Body:

    • folder: The path for the new folder.
  • Example:

    Create New Folder
    {
      "folder": "newFolder"
    }
  • Response:

    • A confirmation message indicating the folder was created successfully.
    {
      "message": "Folder created successfully."
    }

7. DELETE /:uuid/files/delete

  • Purpose: Delete a specific file or folder.

  • Request Body:

    • item: The file or folder to delete.
  • Example:

    Delete File or Folder
    {
      "item": "path/to/item"
    }
  • Response:

    • A confirmation message indicating the file or folder was deleted successfully.
    {
      "message": "File deleted successfully."
    }

8. POST /:uuid/files/move

  • Purpose: Move a file or folder from one location to another.

  • Request Body:

    • oldPath: The current path of the file or folder.
    • newPath: The new path for the file or folder.
  • Example:

    Move File or Folder
    {
      "oldPath": "path/to/old/file.txt",
      "newPath": "path/to/new/file.txt"
    }
  • Response:

    • A confirmation message indicating the file or folder was moved successfully.
    {
      "message": "File/folder moved successfully."
    }

9. POST /:uuid/files/rename

  • Purpose: Rename a file or folder.

  • Request Body:

    • oldPath: The current path of the file or folder.
    • newName: The new name for the file or folder.
  • Example:

    Rename File or Folder
    {
      "oldPath": "path/to/old/file.txt",
      "newName": "newFile.txt"
    }
  • Response:

    • A confirmation message indicating the file or folder was renamed successfully.
    {
      "message": "File/folder renamed successfully."
    }

10. GET /:uuid/files/download

  • Purpose: Download a specific file.

  • Query Parameter:

    • file: The file to download.
  • Example:

    GET /abc123/files/download?file=path/to/file.txt
  • Response:

    • A file download prompt for the specified file.