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

Added QR code generation #176

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

joshterrill
Copy link
Contributor

This is in place of #104

And uses the kjua library that was recommended in #94

@joshterrill joshterrill mentioned this pull request Jul 4, 2018
@joshterrill
Copy link
Contributor Author

@feross The standard test is failing on the ci because I'm using location as a means of getting the domain that instant.io is running on, and location is not specifically defined anywhere. Is there a better way of getting the current domain in this app?

@willstott101
Copy link
Contributor

You have to use window.location to make standard happy.

@kaotisk-hund
Copy link

Hi everyone, I see on my tests that node v18 passes the test while v14 doesn't.
Log output:

standard: Unexpected linter output:                                                                                                            [70/529]
                                                                           
Error: EACCES: permission denied, scandir '/proc/tty/driver'                                                                                           
    at Object.readdirSync (fs.js:1048:3)                                                                                                               
    at readdirSafeSync (/node_modules/eslint/lib/cli-engine/file-enumerator.js:140:19)                                                                 
    at FileEnumerator._iterateFilesRecursive (/node_modules/eslint/lib/cli-engine/file-enumerator.js:434:29)                                           
    at _iterateFilesRecursive.next (<anonymous>)                           
    at FileEnumerator._iterateFilesRecursive (/node_modules/eslint/lib/cli-engine/file-enumerator.js:487:33)                                           
    at _iterateFilesRecursive.next (<anonymous>)                           
    at FileEnumerator._iterateFilesRecursive (/node_modules/eslint/lib/cli-engine/file-enumerator.js:487:33)                                           
    at _iterateFilesRecursive.next (<anonymous>)                           
    at FileEnumerator._iterateFilesRecursive (/node_modules/eslint/lib/cli-engine/file-enumerator.js:487:33)                                           
    at _iterateFilesRecursive.next (<anonymous>)                           
                                                                           
If you think this is a bug in `standard`, open an issue: https://github.com/standard/standard/issues                                                   
npm ERR! Test failed.  See above for more details.

This is reproduced with the window.location.origin, under docker.io/library/node:14 using podman as container.

Copy link

@kaotisk-hund kaotisk-hund left a comment

Choose a reason for hiding this comment

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

The <div id="qr-code"></div> is output inside a <p> element literally displaying the tag unrendered.

Copy link

@kaotisk-hund kaotisk-hund left a comment

Choose a reason for hiding this comment

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

That's my first review of code, I hope it helps

@@ -186,6 +187,10 @@ function onTorrent (torrent) {
'<a href="' + torrent.torrentFileBlobURL + '" target="_blank" download="' + torrentFileName + '">[Download .torrent]</a>'
)

util.log('<div id="qr-code"></div>')

Choose a reason for hiding this comment

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

This should be changed to util.unsafeLog

Copy link

Choose a reason for hiding this comment

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

According to suggestion below we won't need this line

Suggested change
util.log('<div id="qr-code"></div>')

@@ -186,6 +187,10 @@ function onTorrent (torrent) {
'<a href="' + torrent.torrentFileBlobURL + '" target="_blank" download="' + torrentFileName + '">[Download .torrent]</a>'
)

util.log('<div id="qr-code"></div>')

util.log(document.getElementById('qr-code').appendChild(kjua({text: location.origin + '/#' + torrent.infoHash, crisp: true})))

Choose a reason for hiding this comment

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

I am really unsure if you need to encapsulate to document.getElementById into util.log. Simply leaving it out produces the same result cause you are already selecting the "qr-code" id div and putting stuff there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a pretty old PR request, happy to make the changes to it. I do remember the templating being a little weird when trying to reference document outside of util.log because (at least at the time), document would get seen as undefined by the tests.

Copy link

Choose a reason for hiding this comment

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

Actually, for multiple "uploads" in the implementation you made you putting the qr code on the original first drawn div.
You could replace both lines with

Suggested change
util.log(document.getElementById('qr-code').appendChild(kjua({text: location.origin + '/#' + torrent.infoHash, crisp: true})))
util.unsafeLog(kjua({
text: window.location.origin + '/#' + torrent.infoHash,
crisp: true
}).outerHTML)

This will output "in place" each time you make an upload,underneath the buttons, above the content preview (if any).

Choose a reason for hiding this comment

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

@joshterrill I feel like the QR codes are a feature to help adoption and provide ease of use. I think it's important, furthermore, it's not resolved in other PRs. Personally, I just stroll through repositories I like and try to help in whichever way I can. So, if you still wish to make this contribution, here is my review 😃 I guess @feross should also agree to push this, but I saw it was stuck because of a test failing (standard). The error I post I was getting is about wrong permissions on podman in my attempt to replicate the "testing" method from the repo (node 14, ubuntu latest). I am not affiliated with the development team, so my opinion is as good as that can be. Cheers!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm good to make these changes, would love to see this implemented as well. You'll see in this PR that I asked a question to resolve the issue with the standard tests not recognizing javascript window objects in the node environment, and it went unanswered for two years. So I hope that we can resolve this! I also see some of the suggestions you made (like util.unsafelog) were things that didn't even exist in the repo (as far as I can tell) at the time that this code was originally written, so that's cool. I'll take a look at this today and get back to you. Thanks.

@joshterrill joshterrill marked this pull request as draft December 13, 2022 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants