-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8a83ec
commit a42aef5
Showing
7 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ node_modules | |
.git | ||
.idea | ||
.tmp | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,3 @@ export async function getFileContent(key) { | |
throw error; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
async function uploadVideo(request, h) { | ||
try { | ||
const data = request.payload; | ||
|
||
if (data.video) { | ||
const file = data.video; | ||
console.log(file); | ||
const filename = 'test.mov'; | ||
|
||
const uploadDir = `uploads/`; | ||
fs.mkdirSync(uploadDir, { recursive: true }); | ||
|
||
if (!fs.existsSync(uploadDir)) { | ||
fs.mkdirSync(uploadDir); | ||
} | ||
|
||
const filePath = path.join(uploadDir, filename); | ||
const fileStream = fs.createWriteStream(filePath); | ||
|
||
// Pipe the file to the file system | ||
await new Promise((resolve, reject) => { | ||
file.on('error', (err) => reject(err)); | ||
file.pipe(fileStream); | ||
file.on('end', () => resolve()); | ||
}); | ||
|
||
return h | ||
.response({ | ||
status: 'success', | ||
message: 'File uploaded successfully', | ||
data: { | ||
filename: filename, | ||
path: filePath, | ||
}, | ||
}) | ||
.code(200); | ||
} else { | ||
return h | ||
.response({ status: 'fail', message: 'No file received' }) | ||
.code(400); | ||
} | ||
} catch (error) { | ||
console.error('File upload failed:', error); | ||
return h | ||
.response({ status: 'error', message: 'Internal Server Error' }) | ||
.code(500); | ||
} | ||
} | ||
|
||
export function uploadVideoController(server) { | ||
server.route({ | ||
method: 'POST', | ||
path: '/upload-video', | ||
handler: uploadVideo, | ||
options: { | ||
auth: 'adminSession', | ||
payload: { | ||
output: 'stream', | ||
parse: true, | ||
allow: 'multipart/form-data', | ||
maxBytes: 16 * 1024 * 1024 * 1024, // 16 GB | ||
multipart: true, | ||
}, | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="w-full sm:p-0 sm:m-0 mx-auto-2 lg:px-0"> | ||
{{#if showAudio}} | ||
<div id="audio-player-container"> | ||
<audio id="audio-player" controls class="w-full"> | ||
<source src="{{audioUrl}}" type="audio/mpeg"> | ||
Your browser does not support the audio element. | ||
</audio> | ||
</div> | ||
{{/if}} | ||
</div> | ||
|
||
<div class="w-full"> | ||
{{#if showVideo}} | ||
<div id="video-player-container"> | ||
<video id="video-player" controls class="w-full"> | ||
<source src="{{videoUrl}}" type="video/mp4"> | ||
Your browser does not support the video element. | ||
</video> | ||
</div> | ||
{{/if}} | ||
</div> | ||
|
||
{{#if showUploadVideoButton}} | ||
<div class="w-full"> | ||
<form action="{{uploadUrl}}" method="POST" enctype="multipart/form-data"> | ||
<input type="file" name="video" accept=".mov" required /> | ||
<button type="submit" class="common-button w-full px-4 py-2 my-2 transition-all duration-300 ease-in-out">Upload | ||
Video</button> | ||
</form> | ||
</div> | ||
{{/if}} |