Browse Source

Work around nextcloud's slash deduplication.

tags/v0.1.0
Gerben 2 years ago
parent
commit
b690d7aae1
4 changed files with 19 additions and 7 deletions
  1. +3
    -0
      lib/Controller/TimeGateController.php
  2. +3
    -2
      lib/Controller/TimeMapController.php
  3. +0
    -5
      lib/Controller/findMementos.php
  4. +13
    -0
      lib/Controller/getUrlParameter.php

+ 3
- 0
lib/Controller/TimeGateController.php View File

@@ -3,6 +3,7 @@ namespace OCA\Memento\Controller;

require_once __DIR__ . '/findMementos.php';
require_once __DIR__ . '/datetimeConversion.php';
require_once __DIR__ . '/getUrlParameter.php';

use OCP\IRequest;
use OCP\IURLGenerator;
@@ -32,6 +33,8 @@ class TimeGateController extends Controller {
* @NoCSRFRequired
*/
public function timeGate($url) {
$url = getUrlParameter('timegate'); // XXX workaround, as nextcloud corrupts the $url parameter.

$matchingMementos = findMementos($this->userFolder, $url);

// Choose one of the matched mementos, if any.


+ 3
- 2
lib/Controller/TimeMapController.php View File

@@ -3,6 +3,7 @@ namespace OCA\Memento\Controller;

require_once __DIR__ . '/findMementos.php';
require_once __DIR__ . '/datetimeConversion.php';
require_once __DIR__ . '/getUrlParameter.php';

use OCP\IRequest;
use OCP\IServerContainer;
@@ -10,7 +11,6 @@ use OCP\IURLGenerator;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataDisplayResponse;


class TimeMapController extends Controller {
private $userFolder;
private $URLGenerator;
@@ -32,6 +32,8 @@ class TimeMapController extends Controller {
* @NoCSRFRequired
*/
public function timeMap($url) {
$url = getUrlParameter('timemap'); // XXX workaround, as nextcloud corrupts the $url parameter.

$matchingMementos = findMementos($this->userFolder, $url);

// Build the list of links.
@@ -46,7 +48,6 @@ class TimeMapController extends Controller {
$lastDatetime = datetimeTimestampToString($lastMemento['datetime']);
}
$links = [
// FIXME Our $url param has its duplicate slashes removed, so it looks like 'http:/abc'.
"<$url>;rel=\"original\"",
"<$timeGateUrl>;rel=\"timegate\"",
"<$timeMapUrl>;rel=\"self\";type=\"application/link-format\"" .


+ 0
- 5
lib/Controller/findMementos.php View File

@@ -91,10 +91,5 @@ function getDatetime($headElement) {
function normaliseUrl($url) {
// Ignore trailing slashes. Because everybody does.
$url = rtrim($url, '/');

// HACK. Replace multiple slashes with a single one. Because Nextcloud will have already done this
// to the queried url (e.g. 'http://abc' arrives to us as 'http:/abc').
$url = preg_replace('%/{2,}%', '/', $url);

return $url;
}

+ 13
- 0
lib/Controller/getUrlParameter.php View File

@@ -0,0 +1,13 @@
<?php
// Nextcloud deduplicates subsequent slashes in the path, so our $url route parameter will have been
// corrupted to http:/something. As a workaround, we manually read the URL from the unmodified path.
function getUrlParameter($routeName) {
$path = $_SERVER['REQUEST_URI'];
$routePath = "apps/memento/$routeName/"; // (presumably nobody has this string in their web root)
$index = strpos($path, $routePath);
if ($index === false) {
throw new Exception("Cannot get URL parameter from unexpected path '$path'.");
}
$url = substr($path, $index + strlen($routePath));
return $url;
}

Loading…
Cancel
Save