Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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...
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)
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;
// 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;
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("");
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);
});
}
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);
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);
});
}
function(blogID, next) {
Blog.get({id: blogID}, next);
},
function(err, blogs) {