top of page
LinkMe Open Source Code
URL Redirector Source
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
// Get the ID of the dynamic page
const itemId = $w('#dynamicDataset').getCurrentItem()._id;
// Query the database for the link associated with the dynamic page
wixData.query('Links')
.eq('_id', itemId)
.find()
.then(result => {
// Redirect to the link
const link = result.items[0].link;
wixLocation.to(link);
})
.catch(error => {
console.error(error);
});
});
QR Code Generator Source
import { generateQRcode, uploadImage, getDownloadUrl } from 'backend/qrCode.jsw';
let fileUrl, downloadUrl;
$w.onReady(() => {
$w('#generateButton').onClick(async () => {
const qrValue = $w('#qrInput').value;
const qr = await generateQRcode(qrValue);
//Upload QR to Media Manager
const upload = await uploadImage(qr, qrValue);
fileUrl = upload.fileUrl;
//Show QR Code on Client Side
$w('#qrVector').src = qr;
//Adds Download Link to Button
downloadUrl = await getDownloadUrl(fileUrl);
$w('#downloadQR').link = downloadUrl;
});
});
import QRCode from 'qrcode';
export function generateQRcode(toEncode) {
let opts = {
errorCorrectionLevel: 'H',
type: 'svg',
rendererOpts: {
quality: 0.3
}
};
return QRCode.toString(toEncode, opts, (err, string) => {
if (err) throw err;
return string;
})
}
import { mediaManager } from 'wix-media-backend';
export async function getDownloadUrl(fileUrl) {
const getDownloadUrl = await mediaManager.getDownloadUrl(fileUrl);
return getDownloadUrl;
}
export function uploadImage(buffer,fileName) {
//Ensures proper filename is established (no invalid characters)
fileName = fileName.replace(/[/\\?%*:|."<>]/g, '-');
return mediaManager.upload(
"/QR",
buffer,
`${fileName}`,
{
"mediaOptions": {
"mimeType": "image/svg+xml",
"mediaType": "vector"
},
"metadataOptions": {
"isPrivate": false,
"isVisitorUpload": true
}
}
);
}
URL Parameter Source
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#addButton").onClick((event) => {
const key = $w('#addKey').value;
const value = $w('#addValue').value;
if (key && value) {
const toAdd = { [key]: value };
wixLocation.queryParams.add(toAdd);
$w('#addKey').value = undefined;
$w('#addValue').value = undefined;
}
});
$w("#removeButton").onClick((event) => {
const paramToRemove = [$w('#removeKey').value];
wixLocation.queryParams.remove(paramToRemove);
$w('#removeKey').value = undefined;
});
$w("#getButton").onClick((event) => {
const query = wixLocation.query;
if (query) {
$w('#getText').value = JSON.stringify(query, null, 2);
}
});
});
bottom of page