Client side name validation #99
No reviewers
Labels
No labels
area: devops
area: discovery
area: docs
area: livestream
area: proposal
consider soon
dependencies
Epic
good first issue
hacktoberfest
help wanted
icebox
level: 1
level: 2
level: 3
level: 4
needs: exploration
needs: grooming
needs: priority
needs: repro
needs: tech design
on hold
Osprey
priority: blocker
priority: high
priority: low
priority: medium
protocol dependent
resilience
Tom's Wishlist
type: bug
type: discussion
type: error handling
type: improvement
type: new feature
type: refactor
type: task
type: testing
unplanned
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: LBRYCommunity/spee.ch#99
Loading…
Reference in a new issue
No description provided.
Delete branch "client-side-name-validation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ -45,2 +34,4 @@
function validateClaimName (name) {
var deferred = new Promise(function(resolve, reject) {
// validate the characters in the 'name' field
if (name.length < 1) {
@98farhan94 This function is used to validate the file on the client side before it is submitted. I added a check to make sure there are no special characters in the file name. Unfortunately, the file.name in the file object is read only so we can't simply replace the spaces. For now we will just prompt the user to fix their file name.
@ -58,3 +57,4 @@
reject( new NameError("That name has already been claimed by spee.ch. Please choose a different name."));
}
} else {
reject("request to check claim name failed with status:" + this.status);
@98farhan94 note that there are two functions in this file. One to validate the file itself, and one to validate the claim name that the user chooses. The file name can have spaces in it, but the claim name cannot.
@ -103,0 +130,4 @@
function publishSelectedImage(event) {
event.preventDefault();
var name = document.getElementById('publish-name').value;
validateSubmission(stagedFiles, name)
@98farhan94 this function is run when the submit button is clicked to submit the file for publishing.
@98farhan94 this is where the claim-name input box is filled based off of the file name. I added a check here to replace spaces with dashes as you suggested (line 123)
@ -17,0 +62,4 @@
//event listener to filter claim name inputs
document.getElementById('publish-name').addEventListener('input', function() {
var name = this.value;
this.value = name.replace(/\s+/g, '-');
@98farhan94 I added an event listener to the claim name input box so that if a space is entered it will be changed to a dash. I suppose we could also use this filter to disallow all the other extraneous characters from being inputted.
Thanks - and also for all the comments, they are really helpful!
@ -47,0 +37,4 @@
if (name.length < 1) {
reject(new NameError("You must enter a name for your claim"));
return;
}
Can this just be fixed/stripped rather than erroring?
@ -65,41 +65,87 @@ function validateClaimName (name) {
});
return deferred;
}
// validation function which checks all aspects of the publish submission
Might want to consider adopting a validator pattern/standard. Look at validator patterns in a popular JS web framework, for example.
@ -47,0 +37,4 @@
if (name.length < 1) {
reject(new NameError("You must enter a name for your claim"));
return;
}
Yes, but not easily at the moment. 1. I can't strip or fix it client side because the file name is read only on the file object. I did some snooping on google and stack overflow and it seemed like it was more or less immutable. 2. The solution I imagine is then to rename the file when it is saved on the server. Unfortunately, the socket.io uploader library I am using doesn't have a built in option to rename the file. So, I think to fix would be to rename the file on the server side with the node filesystem tools. I will make an issue to add this.
@ -65,41 +65,87 @@ function validateClaimName (name) {
});
return deferred;
}
// validation function which checks all aspects of the publish submission
I did a little bit of research on this. There are some validator libraries out there, or at least we can make a more standard pattern that fits our unique needs. Will make an issue.