Mark-Lasfar commited on
Commit
c090961
·
1 Parent(s): a29cbf6

Add GraphQL

Browse files
Files changed (3) hide show
  1. graphql/resolvers.js +28 -0
  2. graphql/schema.js +33 -0
  3. server.js +113 -36
graphql/resolvers.js CHANGED
@@ -2359,7 +2359,13 @@ const Query = {
2359
  reactionsCount: (story.reactions || []).length,
2360
  hasViewed: hasViewed,
2361
  textColor: story.textColor || '#ffffff',
 
2362
  allowDownload: story.allowDownload || false,
 
 
 
 
 
2363
 
2364
  textStyle: story.textStyle || { // ✅ أضف هذا
2365
  fontSize: 32,
@@ -2431,7 +2437,13 @@ const Query = {
2431
  reactionsCount: (story.reactions || []).length,
2432
  hasViewed: hasViewed,
2433
  textColor: story.textColor || '#ffffff',
 
2434
  allowDownload: story.allowDownload || false,
 
 
 
 
 
2435
  textStyle: story.textStyle || { // ✅ أضف هذا
2436
  fontSize: 32,
2437
  fontFamily: 'Inter',
@@ -2524,7 +2536,13 @@ const Query = {
2524
  reactionsCount: (story.reactions || []).length,
2525
  hasViewed: hasViewed,
2526
  textColor: story.textColor || '#ffffff',
 
2527
  allowDownload: story.allowDownload || false,
 
 
 
 
 
2528
  textStyle: story.textStyle || { // ✅ أضف هذا
2529
  fontSize: 32,
2530
  fontFamily: 'Inter',
@@ -2617,6 +2635,11 @@ const Query = {
2617
  userId: story.userId,
2618
  textColor: story.textColor || '#ffffff',
2619
  allowDownload: story.allowDownload || false,
 
 
 
 
 
2620
  textStyle: story.textStyle || { // ✅ أضف هذا
2621
  fontSize: 32,
2622
  fontFamily: 'Inter',
@@ -2714,6 +2737,11 @@ const Query = {
2714
  userId: story.userId,
2715
  textColor: story.textColor || '#ffffff',
2716
  allowDownload: story.allowDownload || false,
 
 
 
 
 
2717
  textStyle: story.textStyle || { // ✅ أضف هذا
2718
  fontSize: 32,
2719
  fontFamily: 'Inter',
 
2359
  reactionsCount: (story.reactions || []).length,
2360
  hasViewed: hasViewed,
2361
  textColor: story.textColor || '#ffffff',
2362
+ userId: story.userId,
2363
  allowDownload: story.allowDownload || false,
2364
+ filter: story.filter || 'none', // ✅ أضف هذا
2365
+ filterIntensity: story.filterIntensity || 0.5, // ✅ أضف هذا
2366
+ filterApplied: story.filterApplied || false, // ✅ أضف هذا
2367
+ audio: story.audio || { url: null, publicId: null, duration: 0 }, // ✅ أضف هذا
2368
+
2369
 
2370
  textStyle: story.textStyle || { // ✅ أضف هذا
2371
  fontSize: 32,
 
2437
  reactionsCount: (story.reactions || []).length,
2438
  hasViewed: hasViewed,
2439
  textColor: story.textColor || '#ffffff',
2440
+ userId: story.userId,
2441
  allowDownload: story.allowDownload || false,
2442
+ filter: story.filter || 'none', // ✅ أضف هذا
2443
+ filterIntensity: story.filterIntensity || 0.5, // ✅ أضف هذا
2444
+ filterApplied: story.filterApplied || false, // ✅ أضف هذا
2445
+ audio: story.audio || { url: null, publicId: null, duration: 0 }, // ✅ أضف هذا
2446
+
2447
  textStyle: story.textStyle || { // ✅ أضف هذا
2448
  fontSize: 32,
2449
  fontFamily: 'Inter',
 
2536
  reactionsCount: (story.reactions || []).length,
2537
  hasViewed: hasViewed,
2538
  textColor: story.textColor || '#ffffff',
2539
+ userId: story.userId,
2540
  allowDownload: story.allowDownload || false,
2541
+ filter: story.filter || 'none', // ✅ أضف هذا
2542
+ filterIntensity: story.filterIntensity || 0.5, // ✅ أضف هذا
2543
+ filterApplied: story.filterApplied || false, // ✅ أضف هذا
2544
+ audio: story.audio || { url: null, publicId: null, duration: 0 }, // ✅ أضف هذا
2545
+
2546
  textStyle: story.textStyle || { // ✅ أضف هذا
2547
  fontSize: 32,
2548
  fontFamily: 'Inter',
 
2635
  userId: story.userId,
2636
  textColor: story.textColor || '#ffffff',
2637
  allowDownload: story.allowDownload || false,
2638
+ filer: story.filter || 'none', // ✅ أضف هذا
2639
+ filterIntensity: story.filterIntensity || 0.5, // ✅ أضف هذا
2640
+ filterApplied: story.filterApplied || false, // ✅ أضف هذا
2641
+ audio: story.audio || { url: null, publicId: null, duration: 0 }, // ✅ أضف هذا
2642
+
2643
  textStyle: story.textStyle || { // ✅ أضف هذا
2644
  fontSize: 32,
2645
  fontFamily: 'Inter',
 
2737
  userId: story.userId,
2738
  textColor: story.textColor || '#ffffff',
2739
  allowDownload: story.allowDownload || false,
2740
+ filer: story.filter || 'none', // ✅ أضف هذا
2741
+ filterIntensity: story.filterIntensity || 0.5, // ✅ أضف هذا
2742
+ filterApplied: story.filterApplied || false, // ✅ أضف هذا
2743
+ audio: story.audio || { url: null, publicId: null, duration: 0 }, // ✅ أضف هذا
2744
+
2745
  textStyle: story.textStyle || { // ✅ أضف هذا
2746
  fontSize: 32,
2747
  fontFamily: 'Inter',
graphql/schema.js CHANGED
@@ -10,6 +10,27 @@ const typeDefs = gql`
10
  scalar Upload
11
  scalar FileUpload
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # ============================================
14
  # 🔹 INPUT TYPES
15
  # ============================================
@@ -734,10 +755,16 @@ const typeDefs = gql`
734
  _id: ID!
735
  userId: User!
736
  media: StoryMedia
 
737
  text: String!
738
  backgroundColor: String!
739
  textColor: String!
740
  allowDownload: Boolean!
 
 
 
 
 
741
  textStyle: TextStyle!
742
  views: [StoryView!]!
743
  reactions: [StoryReaction!]!
@@ -750,6 +777,12 @@ const typeDefs = gql`
750
  hasViewed: Boolean
751
  }
752
 
 
 
 
 
 
 
753
  type TextStyle {
754
  fontSize: Int!
755
  fontFamily: String!
 
10
  scalar Upload
11
  scalar FileUpload
12
 
13
+ enum FilterType {
14
+ NONE
15
+ VINTAGE
16
+ NOIR
17
+ COOL
18
+ WARM
19
+ DRAMATIC
20
+ DREAMY
21
+ VIVID
22
+ FADE
23
+ SEPIA
24
+ GRAYSCALE
25
+ BLUR
26
+ GRAIN
27
+ VIGNETTE
28
+ NEON
29
+ RETRO
30
+ CINEMATIC
31
+ PASTEL
32
+ }
33
+
34
  # ============================================
35
  # 🔹 INPUT TYPES
36
  # ============================================
 
755
  _id: ID!
756
  userId: User!
757
  media: StoryMedia
758
+ audio: AudioData
759
  text: String!
760
  backgroundColor: String!
761
  textColor: String!
762
  allowDownload: Boolean!
763
+ filter: String!
764
+ filterIntensity: Float!
765
+ filterApplied: Boolean!
766
+
767
+
768
  textStyle: TextStyle!
769
  views: [StoryView!]!
770
  reactions: [StoryReaction!]!
 
777
  hasViewed: Boolean
778
  }
779
 
780
+ type AudioData {
781
+ url: String
782
+ publicId: String
783
+ duration: Int
784
+ waveform: [Float]
785
+ }
786
  type TextStyle {
787
  fontSize: Int!
788
  fontFamily: String!
server.js CHANGED
@@ -938,6 +938,7 @@ const uploadStory = multer({
938
  let folder = `Stories/${req.user.userId}`;
939
  let allowedFormats = [];
940
  let transformation = [];
 
941
 
942
  // 📸 الصور
943
  if (file.mimetype.startsWith('image/')) {
@@ -951,6 +952,10 @@ const uploadStory = multer({
951
  { quality: 'auto:good' },
952
  { fetch_format: 'auto' }
953
  ];
 
 
 
 
954
  }
955
  // 🎬 الفيديوهات
956
  else if (file.mimetype.startsWith('video/')) {
@@ -963,13 +968,35 @@ const uploadStory = multer({
963
  transformation = [
964
  { quality: 'auto' }
965
  ];
 
 
 
 
966
  }
967
- // 🎵 الصوتيات (لو أضفناها مستقبلاً)
968
  else if (file.mimetype.startsWith('audio/')) {
969
- resourceType = 'video'; // Cloudinary بيتعامل مع الصوت كـ video
970
- allowedFormats = ['mp3', 'wav', 'aac', 'ogg', 'm4a', 'flac'];
971
  folder = `Stories/${req.user.userId}/audio`;
972
- transformation = [];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  }
974
 
975
  return {
@@ -978,26 +1005,13 @@ const uploadStory = multer({
978
  resource_type: resourceType,
979
  public_id: `story_${Date.now()}_${file.originalname.split('.')[0]}`,
980
  transformation: transformation.length > 0 ? transformation : undefined,
981
- // تحسينات إضافية
982
- ...(resourceType === 'image' && {
983
- eager: [
984
- { width: 1080, height: 1920, crop: 'limit' },
985
- { width: 540, height: 960, crop: 'limit' }
986
- ],
987
- eager_async: true
988
- }),
989
- ...(resourceType === 'video' && {
990
- eager: [
991
- { format: 'mp4', quality: 'auto' },
992
- { format: 'webm', quality: 'auto' }
993
- ],
994
- eager_async: true
995
- })
996
  };
997
  }
998
  }),
999
  limits: {
1000
- fileSize: 50 * 1024 * 1024 // 50MB للفيديوهات الكبيرة
1001
  },
1002
  fileFilter: (req, file, cb) => {
1003
  const imageTypes = [
@@ -1016,7 +1030,7 @@ const uploadStory = multer({
1016
 
1017
  const audioTypes = [
1018
  'audio/mpeg', 'audio/wav', 'audio/aac', 'audio/ogg',
1019
- 'audio/mp4', 'audio/flac'
1020
  ];
1021
 
1022
  const allAllowed = [...imageTypes, ...videoTypes, ...audioTypes];
@@ -1027,7 +1041,7 @@ const uploadStory = multer({
1027
  'Unsupported file type. Supported formats:\n' +
1028
  '📸 Images: JPEG, PNG, GIF, WEBP, BMP, TIFF, SVG, AVIF, HEIC\n' +
1029
  '🎬 Videos: MP4, WEBM, OGG, MOV, AVI, MKV, FLV, WMV, MPEG, 3GP\n' +
1030
- '🎵 Audio: MP3, WAV, AAC, OGG, M4A, FLAC'
1031
  ), false);
1032
  }
1033
 
@@ -1039,7 +1053,7 @@ const uploadStory = multer({
1039
  } else if (file.mimetype.startsWith('video/')) {
1040
  maxSize = 50 * 1024 * 1024; // 50MB للفيديوهات
1041
  } else if (file.mimetype.startsWith('audio/')) {
1042
- maxSize = 20 * 1024 * 1024; // 20MB للصوتيات
1043
  }
1044
 
1045
  if (file.size > maxSize) {
@@ -1834,10 +1848,25 @@ const storySchema = new mongoose.Schema({
1834
  publicId: { type: String, default: null },
1835
  type: {
1836
  type: String,
1837
- enum: ['image', 'video', 'none'],
1838
  default: 'none'
1839
  }
1840
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1841
  text: {
1842
  type: String,
1843
  maxlength: 2000,
@@ -1856,6 +1885,19 @@ const storySchema = new mongoose.Schema({
1856
  default: false
1857
  },
1858
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1859
  textStyle: {
1860
  fontSize: { type: Number, default: 32 }, // حجم الخط
1861
  fontFamily: { type: String, default: 'Inter' }, // نوع الخط
@@ -1939,6 +1981,9 @@ const storySchema = new mongoose.Schema({
1939
  // فهارس محسّنة
1940
  storySchema.index({ userId: 1, createdAt: -1 });
1941
  storySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
 
 
 
1942
 
1943
  // فيريتول (Virtual) لحساب عدد المشاهدات
1944
  storySchema.virtual('viewsCount').get(function() {
@@ -15512,11 +15557,17 @@ app.put('/api/notifications/:id/read', authenticateToken, async (req, res) => {
15512
  // ============================================
15513
  // POST /api/stories - إنشاء story (باستخدام uploadStory)
15514
  // ============================================
15515
- app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
 
 
 
 
15516
  body('text').optional().isString(),
15517
  body('backgroundColor').optional().isString(),
15518
  body('textColor').optional().isString(),
15519
  body('textStyle').optional().isString(),
 
 
15520
  body('allowDownload').optional().isBoolean(),
15521
  body('visibility').optional().isIn(['public', 'followers', 'only-me'])
15522
  ], handleUploadError, async (req, res) => {
@@ -15530,15 +15581,35 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15530
  let publicId = null;
15531
  let mediaType = 'none';
15532
 
15533
- if (req.file) {
15534
- mediaUrl = req.file.path || req.file.secure_url || null;
15535
- publicId = req.file.filename || req.file.public_id || null;
15536
- mediaType = req.file.mimetype?.startsWith('video') ? 'video' : 'image';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15537
  }
15538
 
15539
- if (!mediaUrl && !req.body.text) {
 
15540
  return res.status(400).json({
15541
- error: 'Story must have media or text content'
15542
  });
15543
  }
15544
 
@@ -15560,18 +15631,17 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15560
  let textStyleObj = defaultTextStyle;
15561
  if (req.body.textStyle) {
15562
  try {
15563
- // إذا كان String، نحوله إلى Object
15564
  const parsed = typeof req.body.textStyle === 'string'
15565
  ? JSON.parse(req.body.textStyle)
15566
  : req.body.textStyle;
15567
  textStyleObj = { ...defaultTextStyle, ...parsed };
15568
  } catch (e) {
15569
  console.error('Error parsing textStyle:', e);
15570
- // إذا فشل التحويل، نستخدم الـ default
15571
  textStyleObj = defaultTextStyle;
15572
  }
15573
  }
15574
 
 
15575
  const story = new Story({
15576
  userId: req.user.userId,
15577
  media: {
@@ -15579,6 +15649,15 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15579
  publicId: publicId,
15580
  type: mediaType
15581
  },
 
 
 
 
 
 
 
 
 
15582
  text: req.body.text || '',
15583
  backgroundColor: req.body.backgroundColor || '#000000',
15584
  textColor: req.body.textColor || '#ffffff',
@@ -15587,9 +15666,8 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15587
  visibility: req.body.visibility || 'followers'
15588
  });
15589
 
15590
-
15591
  await story.save();
15592
- await notifyFollowersAboutStory(req.user.userId);
15593
 
15594
  res.status(201).json({
15595
  success: true,
@@ -15609,7 +15687,6 @@ app.post('/api/stories', authenticateToken, uploadStory.single('media'), [
15609
  }
15610
  });
15611
 
15612
-
15613
  // ============================================
15614
  // NOTIFY FOLLOWERS ABOUT STORY - إشعار المتابعين بقصة جديدة
15615
  // ============================================
 
938
  let folder = `Stories/${req.user.userId}`;
939
  let allowedFormats = [];
940
  let transformation = [];
941
+ let eager = [];
942
 
943
  // 📸 الصور
944
  if (file.mimetype.startsWith('image/')) {
 
952
  { quality: 'auto:good' },
953
  { fetch_format: 'auto' }
954
  ];
955
+ eager = [
956
+ { width: 1080, height: 1920, crop: 'limit' },
957
+ { width: 540, height: 960, crop: 'limit' }
958
+ ];
959
  }
960
  // 🎬 الفيديوهات
961
  else if (file.mimetype.startsWith('video/')) {
 
968
  transformation = [
969
  { quality: 'auto' }
970
  ];
971
+ eager = [
972
+ { format: 'mp4', quality: 'auto' },
973
+ { format: 'webm', quality: 'auto' }
974
+ ];
975
  }
976
+ // 🎵 الصوتيات
977
  else if (file.mimetype.startsWith('audio/')) {
978
+ resourceType = 'video'; // Cloudinary يتعامل مع الصوت كـ video
979
+ allowedFormats = ['mp3', 'wav', 'aac', 'ogg', 'm4a', 'flac', 'webm'];
980
  folder = `Stories/${req.user.userId}/audio`;
981
+ transformation = [
982
+ { quality: 'auto' },
983
+ { audio_codec: 'aac' }
984
+ ];
985
+ eager = [
986
+ { format: 'mp3', audio_codec: 'mp3' },
987
+ { format: 'm4a', audio_codec: 'aac' }
988
+ ];
989
+
990
+ // ✅ إرجاع مباشر للصوتيات
991
+ return {
992
+ folder: folder,
993
+ allowed_formats: allowedFormats,
994
+ resource_type: resourceType,
995
+ public_id: `audio_${Date.now()}_${file.originalname.split('.')[0]}`,
996
+ transformation: transformation,
997
+ eager: eager,
998
+ eager_async: true
999
+ };
1000
  }
1001
 
1002
  return {
 
1005
  resource_type: resourceType,
1006
  public_id: `story_${Date.now()}_${file.originalname.split('.')[0]}`,
1007
  transformation: transformation.length > 0 ? transformation : undefined,
1008
+ eager: eager.length > 0 ? eager : undefined,
1009
+ eager_async: true
 
 
 
 
 
 
 
 
 
 
 
 
 
1010
  };
1011
  }
1012
  }),
1013
  limits: {
1014
+ fileSize: 50 * 1024 * 1024 // 50MB
1015
  },
1016
  fileFilter: (req, file, cb) => {
1017
  const imageTypes = [
 
1030
 
1031
  const audioTypes = [
1032
  'audio/mpeg', 'audio/wav', 'audio/aac', 'audio/ogg',
1033
+ 'audio/mp4', 'audio/flac', 'audio/webm', 'audio/x-m4a'
1034
  ];
1035
 
1036
  const allAllowed = [...imageTypes, ...videoTypes, ...audioTypes];
 
1041
  'Unsupported file type. Supported formats:\n' +
1042
  '📸 Images: JPEG, PNG, GIF, WEBP, BMP, TIFF, SVG, AVIF, HEIC\n' +
1043
  '🎬 Videos: MP4, WEBM, OGG, MOV, AVI, MKV, FLV, WMV, MPEG, 3GP\n' +
1044
+ '🎵 Audio: MP3, WAV, AAC, OGG, M4A, FLAC, WEBM'
1045
  ), false);
1046
  }
1047
 
 
1053
  } else if (file.mimetype.startsWith('video/')) {
1054
  maxSize = 50 * 1024 * 1024; // 50MB للفيديوهات
1055
  } else if (file.mimetype.startsWith('audio/')) {
1056
+ maxSize = 15 * 1024 * 1024; // 15MB للصوتيات
1057
  }
1058
 
1059
  if (file.size > maxSize) {
 
1848
  publicId: { type: String, default: null },
1849
  type: {
1850
  type: String,
1851
+ enum: ['image', 'video', 'audio', 'none'],
1852
  default: 'none'
1853
  }
1854
  },
1855
+
1856
+ filter: {
1857
+ type: String,
1858
+ default: 'none',
1859
+ enum: ['none', 'vintage', 'noir', 'cool', 'warm', 'dramatic',
1860
+ 'dreamy', 'vivid', 'fade', 'sepia', 'grayscale', 'blur',
1861
+ 'grain', 'vignette', 'neon', 'retro', 'cinematic', 'pastel']
1862
+ },
1863
+ // ✅ حقل جديد لضبط قوة الفلتر
1864
+ filterIntensity: {
1865
+ type: Number,
1866
+ default: 0.5,
1867
+ min: 0,
1868
+ max: 1
1869
+ },
1870
  text: {
1871
  type: String,
1872
  maxlength: 2000,
 
1885
  default: false
1886
  },
1887
 
1888
+ audio: {
1889
+ url: { type: String, default: null },
1890
+ publicId: { type: String, default: null },
1891
+ duration: { type: Number, default: 0 }, // مدة التسجيل بالثواني
1892
+ waveform: { type: Array, default: [] } // شكل الموجة للتسجيل
1893
+ },
1894
+ // ✅ حقل جديد لدعم الفلاتر
1895
+ filterApplied: {
1896
+ type: Boolean,
1897
+ default: false
1898
+ },
1899
+
1900
+
1901
  textStyle: {
1902
  fontSize: { type: Number, default: 32 }, // حجم الخط
1903
  fontFamily: { type: String, default: 'Inter' }, // نوع الخط
 
1981
  // فهارس محسّنة
1982
  storySchema.index({ userId: 1, createdAt: -1 });
1983
  storySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
1984
+ storySchema.index({ 'audio.url': 1 });
1985
+ storySchema.index({ filter: 1 });
1986
+
1987
 
1988
  // فيريتول (Virtual) لحساب عدد المشاهدات
1989
  storySchema.virtual('viewsCount').get(function() {
 
15557
  // ============================================
15558
  // POST /api/stories - إنشاء story (باستخدام uploadStory)
15559
  // ============================================
15560
+
15561
+ app.post('/api/stories', authenticateToken, uploadStory.fields([
15562
+ { name: 'media', maxCount: 1 },
15563
+ { name: 'audio', maxCount: 1 }
15564
+ ]), [
15565
  body('text').optional().isString(),
15566
  body('backgroundColor').optional().isString(),
15567
  body('textColor').optional().isString(),
15568
  body('textStyle').optional().isString(),
15569
+ body('filter').optional().isString(),
15570
+ body('filterIntensity').optional().isNumeric(),
15571
  body('allowDownload').optional().isBoolean(),
15572
  body('visibility').optional().isIn(['public', 'followers', 'only-me'])
15573
  ], handleUploadError, async (req, res) => {
 
15581
  let publicId = null;
15582
  let mediaType = 'none';
15583
 
15584
+ let audioUrl = null;
15585
+ let audioPublicId = null;
15586
+ let audioDuration = 0;
15587
+
15588
+ // ✅ معالجة الميديا (صورة/فيديو)
15589
+ if (req.files && req.files.media && req.files.media[0]) {
15590
+ const file = req.files.media[0];
15591
+ mediaUrl = file.path || file.secure_url || null;
15592
+ publicId = file.filename || file.public_id || null;
15593
+ mediaType = file.mimetype?.startsWith('video') ? 'video' : 'image';
15594
+ }
15595
+
15596
+ // ✅ معالجة الصوت
15597
+ if (req.files && req.files.audio && req.files.audio[0]) {
15598
+ const audioFile = req.files.audio[0];
15599
+ audioUrl = audioFile.path || audioFile.secure_url || null;
15600
+ audioPublicId = audioFile.filename || audioFile.public_id || null;
15601
+ audioDuration = parseInt(req.body.audioDuration) || 0;
15602
+
15603
+ // ✅ إذا كان هناك صوت، نحدد نوع القصة كـ 'audio'
15604
+ if (audioUrl) {
15605
+ mediaType = 'audio';
15606
+ }
15607
  }
15608
 
15609
+ // ✅ التحقق من وجود محتوى
15610
+ if (!mediaUrl && !audioUrl && !req.body.text) {
15611
  return res.status(400).json({
15612
+ error: 'Story must have media, audio, or text content'
15613
  });
15614
  }
15615
 
 
15631
  let textStyleObj = defaultTextStyle;
15632
  if (req.body.textStyle) {
15633
  try {
 
15634
  const parsed = typeof req.body.textStyle === 'string'
15635
  ? JSON.parse(req.body.textStyle)
15636
  : req.body.textStyle;
15637
  textStyleObj = { ...defaultTextStyle, ...parsed };
15638
  } catch (e) {
15639
  console.error('Error parsing textStyle:', e);
 
15640
  textStyleObj = defaultTextStyle;
15641
  }
15642
  }
15643
 
15644
+ // ✅ إنشاء القصة مع جميع الحقول
15645
  const story = new Story({
15646
  userId: req.user.userId,
15647
  media: {
 
15649
  publicId: publicId,
15650
  type: mediaType
15651
  },
15652
+ audio: {
15653
+ url: audioUrl,
15654
+ publicId: audioPublicId,
15655
+ duration: audioDuration,
15656
+ waveform: req.body.waveform ? JSON.parse(req.body.waveform) : []
15657
+ },
15658
+ filter: req.body.filter || 'none',
15659
+ filterIntensity: parseFloat(req.body.filterIntensity) || 0.5,
15660
+ filterApplied: req.body.filter && req.body.filter !== 'none',
15661
  text: req.body.text || '',
15662
  backgroundColor: req.body.backgroundColor || '#000000',
15663
  textColor: req.body.textColor || '#ffffff',
 
15666
  visibility: req.body.visibility || 'followers'
15667
  });
15668
 
 
15669
  await story.save();
15670
+ await notifyFollowersAboutStory(story);
15671
 
15672
  res.status(201).json({
15673
  success: true,
 
15687
  }
15688
  });
15689
 
 
15690
  // ============================================
15691
  // NOTIFY FOLLOWERS ABOUT STORY - إشعار المتابعين بقصة جديدة
15692
  // ============================================