Commit c49e48a7 by Jonathan Thomas

Added sessionStorage to blob image thumbnails (caching them for a session).…

Added sessionStorage to blob image thumbnails (caching them for a session). Reloading the browser tab seems to clear the blob URLs, causing 404s, and then the thumbnails are regenerated. Also made image thumbnail 100% width by default.
parent 2481761d
...@@ -313,4 +313,7 @@ video { ...@@ -313,4 +313,7 @@ video {
width: 100%; width: 100%;
padding: 0.15em; padding: 0.15em;
} }
.img-thumbnail {
width: 100%!important;
}
</style> </style>
\ No newline at end of file
import {create} from "axios"; import {create} from "axios";
//import store from './index'
// Init a new axios instance, with auth // Init a new axios instance, with auth
...@@ -7,6 +6,9 @@ const instance = create({ ...@@ -7,6 +6,9 @@ const instance = create({
baseURL: 'https://cloud.openshot.org' baseURL: 'https://cloud.openshot.org'
}); });
// Init a new axios instance, with auth
const blob_instance = create({});
// Set the AUTH token for any request // Set the AUTH token for any request
instance.interceptors.request.use(function (config) { instance.interceptors.request.use(function (config) {
const token = localStorage.auth const token = localStorage.auth
...@@ -22,4 +24,4 @@ function fixImageDuration(duration) { ...@@ -22,4 +24,4 @@ function fixImageDuration(duration) {
} }
} }
export { instance, fixImageDuration }; export { instance, blob_instance, fixImageDuration };
\ No newline at end of file \ No newline at end of file
import { createStore } from 'vuex' import { createStore } from 'vuex'
import { v4 as uuidv4 } from "uuid" import { v4 as uuidv4 } from "uuid"
import { instance, fixImageDuration } from "./axios" import { instance, blob_instance, fixImageDuration } from "./axios"
export default createStore({ export default createStore({
...@@ -331,6 +331,7 @@ export default createStore({ ...@@ -331,6 +331,7 @@ export default createStore({
fileObj = payload.obj fileObj = payload.obj
objectType = 'file' objectType = 'file'
} }
let sessionKey = `${objectType}-${fileObj.id}-frame${payload.frame}`
let data = { let data = {
"frame_number": payload.frame, "frame_number": payload.frame,
...@@ -340,13 +341,27 @@ export default createStore({ ...@@ -340,13 +341,27 @@ export default createStore({
"image_quality": 100 "image_quality": 100
} }
try { try {
const response = await instance.post(`${fileObj.url}thumbnail/`, data, { responseType: 'arraybuffer' }) let thumbnailUrl = sessionStorage.getItem(sessionKey)
let blob = new Blob( if (thumbnailUrl) {
[response.data], try {
{ type: response.headers['content-type'] } // Verify blob
) await blob_instance.get(thumbnailUrl)
} catch(err) {
// Failed to find blob
thumbnailUrl = null
}
}
if (!thumbnailUrl) {
const response = await instance.post(`${fileObj.url}thumbnail/`, data, { responseType: 'arraybuffer' })
let blob = new Blob(
[response.data],
{ type: response.headers['content-type'] }
)
thumbnailUrl = URL.createObjectURL(blob)
sessionStorage.setItem(sessionKey, thumbnailUrl)
}
// Append thumbnail attribute to each file object // Append thumbnail attribute to each file object
let thumbnailUrl = URL.createObjectURL(blob)
payload.obj.thumbnail = thumbnailUrl payload.obj.thumbnail = thumbnailUrl
if (objectType == 'file') { if (objectType == 'file') {
commit('updateFileThumbnail', payload) commit('updateFileThumbnail', payload)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment