How to use the node-persist.getItem function in node-persist

To help you get started, we’ve selected a few node-persist 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 akhoury / nodebb-plugin-import / lib / import.js View on Github external
async.eachLimit(this.mem._pids, this.config.nbb.postsBatchSize, function(_pid, done) {
			count++;

			var storedPost = storage.getItem('p.' + _pid);
			if (!storedPost || !storedPost.normalized) {
				logger.warn('[count:' + count + '] skipped post:_pid: ' + _pid + ' it doesn\'t exist in storage');

				// todo [async-going-sync-hack]
				setTimeout(function(){done();}, 0); return;
			}

			var	normalizedPost = storedPost.normalized,
				importedPost = flushed ? null : storedPost.imported,
				skippedPost = normalizedPost._skip ? {_pid: _pid} : flushed ? null : storedPost.skipped;

			if (importedPost || skippedPost) {
				logger.warn('skipping post:_pid: ' + _pid + ' already processed, destiny: ' + (importedPost ? 'imported' : 'skipped'));

				// todo [async-going-sync-hack]
				setTimeout(function(){done();}, 0);
github xyfir / accownt / server / lib / register / finish.ts View on Github external
export async function finishRegistration(jwt?: Accownt.JWT): Promise {
  if (jwt === null) throw 'Invalid or expired token';

  // Verify JWT's userId matches the userId that the JWT's email points to
  // This way only the most recent email verification JWT is valid since it
  // will point to the newest user
  const userId = await emailToId(jwt.email);
  if (userId != jwt.userId)
    throw 'This token has been invalidated by a newer one';

  // Verify user's email
  await storage.init(STORAGE);
  const user: Accownt.User = await storage.getItem(`user-${jwt.userId}`);
  user.verified = true;
  await storage.setItem(`user-${jwt.userId}`, user);

  return await signJWT(jwt.userId, jwt.email, JWT_EXPIRES_IN);
}
github macecchi / pebble-itunesify-remote / osx / app / index.js View on Github external
// Load preferences

storage.initSync();

if (typeof storage.getItem('activePlayer') === 'undefined') {
    storage.setItem('activePlayer', 'itunes');
}
var activePlayer = storage.getItem('activePlayer');
console.log("Starting with active player: " + activePlayer);

if (typeof storage.getItem('controlGlobalVolume') === 'undefined') {
    storage.setItem('controlGlobalVolume', true);
}
var controlGlobalVolume = storage.getItem('controlGlobalVolume');
console.log("Controls global volume: " + controlGlobalVolume);


// GUI

var localIP;

require('dns').lookup(require('os').hostname(), function (err, add, fam) {
  localIP = add;
	menu.insert(new gui.MenuItem({
	    label: 'Server running on ' + localIP,
	    enabled: false
	}), 0);
})

var tray = new gui.Tray({
github xyfir / accownt / server / lib / login / register.ts View on Github external
export async function finishRegistration(jwt?: Accownt.JWT): Promise {
  if (jwt === null) throw 'Invalid or expired token';

  // Verify JWT's userId matches the userId that the JWT's email points to
  // This way only the most recent email verification JWT is valid since it
  // will point to the newest user
  const userId = await emailToId(jwt.email);
  if (userId != jwt.userId)
    throw 'This token has been invalidated by a newer one';

  // Verify user's email
  const user: Accownt.User = await storage.getItem(`user-${jwt.userId}`);
  user.verified = true;
  await storage.setItem(`user-${jwt.userId}`, user);

  return await signJWT(jwt.userId, jwt.email, JWT_EXPIRES_IN);
}
github xyfir / accownt / server / lib / login / normal.ts View on Github external
export async function login(
  email: Accownt.User['email'],
  pass: Accownt.User['password'],
  otp?: string
): Promise {
  // Get user from email
  const userId = await emailToId(cleanEmail(email));
  const user: Accownt.User = await storage.getItem(`user-${userId}`);

  if (!user.password) throw 'You must request a passwordless login link';
  if (
    user.failedLogins >= 5 &&
    user.lastFailedLogin + 15 * 60 * 1000 > Date.now()
  )
    throw 'Too many failed logins; wait 15 minutes';

  // Check password
  const match = await bcrypt.compare(pass, user.password);
  if (!match) {
    // Reset failedLogins after 15 minutes
    if (user.lastFailedLogin + 15 * 60 * 1000 < Date.now())
      user.failedLogins = 0;

    user.failedLogins++;
github akhoury / nodebb-plugin-import / lib / import.js View on Github external
// todo [async-going-sync-hack]
				setTimeout(function(){done();}, 0); return;
			}
			var normalizedTopic = storedTopic.normalized,
				importedTopic = flushed ?  null : storedTopic.imported,
				skippedTopic = normalizedTopic._skip ? {_tid: _tid} : flushed ? null : storedTopic.skipped;

			if (importedTopic || skippedTopic) {
				logger.warn('[count:' + count + '] topic:_tid: ' + _tid + ' already processed, destiny: ' + (importedTopic ? 'imported' : 'skipped'));

				// todo [async-going-sync-hack]
				setTimeout(function(){done();}, 0);
			}  else {

				var importedCategory = (storage.getItem('c.' + normalizedTopic._cid) || {}).imported;
				var importedUser = (storage.getItem('u.' + normalizedTopic._uid) || {}).imported || {};

				if (!importedCategory) {
					logger.warn('[count:' + count + '] skipping topic:_tid:"' + _tid + '" --> _cid:valid: ' + !!importedCategory);
					storedTopic.skipped = normalizedTopic;
					storage.setItem('t.' + _tid, storedTopic, function(err){
						if (err) throw err;

						// todo [async-going-sync-hack]
						setTimeout(function(){done();}, 0);
					});
				} else {
					logger.debug('[count:' + count + '] saving topic:_tid: ' + _tid);

					Topics.post({

						uid: importedUser.uid,
github mistval / kotoba / core / implementations / persistence_implementation.js View on Github external
function getData(key) {
  return storage.getItem(key).then(data => {
    if (data) {
      return data;
    } else {
      return {};
    }
  });
}
github akhoury / nodebb-plugin-import / lib / import.js View on Github external
this.mem._cids.forEach(function(cid) {
			//
			var category = storage.getItem('c.' + cid);
			if (category && category.imported) {
				Group.join('group:cid:' + cid + ':privileges:mods:members', uid, function(err){
					if (err)
						logger.error(err);
				});
			}
		});
	},
github maxkrieger / alienbox / src / reddit.js View on Github external
reddit.on("access_token_expired", function(responseError) {
	var tokens = persist.getItem("tokens");
	if (tokens.refresh !== "") {
		reddit.refresh(tokens.refresh).then(function(refresh) {
			var tokens = {
				token: reddit.getAccessToken(),
				refresh: reddit.getRefreshToken()
			};
			persist.setItem("tokens", tokens);
		});
	}
});