mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
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:
@@ -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').
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user