]>
Commit | Line | Data |
---|---|---|
1 | import { ACTIVITY_PUB } from '@server/initializers/constants' | |
2 | import { VideoPlaylistModel } from '@server/models/video/video-playlist' | |
3 | import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' | |
4 | import { MVideoId, MVideoPlaylistId } from '@server/types/models' | |
5 | import { AttributesOnly } from '@shared/typescript-utils' | |
6 | import { PlaylistElementObject, PlaylistObject, VideoPlaylistPrivacy } from '@shared/models' | |
7 | ||
8 | function playlistObjectToDBAttributes (playlistObject: PlaylistObject, to: string[]) { | |
9 | const privacy = to.includes(ACTIVITY_PUB.PUBLIC) | |
10 | ? VideoPlaylistPrivacy.PUBLIC | |
11 | : VideoPlaylistPrivacy.UNLISTED | |
12 | ||
13 | return { | |
14 | name: playlistObject.name, | |
15 | description: playlistObject.content, | |
16 | privacy, | |
17 | url: playlistObject.id, | |
18 | uuid: playlistObject.uuid, | |
19 | ownerAccountId: null, | |
20 | videoChannelId: null, | |
21 | createdAt: new Date(playlistObject.published), | |
22 | updatedAt: new Date(playlistObject.updated) | |
23 | } as AttributesOnly<VideoPlaylistModel> | |
24 | } | |
25 | ||
26 | function playlistElementObjectToDBAttributes (elementObject: PlaylistElementObject, videoPlaylist: MVideoPlaylistId, video: MVideoId) { | |
27 | return { | |
28 | position: elementObject.position, | |
29 | url: elementObject.id, | |
30 | startTimestamp: elementObject.startTimestamp || null, | |
31 | stopTimestamp: elementObject.stopTimestamp || null, | |
32 | videoPlaylistId: videoPlaylist.id, | |
33 | videoId: video.id | |
34 | } as AttributesOnly<VideoPlaylistElementModel> | |
35 | } | |
36 | ||
37 | export { | |
38 | playlistObjectToDBAttributes, | |
39 | playlistElementObjectToDBAttributes | |
40 | } |