Browse Source

Support files inside shared folders

tags/v0.1.0
Gerben 6 years ago
parent
commit
2156a198ef
1 changed files with 17 additions and 3 deletions
  1. +17
    -3
      lib/Controller/findMementos.php

+ 17
- 3
lib/Controller/findMementos.php View File

@@ -92,9 +92,14 @@ function findPublicMementos($shareManager, $userId) {
-1 /* no limit */ -1 /* no limit */
); );


$urlForShare = function ($share) {
$urlForSharedFile = function ($share) {
return "/apps/raw/s/" . $share->getToken(); // XXX hardcoded dependency return "/apps/raw/s/" . $share->getToken(); // XXX hardcoded dependency
}; };
$urlForFileInsideSharedFolder = function ($share, $folder, $file) {
$absoluteFilePath = $file->getPath();
$relativeFilePath = $folder->getRelativePath($absoluteFilePath);
return joinPaths("/apps/raw/s/{$share->getToken()}", $relativeFilePath);
};


// Look into every shared file to see if it is a memento. // Look into every shared file to see if it is a memento.
$foundMementos = []; $foundMementos = [];
@@ -103,11 +108,20 @@ function findPublicMementos($shareManager, $userId) {
if ($node->getType() === FileInfo::TYPE_FILE) { if ($node->getType() === FileInfo::TYPE_FILE) {
$mementoInfo = extractMementoInfo($node); $mementoInfo = extractMementoInfo($node);
if ($mementoInfo) { if ($mementoInfo) {
$mementoInfo['mementoUrl'] = $urlForShare($share);
$mementoInfo['mementoUrl'] = $urlForSharedFile($share);
$foundMementos[] = $mementoInfo; $foundMementos[] = $mementoInfo;
} }
} else { } else {
// TODO add files inside shared folders? How to make URLs for those?
// Share is a folder: Go through all html files inside the shared folder.
$folder = $node;
$files = $folder->searchByMime('text/html');
foreach ($files as $file) {
$mementoInfo = extractMementoInfo($file);
if ($mementoInfo) {
$mementoInfo['mementoUrl'] = $urlForFileInsideSharedFolder($share, $folder, $file);
$foundMementos[] = $mementoInfo;
}
}
} }
} }
return $foundMementos; return $foundMementos;


Loading…
Cancel
Save