mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
fix: supprimer les vidéos PeerTube lors de la suppression d'un TFE
- Ajout de PeerTubeService::deleteVideo() qui appelle DELETE /api/v1/videos/{uuid}
- deleteThesisFileToTrash() appelle maintenant deleteVideo() pour les fichiers peertube_ids:
- hardDeleteThesis() supprime aussi les vidéos PeerTube associées
This commit is contained in:
@@ -1244,6 +1244,9 @@ trait ThesisFileHandler
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($filePath, 'peertube_ids:')) {
|
||||
$uuid = substr($filePath, strlen('peertube_ids:'));
|
||||
require_once __DIR__ . '/../PeerTubeService.php';
|
||||
PeerTubeService::deleteVideo($this->db, $uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2351,7 +2351,16 @@ class Database
|
||||
$storageRoot = defined('STORAGE_ROOT') ? STORAGE_ROOT : '/var/www/xamxam/storage';
|
||||
foreach ($files as $file) {
|
||||
$fp = $file['file_path'] ?? '';
|
||||
if ($fp === '' || str_starts_with($fp, 'http://') || str_starts_with($fp, 'https://') || str_starts_with($fp, 'peertube_ids:')) {
|
||||
if ($fp === '') {
|
||||
continue;
|
||||
}
|
||||
if (str_starts_with($fp, 'http://') || str_starts_with($fp, 'https://')) {
|
||||
continue;
|
||||
}
|
||||
if (str_starts_with($fp, 'peertube_ids:')) {
|
||||
$uuid = substr($fp, strlen('peertube_ids:'));
|
||||
require_once __DIR__ . '/PeerTubeService.php';
|
||||
PeerTubeService::deleteVideo($this, $uuid);
|
||||
continue;
|
||||
}
|
||||
$abs = $storageRoot . '/' . $fp;
|
||||
|
||||
@@ -265,6 +265,43 @@ class PeerTubeService
|
||||
return rtrim($s['instance_url'], '/') . '/videos/watch/' . $uuid;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Delete
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete a video from PeerTube by UUID or shortUUID.
|
||||
*
|
||||
* DELETE /api/v1/videos/{uuid}
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public static function deleteVideo(Database $db, string $uuid): bool
|
||||
{
|
||||
$s = self::getSettings($db);
|
||||
if ($s['instance_url'] === '') {
|
||||
error_log('PeerTubeService::deleteVideo: instance not configured');
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$token = self::obtainToken($s);
|
||||
$url = rtrim($s['instance_url'], '/') . '/api/v1/videos/' . urlencode($uuid);
|
||||
$resp = self::httpRequest($url, 'DELETE', [
|
||||
'headers' => ['Authorization' => 'Bearer ' . $token],
|
||||
'timeout' => 30,
|
||||
]);
|
||||
if ($resp['status'] === 204 || $resp['status'] === 200) {
|
||||
error_log('PeerTubeService: deleted video ' . $uuid);
|
||||
return true;
|
||||
}
|
||||
error_log('PeerTubeService::deleteVideo: unexpected status ' . $resp['status'] . ' for ' . $uuid . ' | body=' . substr($resp['body'], 0, 300));
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
error_log('PeerTubeService::deleteVideo failed: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Channel resolution
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user