2019-05-23 22:51:01 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Captions from '/imports/api/captions';
|
2017-01-18 20:53:33 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
export default function addCaption(meetingId, padId, locale) {
|
2017-01-18 20:53:33 +08:00
|
|
|
check(meetingId, String);
|
2019-05-17 04:11:10 +08:00
|
|
|
check(padId, String);
|
|
|
|
check(locale, {
|
|
|
|
locale: String,
|
|
|
|
name: String,
|
2017-10-12 05:25:18 +08:00
|
|
|
});
|
2017-01-18 20:53:33 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2019-05-17 04:11:10 +08:00
|
|
|
padId,
|
2017-01-18 20:53:33 +08:00
|
|
|
};
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const modifier = {
|
2019-05-17 04:11:10 +08:00
|
|
|
meetingId,
|
|
|
|
padId,
|
|
|
|
locale,
|
2019-05-29 22:31:27 +08:00
|
|
|
ownerId: '',
|
|
|
|
readOnlyPadId: '',
|
|
|
|
data: '',
|
2019-05-17 04:11:10 +08:00
|
|
|
revs: 0,
|
2019-05-22 03:21:46 +08:00
|
|
|
length: 0,
|
2017-01-18 20:53:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
2017-10-13 03:07:02 +08:00
|
|
|
return Logger.error(`Adding caption to collection: ${err}`);
|
2017-01-18 20:53:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const { insertedId } = numChanged;
|
|
|
|
if (insertedId) {
|
2019-05-17 04:11:10 +08:00
|
|
|
return Logger.verbose(`Added caption locale=${locale.locale} meeting=${meetingId}`);
|
2017-01-18 20:53:33 +08:00
|
|
|
}
|
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
return Logger.verbose(`Upserted caption locale=${locale.locale} meeting=${meetingId}`);
|
2017-01-18 20:53:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Captions.upsert(selector, modifier, cb);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|