about summary refs log tree commit diff
path: root/app/javascript/mastodon/storage
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2018-05-20 02:22:11 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-19 19:22:11 +0200
commit4e1400cecb33743335fcf88b4d128aa1954c6c63 (patch)
treefea1d7e2b549c6454a44655478c110c5b4f9189a /app/javascript/mastodon/storage
parentbcbb6aa46ff6f7c634b38e71bd719ccf52b84172 (diff)
Cache media only when storage can be freed (#7547)
Diffstat (limited to 'app/javascript/mastodon/storage')
-rw-r--r--app/javascript/mastodon/storage/modifier.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/app/javascript/mastodon/storage/modifier.js b/app/javascript/mastodon/storage/modifier.js
index a42b6ab12..9fadabef4 100644
--- a/app/javascript/mastodon/storage/modifier.js
+++ b/app/javascript/mastodon/storage/modifier.js
@@ -4,6 +4,11 @@ const accountAssetKeys = ['avatar', 'avatar_static', 'header', 'header_static'];
 const storageMargin = 8388608;
 const storeLimit = 1024;
 
+// navigator.storage is not present on:
+// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.100 Safari/537.36 Edge/16.16299
+// estimate method is not present on Chrome 57.0.2987.98 on Linux.
+export const storageFreeable = 'storage' in navigator && 'estimate' in navigator.storage;
+
 function openCache() {
   // ServiceWorker and Cache API is not available on iOS 11
   // https://webkit.org/status/#specification-service-workers
@@ -182,10 +187,7 @@ export function putStatuses(records) {
 }
 
 export function freeStorage() {
-  // navigator.storage is not present on:
-  // Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.100 Safari/537.36 Edge/16.16299
-  // estimate method is not present on Chrome 57.0.2987.98 on Linux.
-  return 'storage' in navigator && 'estimate' in navigator.storage && navigator.storage.estimate().then(({ quota, usage }) => {
+  return storageFreeable && navigator.storage.estimate().then(({ quota, usage }) => {
     if (usage + storageMargin < quota) {
       return null;
     }