Skip to content

Commit

Permalink
resolve conflict (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
aninda052 committed Aug 2, 2023
1 parent 419d220 commit 1e4c2a5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion client/src/pages/VideoListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function UserPage() {

const [rowsPerPage, setRowsPerPage] = useState(5);

const [videos] = useState([]);
const [videos, setVideos] = useState([]);

useEffect(() => {
const getData = async () => {
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/VideosPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Container, Stack, Typography } from '@mui/material';
// components
import {
ProductSort,
ProductList,
VideoList,
ProductCartWidget,
ProductFilterSidebar,
} from '../sections/@dashboard/products';
Expand All @@ -23,7 +23,7 @@ export default function ProductsPage() {
useEffect(() => {
const getData = async () => {
const response = await axios.post(`${API_SERVER}/api/videos/search`, {});
console.log('getData', response.data);
// console.log('getData', response.data);
setVideos(response.data);
};

Expand Down Expand Up @@ -66,7 +66,7 @@ export default function ProductsPage() {
</Stack>
</Stack>

<ProductList products={videos} />
<VideoList videos={videos} />
<ProductCartWidget />
</Container>
</>
Expand Down
8 changes: 4 additions & 4 deletions client/src/sections/@dashboard/products/VideoCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function VideoCard({ video }) {
title: name,
thumbnailUrl: cover,
viewCount,
durations,
duration,
status,
recordingDate,
_id: id,
Expand All @@ -41,8 +41,8 @@ export default function VideoCard({ video }) {
console.log('clicked', video);
};

let videoDurations = 0
if(durations) videoDurations = durations
let videoDuration = 0
if(duration) videoDuration = duration

return (
<Card onClick={onClickHandler}>
Expand Down Expand Up @@ -80,7 +80,7 @@ export default function VideoCard({ video }) {
<Stack direction='row' alignItems='center' justifyContent='space-between'>
<Typography variant='subtitle1'>{viewCount} views</Typography>
<Typography variant='subtitle1'>
<Moment utc format='HH:mm:ss'>{videoDurations*1000}</Moment>
<Moment utc format='HH:mm:ss'>{videoDuration*1000}</Moment>
</Typography>
</Stack>
</Stack>
Expand Down
4 changes: 2 additions & 2 deletions server/src/modules/db/schemas/videos.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const updateSchema = async (db) => {
description: 'can only be one of the enum values and is required',
},
duration: {
bsonType: 'int',
bsonType: "int",
minimum: 1,
description: 'must be an integer',
description: "video duration in second. Must be an integer",
},
playlistId: {
bsonType: 'objectId',
Expand Down
9 changes: 5 additions & 4 deletions server/src/modules/models/video/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const {
search,
update,
getById,
updateViewCount,
deleteById,
} = require('./service');
const { validate } = require('./request');
const { VIDEO_QUEUE_EVENTS: QUEUE_EVENTS } = require('../../queues/constants');
const { addQueueItem } = require('../../queues/queue');
const { getVideoDurations } = require('../../queues/video-processor');
const { getVideoDuration } = require('../../queues/video-processor');

const BASE_URL = `/api/videos`;

Expand All @@ -30,7 +31,7 @@ const setupRoutes = (app) => {

app.get(`${BASE_URL}/detail/:id`, async (req, res) => {
console.log(`GET`, req.params);
const video = await getById(req.params.id);
const video = await updateViewCount(req.params.id);
if (video instanceof Error) {
return res.status(400).json(JSON.parse(video.message));
}
Expand Down Expand Up @@ -135,15 +136,15 @@ const setupRoutes = (app) => {
app.post(`${BASE_URL}/upload`, uploadProcessor, async (req, res) => {
try {

const videoDurations = await getVideoDurations(`./${req.file.path}`)
const videoDuration = await getVideoDuration(`./${req.file.path}`)
const dbPayload = {
...req.body,
fileName: req.file.filename,
originalName: req.file.originalname,
recordingDate: new Date(),
videoLink: req.file.path,
viewCount:0,
durations:videoDurations
duration:videoDuration
};
console.log('dbPayload', dbPayload);
// TODO: save the file info and get the id from the database
Expand Down
12 changes: 6 additions & 6 deletions server/src/modules/queues/video-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ const processMp4ToHls = async (filePath, outputFolder, jobData) => {
return;
};

const getVideoDurations = (filePath) => {
const getVideoDuration = (filePath) => {

// if any error occour return 0.0 second as default video duration
// else return video durations
return new Promise((resolve,reject) => {
let durations = 0.0
let duration = 0
ffmpeg.ffprobe(filePath, function(err, metadata) {
// getting video durations in second
// getting video duration in second
if(!err){
durations = metadata.format.duration
duration = parseInt(metadata.format.duration)
}
resolve(durations)
resolve(duration)
});
})


}


module.exports = { processRawFileToMp4, processMp4ToHls, generateThumbnail, getVideoDurations };
module.exports = { processRawFileToMp4, processMp4ToHls, generateThumbnail, getVideoDuration };

0 comments on commit 1e4c2a5

Please sign in to comment.