top of page
6. Başlık

// BU BLOĞU KULLANMADAN ÖNCE backend/http-functions.js IMPORTLARINA ŞUNU EKLE: // // import { ensureSocialCover } from 'backend/coverGen.jsw'; // // Sonra mevcut SOCIAL SHARE — SONG SHARE ENDPOINT bloğunu aşağıdakiyle değiştir. // ============================================================ // SOCIAL SHARE — SONG SHARE ENDPOINT // backend/http-functions.js DOSYASININ EN SONUNA EKLE // // Public URL: // https://www.bestebankasi.net/_functions/songShare?songId=... // ============================================================ const SHARE_ALLOWED_LANDINGS = new Set([ "/beste-al-standart-alan-giris", "/kopyasi-muzik-listeleri", "/muzik-listeleri" ]); function sharePickLanding(raw) { try { const decoded = decodeURIComponent(safeStr(raw)); if (!decoded) return "/beste-al-standart-alan-giris"; if (decoded.startsWith("http://") || decoded.startsWith("https://")) { return "/beste-al-standart-alan-giris"; } return SHARE_ALLOWED_LANDINGS.has(decoded) ? decoded : "/beste-al-standart-alan-giris"; } catch (_) { return "/beste-al-standart-alan-giris"; } } function shareImageValue(value) { if (!value) return ""; if (typeof value === "string") { return value.trim(); } if (typeof value === "object") { return shareImageValue( value.src || value.url || value.fileUrl || value.image || "" ); } return ""; } function sharePublicImageUrl(value) { const src = shareImageValue(value); if (!src) return ""; if (src.startsWith("https://") || src.startsWith("http://")) { return src; } if (src.startsWith("wix:image://v1/")) { const clean = src.replace("wix:image://v1/", ""); const mediaId = clean.split("/")[0]; return mediaId ? `https://static.wixstatic.com/media/${mediaId}` : ""; } if (src.startsWith("image://v1/")) { const clean = src.replace("image://v1/", ""); const mediaId = clean.split("/")[0]; return mediaId ? `https://static.wixstatic.com/media/${mediaId}` : ""; } return ""; } function sharePickCover(item) { return ( item?.coverUrl || item?.kapak || item?.kapakGorsel?.src || item?.coverImage || item?.image || item?.albumCover || item?.dosyaYuklemeAlani2 || "" ); } export async function get_songShare(request) { try { const q = request?.query || {}; const songId = safeStr(q.songId); if (!songId) { return ok({ headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" }, body: `<!doctype html> <html lang="tr"> <head> <meta charset="utf-8"> <title>Beste Bankası</title> </head> <body>Şarkı bulunamadı.</body> </html>` }); } const item = await wixData .get("contact017", songId, { suppressAuth: true, suppressHooks: true }) .catch(() => null); if (!item) { return ok({ headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" }, body: `<!doctype html> <html lang="tr"> <head> <meta charset="utf-8"> <title>Beste Bankası</title> </head> <body>Şarkı bulunamadı.</body> </html>` }); } const title = safeStr( item.kisaMetinAlani2 || item.title || "Şarkı" ); const code = safeStr(item.kod); const description = code ? `“${title}” • Beste Kodu: ${code} • Beste Bankası'nda dinle ve keşfet.` : `“${title}” eserini Beste Bankası'nda dinle ve keşfet.`; // Önce coverGen sosyal medya için gerçek raster kapak üretmeye/çözmeye çalışır. // Bu çağrı native npm paketi kullanmaz. let ensuredCover = ''; try { const coverResult = await ensureSocialCover(songId); ensuredCover = coverResult?.ok ? safeStr(coverResult.url) : ''; } catch (_) {} const rawCover = ensuredCover || sharePickCover(item); const coverUrl = sharePublicImageUrl(rawCover); const landingBase = sharePickLanding(q.landing); const landingParams = new URLSearchParams(); landingParams.set("songId", songId); landingParams.set("utm_source", safeStr(q.utm_source) || "social"); landingParams.set("utm_medium", safeStr(q.utm_medium) || "share"); landingParams.set("utm_campaign", safeStr(q.utm_campaign) || "song-share"); const landingUrl = `https://www.bestebankasi.net${landingBase}?${landingParams.toString()}`; const canonicalParams = new URLSearchParams(); canonicalParams.set("songId", songId); if (q.landing) { canonicalParams.set("landing", safeStr(q.landing)); } // Facebook cache'ini sürüm bazında ayır. if (q.share_v) { canonicalParams.set("share_v", safeStr(q.share_v)); } const canonicalUrl = `https://www.bestebankasi.net/_functions/songShare?${canonicalParams.toString()}`; const imageTags = coverUrl ? ` <meta property="og:image" content="${esc(coverUrl)}"> <meta property="og:image:secure_url" content="${esc(coverUrl)}"> <meta property="og:image:type" content="image/png"> <meta property="og:image:width" content="1200"> <meta property="og:image:height" content="1200"> <meta name="twitter:image" content="${esc(coverUrl)}">` : ""; const html = `<!doctype html> <html lang="tr"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>${esc(title)} | Beste Bankası</title> <meta name="description" content="${esc(description)}"> <meta property="og:title" content="${esc(title)}"> <meta property="og:description" content="${esc(description)}"> <meta property="og:type" content="website"> <meta property="og:site_name" content="Beste Bankası"> <meta property="og:url" content="${esc(canonicalUrl)}"> ${imageTags} <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:title" content="${esc(title)}"> <meta name="twitter:description" content="${esc(description)}"> <link rel="canonical" href="${esc(canonicalUrl)}"> <style> html,body{ margin:0; min-height:100%; background:#0b0b0b; color:#fff; font-family:Arial,sans-serif; } body{ display:flex; align-items:center; justify-content:center; min-height:100vh; text-align:center; padding:24px; box-sizing:border-box; } .card{ width:min(520px,92vw); padding:28px; border:1px solid #333; border-radius:18px; background:#111; } img{ width:180px; height:180px; border-radius:16px; object-fit:cover; display:block; margin:0 auto 20px; } h1{ font-size:26px; margin:0 0 10px; } p{ opacity:.75; line-height:1.5; } a{ display:inline-block; margin-top:14px; padding:12px 18px; border-radius:10px; background:#ff8a1f; color:#111; font-weight:700; text-decoration:none; } </style> <script> setTimeout(function () { window.location.replace(${JSON.stringify(landingUrl)}); }, 900); </script> </head> <body> <div class="card"> ${coverUrl ? `<img src="${esc(coverUrl)}" alt="${esc(title)}">` : ""} <h1>${esc(title)}</h1> <p>${esc(description)}</p> <a href="${esc(landingUrl)}">Dinle / Satın Al</a> </div> </body> </html>`; return ok({ headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store, no-cache, must-revalidate, max-age=0" }, body: html }); } catch (e) { return serverError({ headers: { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store" }, body: "ERR " + safeStr(e?.message || e) }); } }

bottom of page