Skip to content

Update index.html based on whether meta-tag is set or not#953

Merged
kjetilk merged 16 commits into
release/v5.0.0from
feature/index-update
Nov 27, 2018
Merged

Update index.html based on whether meta-tag is set or not#953
kjetilk merged 16 commits into
release/v5.0.0from
feature/index-update

Conversation

@megoth

@megoth megoth commented Nov 20, 2018

Copy link
Copy Markdown
Contributor

This is a fix for #688 that uses the solution in #936.

  • It will update if is set
  • It will update if meta-tag is not set at all
  • It will not update if content is set to false (or any other value than true for that matter)

Parsing HTML is non-trivial, but I hope cheerio will do the work (I initially tried using htmlparser2, but I found the abstraction layer of cheerio much easier to handle).

Added some tests for getWebId and getName.

@ghost ghost assigned megoth Nov 20, 2018
@ghost ghost added the in progress label Nov 20, 2018

@kjetilk kjetilk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but I think I'll let others comment.

@megoth megoth requested a review from rubensworks November 20, 2018 15:00
@megoth

megoth commented Nov 20, 2018

Copy link
Copy Markdown
Contributor Author

@RubenVerborgh and @dmitrizagidulin might be busy, so I hope that @rubensworks might be able to take a look.

@kjetilk kjetilk requested a review from mielvds November 20, 2018 15:02
@kjetilk

kjetilk commented Nov 20, 2018

Copy link
Copy Markdown
Member

And how about you, @mielvds , you did a bit of looking on the frontend?

@rubensworks rubensworks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Just a few minor comments.

Comment thread bin/lib/cli-utils.js Outdated

// Use flags with priority over config file
const config = JSON.parse(file)
Object.keys(config).forEach((option) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency, like on line 31, this block may also be possible using an extend .

Comment thread lib/ldp.js Outdated
}

readContainerMeta (directory, callback) {
async readContainerMeta (directory, callback = function () {}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having both promise-based and callback-based resolving might be confusing. I propose to remove the callback parameter.

Comment thread bin/lib/cli-utils.js
let configFile = argv['configFile'] || './config.json'

try {
const file = fs.readFileSync(configFile)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hm. Given that argv['configFile'] is user input... Could this be leveraged to a directory traversal attack?

I imagine accessing files from another user on the same pod.

So some sanitation would need to happen...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The user that provides this input is the server admin, so they can do way worse 😉

Comment thread bin/lib/cli-utils.js
const isUserDirectory = new RegExp(`.${hostname}$`)
return files
.filter(file => isUserDirectory.test(file))
.map(userDirectory => userDirectory.substr(0, userDirectory.length - hostname.length - 1))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since the right hand side comes up again and again, maybe it's time for aa helper function to make it more speaking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where is this coming up again and again?

Comment thread bin/lib/updateIndex.js Outdated
const indexTemplate = await compileTemplate(indexTemplatePath)
const ldp = new LDP(config)
const accountManager = getAccountManager(config, { ldp })
const usernames = loadUsernames(config)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So many local variables. Personally I'd have split up the function into smaller ones to ease understanding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would've done that myself, but the server is sometimes difficult to write for, because there are so many things that need to be set up. The CLI scripts are kind of extreme in this sense =/

If you have concrete ways of rewriting this to make it easier to read, I'm all ears, but until then I'll leave it as it is.

@megoth

megoth commented Nov 24, 2018

Copy link
Copy Markdown
Contributor Author

Hmm, something strange happened when I tried to rebase this branch to master. There are a lot of commits in this that I'm unsure why is there =/

That being said, I've done a couple of changes based on the feedback here, and think the branch should be good for merge. Maybe @rubensworks wants to verify?

@rubensworks

Copy link
Copy Markdown
Contributor

It looks like something indeed went wrong during the rebase, the last 3 commits on master seem duplicated.

I'm wondering if this should be targeted to the release branch? If so, it should be rebased on that. (In that case it might be easier to just fork a clean branch and cherry-pick your commits on there. This would fix the additional commits being here)

@megoth megoth changed the base branch from master to release/v5.0.0 November 27, 2018 18:02
@megoth megoth force-pushed the feature/index-update branch from 9b2a592 to bf9a59e Compare November 27, 2018 18:04
@megoth

megoth commented Nov 27, 2018

Copy link
Copy Markdown
Contributor Author

Then I've finally managed to rebase it to v5.0.0 (here's hoping Travis run all tests). Will continue with #937 when this is merged into the release-branch

Comment thread bin/lib/cli-utils.js
const AccountManager = require('../../lib/models/account-manager')
const SolidHost = require('../../lib/models/solid-host')

module.exports.getAccountManager = getAccountManager

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be rephrased as:

module.exports = {
  getAccountManager,
  loadAccounts,
  loadConfig,
  loadUsernames
}

@dmitrizagidulin

Copy link
Copy Markdown
Contributor

👍 , looks good!

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

Successfully merging this pull request may close these issues.

9 participants