Editor Info - thepoopooman652/proishs-webtools GitHub Wiki

Editor — web-based file editor

Overview

This folder implements a single-page web-based file editor with a front-end UI and a server-side JSON API. The editor provides a file list view, text editing (CodeMirror), file upload, file creation, file deletion (soft-delete), and binary file streaming for media types.

Repository contents

  • index.php — Front-end UI. Uses CodeMirror for editing text files and includes client-side logic to display a file tree, handle uploads, and stream binary files. The UI supports single- and multi-file uploads and inline viewing of images, audio, video, and PDFs.
  • api.php — Server-side router exposing JSON endpoints and binary streaming behavior. Implemented actions include list-files, get-content, create-file, save-file, upload-file, and delete-file.
  • files/ — Storage area containing shared files and per-user folders. The default configured base directory is __DIR__ . '/files/'.

API reference

GET api.php?action=list-files

  • Returns a JSON object with files (array) and user_ip.
  • Each file entry contains: name, path, size (bytes), type (MIME type), and readonly (boolean).

GET api.php?action=get-content&path=<path>

  • For text-like files returns JSON:
{
	"success": true,
	"content": "...",
	"mime": "text/plain"
}
  • For binary files the endpoint streams the file with the appropriate Content-Type and Content-Length headers.

POST api.php?action=create-file

  • Parameters: filename (string). Creates an empty file under the caller's directory and returns a JSON success message with path.

POST api.php?action=save-file

  • Parameters: path, content. Writes content to the resolved path and returns a JSON status object.

POST api.php?action=upload-file

  • Multipart field: uploadedFile. Accepts an uploaded file and moves it into the caller's folder. Returns JSON with operation status.

POST api.php?action=delete-file

  • Parameters: path. Performs a soft delete by moving the file into a deleted-files/ subfolder with a timestamped name and returns a JSON status object.

Data models and conventions

  • File paths returned by list-files use either the root path (for shared files) or user_ip/filename for per-user entries.
  • MIME types are derived via mime_content_type() when available; empty files are labeled text/plain.

Client examples

Fetch file list (browser):

fetch('api.php?action=list-files')
	.then(r => r.json())
	.then(data => console.log(data.files));

Save a file (client):

const form = new FormData();
form.append('path', '127.0.0.1/myfile.txt');
form.append('content', 'New content');
fetch('api.php?action=save-file', { method: 'POST', body: form })
	.then(r => r.json())
	.then(res => console.log(res));

Developer guidance

  • The front-end in index.php uses CodeMirror modes to determine editing behavior based on MIME type; mode detection is performed with CodeMirror.findModeByMIME().
  • The server-side get_safe_path() function canonicalizes and validates file paths; it resolves paths using realpath() and only accepts files within the configured FILES_BASE_DIR or the per-user directory.
  • Per-user folders follow the pattern files/<REMOTE_ADDR>/ by default. Alternate user identification mechanisms can be used by adapting the server-side code responsible for user_dir computation.

Testing and local run

Run the built-in PHP server from the editor directory to exercise the UI and API locally:

cd 'C:\Users\Administrator\Documents\GitHub\proish-webtools\editor'
php -S 127.0.0.1:8000 -t .

Open http://127.0.0.1:8000/index.php and exercise: file listing, open/save of text files, uploads, and viewing of media files.

Changelog

  • 2025-11-06: Documented API contract, client usage examples, and developer guidance for path resolution and client integration.

Notes

This README provides a reference for integrating with the editor UI and server-side API and documents the expected request/response shapes for programmatic interaction.

⚠️ **GitHub.com Fallback** ⚠️