Build a blog with Areto Node.js framework

Photo model

The Photo class manages photos of the blog's frontend. Batch processing of image files are available in the administration module only.

model/Photo.js

const Base = require('areto/db/ActiveRecord');
module.exports = class Photo extends Base {

  static getConstants () {
    return {
      TABLE: 'photo',
      SIZE_LARGE: 720,
      SIZE_MEDIUM: 360,
      SIZE_SMALL: 128
    };
  }

  getTitle () {
    return this.get('title') || '';
  }

  // place methods here
};
module.exports.init(module);
const path = require('path');

The getThumb method returns an address that contains the preview specified size. It is used to display the photos in view templates: <img src="<%- photo.getThumb(128) %>" alt="<%- photo.getTitle() %>">. Other methods are shortcuts to the getThumb with different size of images.

model/Photo.js

 getLarge () {
  return this.getThumb(this.SIZE_LARGE);
}

getMedium () {
  return this.getThumb(this.SIZE_MEDIUM);
}

getSmall () {
  return this.getThumb(this.SIZE_SMALL);
}

getThumb (size) {
  return `photo/${size}/${this.get('filename')}`;
}