Extend clean up expired shared entries

This commit is contained in:
Ryan
2025-05-04 02:28:33 -04:00
committed by GitHub
parent 8d6a1be777
commit bde35d1d31
5 changed files with 131 additions and 50 deletions

View File

@@ -1582,6 +1582,31 @@ class FileController
echo json_encode($shareFile, JSON_PRETTY_PRINT);
}
public function getAllShareLinks(): void
{
header('Content-Type: application/json');
$shareFile = META_DIR . 'share_links.json';
$links = file_exists($shareFile)
? json_decode(file_get_contents($shareFile), true) ?? []
: [];
$now = time();
$cleaned = [];
// remove expired
foreach ($links as $token => $record) {
if (!empty($record['expires']) && $record['expires'] < $now) {
continue;
}
$cleaned[$token] = $record;
}
if (count($cleaned) !== count($links)) {
file_put_contents($shareFile, json_encode($cleaned, JSON_PRETTY_PRINT));
}
echo json_encode($cleaned);
}
/**
* POST /api/file/deleteShareLink.php
*/

View File

@@ -1082,11 +1082,30 @@ class FolderController
/**
* GET /api/folder/getShareFolderLinks.php
*/
public function getShareFolderLinks()
public function getAllShareFolderLinks(): void
{
header('Content-Type: application/json');
$links = FolderModel::getAllShareFolderLinks();
echo json_encode($links, JSON_PRETTY_PRINT);
$shareFile = META_DIR . 'share_folder_links.json';
$links = file_exists($shareFile)
? json_decode(file_get_contents($shareFile), true) ?? []
: [];
$now = time();
$cleaned = [];
// 1) Remove expired
foreach ($links as $token => $record) {
if (!empty($record['expires']) && $record['expires'] < $now) {
continue;
}
$cleaned[$token] = $record;
}
// 2) Persist back if anything was pruned
if (count($cleaned) !== count($links)) {
file_put_contents($shareFile, json_encode($cleaned, JSON_PRETTY_PRINT));
}
echo json_encode($cleaned);
}
/**