vnphanquang / svelte-put

Useful svelte stuff to put in your projects
https://svelte-put.vnphanquang.com
MIT License
836 stars 25 forks source link

qr - data path to vcard #289

Closed extensionteamhq closed 7 months ago

extensionteamhq commented 7 months ago

It appears that the qr data to encode will not work with a relative path /vcard.vcf and it also doesn't seem to recognize when it is a file to be downloaded.

If I use the relative path /vcard.vcf the result is search "/vcard.vcf".

If I use a full path, https://example.com/vcard.vcf, the result is a link to https://example.com/.

vnphanquang commented 7 months ago

Hello @extensionteamhq. A couple of things:

If I use the relative path /vcard.vcf the result is search "/vcard.vcf".

Data is encoded as is, and I believe that is how it should be with any QR. @svelte-put/qr cannot assume any external context, i.e it cannot automatically prepend the current origin, if any, to your relative path, if that is what you mean.


If I use a full path, https://example.com/vcard.vcf, the result is a link to https://example.com/.

Can you provide a reproduction for this? Here is a REPL using https://example.com/ as the data for enconding.

extensionteamhq commented 7 months ago

Hi @vnphanquang, thanks for the quick reply.

It's not encoding the contents of the file /vcard.vcf but instead encoding the literal string of /vcard.vcf.

The examples I've seen are using a URL (e.g., https://example.org/) and that works fine, or as intended, passing a URL as the string of data to encode.

I would, however, like to encode the contents of the file at /vcard.vcf, which is just a text file—similar to this:

BEGIN:VCARD
VERSION:3.0
REV:2024-04-08T00:00:00Z
PROFILE:VCARD
SOURCE:http://personaldomain.com/vcard.vcf
CLASS:public
FN:Alex Suprun
ORG:Company Name
LOGO;TYPE=PNG:http://workdomain.com/logo.png
ADR;TYPE=WORK;TYPE=PREF:Company Name;Ste 100;7900 4th St N;St. Petersburg;FL;33702;USA
URL;TYPE=WORK;TYPE=PREF:https://workdomain.com/
TEL;TYPE=WORK;TYPE=VOICE:+1 (727) 555-0000
EMAIL;TYPE=INTERNET;TYPE=WORK;TYPE=PREF:hello@workdomain.com
TITLE:Avatar
ROLE:Member
N:Suprun;Alex;;;
NICKNAME:Spuns
PHOTO;TYPE=PNG;VALUE=URI:http://personaldomain.com/photo.jpg
ADR;TYPE=HOME:;;1234 Main St N;St. Petersburg;FL;33701;USA
TEL;TYPE=CELL;TYPE=VOICE;TYPE=PREF:+1 (727) 222-4444
TEL;TYPE=OTHER;TYPE=VOICE:+1 (727) 321-9876
EMAIL;TYPE=INTERNET;TYPE=HOME:alexsuprun@personaldomain.com
EMAIL;TYPE=INTERNET;TYPE=OTHER:alexsuprun@otherdomain.com
URL;TYPE=HOME:https://personaldomain.com/
URL;TYPE=OTHER:https://otherdomain.com/
TZ:-0500
X-SOCIALPROFILE;TYPE=Facebook:alexsuprun
X-SOCIALPROFILE;TYPE=Twitter:alexsuprun
X-SOCIALPROFILE;TYPE=LinkedIn:alexsuprun
X-SOCIALPROFILE;TYPE=Instagram:alexsuprun
X-SOCIALPROFILE;TYPE=YouTube:alexsuprun
X-SOCIALPROFILE;TYPE=TikTok:alexsuprun
CATEGORIES:avatar,persona,mockup
NOTE:I'm Alex Suprun, a connoisseur of the subtle art of connection. I weave the mundane into the magical with ease, turning pet whispers into the talk of the town. My knack for reading a room's vibe rivals ancient oracles, and my adventures often involve epic quests for legendary late-night snacks.
END:VCARD

I hope that examples my scenario better.

vnphanquang commented 7 months ago

Hello @extensionteamhq, thanks for the clarification. Just so we are on the same page, you want to encode the content of your vcard.vcf file in the QR code yes?

As I've mentioned, whatever passed to the data option is the QR-encoded data; @svelte-put does not automatically fetch the file for you. In other words, if you want to encode the file content, you need to pass that content as the data option. There are multiple ways to do this:

I've put together an example here showing both of the methods above. Please take a look and let me know if that's what you are looking for.

[!IMPORTANT] The content of your vcard.vcf is quite a lot in size. Notice, in the given example, I had to change the error correction level to either S or M to be able to fit the data in the generated QR. You can check out the QR capacity and play around more using this demo site.

extensionteamhq commented 7 months ago

Hi @vnphanquang, Thanks again for the quick reply. What you provided was very helpful and informative. Also, thank you for building out the two examples; they helped me understand what was being said.