Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 4877ba3

Browse files
committed
Fix #1108: Caching issues for unoconv-generated previews of office files.
1 parent 94a5e24 commit 4877ba3

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

core/src/plugins/editor.diaporama/class.Diaporama.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,7 @@ Class.create("Diaporama", AbstractEditor, {
536536
updateImage : function(){
537537

538538
var node = this.nodes.get(this.currentFile);
539-
var mstring = '';
540-
if(node && node.getMetadata().get('ajxp_modiftime')){
541-
mstring = '&time_seed=' + node.getMetadata().get('ajxp_modiftime');
542-
}
539+
var mstring = this.buildRandomSeed(node);
543540

544541
if(node && node.getMetadata().get("image_dimensions_thumb")){
545542
var sizeLoader = new Image();
@@ -817,18 +814,22 @@ Class.create("Diaporama", AbstractEditor, {
817814

818815
getThumbnailSource : function(ajxpNode){
819816
var repoString = "";
820-
if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
817+
if(pydio.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != pydio.repositoryId){
821818
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
822819
}
820+
var mtimeString = this.buildRandomSeed(ajxpNode);
821+
return pydioBootstrap.parameters.get('ajxpServerAccess') + repoString + mtimeString + "&get_action=preview_data_proxy&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
822+
},
823+
824+
buildRandomSeed : function(ajxpNode){
823825
var mtimeString = "&time_seed=" + ajxpNode.getMetadata().get("ajxp_modiftime");
824-
var source = ajxpServerAccessPath + repoString + mtimeString + "&get_action=preview_data_proxy&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
825-
if(ajxpNode.getParent()){
826+
if(ajxpNode.getParent()){
826827
var preview_seed = ajxpNode.getParent().getMetadata().get('preview_seed');
827-
if(preview_seed){
828-
source += "&rand="+preview_seed;
829-
}
828+
if(preview_seed){
829+
mtimeString += "&rand="+preview_seed;
830+
}
830831
}
831-
return source;
832-
}
832+
return mtimeString;
833+
}
833834

834835
});

core/src/plugins/editor.imagick/class.IMagickPreviewer.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Class.create("IMagickPreviewer", Diaporama, {
3131
actions : {}
3232
}, editorOptions);
3333
$super(oFormObject, options);
34-
this.baseUrl = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=get_extracted_page&file=";
34+
this.baseUrl = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=get_extracted_page";
3535
// Override onload for the text
3636
this.jsImage.onload = function(){
3737
this.jsImageLoading = false;
@@ -53,6 +53,7 @@ Class.create("IMagickPreviewer", Diaporama, {
5353

5454
open : function($super, node)
5555
{
56+
this.inputNode = node;
5657
this.src_file = node.getPath();
5758
this.currentIM = getBaseName(this.src_file);
5859
// Extract the pages and load result!
@@ -170,11 +171,11 @@ Class.create("IMagickPreviewer", Diaporama, {
170171

171172
getThumbnailSource : function(ajxpNode){
172173
var repoString = "";
173-
if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
174+
if(pydio.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != pydio.repositoryId){
174175
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
175176
}
176-
var mtimeString = "&time_seed=" + ajxpNode.getMetadata().get("ajxp_modiftime");
177-
return ajxpServerAccessPath+"&get_action=imagick_data_proxy"+repoString + mtimeString +"&file="+encodeURIComponent(ajxpNode.getPath());
177+
var mtimeString = this.buildRandomSeed(ajxpNode);
178+
return pydioBootstrap.parameters.get('ajxpServerAccess') + "&get_action=imagick_data_proxy"+repoString + mtimeString +"&file="+encodeURIComponent(ajxpNode.getPath());
178179
},
179180

180181
setOnLoad: function() {
@@ -198,9 +199,10 @@ Class.create("IMagickPreviewer", Diaporama, {
198199
if(this.crtWidth){
199200
this.crtRatio = this.crtHeight / this.crtWidth;
200201
}
202+
var mstring = this.buildRandomSeed(this.inputNode);
201203
new Effect.Opacity(this.imgTag, {afterFinish : function(){
202204
this.jsImageLoading = true;
203-
this.jsImage.src = this.baseUrl + encodeURIComponent(this.currentFile) + "&src_file=" + this.src_file;
205+
this.jsImage.src = this.baseUrl + mstring + "&file=" + encodeURIComponent(this.currentFile) + "&src_file=" + this.src_file;
204206
if(!this.crtWidth && !this.crtHeight){
205207
this.crtWidth = this.imgTag.getWidth();
206208
this.crtHeight = this.imgTag.getHeight();

core/src/plugins/editor.imagick/class.IMagickPreviewer.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,34 @@ public function deleteImagickCache($oldNode, $newNode = null, $copy = false)
156156
// Should remove imagick cache file
157157
if(!$this->handleMime($oldFile)) return;
158158
if ($newNode == null || $copy == false) {
159+
160+
// Main Thumb
159161
AJXP_Cache::clearItem("imagick_thumb", $oldFile);
162+
163+
// Unoconv small PDF
164+
$thumbCache = AJXP_Cache::getItem("imagick_thumb", $oldFile, false);
165+
$unoFile = pathinfo($thumbCache->getId(), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.pathinfo($thumbCache->getId(), PATHINFO_FILENAME)."_unoconv.pdf";
166+
if(file_exists($unoFile)){
167+
unlink($unoFile);
168+
}
169+
160170
$cache = AJXP_Cache::getItem("imagick_full", $oldFile, false);
171+
// Unoconv full pdf
172+
$unoFile = pathinfo($cache->getId(), PATHINFO_DIRNAME).DIRECTORY_SEPARATOR.pathinfo($cache->getId(), PATHINFO_FILENAME)."_unoconv.pdf";
173+
if(file_exists($unoFile)){
174+
unlink($unoFile);
175+
}
161176
$prefix = str_replace(".".pathinfo($cache->getId(), PATHINFO_EXTENSION), "", $cache->getId());
177+
// Additional Extracted pages
162178
$files = $this->listExtractedJpg($oldFile, $prefix);
179+
$cacheDir = (defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/imagick_full";
163180
foreach ($files as $file) {
164-
if(is_file((defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/".$file["file"])) unlink(AJXP_CACHE_DIR."/".$file["file"]);
181+
if(is_file($cacheDir."/".$file["file"])) {
182+
unlink($cacheDir."/".$file["file"]);
183+
}
165184
}
185+
186+
166187
}
167188
}
168189

0 commit comments

Comments
 (0)