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.

models/Photo.js

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

  static getConstants () {
    return {
      TABLE: 'photo'
    };
  }

  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.

models/Photo.js

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

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

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

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