larvitfiles
Advanced tools
Comparing version 3.0.0 to 3.0.1
'use strict'; | ||
const logPrefix = 'larvitfiles: ./dbmigration/2.js: ', | ||
lFiles = require(__dirname + '/../index.js'), | ||
filesLib = require(__dirname + '/../index.js'), | ||
lUtils = require('larvitutils'), | ||
@@ -14,21 +14,21 @@ async = require('async'), | ||
let files; | ||
let files; | ||
if (lFiles.storagePath === null) { | ||
const e = new Error('storagePath not set on larvitfiles'); | ||
log.warn(logPrefix + e.message); | ||
throw e; | ||
if (filesLib.storagePath === null) { | ||
const err = new Error('storagePath not set on larvitfiles'); | ||
log.warn(logPrefix + err.message); | ||
throw err; | ||
} | ||
if ( ! fs.existsSync(lFiles.storagePath)) { | ||
if ( ! fs.existsSync(filesLib.storagePath)) { | ||
tasks.push(function (cb) { | ||
log.info(logPrefix + 'storagePath "' + lFiles.storagePath + '" does not exist, creating'); | ||
fs.mkdir(lFiles.storagePath, cb); | ||
log.info(logPrefix + 'storagePath "' + filesLib.storagePath + '" does not exist, creating'); | ||
fs.mkdir(filesLib.storagePath, cb); | ||
}); | ||
} | ||
// get list of slugs and uuids | ||
// Get list of slugs and uuids | ||
tasks.push(function (cb) { | ||
db.query('SELECT uuid, slug FROM larvitfiles_files', function (err, rows) { | ||
files = rows; | ||
files = rows; | ||
cb(err); | ||
@@ -38,3 +38,3 @@ }); | ||
// write files to disk and save type in db | ||
// Write files to disk and save type in db | ||
tasks.push(function (cb) { | ||
@@ -45,11 +45,11 @@ const tasks = []; | ||
tasks.push(function (cb) { | ||
db.query('SELECT data FROM larvitfiles_files WHERE uuid = ?', [lUtils.uuidToBuffer(file.uuid)], function (err, result) { | ||
db.query('SELECT data FROM larvitfiles_files WHERE uuid = ?', file.uuid, function (err, result) { | ||
if (err) return cb(err); | ||
if (result.length === 0) { | ||
log.warn(logPrefix + 'Could not find file with uuid "' + lUtils.formatUuid(file.uuid) + '"'); | ||
log.warn(logPrefix + 'Could not find file with uuid "' + Utils.formatUuid(file.uuid) + '"'); | ||
return cb(); | ||
} | ||
fs.writeFile(lFiles.storagePath + '/' + lUtils.formatUuid(file.uuid), result[0].data, cb); | ||
fs.writeFile(filesLib.storagePath + '/' + lUtils.formatUuid(file.uuid), result[0].data, cb); | ||
}); | ||
@@ -56,0 +56,0 @@ }); |
{ | ||
"name": "larvitfiles", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Storage of files with an API and database to use in web environments", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
47524