GigHive bee gighive

API Current State (Webroot)

This document describes the current, implemented API behavior under ansible/roles/docker/files/apache/webroot and outlines planned enhancements.

High-level best practices followed here:


1. Directory Overview

The Apache webroot for the API and UI is:

Key subdirectories relevant to the API:


2. Upload API Routing

2.1 MVC Router (/src/index.php)

The main Router lives in:

Responsibilities:

Net effect: All modern upload behavior is implemented in the MVC layer and routed through src/index.php.

2.2 Legacy Shim (/api/uploads.php)

File:

Current behavior:

Result:


3. Upload Forms (/db/)

There are two main upload forms under /db/:

  1. User-facing form
    • File: db/upload_form.php
    • Purpose: simple upload UI for regular users.
    • Form action (current):
      • action="/api/uploads.php"
  2. Admin form
    • File: db/upload_form_admin.php
    • Purpose: admin-focused upload UI with advanced fields.
    • Form action (current):
      • action="/api/uploads.php"

Important notes:


4. Database Listing (/db/database.php)

File:

Behavior (high level):

Note:


5. Relationship to OpenAPI Spec and Swagger UI

The Swagger/OpenAPI documentation is served as static files under:

Key points:


6. Current Status vs API_CLEANUP Plan

The docs/API_CLEANUP.md plan outlined a migration from the legacy /api/uploads.php script into a centralized MVC router and then toward cleaner, REST-style API URLs. That migration has largely happened at the implementation level (via src/index.php), while /api/uploads.php remains as a backward-compatible entrypoint.

What has been implemented:

What remains from the original plan:

Why prefer the canonical endpoints directly (/api/uploads, /api/uploads/{id}):

This document reflects the actual, deployed state, not just the plan, and treats /api/uploads / /api/uploads/{id} as the preferred public API URLs for uploads today.


7. Planned Enhancements

7.1 Deprecate /api/uploads.php and /api/

Goal:

Planned steps:

  1. Update upload forms to use /src/uploads
    • Change action in db/upload_form.php and db/upload_form_admin.php:
      • From: /api/uploads.php
      • To: /src/uploads
    • Verify that form submissions still succeed (since src/index.php is already the canonical handler for uploads).
  2. Maintain /api/uploads.php as a legacy alias temporarily
    • Keep the shim file in place so any hard-coded clients using /api/uploads.php continue to work.
    • Optionally add logging to measure remaining usage of the legacy path.
  3. Document deprecation in OpenAPI spec
    • In docs/openapi.yaml, mark the /uploads (or /api/uploads.php) path as deprecated: true once the new naming is introduced (see 7.2).
  4. Final cleanup (future)
    • After you are confident no clients depend on /api/uploads.php:
      • Remove api/uploads.php.
      • Remove the /api/ directory if it has no other responsibilities.
    • Update documentation to remove references to the legacy path.

7.2 Introduce /api/media-files GET/POST Endpoints

Goal:

Design principles:

7.2.1 PHP / Routing Plan

  1. Extend the router (src/index.php)
    • Add new routes that map to the existing upload and listing logic:
      • Public URLs: POST /api/media-files and GET /api/media-files.
      • Internally, after the router strips the /api prefix, it will match on /media-files and:
        • POST /media-files → same behavior as POST /uploads today.
        • GET /media-files → same JSON list behavior as GET /database.php?format=json.
    • Internally, ensure there is a single implementation of each behavior, with the new /media-files routes and the existing routes both calling into the same functions/services.
  2. Keep legacy URLs functioning
    • Continue to support:
      • Uploads via /src/uploads (and /api/uploads.php during the deprecation period).
      • Listings via /db/database.php and /db/database.php?format=json.
    • This allows a gradual migration of clients and documentation without forcing a breaking change.
  3. Apache auth and ModSecurity behavior
    • Authentication:
      • All /api/... paths already require Basic Auth (Require valid-user) via the main LocationMatch in default-ssl.conf.
      • Both /api/uploads.php and /api/media-files have a stricter Location block that limits access to admin and uploader users.
    • ModSecurity:
      • The ModSecurity template (modsecurity.conf.j2) is configured so that the upload-specific rules (large body limit, multipart/form-data requirement, disallowed extensions) apply to both /api/uploads.php and /api/media-files.

7.2.2 OpenAPI Spec Plan

  1. Add new path definitions to openapi.yaml
    • POST /api/media-files
      • Summary: “Upload media file”.
      • Request body: reuse the schema from the current upload endpoint.
      • Responses: mirror existing upload responses (including file metadata plus session information, errors, etc.).
      • operationId: uploadMediaFile.
    • GET /api/media-files
      • Summary: “Get media file list”.
      • Response: JSON array/object structure equivalent to what database.php?format=json returns today.
      • operationId: getMediaFileList.
  2. Mark legacy paths as deprecated
    • For the existing upload path and /database.php list path in openapi.yaml, add deprecated: true once /media-files is present and documented as the preferred interface.
    • Update descriptions to state that /media-files is the preferred endpoint for new integrations.

7.2.3 Documentation and Client Updates

  1. Docs
    • Update relevant Markdown in /docs (e.g., upload options, request flow diagrams) to reference /media-files as the primary API.
    • Clearly indicate that older paths remain available for backward compatibility during a transition period.
  2. Client code
    • When convenient, update any client integrations (curl examples, iOS app, admin tools) to call:
      • POST /media-files for uploads.
      • GET /media-files for listings.
  3. Migration window
    • Maintain both old and new paths for a defined period.
    • Once all important clients are updated and tested, consider:
      • Removing deprecated endpoints in a future major version, or
      • Keeping them as permanent aliases if the maintenance cost is low.

This document is intended to be the authoritative reference for what is currently implemented in the webroot API and how we plan to evolve it toward cleaner, REST-style endpoints while maintaining backward compatibility.