-
Notifications
You must be signed in to change notification settings - Fork 251
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
nodejs connector #30
Comments
It sounds good if you are going to make it optional without breaking the current implementation, because most of FM users utilizes web server indeed. Also I have to say that most of ajax calls will be overwritten (wrapped) to use Deffered objects. Take a look at PR #21 Before you create your PR you could share your thoughts and code snippets of how you want to implement your idea, modify ajax calls and so on. Write the things right here and we will discuss them. |
Maybe I misunderstood something but it's already possible to use a custom URL for the connector. If you set in the config
Then the file manager will call
We only needs to implement two optional parameters to the configuration object , something like :
(I already need something like this in my case, to add a CRSF parameter for the post requests.) |
@fabriceci Thank you for the example. |
I totally missed the fileConnector option digging through the code, I'll look for that today. This is a pretty large code base, so excuse me while I get familiar with it :) I think fabriceci's right on the money, all I would need is to add credentials true and crossDomain true to the getParams and postParams and I think I'd be set to get to work on the node api. I'll get my environment setup when I get to work today and start plugging away and see what I can figure out. |
The getParams/postParams was a suggestion, those parameters doesn't exist yet. I plan to add in a PR this weekend (like I said I need to pass a CSRF token for POST request) It can be easy, simply add the "getParams" in the $.Ajax function and "postParams" in the upload function. ( But the best way is like you said wrap all the Ajax calls in one function, cleaner but take more time.) @servocoder Could you tell me why all requests are not sent asynchronously? (I never used this param)
|
It is required because some Ajax requests supposed to be invoked in a chain. But I plan to rewrite this behavior, remove sync flag and utilize $.Deferred() as it was suggested in PR #21 |
fabriceci, I understood that it was a suggestion, I just thought it to be a very good one and I was just rolling with it as an assumed solution. I tried the fileConnector option and it works, I can't believe I missed that :) Oddly, it didn't complain about my CORS, so I wonder if it's going to pick that up from my websites default jquery config? That would actually be pretty awesome. Either way, I don't see any roadblocks to me getting to work on a nodejs api connector, I already have the first request sent, so it's just a matter of working through each option I guess, yay! |
Ok, I have my api started, and files and folders loading :) However, I ran into an issue where either the documentation is wrong, or the code is wrong. In the documentation is says to return an array of documents in the form
However, the code is assuming that the key : value pair at the root level is NOT there, it is doing this
So, if I leave out the root level key which is the filename, it works. I am assuming the documentation is wrong since this code matches the old behavior, but I wanted to run it past y'all before moving forward with that assumption. Here's what works
|
Also, it is ignoring my fileRoot and always sending me "/". This is my settings that have always worked with previous versions |
So I moved onto downloading the file, and oh boy. What is this crazyness? It's checking for code == 0 on a downloaded file? So I have to check for a query force === 'true' and either respond with {Code: 0} or the actual file. Then it's just setting windows.location.href = the entire endpoint, so I have to set weird headers. This works, but are there plans to change it? Sorry for the bombardment, I'm working on this fulltime until it's done :) |
Btw, you forgot to add "Preview" key in your response for each item. It was discussed and approved just a few days ago so it has not yet been added to the API. Check this thread for the details and, of course, I am going to describe it in API.
If you want to change web path to the connector, use
Thanks for your efforts in nodejs connector! |
@jlaustill have you already implemented the getParams/postParams, if not, do you plan to do it? |
@fabriceci Ok, I will take a look deeply. |
Fabriceci, I have not implemented the getParams/postParams at all. I will let you do that if you want :) servocoder,
and errors inside an errors array exactly the same way. This has many advantages in javascript, but we can discuss them later, I'll stick to the current implementation for now :) Also, I didn't even notice the preview attribute, so I'll check that out today
Lastly, I've been giving some thought to the config file. As it is, with the api and ui on seperate servers, it looks like I'll have to do an ajax request back to origin to grab the config file for every single request. This isn't great, it opens up to spoofing attacks. I would recommend maybe in future seperating the config file into two, server side config, and ui side config. For now, I may just require a second copy of the config on the api server for the nodejs connector, it's just as messy as an http request back to origin though. This issue doesn't exist when api and ui are on the same server because the connector can just open the file directly. |
Ok, after today I am mostly functional. I have the nodejs api browsing, uploading, renaming, moving, deleting, and adding folders. I still need to do the replace and I ran into a few new issues :)
I think one more good day on this and I'll have it ready to upload so you all can start looking at it. The QA process is going to be crazy because I'm writing this insanely fast. After two days it's 397 lines of code... |
Hi @jlaustill Answer for 1 and 2 points: As FM was initially designed to be utilized for web servers it always tends to return absolute path for a preview file, thumbnail or WYSIWYG editor. PHP connector is designed to return fileConnector path only if userfiles folder is located beyond document root folder. We could modify this logic like:
We could add condition to check it by domain name or some other way. Do you have any proposals? Another way is to create new option in config file to force fileConnector path to return. But it would be better to keep this logic inside connector if possible. |
As to splitting config file to UI and server files. I like this idea and some basics have been implemented for PHP connector in fact. There is a config file which contains server specific config solely. The same thing for AWS S3 plugin, because it's not safe to keep AWS credentials in json file for sure. As far as I can see FM was initially desined to keep all config options in one place because it's extremely convenient for users. On the other hand there are some options defined in json file, which are relate to server-side exclusively, for instance |
I'm going to respond in two separate responses here to try to keep this less confusing :) I think I'm beginning to see how this came to since FM started as a totally all in one thing. To make this work with nodejs, I HAVE to seperate the api logic from the ui logic 100%. The ui will have zero idea about the path on the api server. It's also best practice to keep these separate, and I think we can do this with very little interruption to working code. I will try to draw this out in an example to make it as clear as possible. API server -> http://api.com Our api server exposes an endpoint /filemanager, so the fileConnector will become http://api.com/filemanager . The ui sends a request for getfolder(maybe not the easiest example) and the api responds with 3 files as such These are stored "somewhere" on the api server, but the ui doesn't have any way to know, or care because the ONLY way the ui can access them is through the endpoint. So lets say the api saves them in /var/share/filemanager/files/folder/file1.jpg etc etc. It generates previews in /var/share/filemanager/previews/folder/file1.jpg etc. It then returns the following path -> preview The ui can ONLY get these files from its endpoint because it has zero physical access to the api server, so for the first preview it needs to ask for This can work exactly the same way for the normal php connector on the same server, there is no reason it has to work differently, the fileConnector will simply be the local server. I see all over the code in filemanager.js that it calculates this over and over. I would change the fileConnector upon loading the config file and if it's set to false, just replace the calculated url into once and only to it once, then everywhere in the UI code you can always just reference the fileConnector + '?mode=download...' This would move you much closer to having a clear separation of ui and api. |
There is zero reason that the api should even know the fileConnector, it means nothing to it whatsoever, that is a client side config only. If the current implementation is using it, it clearly violates the separation of concerns. The api should only care about its fileRoot location, and the UI should never even know that location, ever. Even in the case of the php connector running on the same server, the ui should always ask the connector for its files, and the the connector should always return a relative path to itself. The good news is that the way the code is currently written, this will be very easy. I can work on a roadmap for making this happen, and it will only take a few days for the ui code and the nodejs code. I don't know php at all, so I can't speak to that :) |
@fabriceci I did up a quick example of what we were talking about consolidating ajax requests and extending with getParams. Check out repo and search filemanager.js for _$.apiGet to find the definition and usage I put in place. Let me know what you think. |
Hi @jlaustill I have created "api" section in config file and prepared "requestParams" param inside of it. Initially I though to set all params for both "get" and "post"(put) methods to "requestParams" and now I tend to split it to two different options to handle each method separately. Is that will be enough for your idea of "apiGet" and "apiPut" options? |
Hi @jlaustill |
Closed since there is no activity for a long time. If you want to implement nodejs connector I will gladly reopen this issue. |
The latest commit should refer to issue #210 (mismatch) |
I have modified the NodeJS connector from the repo into a new project https://github.com/dekyfin/RichFilemanager-NODE . |
@dekyfin Awesome! Thanks a lot. Have you checked all API functions to work well? |
All API functions have been implemented with the exception of the following
|
Ok, I will include link to your repo into the wiki. Are you going to implement the rest of API methods? |
Btw, I have got been reported with a following issue: #300 Сan you confirm or deny this statement? |
The issue hasn't yet occurred in my instance. I'll go through the code to check it |
Thanks. |
Hi there, i tried to run your project using nodejs coonector https://github.com/dekyfin/RichFilemanager-NODE . But, it doesn't work to me. i always get this error TypeError: Cannot read property 'trim' of undefined in rich-filemanager-node\index.js |
I just looked over the code base, and I realized this is going to be a LOT tougher than I expected. The code expects the connector to be on the web server, and not an api server. My environment is separating the api from the web server. So my question is, are you willing to work with these changes to set an api url instead of a connector path? It requires setting credentials and cors on the ajax calls as well.
I would solve this by factoring all the ajax calls into functions that emulate jqueries$.get, $ .put, etc., and either calling the connector, or the api endpoint based upon the configuration. I would be willing to do this, but I wanted to check and see if anyone had issues with it?
The text was updated successfully, but these errors were encountered: