feat: dual upload system — direct file storage + PeerTube API integration

Adds a parallel PeerTube upload system behind a feature flag (disabled by default
until upload quota is granted). When disabled, the existing direct file upload
path works unchanged.

Files:
- src/PeerTubeService.php — credential storage (encrypted), OAuth2 token
  retrieval, multipart upload to /api/v1/videos/upload
- migrations/021_peertube_settings.sql — peertube_settings singleton table
  + peertube_upload_enabled site_setting (default 0)
- admin/actions/settings.php — peertube section handler
- admin/parametres.php / templates/admin/parametres.php — PeerTube UI section
- partage/fichiers-fragment.php — shows file inputs when enabled, TODO notice otherwise
- ThesisCreateController / ThesisEditController — handlePeerTubeUpload()
- tfe.php — PeerTube iframe embed detection
- AdminLogger — logPeerTubeUpdate()
This commit is contained in:
Pontoporeia
2026-05-08 16:48:34 +02:00
parent 11e61226e2
commit 03c5fd217e
12 changed files with 658 additions and 4 deletions

View File

@@ -220,6 +220,10 @@ class ThesisCreateController
$this->handleCoverUpload($thesisId, $files['couverture'] ?? null);
$this->handleThesisFiles($thesisId, $data['annee'], $identifier, $files['files'] ?? null, $authorSlug, $post);
// ── 5b. PeerTube video / audio uploads ────────────────────────────────
$this->handlePeerTubeUpload($thesisId, $data['titre'], $files, 'peertube_video');
$this->handlePeerTubeUpload($thesisId, $data['titre'], $files, 'peertube_audio');
// ── 6. Website URL — stored as thesis_files row ──────────────────────
$this->handleWebsiteUrl($thesisId, $post);
@@ -834,6 +838,52 @@ class ThesisCreateController
return $candidate;
}
/**
* Upload a video or audio file to PeerTube when the feature is enabled.
*
* @param int $thesisId Thesis to attach the result to.
* @param string $title Title to use on PeerTube.
* @param array $files $_FILES array.
* @param string $inputName 'peertube_video' or 'peertube_audio'.
*/
protected function handlePeerTubeUpload(int $thesisId, string $title, array $files, string $inputName): void
{
$upload = $files[$inputName] ?? null;
if (!$upload || !isset($upload['error']) || $upload['error'] !== UPLOAD_ERR_OK) {
return;
}
require_once APP_ROOT . '/src/PeerTubeService.php';
if (!PeerTubeService::isEnabled($this->db)) {
return;
}
try {
$watchUrl = PeerTubeService::upload(
$this->db,
$upload['tmp_name'],
$title,
''
);
$fileType = str_contains($inputName, 'audio') ? 'audio' : 'video';
$this->db->insertThesisFile(
$thesisId,
$fileType,
$watchUrl, // stored as the watch URL (no local file)
basename($upload['name']),
$upload['size'],
$upload['type'] ?? 'application/octet-stream',
null,
null
);
error_log("ThesisCreateController: PeerTube upload OK → $watchUrl");
} catch (\Throwable $e) {
error_log('ThesisCreateController: PeerTube upload failed — ' . $e->getMessage());
// Non-fatal: the thesis is already saved; admin can re-upload manually.
}
}
/**
* Store a website URL as a thesis_files row (file_type = 'website').
*