mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-15 10:21:10 +02:00
Provides ShareModal component and initSharedUload/createShortLink utilities for other apps to create uLoad short links with source tracking. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
29 lines
952 B
TypeScript
29 lines
952 B
TypeScript
export const QR_API = 'https://api.qrserver.com/v1/create-qr-code';
|
|
|
|
export function generateShortCode(length = 6): string {
|
|
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
let code = '';
|
|
for (let i = 0; i < length; i++) {
|
|
code += chars[Math.floor(Math.random() * chars.length)];
|
|
}
|
|
return code;
|
|
}
|
|
|
|
export function getQrCodeUrl(shortUrl: string, size = 400): string {
|
|
return `${QR_API}/?size=${size}x${size}&data=${encodeURIComponent(shortUrl)}`;
|
|
}
|
|
|
|
export function getShortUrl(shortCode: string, baseUrl?: string): string {
|
|
const base =
|
|
baseUrl || (typeof window !== 'undefined' ? window.location.origin : 'https://ulo.ad');
|
|
return `${base}/${shortCode}`;
|
|
}
|
|
|
|
export function downloadQrCode(shortCode: string, baseUrl?: string): void {
|
|
const shortUrl = getShortUrl(shortCode, baseUrl);
|
|
const url = getQrCodeUrl(shortUrl, 400);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = `qr-${shortCode}.png`;
|
|
a.click();
|
|
}
|