Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-80: WebArchiving my old friend #81

Merged
merged 12 commits into from Jul 6, 2020
12 changes: 11 additions & 1 deletion format_strawberryfield.libraries.yml
Expand Up @@ -184,4 +184,14 @@ leaflet_strawberry:
- core/jquery
- core/drupal
- core/drupalSettings
- format_strawberryfield/leaflet_ajax
- format_strawberryfield/leaflet_ajax
# Don't forget to update \Drupal\format_strawberryfield\Controller\JsWorkerController::servereplay
# when moving versions up!
replayweb:
version: 1.0
license:
name: AGPLv3
url: https://github.com/webrecorder/replayweb.page/blob/master/LICENSE
gpl-compatible: true
js:
https://cdn.jsdelivr.net/npm/replaywebpage@1.0.1/ui.js: { external: true, minified: true, preprocess: false}
7 changes: 6 additions & 1 deletion format_strawberryfield.module
Expand Up @@ -92,8 +92,13 @@ function format_strawberryfield_theme() {
*/
function format_strawberryfield_file_mimetype_mapping_alter(&$mapping) {
// Add relevant Repository Mimetypes missing from D8
$mapping['mimetypes']['obj_model_mimetype'] = 'model/obj';
$mapping['mimetypes']['webarchive_mimetype'] = 'application/warc';
$mapping['extensions']['obj'] = 'obj_model_mimetype';
$mapping['extensions']['warc'] = 'webarchive_mimetype';
$mapping['extensions']['wacz'] = 'webarchive_mimetype';
$mapping['extensions']['warc.gz'] = 'webarchive_mimetype';
// @see https://www.iana.org/assignments/media-types/media-types.xhtml
$mapping['mimetypes']['obj_model_mimetype'] = 'model/obj';


}
18 changes: 18 additions & 0 deletions format_strawberryfield.routing.yml
Expand Up @@ -114,3 +114,21 @@ format_strawberryfield.view_mode_mapping_settings_form:
_permission: 'access administration pages'
options:
_admin_route: TRUE

# Direct File access for replayweb JS Worker
# This file will be called by replayweb library and needs to exist in that exact path
# Reason why we went for a controller. Just an overhead!
format_strawberryfield.replayweb:
path: '/replay/sw.js'
methods: [GET]
defaults:
_controller: '\Drupal\format_strawberryfield\Controller\JsWorkerController::servereplay'
requirements:
_permission: 'access content'
format_strawberryfield.replayweb_index:
path: '/replay/index.html'
methods: [GET]
defaults:
_controller: '\Drupal\format_strawberryfield\Controller\JsWorkerController::serveindex'
requirements:
_permission: 'access content'
59 changes: 59 additions & 0 deletions src/Controller/JsWorkerController.php
@@ -0,0 +1,59 @@
<?php

namespace Drupal\format_strawberryfield\Controller;


use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Response;


/**
* A JS Worker Static JS controller.
*/
class JsWorkerController extends ControllerBase {


/**
* Serves 'statically' the replay web JS Worker file.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function servereplay() {
$response = new Response(
'importScripts("https://cdn.jsdelivr.net/npm/replaywebpage@1.0.1/sw.js");'
);
// Alternative https://unpkg.com/replaywebpage@1.0.0/sw.js
$response->headers->set('Content-Type', 'text/javascript');
return $response;
}

/**
* Serves 'statically' Index to avoid failure while worker is warmin up.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function serveindex() {

$index = <<<'EOD'
<!doctype html>
<html class="no-overflow">
<head>
<link rel="manifest" href="/webmanifest.json">
<link rel="icon" href="build/icon.png" type="image/png" />
<title>ReplayWeb.page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./ui.js"></script>
</head>
<body>
<replay-app-main></replay-app-main>
</body>
</html>;
EOD;
$response = new Response($index);
$response->headers->set('Content-Type', 'text/html');
return $response;

}


}
4 changes: 2 additions & 2 deletions src/Plugin/Field/FieldFormatter/StrawberryMediaFormatter.php
Expand Up @@ -13,6 +13,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\format_strawberryfield\Tools\IiifHelper;
use Drupal\strawberryfield\Tools\StrawberryfieldJsonHelper;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
/**
* Simplistic Strawberry Field formatter.
*
Expand Down Expand Up @@ -192,9 +193,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
}
if ($this->checkAccess($file)) {
$iiifidentifier = urlencode(
file_uri_target($file->getFileUri())
StreamWrapperManager::getTarget($file->getFileUri())
);
//@TODO replace with \Drupal::service('stream_wrapper_manager')->getTarget()
if ($iiifidentifier == NULL || empty($iiifidentifier)) {
continue;
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
use Drupal\format_strawberryfield\Tools\IiifHelper;
use Drupal\file\FileInterface;
use Drupal\strawberryfield\Tools\StrawberryfieldJsonHelper;
use Drupal\Core\StreamWrapper\StreamWrapperManager;

/**
* Simplistic Strawberry Field formatter.
Expand Down Expand Up @@ -260,7 +261,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
// we should inform to logs and continue
if ($this->checkAccess($file)) {
$iiifidentifier = urlencode(
file_uri_target($file->getFileUri())
StreamWrapperManager::getTarget($file->getFileUri())
);

if ($iiifidentifier == NULL || empty($iiifidentifier)) {
Expand Down