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

View File

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