ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
refactor(ftp): extract FTP backend into serverkit-ftp builtin extension
Juan Denis2a060c518dc5
diff --git a/backend/app/__init__.py b/backend/app/__init__.pyindex 19e297fd..9d3a29a4 100644--- a/backend/app/__init__.py+++ b/backend/app/__init__.py@@ -248,9 +248,9 @@ def create_app(config_name=None):from app.api.files import files_bpapp.register_blueprint(files_bp, url_prefix='/api/v1/files')- # Register blueprints - FTP Server- from app.api.ftp import ftp_bp- app.register_blueprint(ftp_bp, url_prefix='/api/v1/ftp')+ # FTP Server is an opt-in builtin extension (serverkit-ftp, plan 47) — its+ # blueprint loads from builtin-extensions/serverkit-ftp/ when installed, not+ # from core. A fresh panel that never touches FTP loads none of it.# Register blueprints - Firewallfrom app.api.firewall import firewall_bpdiff --git a/backend/tests/test_ftp_extraction.py b/backend/tests/test_ftp_extraction.pynew file mode 100644index 00000000..e28b8d29--- /dev/null+++ b/backend/tests/test_ftp_extraction.py@@ -0,0 +1,76 @@+"""Prove the FTP extraction (plan 47 Phase 2).++A fresh panel no longer carries the FTP API in core; installing the+serverkit-ftp builtin registers `/api/v1/ftp` and its routes respond (which also+exercises the extension's relative-import rewiring). Uninstall removes it again.+"""+import sys++import pytest++import app as app_pkg+from app.models.plugin import InstalledPlugin+from app.services import plugin_service++SLUG = 'serverkit-ftp'+_PKG = f'app.plugins.{SLUG}'+++def test_core_has_no_ftp_routes(app):+ rules = [r.rule for r in app.url_map.iter_rules()]+ assert [r for r in rules if r.startswith('/api/v1/ftp')] == []+++def test_core_import_of_ftp_service_is_gone():+ """The FTP service left core — importing it from app.services must fail."""+ import importlib+ with pytest.raises(ModuleNotFoundError):+ importlib.import_module('app.services.ftp_service')+++def test_ftp_in_converted_builtin_slugs():+ from app.services.extension_migration import CONVERTED_BUILTIN_SLUGS+ assert SLUG in CONVERTED_BUILTIN_SLUGS+++def install_dirs(tmp_path, monkeypatch):+ backend = tmp_path / 'plugins_backend'+ frontend = tmp_path / 'plugins_frontend'+ backend.mkdir()+ frontend.mkdir()+ monkeypatch.setattr(plugin_service, 'BACKEND_PLUGINS_DIR', str(backend))+ monkeypatch.setattr(plugin_service, 'FRONTEND_PLUGINS_DIR', str(frontend))++ added = str(backend)+ import importlib+ app_pkg_plugins = importlib.import_module('app.plugins')+ if added not in app_pkg_plugins.__path__:+ app_pkg_plugins.__path__.append(added)++ yield {'backend': backend, 'frontend': frontend}++ if added in app_pkg_plugins.__path__:+ app_pkg_plugins.__path__.remove(added)+ for name in list(sys.modules):+ if name == _PKG or name.startswith(_PKG + '.'):+ del sys.modules[name]+++def test_install_ftp_extension_registers_routes(app, client, auth_headers, install_dirs):+ available = {e['slug'] for e in plugin_service.list_builtin_extensions()}+ assert SLUG in available, 'serverkit-ftp builtin folder should exist'++ plugin = plugin_service.install_builtin_extension(SLUG)+ assert plugin.status == InstalledPlugin.STATUS_ACTIVE+ assert plugin.has_backend is True+ assert plugin.url_prefix == '/api/v1/ftp'++ resp = client.get('/api/v1/ftp/status', headers=auth_headers)+ assert resp.status_code not in (404, 503), resp.status_code+++def test_uninstall_removes_ftp_plugin(app, install_dirs):+ plugin = plugin_service.install_builtin_extension(SLUG)+ assert plugin_service.uninstall_plugin(plugin.id) is True+ assert InstalledPlugin.query.filter_by(slug=SLUG).first() is Nonediff --git a/builtin-extensions/serverkit-ftp/backend/__init__.py b/builtin-extensions/serverkit-ftp/backend/__init__.pynew file mode 100644index 00000000..a4514248--- /dev/null+++ b/builtin-extensions/serverkit-ftp/backend/__init__.py@@ -0,0 +1,10 @@+"""ServerKit FTP extension backend package.++Extracted from core (plan 47): the FTP blueprint + service ship here so a fresh+panel that never touches FTP loads none of it. Mounted under ``/api/v1/ftp`` via+the manifest's ``url_prefix``; upgrades re-acquire it automatically+(``CONVERTED_BUILTIN_SLUGS``).+"""+from .ftp import ftp_bp++__all__ = ['ftp_bp']diff --git a/backend/app/api/ftp.py b/builtin-extensions/serverkit-ftp/backend/ftp.pysimilarity index 98%rename from backend/app/api/ftp.pyrename to builtin-extensions/serverkit-ftp/backend/ftp.pyindex 48e5bd09..8f304031 100644--- a/backend/app/api/ftp.py+++ b/builtin-extensions/serverkit-ftp/backend/ftp.py@@ -2,8 +2,8 @@from flask import Blueprint, request, jsonify-from ..middleware.rbac import admin_required, viewer_required-from ..services.ftp_service import FTPService+from app.middleware.rbac import admin_required, viewer_required+from .ftp_service import FTPServiceftp_bp = Blueprint('ftp', __name__)diff --git a/backend/app/services/ftp_service.py b/builtin-extensions/serverkit-ftp/backend/ftp_service.pysimilarity index 100%rename from backend/app/services/ftp_service.pyrename to builtin-extensions/serverkit-ftp/backend/ftp_service.pydiff --git a/builtin-extensions/serverkit-ftp/plugin.json b/builtin-extensions/serverkit-ftp/plugin.jsonindex 3f8ddc9f..6ec9d253 100644--- a/builtin-extensions/serverkit-ftp/plugin.json+++ b/builtin-extensions/serverkit-ftp/plugin.json@@ -8,6 +8,8 @@"category": "utility","homepage": "https://github.com/jhd3197/ServerKit","permissions": ["shell", "filesystem"],+ "entry_point": "ftp:ftp_bp",+ "url_prefix": "/api/v1/ftp","icon": "<rect x=\"16\" y=\"16\" width=\"6\" height=\"6\" rx=\"1\"/><rect x=\"2\" y=\"16\" width=\"6\" height=\"6\" rx=\"1\"/><rect x=\"9\" y=\"2\" width=\"6\" height=\"6\" rx=\"1\"/><path d=\"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3\"/><path d=\"M12 12V8\"/>","contributions": {"tabs": [