Fix filename for shared folders

old-stable24^2
Varun Patil 2022-10-28 18:29:28 -07:00
parent cd2f714e92
commit 2c40f8d57e
2 changed files with 44 additions and 37 deletions

View File

@ -87,13 +87,8 @@ class ApiController extends Controller
*/ */
public function days(): JSONResponse public function days(): JSONResponse
{ {
$user = $this->userSession->getUser();
if (null === $user && !$this->getShareToken()) {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}
$uid = $user ? $user->getUID() : '';
// Get the folder to show // Get the folder to show
$uid = $this->getUid();
$folder = null; $folder = null;
try { try {
@ -122,7 +117,7 @@ class ApiController extends Controller
); );
// Preload some day responses // Preload some day responses
$this->preloadDays($list, $folder, $recursive, $archive); $this->preloadDays($list, $uid, $folder, $recursive, $archive);
// Add subfolder info if querying non-recursively // Add subfolder info if querying non-recursively
if (!$recursive) { if (!$recursive) {
@ -157,11 +152,8 @@ class ApiController extends Controller
*/ */
public function day(string $id): JSONResponse public function day(string $id): JSONResponse
{ {
$user = $this->userSession->getUser(); // Get user
if (null === $user && !$this->getShareToken()) { $uid = $this->getUid();
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}
$uid = $user ? $user->getUID() : '';
// Check for wildcard // Check for wildcard
$day_ids = []; $day_ids = [];
@ -698,6 +690,19 @@ class ApiController extends Controller
return $response; return $response;
} }
/** Get logged in user's UID or throw HTTP error */
private function getUid(): string
{
$user = $this->userSession->getUser();
if ($this->getShareToken()) {
$user = null;
} elseif (null === $user) {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}
return $user ? $user->getUID() : '';
}
/** /**
* Get transformations depending on the request. * Get transformations depending on the request.
* *
@ -768,15 +773,13 @@ class ApiController extends Controller
* Preload a few "day" at the start of "days" response. * Preload a few "day" at the start of "days" response.
* *
* @param array $days the days array * @param array $days the days array
* @param string $uid User ID or blank for public shares
* @param null|Folder $folder the folder to search in * @param null|Folder $folder the folder to search in
* @param bool $recursive search in subfolders * @param bool $recursive search in subfolders
* @param bool $archive search in archive folder only * @param bool $archive search in archive folder only
*/ */
private function preloadDays(array &$days, &$folder, bool $recursive, bool $archive) private function preloadDays(array &$days, string $uid, &$folder, bool $recursive, bool $archive)
{ {
$user = $this->userSession->getUser();
$uid = $user ? $user->getUID() : '';
$transforms = $this->getTransformations(false); $transforms = $this->getTransformations(false);
$preloaded = 0; $preloaded = 0;
$preloadDayIds = []; $preloadDayIds = [];
@ -822,9 +825,7 @@ class ApiController extends Controller
/** Get the Folder object relevant to the request */ /** Get the Folder object relevant to the request */
private function getRequestFolder() private function getRequestFolder()
{ {
$user = $this->userSession->getUser(); // Public shared folder
if (null === $user) {
// Public shares only
if ($token = $this->getShareToken()) { if ($token = $this->getShareToken()) {
$share = $this->shareManager->getShareByToken($token)->getNode(); // throws exception if not found $share = $this->shareManager->getShareByToken($token)->getNode(); // throws exception if not found
if (!$share instanceof Folder) { if (!$share instanceof Folder) {
@ -834,9 +835,11 @@ class ApiController extends Controller
return $share; return $share;
} }
// Anything else needs a user
$user = $this->userSession->getUser();
if (null === $user) {
return null; return null;
} }
$uid = $user->getUID(); $uid = $user->getUID();
$folder = null; $folder = null;

View File

@ -136,7 +136,7 @@ trait TimelineQueryDays
$rows = $cursor->fetchAll(); $rows = $cursor->fetchAll();
$cursor->closeCursor(); $cursor->closeCursor();
return $this->processDay($rows, $folder); return $this->processDay($rows, $uid, $folder);
} }
/** /**
@ -158,12 +158,13 @@ trait TimelineQueryDays
* Process the single day response. * Process the single day response.
* *
* @param array $day * @param array $day
* @param string $uid User or blank if not logged in
* @param null|Folder $folder * @param null|Folder $folder
*/ */
private function processDay(&$day, $folder) private function processDay(&$day, $uid, $folder)
{ {
$basePath = '#__#__#'; $basePath = '#__#__#';
$davPath = '/'; $davPath = '';
if (null !== $folder) { if (null !== $folder) {
// No way to get the internal path from the folder // No way to get the internal path from the folder
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
@ -177,6 +178,8 @@ trait TimelineQueryDays
// Get user facing path // Get user facing path
// getPath looks like /user/files/... but we want /files/user/... // getPath looks like /user/files/... but we want /files/user/...
// Split at / and swap these // Split at / and swap these
// For public shares, we just give the relative path
if (!empty($uid)) {
$actualPath = $folder->getPath(); $actualPath = $folder->getPath();
$actualPath = explode('/', $actualPath); $actualPath = explode('/', $actualPath);
if (\count($actualPath) >= 3) { if (\count($actualPath) >= 3) {
@ -186,6 +189,7 @@ trait TimelineQueryDays
$davPath = implode('/', $actualPath); $davPath = implode('/', $actualPath);
} }
} }
}
foreach ($day as &$row) { foreach ($day as &$row) {
// We don't need date taken (see query builder) // We don't need date taken (see query builder)