-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepareEvents.js
More file actions
60 lines (53 loc) · 1.98 KB
/
prepareEvents.js
File metadata and controls
60 lines (53 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { format, parse } from 'date-fns';
import { zonedTimeToUtc } from 'date-fns-tz';
import { getCollection } from './dbHelper.js';
export function prepareEvents(videoList) {
const talentsIconCollection = getCollection('talentsIcon');
return videoList.map(video => {
let attendees = [{
name: video.name,
email: 'talent@hololivepro.com', // Modify as needed
rsvp: false,
partstat: 'ACCEPTED',
role: 'REQ-PARTICIPANT'
}]; // add streamer as default
if (video.collaboTalents && video.collaboTalents.length > 0) {
attendees.concat(video.collaboTalents.map(collaboTalent => {
let talent = talentsIconCollection.findOne({ iconImageUrl: collaboTalent.iconImageUrl });
if (talent){
return {
name: talent.name,
email: 'talent@hololivepro.com',
rsvp: false,
partstat: 'ACCEPTED',
role: 'REQ-PARTICIPANT'
}
}
})) ;
}
let categories = [];
const regex = /#[^\s#]+/g;
categories = video.title.match(regex);
const platformsCollection = getCollection('platforms');
const platform = platformsCollection.findOne({ id: video.platformType }) ;
const zonedDate = parse(video.datetime, 'yyyy/MM/dd HH:mm:ss', new Date());
const utcDate = zonedTimeToUtc(zonedDate, 'Asia/Tokyo');
const event = {
start: format(utcDate, 'yyyy,MM,dd,HH,mm').split(',').map(Number),
duration: { hours: 2 }, // we don't know how long. set to 2hr
title: video.name, // will fill in summery
description: video.title.replace(/\s/g, ' '), // use replace to make safe string
url: video.url,
location: platform ? platform.name : ' ',
attendees: attendees,
organizer: {
name: video.name,
email: 'talent@hololivepro.com' // modify as needed
}
};
if (categories){
event.categories = categories.map(category => category.slice(1)); // remove '#' prefix;
}
return event;
});
}