* Properly merged changes from master.

* database/migration.js will now exit after migartion.

* Replaced all instances of createTableIfNotExists() into a combination of hasTable() and createTable() in db.js.
This commit is contained in:
Bobby Wibowo 2018-03-14 13:57:09 +07:00
commit c2b2f5b14b
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
7 changed files with 1162 additions and 661 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM node:9
LABEL name "lolisafe"
LABEL version "3.0.0"
LABEL maintainer "iCrawl <icrawltogo@gmail.com>"
WORKDIR /usr/src/lolisafe
COPY package.json yarn.lock ./
RUN sh -c 'echo "deb http://www.deb-multimedia.org jessie main" >> /etc/apt/sources.list' \
&& apt-key adv --keyserver keyring.debian.org --recv-keys 5C808C2B65558117 \
&& apt-get update \
&& apt-get install -y ffmpeg graphicsmagick \
&& yarn install
COPY . .
CMD ["node", "lolisafe.js"]

View File

@ -15,6 +15,12 @@ authController.verify = async (req, res, next) => {
const user = await db.table('users').where('username', username).first() const user = await db.table('users').where('username', username).first()
if (!user) return res.json({ success: false, description: 'Username doesn\'t exist' }) if (!user) return res.json({ success: false, description: 'Username doesn\'t exist' })
if (user.enabled === false || user.enabled === 0) {
return res.json({
success: false,
description: 'This account has been disabled'
})
}
bcrypt.compare(password, user.password, (err, result) => { bcrypt.compare(password, user.password, (err, result) => {
if (err) { if (err) {
@ -56,7 +62,8 @@ authController.register = async (req, res, next) => {
await db.table('users').insert({ await db.table('users').insert({
username: username, username: username,
password: hash, password: hash,
token: token token: token,
enabled: 1
}) })
return res.json({ success: true, token: token }) return res.json({ success: true, token: token })
}) })

View File

@ -60,6 +60,12 @@ uploadsController.upload = async (req, res, next) => {
const token = req.headers.token || '' const token = req.headers.token || ''
const user = await db.table('users').where('token', token).first() const user = await db.table('users').where('token', token).first()
if (user && (user.enabled === false || user.enabled === 0)) {
return res.json({
success: false,
description: 'This account has been disabled'
})
}
const albumid = req.headers.albumid || req.params.albumid const albumid = req.headers.albumid || req.params.albumid
if (albumid && user) { if (albumid && user) {

View File

@ -1,50 +1,63 @@
let init = function (db) { let init = function (db) {
// Create the tables we need to store galleries and files // Create the tables we need to store galleries and files
db.schema.createTableIfNotExists('albums', function (table) { db.schema.hasTable('albums').then(exists => {
table.increments() if (!exists) {
table.integer('userid') db.schema.createTable('albums', function (table) {
table.string('name') table.increments()
table.string('identifier') table.integer('userid')
table.integer('enabled') table.string('name')
table.integer('timestamp') table.string('identifier')
table.integer('editedAt').defaultTo(0) table.integer('enabled')
table.integer('zipGeneratedAt').defaultTo(0) table.integer('timestamp')
}).then(() => {}) table.dateTime('editedAt')
table.dateTime('zipGeneratedAt')
}).then(() => {})
}
})
db.schema.createTableIfNotExists('files', function (table) { db.schema.hasTable('files').then(exists => {
table.increments() if (!exists) {
table.integer('userid') db.schema.createTable('files', function (table) {
table.string('name') table.increments()
table.string('original') table.integer('userid')
table.string('type') table.string('name')
table.string('size') table.string('original')
table.string('hash') table.string('type')
table.string('ip') table.string('size')
table.integer('albumid') table.string('hash')
table.integer('timestamp') table.string('ip')
}).then(() => {}) table.integer('albumid')
table.integer('timestamp')
}).then(() => {})
}
})
db.schema.createTableIfNotExists('users', function (table) { db.schema.hasTable('users').then(exists => {
table.increments() if (!exists) {
table.string('username') db.schema.createTable('users', function (table) {
table.string('password') table.increments()
table.string('token') table.string('username')
table.integer('timestamp') table.string('password')
}).then(() => { table.string('token')
db.table('users').where({username: 'root'}).then((user) => { table.integer('enabled')
if (user.length > 0) return table.integer('timestamp')
}).then(() => {
db.table('users').where({username: 'root'}).then((user) => {
if (user.length > 0) return
require('bcrypt').hash('root', 10, function (err, hash) { require('bcrypt').hash('root', 10, function (err, hash) {
if (err) console.error('Error generating password hash for root') if (err) console.error('Error generating password hash for root')
db.table('users').insert({ db.table('users').insert({
username: 'root', username: 'root',
password: hash, password: hash,
token: require('randomstring').generate(64), token: require('randomstring').generate(64),
timestamp: Math.floor(Date.now() / 1000) timestamp: Math.floor(Date.now() / 1000)
}).then(() => {}) }).then(() => {})
})
})
}) })
}) }
}) })
} }

View File

@ -8,6 +8,7 @@ migration.start = async () => {
table.dateTime('zipGeneratedAt') table.dateTime('zipGeneratedAt')
}) })
console.log('Migration finished! Now start lolisafe normally') console.log('Migration finished! Now start lolisafe normally')
process.exit(0)
} }
migration.start() migration.start()

View File

@ -21,20 +21,20 @@
"dependencies": { "dependencies": {
"bcrypt": "^1.0.3", "bcrypt": "^1.0.3",
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"express": "^4.16.2", "express": "^4.16.1",
"express-handlebars": "^3.0.0", "express-handlebars": "^3.0.0",
"express-rate-limit": "^2.11.0", "express-rate-limit": "^2.11.0",
"fluent-ffmpeg": "^2.1.0", "fluent-ffmpeg": "^2.1.2",
"gm": "^1.23.1", "gm": "^1.23.1",
"helmet": "^3.10.0", "helmet": "^3.11.0",
"jszip": "^3.1.4", "jszip": "^3.1.5",
"knex": "^0.14.2", "knex": "^0.14.4",
"multer": "^1.2.1", "multer": "^1.3.0",
"randomstring": "^1.1.5", "randomstring": "^1.1.5",
"sqlite3": "^3.1.13" "sqlite3": "^3.1.13"
}, },
"devDependencies": { "devDependencies": {
"standard": "^10.0.3" "standard": "^11.0.0"
}, },
"standard": { "standard": {
"envs": [ "envs": [

1681
yarn.lock

File diff suppressed because it is too large Load Diff