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:
@@ -334,6 +334,10 @@ class ThesisEditController
|
||||
$this->handleThesisFiles($thesisId, $post, $files['files']);
|
||||
}
|
||||
|
||||
// ── PeerTube video / audio uploads ────────────────────────────────────
|
||||
$this->handlePeerTubeUpload($thesisId, trim($post['titre'] ?? ''), $files, 'peertube_video');
|
||||
$this->handlePeerTubeUpload($thesisId, trim($post['titre'] ?? ''), $files, 'peertube_audio');
|
||||
|
||||
// ── Website URL — add or update ──────────────────────────────────────
|
||||
$this->handleWebsiteUrl($thesisId, $post);
|
||||
}
|
||||
@@ -685,6 +689,51 @@ class ThesisEditController
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'.
|
||||
*/
|
||||
private 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,
|
||||
basename($upload['name']),
|
||||
$upload['size'],
|
||||
$upload['type'] ?? 'application/octet-stream',
|
||||
null,
|
||||
null
|
||||
);
|
||||
error_log("ThesisEditController: PeerTube upload OK → $watchUrl");
|
||||
} catch (\Throwable $e) {
|
||||
error_log('ThesisEditController: PeerTube upload failed — ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a website URL thesis_file row.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user