How to use the blog.get function in blog

To help you get started, we’ve selected a few blog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidmerfield / Blot / app / clients / git / disconnect.js View on Github external
module.exports = function disconnect(blogID, callback) {
  var liveRepoDirectory = localPath(blogID, "/");
  var liveRepo;

  // Throws an error if directory does not exist
  try {
    liveRepo = Git(liveRepoDirectory).silent(true);    
  } catch (err) {
    return callback(err);
  }

  // TODO, this shit should be handled at the next layer up
  // we shouldn't worry about setting blog.client to ""
  Blog.get({ id: blogID }, function(err, blog) {
    if (err || !blog) {
      return callback(err || new Error("No blog"));
    }

    Blog.set(blogID, { client: "" }, function(err) {
      if (err) return callback(err);

      database.flush(blog.owner, function(err) {
        if (err) return callback(err);

        // Remove the bare git repo in /repos
        fs.remove(dataDir + "/" + blog.handle + ".git", function(err) {
          if (err) return callback(err);

          // Remove the .git directory in the user's blog folder?
          // maybe don't do this... they might want it...
github davidmerfield / Blot / app / sync / index.js View on Github external
driftFactor: options.driftFactor || 0.01, // time in ms

    // the max number of times Redlock will attempt
    // to lock a resource before erroring
    retryCount: options.retryCount || 10,

    // the time in ms between attempts
    retryDelay: options.retryDelay || 200, // time in ms

    // the max time in ms randomly added to retries
    // to improve performance under high contention
    // see https://www.awsarchitectureblog.com/2015/03/backoff.html
    retryJitter: options.retryJitter || 200 // time in ms
  });

  Blog.get({ id: blogID }, function(err, blog) {
    // It would be nice to get an error from Blog.get instead of this...
    if (err || !blog || !blog.id || blog.isDisabled) {
      return callback(new Error("Cannot sync blog " + blogID));
    }

    redlock.lock(resource, ttl, function(err, lock) {
      // We failed to acquire a lock on the resource
      if (err) return callback(err);

      // Store list of locks created by this process
      // so if it dies, we can unlock them all...
      locks[blogID] = lock;

      folder = {
        path: localPath(blogID, "/"),
        update: new Update(blog)
github davidmerfield / Blot / app / sync / start.js View on Github external
function start (blogID, callback) {

  ensure(blogID, 'string')
    .and(callback, 'function');

  var options = {};

  Blog.get({id: blogID}, function(err, blog){

    if (!blog || !blog.id)
      return callback(blogID + ' ' + ERROR.NO_BLOG);

    if (blog.isDisabled)
      return callback(blogID + ' ' + ERROR.DISABLED);

    // Tag all the logs for this sync process
    var log = new Log({uid: blogID, process: 'Sync'});

    // Allow debug passed in options
    if (options.debug) log.debug = log;

    // Pass in option logging function
    options.log = options.log || log;
github davidmerfield / Blot / app / blog / vhosts.js View on Github external
// this should be req.locals.originalHost
  req.originalHost = host;

  // We don't want to serve a blog in place of
  // the main blot site so leave now.
  if (host === config.host) return next();

  handle = extractHandle(host);

  if (handle) {
    identifier = { handle: handle };
  } else {
    identifier = { domain: host };
  }

  Blog.get(identifier, function(err, blog) {
    if (err) return next(err);

    if (!blog || blog.isDisabled || blog.isUnpaid) {
      err = new Error("No blog");
      err.code = "ENOENT";
      return next(err);
    }

    // Probably a www -> apex redirect
    if (identifier.domain && blog.domain !== identifier.domain)
      redirect = req.protocol + "://" + blog.domain + req.url;

    // Redirect HTTP to HTTPS
    if (identifier.domain && blog.forceSSL && req.protocol !== "https")
      redirect = "https://" + blog.domain + req.url;
github davidmerfield / Blot / app / site / routes / sites.js View on Github external
function handle() {
        if (is_subdomain) {
          by = { handle: domain.split(".blot.im").join("") };
        } else {
          by = { domain: domain };
        }

        Blog.get(by, function(err, blog) {
          if (err || !blog) {
            console.log(domain, "is not in the database");
            return next();
          }

          if (!is_subdomain && response !== blog.handle) {
            console.log(domain, "is not on blot it points to...");
            return next();
          }

          template = blog.template;

          protocol = domain.indexOf("blot.im") > -1 ? "http" : "https";

          url = protocol + "://" + site[0];
          display_url = domain.split("www.").join("");
github davidmerfield / Blot / scripts / blog / use-cdn / index.js View on Github external
function switchAvatar(blogID, callback) {
  Blog.get({ id: blogID }, function(err, blog) {
    if (err) return callback(err);

    if (blog.avatar.indexOf(AVATAR_DIRECTORY) !== 0) return callback();

    var avatar = config.cdn.origin + "/" + blog.id + blog.avatar;

    console.log(colors.dim("Blog: " + blogID + " -", blog.avatar));
    console.log(colors.dim("Blog: " + blogID) + " +", avatar);

    Blog.set(blogID, { avatar: avatar }, callback);
  });
}
github davidmerfield / Blot / scripts / blog / purge-s3 / detect.js View on Github external
function main(blog, next) {
  Blog.get({ id: blog.id }, function(err, blog) {
    if (err || !blog) return next();

    User.getById(blog.owner, function(err, user) {
      if (err || !user) return next();

      if (JSON.stringify(user).indexOf(CDN) > -1) {
        var listInUser = [];
        for (var x in user) if (user[x].indexOf(CDN) > -1) listInUser.push(x);
        console.log(colors.red(user.uid, "references CDN in", listInUser));
      }

      if (JSON.stringify(blog).indexOf(CDN) > -1) {
        var listInBlog = [];
        for (var i in blog)
          if (blog[i].toString().indexOf(CDN) > -1) listInBlog.push(i);
github davidmerfield / Blot / app / models / template / writeToFolder.js View on Github external
function makeClient(blogID, callback) {
  require("blog").get({ id: blogID }, function(err, blog) {
    var client = require("clients")[blog.client];

    if (!blog.client || !client)
      return callback(new Error("No client for this blog"));

    return callback(null, client);
  });
}
github davidmerfield / Blot / scripts / user / delete.js View on Github external
function(blogID, next) {
      Blog.get({id: blogID}, next);
    },
    function(err, blogs) {

blog

I've just started development on this node module. When i'm done, it will be a generic blog backend for new users to use and try out!

ISC
Latest version published 5 years ago

Package Health Score

40 / 100
Full package analysis

Popular blog functions