Youtube music and video downloader

links.js 700B

123456789101112131415161718192021222324252627282930313233
  1. import { Meteor } from 'meteor/meteor';
  2. import { Mongo } from 'meteor/mongo';
  3. import { check, Match } from 'meteor/check';
  4. export const Links = new Mongo.Collection('links');
  5. const YTExp = /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-_]*)/;
  6. if (Meteor.isServer) {
  7. // This code only runs on the server
  8. Meteor.publish('links', function linksPublication() {
  9. return Links.find({
  10. completed: {$ne: true}
  11. });
  12. });
  13. }
  14. Meteor.methods({
  15. 'links.insert'(url) {
  16. check(url, Match.Where((url) => YTExp.test(url)));
  17. Links.insert({
  18. url,
  19. createdAt: new Date(),
  20. });
  21. },
  22. 'links.remove'(linkId) {
  23. check(linkId, String);
  24. Links.remove(linkId);
  25. },
  26. });