-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
2838 lines (2502 loc) · 99.2 KB
/
server.js
File metadata and controls
2838 lines (2502 loc) · 99.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File: server.js
const express = require('express');
const multer = require('multer');
const path = require('path');
const fs = require('fs');
const bcrypt = require('bcrypt');
const { Op } = require('sequelize');
// Sequelize imports
const sequelize = require('./database');
const User = require('./models/User');
const Book = require('./models/Books');
const Video = require('./models/Video');
const Game = require('./models/Game');
const Article = require('./models/Article');
const Newspaper = require('./models/Newspaper');
const Music = require('./models/music');
const Painting = require('./models/Painting');
// New enhanced models
const Playlist = require('./models/Playlist');
const PlaylistItem = require('./models/PlaylistItem');
const Notification = require('./models/Notification');
const Analytics = require('./models/Analytics');
const Comment = require('./models/Comment');
sequelize.sync()
.then(() => console.log('Database and tables created!'))
.catch(err => console.error('Unable to create tables: ', err));
const app = express();
const port = 3000;
// Database connection and model synchronization
sequelize.sync()
.then(() => console.log('Database and tables created!'))
.catch(err => console.error('Unable to create tables: ', err));
// Middleware setup
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Static file serving
app.use(express.static(path.join(__dirname, 'public')));
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
// Multer storage configuration
const storage = multer.diskStorage({
destination: function (req, file, cb) {
const uploadDir = path.join(__dirname, 'uploads');
if (!fs.existsSync(uploadDir)){
fs.mkdirSync(uploadDir);
}
cb(null, uploadDir);
},
filename: function (req, file, cb) {
cb(null, Date.now() + path.extname(file.originalname));
}
});
const upload = multer({ storage: storage });
// Registration endpoint
app.post('/register', async (req, res) => {
try {
const { fullName, email, username, password, role, securityQuestion, securityAnswer } = req.body;
// Check if user already exists
const existingEmail = await User.findOne({ where: { email } });
if (existingEmail) {
return res.status(400).json({ error: 'Email already in use' });
}
const existingUsername = await User.findOne({ where: { username } });
if (existingUsername) {
return res.status(400).json({ error: 'Username already taken' });
}
// Hash password
const saltRounds = 10;
const passwordHash = await bcrypt.hash(password, saltRounds);
// Create new user with role
const newUser = await User.create({
id: Date.now().toString(),
full_name: fullName,
email: email,
username: username,
password_hash: passwordHash,
role: role || 'client', // Default to client if no role specified
security_question: securityQuestion,
security_answer: securityAnswer
});
// You could generate a token here for auto-login if you want
res.status(201).json({
message: 'User registered and logged in successfully',
user: {
id: newUser.id,
name: newUser.full_name,
username: newUser.username,
email: newUser.email,
role: newUser.role
}
});
} catch (error) {
console.error('Registration error:', error);
res.status(500).json({ error: 'Registration failed. Please try again.' });
}
});
// Add these dependencies at the top of server.js
const jwt = require('jsonwebtoken');
const SECRET_KEY = 'Pass'; // Replace with a secure key in production
// Login endpoint
app.post('/api/login', async (req, res) => {
try {
const { identifier, password } = req.body;
// Find user by email or username
const user = await User.findOne({
where: {
[Op.or]: [
{ email: identifier },
{ username: identifier }
]
}
});
if (!user) {
return res.status(401).json({ success: false, error: 'Invalid credentials' });
}
// Compare password
const isPasswordValid = await bcrypt.compare(password, user.password_hash);
if (!isPasswordValid) {
return res.status(401).json({ success: false, error: 'Invalid credentials' });
}
// Generate JWT token with role included
const token = jwt.sign(
{
id: user.id,
username: user.username,
role: user.role || 'client' // Default to client if no role
},
SECRET_KEY,
{ expiresIn: '1h' } // Token expires in 1 hour
);
res.json({
success: true,
token,
user: {
id: user.id,
name: user.full_name,
username: user.username,
role: user.role || 'client'
}
});
} catch (error) {
console.error('Login error:', error);
res.status(500).json({ success: false, error: 'Login failed. Please try again.' });
}
});
// Forgot Password - Step 1: Verify Email
app.post('/api/forgot-password/verify-email', async (req, res) => {
try {
const { email } = req.body;
const user = await User.findOne({ where: { email } });
if (!user) {
return res.status(404).json({ success: false, error: 'Email not found' });
}
res.json({
success: true,
userId: user.id,
securityQuestion: user.security_question
});
} catch (error) {
console.error('Verify email error:', error);
res.status(500).json({ success: false, error: 'An error occurred. Please try again.' });
}
});
// Forgot Password - Step 2: Verify Security Answer
app.post('/api/forgot-password/verify-security', async (req, res) => {
try {
const { userId, securityAnswer } = req.body;
const user = await User.findByPk(userId);
if (!user) {
return res.status(404).json({ success: false, error: 'User not found' });
}
if (user.security_answer.toLowerCase() !== securityAnswer.toLowerCase()) {
return res.status(401).json({ success: false, error: 'Incorrect security answer' });
}
res.json({ success: true });
} catch (error) {
console.error('Verify security answer error:', error);
res.status(500).json({ success: false, error: 'An error occurred. Please try again.' });
}
});
// Forgot Password - Step 3: Reset Password
app.post('/api/forgot-password/reset', async (req, res) => {
try {
const { userId, newPassword } = req.body;
const user = await User.findByPk(userId);
if (!user) {
return res.status(404).json({ success: false, error: 'User not found' });
}
const saltRounds = 10;
const passwordHash = await bcrypt.hash(newPassword, saltRounds);
await user.update({ password_hash: passwordHash });
res.json({ success: true, message: 'Password reset successful' });
} catch (error) {
console.error('Reset password error:', error);
res.status(500).json({ success: false, error: 'An error occurred. Please try again.' });
}
});
// Add this to check session (optional, for index.html)
app.get('/check_session', (req, res) => {
const token = req.headers.authorization?.split(' ')[1]; // Expecting "Bearer <token>"
if (!token) {
return res.json({ logged_in: false });
}
try {
const decoded = jwt.verify(token, SECRET_KEY);
res.json({
logged_in: true,
user: {
id: decoded.id,
username: decoded.username,
role: decoded.role || 'client'
}
});
} catch (error) {
res.json({ logged_in: false });
}
});
// Logout endpoint (client-side handled, but added for completeness)
app.post('/logout', (req, res) => {
// Since we're using JWT, logout is handled client-side by removing the token
res.json({ success: true, message: 'Logged out successfully' });
});
// Use upload.fields to handle multiple file inputs
app.post('/upload-book', upload.fields([
{ name: 'bookImage', maxCount: 1 },
{ name: 'bookPdf', maxCount: 1 }
]), async (req, res) => {
try {
const bookData = {
id: Date.now().toString(),
bookName: req.body.bookName,
authorName: req.body.authorName,
bookImage: req.files.bookImage ? `/uploads/${req.files.bookImage[0].filename}` : '',
bookPdf: req.files.bookPdf ? `/uploads/${req.files.bookPdf[0].filename}` : '',
birthYear: req.body.birthYear,
deathYear: req.body.deathYear,
language: req.body.language,
genre: req.body.genre,
literaryMovement: req.body.literaryMovement,
importantThemes: req.body.importantThemes,
keyCharacters: req.body.keyCharacters,
bookSummary: req.body.bookSummary,
youtubeLink: req.body.youtubeLink,
bookLink: req.body.bookLink || ''
};
// Generate HTML content
const htmlContent = generateBookPage(bookData);
// Ensure books directory exists
const booksDir = path.join(__dirname, 'public', 'books');
if (!fs.existsSync(booksDir)){
fs.mkdirSync(booksDir);
}
// Generate unique filename
const filename = `book_${bookData.id}.html`;
const outputPath = path.join(booksDir, filename);
// Save generated HTML
fs.writeFileSync(outputPath, htmlContent);
// Add HTML link to book data
bookData.htmlLink = `/books/${filename}`;
// Create book in database
await Book.create(bookData);
// Respond with HTML content
res.send(htmlContent);
} catch (error) {
console.error('Error uploading book:', error);
res.status(500).send('Error uploading book');
}
});
// Route to get all books
app.get('/books', async (req, res) => {
try {
const books = await Book.findAll();
res.json(books);
} catch (error) {
console.error('Error fetching books:', error);
res.status(500).json({ error: 'Unable to fetch books' });
}
});
// Route to get a specific book by ID
app.get('/books/:id', async (req, res) => {
try {
const book = await Book.findByPk(req.params.id);
if (book) {
res.json(book);
} else {
res.status(404).json({ error: 'Book not found' });
}
} catch (error) {
console.error('Error fetching book:', error);
res.status(500).json({ error: 'Unable to fetch book' });
}
});
// Video upload route
app.post('/upload-video', upload.single('videoThumbnail'), async (req, res) => {
try {
const videoData = {
id: Date.now().toString(),
videoTitle: req.body.videoTitle,
creator: req.body.creator,
videoThumbnail: req.file ? `/uploads/${req.file.filename}` : '',
videoEmbedCode: req.body.videoEmbedCode,
genre: req.body.genre,
releaseYear: req.body.releaseYear,
duration: req.body.duration,
language: req.body.language,
videoTags: req.body.videoTags,
videoDescription: req.body.videoDescription
};
// Generate HTML content
const htmlContent = generateVideoPage(videoData);
// Ensure videos directory exists
const videosDir = path.join(__dirname, 'public', 'videos');
if (!fs.existsSync(videosDir)){
fs.mkdirSync(videosDir);
}
// Generate unique filename
const filename = `video_${videoData.id}.html`;
const outputPath = path.join(videosDir, filename);
// Save generated HTML
fs.writeFileSync(outputPath, htmlContent);
// Add HTML link to video data
videoData.htmlLink = `/videos/${filename}`;
// Create video in database
await Video.create(videoData);
// Respond with HTML content
res.send(htmlContent);
} catch (error) {
console.error('Error uploading video:', error);
res.status(500).send('Error uploading video');
}
});
// Route to get all videos
app.get('/videos', async (req, res) => {
try {
const videos = await Video.findAll();
res.json(videos);
} catch (error) {
console.error('Error fetching videos:', error);
res.status(500).json({ error: 'Unable to fetch videos' });
}
});
// Route to get a specific video by ID
app.get('/videos/:id', async (req, res) => {
try {
const video = await Video.findByPk(req.params.id);
if (video) {
res.json(video);
} else {
res.status(404).json({ error: 'Video not found' });
}
} catch (error) {
console.error('Error fetching video:', error);
res.status(500).json({ error: 'Unable to fetch video' });
}
});
// Game upload route
app.post('/upload-game', upload.single('gameThumbnail'), async (req, res) => {
try {
const gameData = {
id: Date.now().toString(),
gameName: req.body.gameName,
developer: req.body.developer,
gameThumbnail: req.file ? `/uploads/${req.file.filename}` : '',
releaseYear: req.body.releaseYear,
genre: req.body.genre,
platform: req.body.platform,
ageRating: req.body.ageRating,
multiplayer: req.body.multiplayer,
keyFeatures: req.body.keyFeatures,
gameDescription: req.body.gameDescription,
embedCode: req.body.embedCode,
gameLink: req.body.gameLink || ''
};
// Generate HTML content
const htmlContent = generateGamePage(gameData);
// Ensure games directory exists
const gamesDir = path.join(__dirname, 'public', 'games');
if (!fs.existsSync(gamesDir)){
fs.mkdirSync(gamesDir);
}
// Generate unique filename
const filename = `game_${gameData.id}.html`;
const outputPath = path.join(gamesDir, filename);
// Save generated HTML
fs.writeFileSync(outputPath, htmlContent);
// Add HTML link to game data
gameData.htmlLink = `/games/${filename}`;
// Create game in database
await Game.create(gameData);
// Respond with HTML content
res.send(htmlContent);
} catch (error) {
console.error('Error uploading game:', error);
res.status(500).send('Error uploading game');
}
});
// Game update route
app.post('/update-game/:id', upload.single('gameThumbnail'), async (req, res) => {
try {
const gameId = req.params.id;
const existingGame = await Game.findByPk(gameId);
if (!existingGame) {
return res.status(404).send('Game not found');
}
// Update game data
const gameData = {
gameName: req.body.gameName,
developer: req.body.developer,
releaseYear: req.body.releaseYear,
genre: req.body.genre,
platform: req.body.platform,
ageRating: req.body.ageRating,
multiplayer: req.body.multiplayer,
keyFeatures: req.body.keyFeatures,
gameDescription: req.body.gameDescription,
embedCode: req.body.embedCode,
gameLink: req.body.gameLink || ''
};
// Only update image if a new one is provided
if (req.file) {
gameData.gameThumbnail = `/uploads/${req.file.filename}`;
}
// Update database record
await existingGame.update(gameData);
// Refresh the full game data
const updatedGame = await Game.findByPk(gameId);
const updatedGameData = updatedGame.toJSON();
// Generate updated HTML content
const htmlContent = generateGamePage(updatedGameData);
// Save updated HTML
const gamesDir = path.join(__dirname, 'public', 'games');
const filename = `game_${gameId}.html`;
const outputPath = path.join(gamesDir, filename);
fs.writeFileSync(outputPath, htmlContent);
// Respond with updated HTML content
res.send(htmlContent);
} catch (error) {
console.error('Error updating game:', error);
res.status(500).send('Error updating game');
}
});
// Route to get all games
app.get('/games', async (req, res) => {
try {
const games = await Game.findAll();
res.json(games);
} catch (error) {
console.error('Error fetching games:', error);
res.status(500).json({ error: 'Unable to fetch games' });
}
});
// Route to get a specific game by ID
app.get('/games/:id', async (req, res) => {
try {
const game = await Game.findByPk(req.params.id);
if (game) {
res.json(game);
} else {
res.status(404).json({ error: 'Game not found' });
}
} catch (error) {
console.error('Error fetching game:', error);
res.status(500).json({ error: 'Unable to fetch game' });
}
});
// Route to get a specific video by ID
app.get('/videos/:id', async (req, res) => {
try {
const video = await Video.findByPk(req.params.id);
if (video) {
res.json(video);
} else {
res.status(404).json({ error: 'Video not found' });
}
} catch (error) {
console.error('Error fetching video:', error);
res.status(500).json({ error: 'Unable to fetch video' });
}
});
// Book page generation function
function generateBookPage(data) {
const readBookButton = data.bookLink
? `<a href="${data.bookLink}" target="_blank" class="read-btn">Read Book</a>`
: '';
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Nanum+Myeongjo&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/icons/font/flaticon.css">
<title>Browsing page</title>
<style type="text/css">
.jumbotron {
background-image: url("https://images.unsplash.com/photo-1532012197267-da84d127e765?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D");
color:floralwhite;
background-size: cover;
}
#advanced-form {
display: none;
}
#header {
font-family:'Nanum Myeongjo', serif;
}
.container_img {
position: relative;
width: 100%;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.container_img:hover .image {
opacity: 0.5;
}
iframe{
padding: 1em;
}
#iframe_container{
margin-top: 2em;
display: flex;
justify-content: center;
}
/* New CSS for Read Button */
.read-btn {
display: block;
width: 200px;
margin: 20px auto;
padding: 10px 20px;
background-color: #007bff;
color: white;
text-align: center;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.read-btn:hover {
background-color: #0056b3;
color: white;
text-decoration: none;
}
.navbar {
background-color: rgba(0,0,0,0.7);
font-family: 'Nanum Myeongjo', serif;
}
.navbar-brand, .navbar-nav .nav-link {
color: floralwhite !important;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="/">THE MULTIMEDIA STORE</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/index.html">Home</a>
</li>
<li class="nav-item" id="loginNavItem">
<a class="nav-link" href="/login.html">Login</a>
</li>
<li class="nav-item" id="registerNavItem">
<a class="nav-link" href="/register.html">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact.html">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about.html">About me</a>
</li>
<li class="nav-item" id="logoutNavItem" style="display:none;">
<a class="nav-link" href="#" onclick="logout()">Logout</a>
</li>
</ul>
</div>
</nav>
<div class="jumbotron">
<br><br>
<div id="header">
<h1 class=display-3 style="text-align:center;"><strong>THE MULTIMEDIA STORE</strong></h1>
<p class="lead" style="text-align:center;"><strong>Unlock the power of multimedia—innovation, quality, and creativity in one place!</strong></p>
</div>
</div>
<div class="container">
<div class="text-center">
<h3 class="my-5">${data.bookName}</h3>
<img src="${data.bookImage}" class="rounded mb-5" alt="${data.bookName} Book Cover" usemap="#book_map">
<map id="book_map" name="book_map">
<area shape="poly" coords="300, 471, 360, 437, 382, 472, 383, 563, 370, 599, 296, 473" href="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Book_icon.svg/220px-Book_icon.svg.png" target="_blank" alt="Book Icon" title="Book Icon">
</map>
${data.bookPdf ? `<a href="${data.bookPdf}" class="read-btn" target="_blank">Read PDF</a>` : ''}
</div>
<table class="table">
<thead>
<tr>
<th scope="col">Author</th>
<td>${data.authorName}</td>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Birth/Death</th>
<td>${data.birthYear} - ${data.deathYear}</td>
</tr>
<tr>
<th scope="row">Language</th>
<td>${data.language}</td>
</tr>
<tr>
<th scope="row">Genre</th>
<td>${data.genre}</td>
</tr>
<tr>
<th scope="row">Literary Movement</th>
<td>${data.literaryMovement}</td>
</tr>
<tr>
<th scope="row">Important Themes</th>
<td>${data.importantThemes}</td>
</tr>
<tr>
<th scope="row">Key Characters</th>
<td>${data.keyCharacters}</td>
</tr>
</tbody>
</table>
${data.bookSummary.split('\n').map(paragraph => `<p>${paragraph}</p>`).join('')}
<div id="iframe_container">
<iframe width="560" height="315" src="${data.youtubeLink}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<br>
<br>
</div>
</div>
<br><br><hr>
<div class="container">
<!-- Footer -->
<footer class="page-footer font-small pt-4">
<div class="container-fluid text-center text-md-left">
<div class="row justify-content-around">
<div class="col-md-6 mt-md-0 mt-3">
</div>
</div>
</div>
<div class="footer-copyright text-center py-3"><p>© 2025 THE MULTIMEDIA STORE.</p></div>
</footer>
</div>
<script>
formData.append('bookLink', document.getElementById('bookLink').value);
// Check authentication status when the page loads
document.addEventListener('DOMContentLoaded', function() {
checkAuth();
});
function checkAuth() {
// Get authentication data from localStorage
const token = localStorage.getItem('userToken');
if (token) {
// User is logged in
// Hide login and register links
document.getElementById('loginNavItem').style.display = 'none';
document.getElementById('registerNavItem').style.display = 'none';
// Show logout link
document.getElementById('logoutNavItem').style.display = 'block';
} else {
// User is not logged in
// Show login and register links
document.getElementById('loginNavItem').style.display = 'block';
document.getElementById('registerNavItem').style.display = 'block';
// Hide logout link
document.getElementById('logoutNavItem').style.display = 'none';
}
}
// Function to handle logout
function logout() {
// Clear user data from localStorage
localStorage.removeItem('userToken');
localStorage.removeItem('userName');
localStorage.removeItem('userRole');
// Update navigation after logout
checkAuth();
// Redirect to home page
window.location.href = 'index.html';
}
// Add this function to show login message
function showLoginMessage(event) {
event.preventDefault();
alert('Please log in first to view book details.');
// Optionally redirect to login page after a short delay
setTimeout(function() {
window.location.href = 'login.html';
}, 1000);
}
</script>
<!-- Bootstrap JS and dependencies -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</body>
</html>
`;
}
// Video page generation function
function generateVideoPage(data) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Nanum+Myeongjo&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/icons/font/flaticon.css">
<title>${data.videoTitle} - The Multimedia Store</title>
<style type="text/css">
.jumbotron {
background-image: url("https://images.unsplash.com/photo-1611162616475-46b635cb6868?q=80&w=1974&auto=format&fit=crop");
color: floralwhite;
background-size: cover;
background-position: center;
background-color: rgba(0,0,0,0.7);
background-blend-mode: overlay;
padding: 3rem 1rem;
margin-bottom: 2rem;
height: auto;
min-height: 300px;
display: flex;
align-items: center;
justify-content: center;
}
#header {
font-family:'Nanum Myeongjo', serif;
}
.container_img {
position: relative;
width: 100%;
}
.image {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.container_img:hover .image {
opacity: 0.5;
}
iframe {
width: 100%;
height: 450px;
padding: 1em;
}
#iframe_container {
margin-top: 2em;
display: flex;
justify-content: center;
}
.navbar {
background-color: rgba(0,0,0,0.7);
font-family: 'Nanum Myeongjo', serif;
}
.navbar-brand, .navbar-nav .nav-link {
color: floralwhite !important;
}
.video-thumbnail {
max-width: 400px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.tag-badge {
margin-right: 5px;
margin-bottom: 5px;
}
</style>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="/index.html">THE VIDEOS STORE</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="/index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/video-list.html">Videos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/login.html">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/register.html">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact.html">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about.html">About</a>
</li>
</ul>
</div>
</nav>
<div class="jumbotron">
<br><br>
<div id="header">
<h1 class="display-3 text-center"><strong>THE VIDEO STORE</strong></h1>
<p class="lead text-center"><strong>Unlock the power of multimedia—innovation, quality, and creativity in one place!</strong></p>
</div>
</div>
<div class="container">
<div class="text-center mb-4">
<h2 class="my-4">${data.videoTitle}</h2>
<img src="${data.videoThumbnail}" class="video-thumbnail mb-4" alt="${data.videoTitle} Thumbnail">
</div>
<div id="iframe_container" class="mb-5">
<iframe src="${data.videoEmbedCode}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<div class="row">
<div class="col-md-8">
<h3>Description</h3>
${data.videoDescription.split('\n').map(paragraph => `<p>${paragraph}</p>`).join('')}
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-info text-white">
<h4 class="mb-0">Video Details</h4>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"><strong>Creator:</strong> ${data.creator}</li>
${data.releaseYear ? `<li class="list-group-item"><strong>Release Year:</strong> ${data.releaseYear}</li>` : ''}
${data.duration ? `<li class="list-group-item"><strong>Duration:</strong> ${data.duration} minutes</li>` : ''}
${data.genre ? `<li class="list-group-item"><strong>Genre:</strong> ${data.genre}</li>` : ''}
${data.language ? `<li class="list-group-item"><strong>Language:</strong> ${data.language}</li>` : ''}
</ul>
</div>
${data.videoTags ? `
<div class="card mt-4">
<div class="card-header bg-info text-white">
<h4 class="mb-0">Tags</h4>
</div>
<div class="card-body">
${data.videoTags.split(',').map(tag => `<span class="badge badge-info tag-badge">${tag.trim()}</span>`).join('')}
</div>
</div>` : ''}
</div>
</div>
</div>
<br><br><hr>
<script>
// Check authentication status when the page loads
document.addEventListener('DOMContentLoaded', function() {
checkAuth();
});