<commit_before>Media.allow({
      insert: function(userId) {
        return isAdminById(userId);
      },
      update: function(userId) {
        return isAdminById(userId);
      },
      remove: function(userId) {
        return isAdminById(userId);
      },
      download: function(userId) {
        return true;
      },
      fetch: []
    });

 Meteor.publish("media", function(options) {
      return Media.find({}, options, { fields: {"copies.default": 0}});
 });

 Meteor.publish("albumMedia", function(albumSlug, options) { 
      var album = Albums.findOne({slug: albumSlug});

      if (!! album) {
        var visible = !! album.isVisible;

        if (visible || isAdminById(this.userId)) {
          return Media.find({'metadata.albums': { $elemMatch: { _id: album._id} }}, 
                              options, { fields: {'copies.default': 0}});

        } else {
          return null;
        }
      }

 });


 Meteor.publish("mediaTags", function(options) { 
      return Media.find({}, { fields: {"metadata.tags": 1, 'metadata.title': 1, 'original.name': 1}});
 });
<commit_msg>added publication for media by tag<commit_after>Media.allow({
      insert: function(userId) {
        return isAdminById(userId);
      },
      update: function(userId) {
        return isAdminById(userId);
      },
      remove: function(userId) {
        return isAdminById(userId);
      },
      download: function(userId) {
        return true;
      },
      fetch: []
    });

 // publish all media, omit unnecessary fields
 Meteor.publish("media", function(options) {
      return Media.find({}, options, { fields: {"copies.default": 0}});
 });


 // publish only media in a specific album 
 Meteor.publish("albumMedia", function(albumSlug, options) { 
      var album = Albums.findOne({slug: albumSlug});

      if (!! album) {
        var visible = !! album.isVisible;

        if (visible || isAdminById(this.userId)) {
          return Media.find({'metadata.albums': { $elemMatch: { _id: album._id} }}, 
                              options, { fields: {'copies.default': 0}});

        } else {
          return null;
        }
      }

 });
 
 // publish all media with a specific tag
 Meteor.publish("tagMedia", function(tagSlug, options) { 
    return Media.find({'metadata.tags.slug': tagSlug}, options, { fields: {'copies.default': 0}});
 });

 // condensed version of media for tags list
 Meteor.publish("mediaTags", function(options) { 
    return Media.find({}, { fields: {"metadata.tags": 1, 'metadata.title': 1, 'original.name': 1}});
 });

{'fraction_non_alphanumeric': 0.15920591669910472, 'fraction_numerical': 0.004281821720513819, 'mean_word_length': 2.4682860998650473, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2830402', 'n_tokens_mistral': 776, 'n_tokens_neox': 750, 'n_words': 170}