mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 07:11:33 +00:00
Updates
* 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:
commit
c2b2f5b14b
19
Dockerfile
Normal file
19
Dockerfile
Normal 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"]
|
@ -15,6 +15,12 @@ authController.verify = async (req, res, next) => {
|
||||
|
||||
const user = await db.table('users').where('username', username).first()
|
||||
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) => {
|
||||
if (err) {
|
||||
@ -56,7 +62,8 @@ authController.register = async (req, res, next) => {
|
||||
await db.table('users').insert({
|
||||
username: username,
|
||||
password: hash,
|
||||
token: token
|
||||
token: token,
|
||||
enabled: 1
|
||||
})
|
||||
return res.json({ success: true, token: token })
|
||||
})
|
||||
|
@ -60,6 +60,12 @@ uploadsController.upload = async (req, res, next) => {
|
||||
|
||||
const token = req.headers.token || ''
|
||||
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
|
||||
|
||||
if (albumid && user) {
|
||||
|
@ -1,50 +1,63 @@
|
||||
let init = function (db) {
|
||||
// Create the tables we need to store galleries and files
|
||||
db.schema.createTableIfNotExists('albums', function (table) {
|
||||
table.increments()
|
||||
table.integer('userid')
|
||||
table.string('name')
|
||||
table.string('identifier')
|
||||
table.integer('enabled')
|
||||
table.integer('timestamp')
|
||||
table.integer('editedAt').defaultTo(0)
|
||||
table.integer('zipGeneratedAt').defaultTo(0)
|
||||
}).then(() => {})
|
||||
db.schema.hasTable('albums').then(exists => {
|
||||
if (!exists) {
|
||||
db.schema.createTable('albums', function (table) {
|
||||
table.increments()
|
||||
table.integer('userid')
|
||||
table.string('name')
|
||||
table.string('identifier')
|
||||
table.integer('enabled')
|
||||
table.integer('timestamp')
|
||||
table.dateTime('editedAt')
|
||||
table.dateTime('zipGeneratedAt')
|
||||
}).then(() => {})
|
||||
}
|
||||
})
|
||||
|
||||
db.schema.createTableIfNotExists('files', function (table) {
|
||||
table.increments()
|
||||
table.integer('userid')
|
||||
table.string('name')
|
||||
table.string('original')
|
||||
table.string('type')
|
||||
table.string('size')
|
||||
table.string('hash')
|
||||
table.string('ip')
|
||||
table.integer('albumid')
|
||||
table.integer('timestamp')
|
||||
}).then(() => {})
|
||||
db.schema.hasTable('files').then(exists => {
|
||||
if (!exists) {
|
||||
db.schema.createTable('files', function (table) {
|
||||
table.increments()
|
||||
table.integer('userid')
|
||||
table.string('name')
|
||||
table.string('original')
|
||||
table.string('type')
|
||||
table.string('size')
|
||||
table.string('hash')
|
||||
table.string('ip')
|
||||
table.integer('albumid')
|
||||
table.integer('timestamp')
|
||||
}).then(() => {})
|
||||
}
|
||||
})
|
||||
|
||||
db.schema.createTableIfNotExists('users', function (table) {
|
||||
table.increments()
|
||||
table.string('username')
|
||||
table.string('password')
|
||||
table.string('token')
|
||||
table.integer('timestamp')
|
||||
}).then(() => {
|
||||
db.table('users').where({username: 'root'}).then((user) => {
|
||||
if (user.length > 0) return
|
||||
db.schema.hasTable('users').then(exists => {
|
||||
if (!exists) {
|
||||
db.schema.createTable('users', function (table) {
|
||||
table.increments()
|
||||
table.string('username')
|
||||
table.string('password')
|
||||
table.string('token')
|
||||
table.integer('enabled')
|
||||
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) {
|
||||
if (err) console.error('Error generating password hash for root')
|
||||
require('bcrypt').hash('root', 10, function (err, hash) {
|
||||
if (err) console.error('Error generating password hash for root')
|
||||
|
||||
db.table('users').insert({
|
||||
username: 'root',
|
||||
password: hash,
|
||||
token: require('randomstring').generate(64),
|
||||
timestamp: Math.floor(Date.now() / 1000)
|
||||
}).then(() => {})
|
||||
db.table('users').insert({
|
||||
username: 'root',
|
||||
password: hash,
|
||||
token: require('randomstring').generate(64),
|
||||
timestamp: Math.floor(Date.now() / 1000)
|
||||
}).then(() => {})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ migration.start = async () => {
|
||||
table.dateTime('zipGeneratedAt')
|
||||
})
|
||||
console.log('Migration finished! Now start lolisafe normally')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
migration.start()
|
||||
|
14
package.json
14
package.json
@ -21,20 +21,20 @@
|
||||
"dependencies": {
|
||||
"bcrypt": "^1.0.3",
|
||||
"body-parser": "^1.18.2",
|
||||
"express": "^4.16.2",
|
||||
"express": "^4.16.1",
|
||||
"express-handlebars": "^3.0.0",
|
||||
"express-rate-limit": "^2.11.0",
|
||||
"fluent-ffmpeg": "^2.1.0",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"gm": "^1.23.1",
|
||||
"helmet": "^3.10.0",
|
||||
"jszip": "^3.1.4",
|
||||
"knex": "^0.14.2",
|
||||
"multer": "^1.2.1",
|
||||
"helmet": "^3.11.0",
|
||||
"jszip": "^3.1.5",
|
||||
"knex": "^0.14.4",
|
||||
"multer": "^1.3.0",
|
||||
"randomstring": "^1.1.5",
|
||||
"sqlite3": "^3.1.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"standard": "^10.0.3"
|
||||
"standard": "^11.0.0"
|
||||
},
|
||||
"standard": {
|
||||
"envs": [
|
||||
|
Loading…
Reference in New Issue
Block a user