Skip to content

Commit

Permalink
[4.0] Media Manager: invalidate browser's cache (#34925)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko committed Jul 27, 2021
1 parent 9180bf3 commit 002ca82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Expand Up @@ -26,6 +26,7 @@ class Api {
this.audioExtensions = options.audioExtensions;
this.videoExtensions = options.videoExtensions;
this.documentExtensions = options.documentExtensions;
this.mediaVersion = (new Date().getTime()).toString();
}

/**
Expand Down
Expand Up @@ -8,7 +8,7 @@
<div class="image-background">
<div
class="image-cropped"
:style="{ backgroundImage: 'url(' + thumbUrl + ')' }"
:style="{ backgroundImage: getHashedURL }"
/>
</div>
</div>
Expand Down Expand Up @@ -187,6 +187,7 @@
</template>

<script>
import { api } from '../../../app/Api.es6';
import * as types from '../../../store/mutation-types.es6';
export default {
Expand All @@ -199,14 +200,17 @@ export default {
};
},
computed: {
/* Get the item url */
thumbUrl() {
return this.item.thumb_path;
},
/* Check if the item is an image to edit */
canEdit() {
return ['jpg', 'jpeg', 'png'].indexOf(this.item.extension.toLowerCase()) > -1;
},
/* Get the hashed URL */
getHashedURL() {
if (this.item.adapter.startsWith('local-')) {
return `url(${this.item.thumb_path}?${api.mediaVersion})`;
}
return `url(${this.item.thumb_path})`;
},
},
methods: {
/* Preview an item */
Expand Down
Expand Up @@ -40,7 +40,7 @@
/>
<img
v-if="isImage()"
:src="item.url"
:src="getHashedURL"
:type="item.mime_type"
>
</div>
Expand All @@ -58,6 +58,7 @@
</template>

<script>
import { api } from '../../app/Api.es6';
import * as types from '../../store/mutation-types.es6';
export default {
Expand All @@ -68,6 +69,13 @@ export default {
// Use the currently selected directory as a fallback
return this.$store.state.previewItem;
},
/* Get the hashed URL */
getHashedURL() {
if (this.item.adapter.startsWith('local-')) {
return `${this.item.url}?${api.mediaVersion}`;
}
return this.item.url;
},
},
methods: {
/* Close the modal */
Expand Down

0 comments on commit 002ca82

Please sign in to comment.