var moment = require("moment"); var _ = require("lodash"); var fs = require('fs'); var mkdirp = require('mkdirp'); var jade = require('jade'); var marked = require('marked'); var path = require('path'); var schemas = require('./schemas.js'); var config = require("./config.js").config; var sharp = require('sharp'); var Photo = function(data) { this.data = this.sanitize(data); } //////////////////////////////////////////////////////////////////////////////////////// // Prototype Setup //////////////////////////////////////////////////////////////////////////////////////// Photo.prototype.data = {} Photo.prototype.get = function (name) { return this.data[name]; } Photo.prototype.set = function (name, value) { this.data[name] = value; } Photo.prototype.sanitize = function (data) { data = data || {}; schema = schemas.photo; return _.pick(_.defaults(data, schema), _.keys(schema)); } Photo.prototype.save = function (date, callback) { var self = this; if (date) { this.set('updatedDate', date); } else { this.set("updatedDate", new Date()); } this.data = this.sanitize(this.data); db.collection("photos").update({uuid: this.get("uuid")}, this.data, {upsert: true}, function(err) { callback(err); }); } //////////////////////////////////////////////////////////////////////////////////////// // Prototype Functions //////////////////////////////////////////////////////////////////////////////////////// // Parse a string of tags // Returns a list of tags Photo.prototype.tagPhoto = function(str) { this.set("tags", []); // we don't need no stinking commas var str = str.replace(/,/g,''); // remove accents, swap ñ for n, etc var from = "àáäâèéëêìíïîòóöôùúüûñç·/,:;&%"; var to = "aaaaeeeeiiiioooouuuunc-------"; for (var i=0, l=from.length ; i= this.updatedDate) && \ this.published' }).toArray( function (err, docs) { if (err) console.log(err); photos = []; if (docs) { for (i=0; i