mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-23 19:26:42 +02:00
feat(shared-uload): add shared package with ShareModal and cross-app link creation
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>
This commit is contained in:
parent
98ca01f466
commit
8050da31ea
7 changed files with 506 additions and 0 deletions
29
packages/shared-uload/src/utils.ts
Normal file
29
packages/shared-uload/src/utils.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue