Permalink
Browse files

Fix caching issues with ImagickPreviewer thumbnail and full extractio…

…ns, especially when using UNOCONV.
  • Loading branch information...
1 parent 9f41e24 commit 58a3c7a18c974737d1a61dd584d2478c1306e822 @cdujeu cdujeu committed Jun 29, 2016
@@ -536,10 +536,7 @@ Class.create("Diaporama", AbstractEditor, {
updateImage : function(){
var node = this.nodes.get(this.currentFile);
- var mstring = '';
- if(node && node.getMetadata().get('ajxp_modiftime')){
- mstring = '&time_seed=' + node.getMetadata().get('ajxp_modiftime');
- }
+ var mstring = this.buildRandomSeed(node);
if(node && node.getMetadata().get("image_dimensions_thumb")){
var sizeLoader = new Image();
@@ -817,18 +814,22 @@ Class.create("Diaporama", AbstractEditor, {
getThumbnailSource : function(ajxpNode){
var repoString = "";
- if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
+ if(pydio.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != pydio.repositoryId){
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
}
+ var mtimeString = this.buildRandomSeed(ajxpNode);
+ return pydioBootstrap.parameters.get('ajxpServerAccess') + repoString + mtimeString + "&get_action=preview_data_proxy&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
+ },
+
+ buildRandomSeed : function(ajxpNode){
var mtimeString = "&time_seed=" + ajxpNode.getMetadata().get("ajxp_modiftime");
- var source = ajxpServerAccessPath + repoString + mtimeString + "&get_action=preview_data_proxy&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
- if(ajxpNode.getParent()){
+ if(ajxpNode.getParent()){
var preview_seed = ajxpNode.getParent().getMetadata().get('preview_seed');
- if(preview_seed){
- source += "&rand="+preview_seed;
- }
+ if(preview_seed){
+ mtimeString += "&rand="+preview_seed;
+ }
}
- return source;
- }
+ return mtimeString;
+ }
});
@@ -187,12 +187,31 @@ public function deleteImagickCache($oldNode, $newNode = null, $copy = false)
// Should remove imagick cache file
if(!$this->handleMime($oldFile)) return;
if ($newNode == null || $copy == false) {
+
+ // Main Thumb
LocalCache::clearItem("imagick_thumb", $oldFile);
+
+ // Unoconv small PDF
+ $thumbCache = LocalCache::getItem("imagick_thumb", $oldFile, false);
+ $unoFile = pathinfo($thumbCache->getId(), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.pathinfo($thumbCache->getId(), PATHINFO_FILENAME)."_unoconv.pdf";
+ if(file_exists($unoFile)){
+ unlink($unoFile);
+ }
+
$cache = LocalCache::getItem("imagick_full", $oldFile, false);
+ // Unoconv full pdf
+ $unoFile = pathinfo($cache->getId(), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.pathinfo($cache->getId(), PATHINFO_FILENAME)."_unoconv.pdf";
+ if(file_exists($unoFile)){
+ unlink($unoFile);
+ }
$prefix = str_replace(".".pathinfo($cache->getId(), PATHINFO_EXTENSION), "", $cache->getId());
+ // Additional Extracted pages
$files = $this->listExtractedJpg($oldFile, $prefix);
+ $cacheDir = (defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/imagick_full";
foreach ($files as $file) {
- if(is_file((defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/".$file["file"])) unlink(AJXP_CACHE_DIR."/".$file["file"]);
+ if(is_file($cacheDir."/".$file["file"])) {
+ unlink($cacheDir."/".$file["file"]);
+ }
}
}
}
@@ -31,7 +31,7 @@ Class.create("IMagickPreviewer", Diaporama, {
actions : {}
}, editorOptions);
$super(oFormObject, options);
- this.baseUrl = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=get_extracted_page&file=";
+ this.baseUrl = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=get_extracted_page";
// Override onload for the text
this.jsImage.onload = function(){
this.jsImageLoading = false;
@@ -53,6 +53,7 @@ Class.create("IMagickPreviewer", Diaporama, {
open : function($super, node)
{
+ this.inputNode = node;
this.src_file = node.getPath();
this.currentIM = getBaseName(this.src_file);
// Extract the pages and load result!
@@ -170,11 +171,11 @@ Class.create("IMagickPreviewer", Diaporama, {
getThumbnailSource : function(ajxpNode){
var repoString = "";
- if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
+ if(pydio.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != pydio.repositoryId){
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
}
- var mtimeString = "&time_seed=" + ajxpNode.getMetadata().get("ajxp_modiftime");
- return ajxpServerAccessPath+"&get_action=imagick_data_proxy"+repoString + mtimeString +"&file="+encodeURIComponent(ajxpNode.getPath());
+ var mtimeString = this.buildRandomSeed(ajxpNode);
+ return pydioBootstrap.parameters.get('ajxpServerAccess') + "&get_action=imagick_data_proxy"+repoString + mtimeString +"&file="+encodeURIComponent(ajxpNode.getPath());
},
setOnLoad: function() {
@@ -198,9 +199,10 @@ Class.create("IMagickPreviewer", Diaporama, {
if(this.crtWidth){
this.crtRatio = this.crtHeight / this.crtWidth;
}
+ var mstring = this.buildRandomSeed(this.inputNode);
new Effect.Opacity(this.imgTag, {afterFinish : function(){
this.jsImageLoading = true;
- this.jsImage.src = this.baseUrl + encodeURIComponent(this.currentFile) + "&src_file=" + this.src_file;
+ this.jsImage.src = this.baseUrl + mstring + "&file=" + encodeURIComponent(this.currentFile) + "&src_file=" + this.src_file;
if(!this.crtWidth && !this.crtHeight){
this.crtWidth = this.imgTag.getWidth();
this.crtHeight = this.imgTag.getHeight();

0 comments on commit 58a3c7a

Please sign in to comment.