-
Notifications
You must be signed in to change notification settings - Fork 16
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
[FEATURE] simplistic serveIndex with additional properties #23
Conversation
2860b59
to
f4bff11
Compare
Pull Request Test Coverage Report for Build 102
💛 - Coveralls |
90bb04f
to
996baab
Compare
The tests may be a bit primitive but at least the logic is executed and a lightweight check for the result has been implemented. |
996baab
to
9af6458
Compare
@@ -102,7 +102,6 @@ | |||
"portscanner": "^2.1.1", | |||
"prompt": "^1.0.0", | |||
"replacestream": "^4.0.3", | |||
"serve-index": "RandomByte/serve-index#fs-option", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected that when the package.json has changed, there also should be a new package-lock.json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did not check that the package-lock.json is submitted. I do not do this normally...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
lib/middleware/serveIndex.js
Outdated
size: formatSize(stat.size), | ||
sizeInBytes: stat.size, | ||
project: resource._project.id, | ||
realPath: resource._project.path + resource.getPath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.join?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
lib/middleware/serveIndex.js
Outdated
} else if (!a.isDir && b.isDir) { | ||
return 1; | ||
} else { | ||
return a.name.localeCompare(b.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is like a filesystem sorts the numbers! ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not how most file system browsers (Finder, Explorer, etc.) sort numbers. I find this sorting rather confusing. Maybe we could also check how Apache and others do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhmm, what sorting do you expect?
The sorting in Windows Explorer is not more than a "nice try" from my POV - I really hate it. Did you ever try to find a GUID in a folder full of GUIDS (some starting with digits, others not? It's a mess. You easily miss a file just because of the sorting. Simple alphanumeric sorting would be much better.
"Smart" sorting only makes sense when a folder only contains a single kind of names (only alpha or only numeric). But that's not how it is implemented, at least not in Windows Explorer.
+1 for strict ASCII sorting...
lib/middleware/serveIndex.js
Outdated
size: formatSize(stat.size), | ||
sizeInBytes: stat.size, | ||
project: resource._project.id, | ||
realPath: resource._project.path + resource.getPath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't work. Appending the full virtual path of the resource to the physical root path of its project (not even the resources reader) can only produce valid paths by pure chance.
For /resources/sap-ui-core.js
you currently get: [...]/node_modules/@openui5/sap.ui.core/resources/sap-ui-core.js
instead of [...]/node_modules/@openui5/sap.ui.core/src/sap-ui-core.js
.
There is currently no way to get the "physical" path of a resource. This is intentional as ui5-fs is explicitly not relying on physical file systems.
In general, I don't know whether we should expose full file paths here just for convenience. People could still use this for module on production systems and the file paths might represent security relevant information. How is this handled by Apache et.al.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent a TODO comment to consider this but keep the logic for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will just use the project path
lib/middleware/serveIndex.js
Outdated
lastModified: new Date(stat.mtime).toLocaleString(), | ||
size: formatSize(stat.size), | ||
sizeInBytes: stat.size, | ||
project: resource._project.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _project
attribute is undocumented and commented as an Experimental, internal parameter
. We should at least deal with it eventually being undefined (which it is for all dynamically generated resources).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written in my comments before, we need to consider whether to expose some more additional information
* @returns {String} HTML content for the resource listing | ||
*/ | ||
function createContent(path, resourceInfos) { | ||
return `<!DOCTYPE html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to have this as a Handlebars template. All with syntax highlighting and stuff. I'm ok with merging this as a start but would offer myself to move it into a proper template later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather tend to do this as an enhancement in future
* @param {Resource} resource the resource | ||
* @returns {String} mime type | ||
*/ | ||
function getMimeType(resource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for this function would be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do this for the serveResource? We should better externalize this in a util function... ;-)
* @param {Number} bytes bytes | ||
* @returns {String} human readable size | ||
*/ | ||
function formatSize(bytes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for this function would be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Util function would be better - but those kind of enhancements might be something for a general cleanup in a separate commit
* @param {Resource} resource the resource to convert | ||
* @returns {Object} resource info object | ||
*/ | ||
function createResourceInfo(resource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for this function would be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally called by serveIndex which runs through that function!
* @param {Resource[]} resources an array of resources | ||
* @returns {Object[]} sorted array of resource infos | ||
*/ | ||
function createResourceInfos(resources) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for this function would be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally called by serveIndex which runs through that function! See line coverage...
* @param {Object[]} resourceInfos an array of resource infos | ||
* @returns {String} HTML content for the resource listing | ||
*/ | ||
function createContent(path, resourceInfos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit test for this function would be great 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internally called by serveIndex which runs through that function! See line coverage...
dcec1be
to
dcf5194
Compare
A rebase is necessary due to conflicts in |
dcf5194
to
7120b4f
Compare
Grml - again a merge conflicT! |
7120b4f
to
2d6876b
Compare
Rebase has been done |
I've added an export in index.js, so that it can be used directly. |
@matz3 thanks for adding the serveIndex to the export - I did not see that place... @RandomByte what about a merge now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough I guess
Things I would like to follow up on:
|
<td${info.isDir ? ">" : " title=\"" + info.sizeInBytes + " Bytes\">" + info.size}</td> | ||
<td><a href="${info.path}">${info.name}</a></td> | ||
<td>${info.mimetype}</td> | ||
<td><a href="file:////${info.projectPath}" title="${info.projectPath}">${info.project}</a></td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file://
URLs neither work in Chrome, nor Safari (didn't test others) for security reasons: https://support.google.com/gsa/answer/2664790?hl=en
Console error logged in both browsers after clicking such a link: Not allowed to load local resource
. From what I found, only resources loaded via file://
can open such links.
I would opt for removing those links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather keep it as the link would be a server absolute link on mac which would point to the wrong location. At least copy and paste can work partially with the file URL...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho this is confusing. A non-clickable link with no explanation whatsoever.
Also, what is the benefit of opening a projects directory in your Browser?
I'm not aware how to open file://
links directly in the Finder or Terminal.
@RandomByte @matz3 please take a look into the new serveIndex alternative for the ui5-server.
There are still some internals from the resource used when creating the resource info object. Maybe some of the internals can also become something for a more official API of the Resource but we could do that in a second step and provide the simplistic serveIndex to avoid the dependency to a github repo.