Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename directory error #33

Closed
jlaustill opened this issue Aug 15, 2016 · 7 comments
Closed

Rename directory error #33

jlaustill opened this issue Aug 15, 2016 · 7 comments

Comments

@jlaustill
Copy link
Contributor

When trying to rename a Directory it is giving the following error.

File type is not allowed.
Only following files are allowed: jpg, jpe, jpeg, gif, png, svg, txt, pdf, odp, ods, odt, rtf, doc, docx, xls, xlsx, ppt, pptx, csv, ogv, avi, mkv, mp4, webm, m4v, ogg, mp3, wav, zip, rar.

@psolom
Copy link
Owner

psolom commented Aug 16, 2016

Hmm, I can't reproduce it in any way. Where did you get that error? Which the connector was?

@jlaustill
Copy link
Contributor Author

I'm only getting this error on the newest master branch, using my nodejs connector. But the connector isn't even getting a request. I'll step through the code today and see I can figure out where it's going wrong :)

@jlaustill
Copy link
Contributor Author

Ok, I figured out what is causing this. The function

// Test if path is dir
var isFile = function(path) {
    return path.charAt(path.length - 1) != '/';
};

on line 407. When you normalize a path in nodejs and it is a directory, it will not include a trailing slash. I think there is a much better way to deal with this since we are also passing back a 'File Type'.

I would write a new function called _$.isFile and take the entire object, first checking if file type = "dir", and if not, checking for a trailing slash to be robust. If the api errors and sends a path with an incorrect file type, it will still work in this case.

This function is used 12 times in filemanager.js, so that is 12 places for this bug to pop up.

I would start with something like this

_$.isFile = function(file) {
    if (file["File Type"] === "dir") {
        return false;
    } else {
        return (file["Path"].charAt(file["Path"].length - 1) !== "/");
    }
}

@psolom
Copy link
Owner

psolom commented Aug 16, 2016

This is not a solution and I'm not going to change isFile function, because there are a lot of places where I check isFile without the whole response object. There is a standard we have that all folder paths should end with trailing slash. You have to modify your connector to return correct paths for folders.

@psolom
Copy link
Owner

psolom commented Aug 16, 2016

But we are able to extend conditions like !isFile(path) && data["File Type"] === "dir" AND isFile(path) && data["File Type"] !== "dir" for the places where we have data object with "File Type" param, or create a new function for that purpose, but not to rewrire isFile function

@psolom
Copy link
Owner

psolom commented Aug 16, 2016

Anyway you should add trailing slash for each folder path in your connector

@psolom
Copy link
Owner

psolom commented Oct 25, 2016

The new API specifies that trailing slash is mandatory for folders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants