Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Check upload limits before trying to upload large files #1876

Merged
merged 11 commits into from
Dec 4, 2018

Conversation

Half-Shot
Copy link
Contributor

@Half-Shot Half-Shot commented May 3, 2018

An explanation is in matrix-org/matrix-spec-proposals#1189.

Depends on #644 and (optionally) #3184.

Demo

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is blocked behind the synapse/spec PRs, but a few bits of feedback here anyway. This looks super useful and is something we've been meaning to do for ages, thank you!

}

uploadFiles(files) {
uploadFiles(files, limits) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, should remove.

@@ -16,6 +16,7 @@ limitations under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import filesize from "filesize";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but consistent quotes :)

}

isFileUploadAllowed(file) {
if (this._uploadLimits.upload_size != null && file.size > this._uploadLimits.upload_size) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= null is slightly confusing here since you're relying on undefined == null (and of course 0 == null too, so a limit of 0 will mean unlimited). Probably better to say === undefined.

}).catch(() => {
// HS can't or won't provide limits, so don't give any.
this._uploadLimits = {};
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will re-fetch the limits every time the composer is mounted, ie. every time you change rooms, which probably isn't what you wanted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was struggling with this because I realised if we restarted the HS (or indeed, just the media server) then the limits become stale. Given it's a small request decided to make it fetch once each time we load it.

However I confess this is a lazy way to achieve that and I should probably hook onto something else.

@Half-Shot
Copy link
Contributor Author

Thanks for the feedback. Will wait on the spec proposal to be finalized before I continue.

@turt2live
Copy link
Member

@Half-Shot I assume you plan on addressing the build failure and merge conflicts on this? It seems to look okay from my perspective otherwise.

@Half-Shot
Copy link
Contributor Author

Ah yes, will do.

@turt2live
Copy link
Member

@Half-Shot looks like you have test failures

@Half-Shot
Copy link
Contributor Author

Half-Shot commented Oct 16, 2018

@turt2live I do, but I don't know how. The errors don't correlate with any of the things I've changed.

EDIT: I never learn, always check the commas after resolving a JSON merge conflict.

The PR still won't work because the JS-SDK doesn't support getMediaConfig() yet, pending matrix-org/matrix-js-sdk#761

@turt2live turt2live assigned turt2live and unassigned dbkr Dec 1, 2018
@turt2live turt2live removed their assignment Dec 3, 2018
@turt2live turt2live merged commit c0ef2f7 into matrix-org:develop Dec 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants