| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { Meteor } from 'meteor/meteor';
- import { Mongo } from 'meteor/mongo';
- import { check, Match } from 'meteor/check';
- import { convertVideo, convertAudio} from './converter';
-
- export const Converted = new Mongo.Collection('links');
-
- const YTExp = /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-_]*)/;
-
- if (Meteor.isServer) {
- Meteor.publish('links', () => Converted.find());
- }
-
- Meteor.methods({
-
- 'links.add'({video, type}) {
- check(video.url, Match.Where(url => YTExp.test(url)));
- check(type, Match.Where(t => ['audio'].includes(t)));
-
- let converted = Converted.findOne({ id: video.id });
-
- if (!converted) {
- let inserted_id = Converted.insert({
- id: video.id, url: video.url,
- title: video.title, createdAt: new Date()
- });
- converted = Converted.findOne({_id: inserted_id });
- }
-
- if (!converted.audio) {
- Converted.update({ _id: converted._id }, { $set: { audio: '', error_audio: '', audio_progress: 0 } });
- convertAudio(converted.url, converted.title.replace(/ /g, '_'), converted._id);
- }
-
- if (!converted.video) {
- Converted.update({ _id: converted._id }, { $set: { video: '', error_video: '', video_progress: 0 } });
- convertVideo(converted.url, converted.title.replace(/ /g, '_'), converted._id);
- }
- },
-
- });
|