]>
Commit | Line | Data |
---|---|---|
1 | import { WatchActionObject } from '@shared/models' | |
2 | import { exists, isDateValid, isUUIDValid } from '../misc' | |
3 | import { isVideoTimeValid } from '../video-view' | |
4 | import { isActivityPubVideoDurationValid, isObjectValid } from './misc' | |
5 | ||
6 | function isWatchActionObjectValid (action: WatchActionObject) { | |
7 | return exists(action) && | |
8 | action.type === 'WatchAction' && | |
9 | isObjectValid(action.id) && | |
10 | isActivityPubVideoDurationValid(action.duration) && | |
11 | isDateValid(action.startTime) && | |
12 | isDateValid(action.endTime) && | |
13 | isLocationValid(action.location) && | |
14 | isUUIDValid(action.uuid) && | |
15 | isObjectValid(action.object) && | |
16 | isWatchSectionsValid(action.watchSections) | |
17 | } | |
18 | ||
19 | // --------------------------------------------------------------------------- | |
20 | ||
21 | export { | |
22 | isWatchActionObjectValid | |
23 | } | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | function isLocationValid (location: any) { | |
28 | if (!location) return true | |
29 | ||
30 | return typeof location === 'object' && typeof location.addressCountry === 'string' | |
31 | } | |
32 | ||
33 | function isWatchSectionsValid (sections: WatchActionObject['watchSections']) { | |
34 | return Array.isArray(sections) && sections.every(s => { | |
35 | return isVideoTimeValid(s.startTimestamp) && isVideoTimeValid(s.endTimestamp) | |
36 | }) | |
37 | } |