-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
f5637d8
commit 1feff46
Showing
1 changed file
with
51 additions
and
10 deletions.
There are no files selected for viewing
61 changes: 51 additions & 10 deletions
61
apps/frontend/src/components/launches/providers/x/x.provider.tsx
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 |
---|---|---|
@@ -1,11 +1,52 @@ | ||
import { withProvider } from '@gitroom/frontend/components/launches/providers/high.order.provider'; | ||
export default withProvider(null, undefined, undefined, async (posts) => { | ||
if (posts.some(p => p.length > 4)) { | ||
return 'There can be maximum 4 pictures in a post.'; | ||
} | ||
|
||
if (posts.some(p => p.some(m => m.path.indexOf('mp4') > -1) && p.length > 1)) { | ||
return 'There can be maximum 1 video in a post.'; | ||
} | ||
return true; | ||
}, 280); | ||
export default withProvider( | ||
null, | ||
undefined, | ||
undefined, | ||
async (posts) => { | ||
if (posts.some((p) => p.length > 4)) { | ||
return 'There can be maximum 4 pictures in a post.'; | ||
} | ||
|
||
if ( | ||
posts.some( | ||
(p) => p.some((m) => m.path.indexOf('mp4') > -1) && p.length > 1 | ||
) | ||
) { | ||
return 'There can be maximum 1 video in a post.'; | ||
} | ||
|
||
for (const load of posts.flatMap((p) => p.flatMap((a) => a.path))) { | ||
if (load.indexOf('mp4') > -1) { | ||
const isValid = await checkVideoDuration(load); | ||
if (!isValid) { | ||
return 'Video duration must be less than or equal to 140 seconds.'; | ||
} | ||
} | ||
} | ||
return true; | ||
}, | ||
280 | ||
); | ||
|
||
const checkVideoDuration = async (url: string): Promise<boolean> => { | ||
return new Promise((resolve, reject) => { | ||
const video = document.createElement('video'); | ||
video.src = url; | ||
video.preload = 'metadata'; | ||
|
||
video.onloadedmetadata = () => { | ||
// Check if the duration is less than or equal to 140 seconds | ||
const duration = video.duration; | ||
if (duration <= 140) { | ||
resolve(true); // Video duration is acceptable | ||
} else { | ||
resolve(false); // Video duration exceeds 140 seconds | ||
} | ||
}; | ||
|
||
video.onerror = () => { | ||
reject(new Error('Failed to load video metadata.')); | ||
}; | ||
}); | ||
}; |