Onttraders commited on
Commit
ee0ac9c
·
verified ·
1 Parent(s): 631d5ed

🐳 14/04 - 06:03 - DO NOT CHANGE ANY EXISTING DESIGN, STRUCTURE, OR FEATURES.We are enhancing the current BeatFridge platform by adding a monetization layer and improving the track upload system.Your

Browse files
Files changed (1) hide show
  1. app.js +255 -1
app.js CHANGED
@@ -1040,11 +1040,31 @@ const BF = (() => {
1040
  artist: _sfArtistName,
1041
  tier: 'Super Fan',
1042
  date: new Date().toISOString(),
1043
- fee: 3.75
 
 
 
 
 
1044
  });
1045
  localStorage.setItem('transactions', JSON.stringify(transactions));
1046
  } catch {}
1047
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1048
  // Show success step
1049
  document.getElementById('bfSfStep3')?.classList.add('hidden');
1050
  document.getElementById('bfSfStep4')?.classList.remove('hidden');
@@ -1246,6 +1266,240 @@ const BF = (() => {
1246
  } catch { return []; }
1247
  };
1248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1249
  // ===== INIT =====
1250
  const init = (activeTab) => {
1251
  injectStyles();
 
1040
  artist: _sfArtistName,
1041
  tier: 'Super Fan',
1042
  date: new Date().toISOString(),
1043
+ fee: 3.75,
1044
+ currency: 'USD',
1045
+ paymentMethod: 'card',
1046
+ cardLast4: last4,
1047
+ status: 'completed',
1048
+ userId: getCurrentUser()?.id || null
1049
  });
1050
  localStorage.setItem('transactions', JSON.stringify(transactions));
1051
  } catch {}
1052
 
1053
+ // Record creator earning
1054
+ recordCreatorEarning({
1055
+ type: 'subscription',
1056
+ amount: 25,
1057
+ artist: _sfArtistName,
1058
+ track: null,
1059
+ trackId: null,
1060
+ fee: 3.75,
1061
+ currency: 'USD',
1062
+ paymentMethod: 'card',
1063
+ cardLast4: last4,
1064
+ status: 'completed',
1065
+ date: new Date().toISOString()
1066
+ });
1067
+
1068
  // Show success step
1069
  document.getElementById('bfSfStep3')?.classList.add('hidden');
1070
  document.getElementById('bfSfStep4')?.classList.remove('hidden');
 
1266
  } catch { return []; }
1267
  };
1268
 
1269
+ // ===== MONETIZATION PRESETS =====
1270
+ const MonetizationPresets = {
1271
+ free: { isMonetized: false, isLocked: false, minimumPrice: 0, suggestedPrice: 0, superFanFree: true },
1272
+ payWhatYouWant: { isMonetized: true, isLocked: true, minimumPrice: 0.50, suggestedPrice: 0, superFanFree: true },
1273
+ fixedPrice: { isMonetized: true, isLocked: true, minimumPrice: 0.99, suggestedPrice: 2.99, superFanFree: true },
1274
+ superFanExclusive: { isMonetized: true, isLocked: true, minimumPrice: 0, suggestedPrice: 0, superFanFree: false },
1275
+ premium: { isMonetized: true, isLocked: true, minimumPrice: 4.99, suggestedPrice: 9.99, superFanFree: true }
1276
+ };
1277
+
1278
+ // ===== UNIFIED PAYMENT PROCESSING =====
1279
+ const processTip = (artistName, amount, options = {}) => {
1280
+ if (!isLoggedIn()) return { success: false, error: 'Must be logged in to tip' };
1281
+ if (!amount || isNaN(amount) || amount < MONETIZATION_DEFAULTS.minimumPrice) {
1282
+ return { success: false, error: 'Minimum tip is
1283
+ const init = (activeTab) => {
1284
+ injectStyles();
1285
+ injectBottomNav(activeTab);
1286
+ migrateSuperFanData();
1287
+ syncPlayer();
1288
+ updateTopNav();
1289
+ adjustTopNav();
1290
+ updateSuperFanButtons();
1291
+ if (window.lucide) lucide.createIcons();
1292
+
1293
+ // Re-sync player every 2 seconds
1294
+ setInterval(syncPlayer, 2000);
1295
+ };
1296
+
1297
+ return {
1298
+ isLoggedIn, isProducer, isFan, getCurrentUser, signIn, signOut, signUp,
1299
+ getAllTracks, getArtists, getGenres, getTrendingTracks, getFreshUploads,
1300
+ searchTracks, searchArtists,
1301
+ init, showSignInModal, closeSignInModal, handleSignIn,
1302
+ showSignUpForm, showSignInForm, showChooseType, handleSignUp,
1303
+ adjustTopNav, showToast, syncPlayer, playTrack, togglePlay,
1304
+ showSuperFanModal, closeSuperFanModal, confirmSuperFanPayment, showSuperFanPaymentStep, showSuperFanSummaryStep, formatCardNumber, formatCardExpiry, isSuperFanOf, updateSuperFanButtons,
1305
+ getSuperFanSubscriptions, cancelSuperFanSubscription,
1306
+ showDownloadModal, closeDownloadModal, isDownloadUnlocked, unlockTrackDownload, getDownloadStates, handleDownloadUnlock, processMockDownload,
1307
+ // Role system
1308
+ ROLES, getUserRole, canBrowse, canDownload, canUpload, canEarn, hasFreeDownloads,
1309
+ // Monetization
1310
+ MONETIZATION_DEFAULTS, getMonetizationConfig,
1311
+ getTrackMonetization, setTrackMonetization, isTrackLocked,
1312
+ // Creator earnings
1313
+ getCreatorEarnings, recordCreatorEarning, getCreatorEarningsSummary,
1314
+ // Enhanced transactions
1315
+ getTransactionHistory,
1316
+ // Monetization presets
1317
+ MonetizationPresets,
1318
+ // Unified payment processing
1319
+ processTip, processSubscription,
1320
+ // User capabilities
1321
+ getUserCapabilities,
1322
+ // Track publishing with monetization
1323
+ publishTrackWithMonetization,
1324
+ // Creator dashboard
1325
+ getCreatorDashboard
1326
+ };
1327
+ })(); + MONETIZATION_DEFAULTS.minimumPrice };
1328
+ }
1329
+ try {
1330
+ const config = getMonetizationConfig();
1331
+ const fee = +(amount * config.platformFeePercent / 100).toFixed(2);
1332
+ const user = getCurrentUser();
1333
+ const last4 = options.cardLast4 || '4242';
1334
+
1335
+ const tx = {
1336
+ type: 'tip',
1337
+ amount: amount,
1338
+ artist: artistName,
1339
+ date: new Date().toISOString(),
1340
+ fee: fee,
1341
+ currency: options.currency || config.currency,
1342
+ paymentMethod: options.paymentMethod || 'card',
1343
+ cardLast4: last4,
1344
+ status: 'completed',
1345
+ userId: user ? user.id : null,
1346
+ message: options.message || null
1347
+ };
1348
+
1349
+ const transactions = JSON.parse(localStorage.getItem('transactions') || '[]');
1350
+ transactions.push(tx);
1351
+ localStorage.setItem('transactions', JSON.stringify(transactions));
1352
+
1353
+ recordCreatorEarning(tx);
1354
+
1355
+ if (options.deductFromWallet !== false) {
1356
+ const balance = parseFloat(localStorage.getItem('walletBalance') || '0');
1357
+ if (balance >= amount) {
1358
+ localStorage.setItem('walletBalance', (balance - amount).toFixed(2));
1359
+ }
1360
+ }
1361
+
1362
+ return { success: true, transaction: tx };
1363
+ } catch (e) {
1364
+ return { success: false, error: 'Tip processing failed' };
1365
+ }
1366
+ };
1367
+
1368
+ const processSubscription = (artistName, amount, tier, options = {}) => {
1369
+ if (!isLoggedIn()) return { success: false, error: 'Must be logged in to subscribe' };
1370
+ try {
1371
+ const config = getMonetizationConfig();
1372
+ const fee = +(amount * config.platformFeePercent / 100).toFixed(2);
1373
+ const user = getCurrentUser();
1374
+ const last4 = options.cardLast4 || '4242';
1375
+
1376
+ const tx = {
1377
+ type: 'subscription',
1378
+ amount: amount,
1379
+ artist: artistName,
1380
+ tier: tier,
1381
+ date: new Date().toISOString(),
1382
+ fee: fee,
1383
+ currency: options.currency || config.currency,
1384
+ paymentMethod: options.paymentMethod || 'card',
1385
+ cardLast4: last4,
1386
+ status: 'completed',
1387
+ userId: user ? user.id : null
1388
+ };
1389
+
1390
+ const transactions = JSON.parse(localStorage.getItem('transactions') || '[]');
1391
+ transactions.push(tx);
1392
+ localStorage.setItem('transactions', JSON.stringify(transactions));
1393
+
1394
+ recordCreatorEarning(tx);
1395
+
1396
+ return { success: true, transaction: tx };
1397
+ } catch (e) {
1398
+ return { success: false, error: 'Subscription processing failed' };
1399
+ }
1400
+ };
1401
+
1402
+ // ===== USER CAPABILITIES =====
1403
+ const getUserCapabilities = () => {
1404
+ const role = getUserRole();
1405
+ const user = getCurrentUser();
1406
+ const isCreatorRole = user && (user.role === 'producer' || user.isArtist);
1407
+ const isSuperFanRole = role === ROLES.SUPERFAN;
1408
+ const isCreator = isCreatorRole || isSuperFanRole;
1409
+ const isGuest = role === ROLES.GUEST;
1410
+ const compositeRoles = [];
1411
+ if (isCreatorRole) compositeRoles.push(ROLES.CREATOR);
1412
+ if (isSuperFanRole) compositeRoles.push(ROLES.SUPERFAN);
1413
+ if (!isCreatorRole && !isSuperFanRole && !isGuest) compositeRoles.push(ROLES.USER);
1414
+ if (isGuest) compositeRoles.push(ROLES.GUEST);
1415
+
1416
+ return {
1417
+ role: role,
1418
+ roles: compositeRoles,
1419
+ canBrowse: true,
1420
+ canPlay: true,
1421
+ canDownload: !isGuest,
1422
+ canUpload: isCreator,
1423
+ canEarn: isCreatorRole,
1424
+ canMonetize: isCreatorRole,
1425
+ hasFreeDownloads: isSuperFanRole,
1426
+ canComment: !isGuest,
1427
+ canFollow: !isGuest,
1428
+ canLike: !isGuest,
1429
+ canCreatePlaylist: !isGuest,
1430
+ canViewAnalytics: isCreatorRole,
1431
+ canSetPricing: isCreatorRole,
1432
+ canManageTracks: isCreatorRole,
1433
+ canUpgradeRole: !isGuest,
1434
+ maxUploadSize: isCreator ? 500 : 0,
1435
+ maxTracks: isCreator ? (localStorage.getItem('isPro') === 'true' ? Infinity : 10) : 0
1436
+ };
1437
+ };
1438
+
1439
+ // ===== PUBLISH TRACK WITH MONETIZATION =====
1440
+ const publishTrackWithMonetization = (trackData, monetizationConfig = null) => {
1441
+ try {
1442
+ let allTracks = JSON.parse(localStorage.getItem('beatfridge_tracks') || '[]');
1443
+ allTracks.push(trackData);
1444
+ localStorage.setItem('beatfridge_tracks', JSON.stringify(allTracks));
1445
+
1446
+ let userTracks = JSON.parse(localStorage.getItem('userTracks') || '[]');
1447
+ userTracks.push(trackData);
1448
+ localStorage.setItem('userTracks', JSON.stringify(userTracks));
1449
+
1450
+ if (monetizationConfig && monetizationConfig.isMonetized) {
1451
+ setTrackMonetization(trackData.id, monetizationConfig);
1452
+ } else if (monetizationConfig) {
1453
+ setTrackMonetization(trackData.id, {
1454
+ isMonetized: false,
1455
+ isLocked: false,
1456
+ superFanFree: true,
1457
+ ...monetizationConfig
1458
+ });
1459
+ }
1460
+
1461
+ return { success: true, track: trackData };
1462
+ } catch (e) {
1463
+ return { success: false, error: 'Publish failed: ' + e.message };
1464
+ }
1465
+ };
1466
+
1467
+ // ===== CREATOR DASHBOARD DATA =====
1468
+ const getCreatorDashboard = (creatorId) => {
1469
+ const earnings = getCreatorEarnings(creatorId);
1470
+ const summary = getCreatorEarningsSummary(creatorId);
1471
+ const allTransactions = getTransactionHistory({});
1472
+ const creatorTransactions = allTransactions.filter(t => t.artist === creatorId || t.artistId === creatorId);
1473
+ const tracks = getAllTracks().filter(t => t.artistId === creatorId || t.artist === creatorId);
1474
+ const config = getMonetizationConfig();
1475
+
1476
+ const trackStats = tracks.map(track => {
1477
+ const monetization = getTrackMonetization(track.id);
1478
+ const trackEarnings = earnings.filter(e => e.trackId === track.id);
1479
+ const trackRevenue = trackEarnings.reduce((sum, e) => sum + e.netAmount, 0);
1480
+ return {
1481
+ trackId: track.id,
1482
+ title: track.title,
1483
+ plays: track.plays,
1484
+ revenue: +trackRevenue.toFixed(2),
1485
+ monetization: monetization,
1486
+ isLocked: monetization ? monetization.isLocked : false,
1487
+ downloadCount: trackEarnings.filter(e => e.source === 'download').length,
1488
+ tipCount: trackEarnings.filter(e => e.source === 'tip').length
1489
+ };
1490
+ });
1491
+
1492
+ return {
1493
+ summary,
1494
+ tracks: trackStats,
1495
+ recentTransactions: creatorTransactions.slice(0, 20),
1496
+ monetizationConfig: config,
1497
+ payoutRate: config.creatorPayoutPercent + '%',
1498
+ pendingPayout: summary.totalNet,
1499
+ lastUpdated: new Date().toISOString()
1500
+ };
1501
+ };
1502
+
1503
  // ===== INIT =====
1504
  const init = (activeTab) => {
1505
  injectStyles();