tus: QuotaExceededError (#935)

* Move into getLocalStorageSummary + always log

- Move into getLocalStorageSummary to clean up the clutter.
- Always log the localStorage info to get a bigger picture of what's going on with the QuotaExceededError.

* Remove 'findPreviousUploads' - we use the url stored in Redux.

Something I forgot to remove in the past. It also reads from localStorage, so remove since we are trying to avoid touching localStorage.

* Ensure localStorage is not used when uploading

I don't think it's being written when `storeFingerprintForResuming` is disabled, but doing the suggestion nonetheless.

`https://github.com/tus/tus-js-client/issues/315#issuecomment-1046821112`
This commit is contained in:
infinite-persistence 2022-02-22 07:11:22 -08:00 committed by GitHub
parent 9a95c9f64d
commit c74dbbb68a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 25 deletions

View file

@ -13,3 +13,13 @@ export function isSessionStorageAvailable() {
return false;
}
}
export function getLocalStorageSummary() {
try {
const count = window.localStorage.length;
const estimatedSize = JSON.stringify(window.localStorage).length;
return `${count} items; ${estimatedSize} bytes`;
} catch (e) {
return 'inaccessible';
}
}

View file

@ -1,8 +1,10 @@
// @flow
import * as tus from 'tus-js-client';
import NoopUrlStorage from 'tus-js-client/lib/noopUrlStorage';
import analytics from '../../ui/analytics';
import { X_LBRY_AUTH_TOKEN } from '../../ui/constants/token';
import { doUpdateUploadAdd, doUpdateUploadProgress, doUpdateUploadRemove } from '../../ui/redux/actions/publish';
import { getLocalStorageSummary } from '../../ui/util/storage';
import { LBRY_WEB_PUBLISH_API_V2 } from 'config';
const RESUMABLE_ENDPOINT = LBRY_WEB_PUBLISH_API_V2;
@ -63,6 +65,7 @@ export function makeResumableUploadRequest(
retryDelays: [5000, 10000, 30000],
parallelUploads: 1,
storeFingerprintForResuming: false,
urlStorage: new NoopUrlStorage(),
removeFingerprintOnSuccess: true,
headers: { [X_LBRY_AUTH_TOKEN]: token },
metadata: {
@ -83,19 +86,7 @@ export function makeResumableUploadRequest(
customErr = 'File is locked. Try resuming after waiting a few minutes';
}
let localStorageInfo;
if (errMsg.includes('QuotaExceededError')) {
try {
localStorageInfo = `${window.localStorage.length} items; ${
JSON.stringify(window.localStorage).length
} bytes`;
} catch (e) {
localStorageInfo = 'inaccessible';
}
}
window.store.dispatch(doUpdateUploadProgress({ guid, status: 'error' }));
analytics.sentryError('tus-upload', err);
reject(
@ -108,7 +99,7 @@ export function makeResumableUploadRequest(
...(uploader._retryAttempt ? { retryAttempt: uploader._retryAttempt } : {}),
...(uploader._offsetBeforeRetry ? { offsetBeforeRetry: uploader._offsetBeforeRetry } : {}),
...(customErr ? { original: errMsg } : {}),
...(localStorageInfo ? { localStorageInfo } : {}),
localStorage: getLocalStorageSummary(),
},
})
);
@ -152,17 +143,7 @@ export function makeResumableUploadRequest(
},
});
uploader
.findPreviousUploads()
.then((previousUploads) => {
if (!isPreview) {
window.store.dispatch(doUpdateUploadAdd(file, params, uploader));
}
uploader.start();
})
.catch((err) => {
reject(new Error(__('Failed to initiate upload (%err%)', { err })));
});
window.store.dispatch(doUpdateUploadAdd(file, params, uploader));
uploader.start();
});
}