mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
First version
This commit is contained in:
parent
b285f24415
commit
376cf10663
30
.eslintrc.json
Normal file
30
.eslintrc.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"indent": [
|
||||||
|
"error",
|
||||||
|
"tab"
|
||||||
|
],
|
||||||
|
"linebreak-style": [
|
||||||
|
"error",
|
||||||
|
"unix"
|
||||||
|
],
|
||||||
|
"quotes": [
|
||||||
|
"error",
|
||||||
|
"single"
|
||||||
|
],
|
||||||
|
"semi": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
|
"no-unused-vars": "warn",
|
||||||
|
"no-console": "off"
|
||||||
|
}
|
||||||
|
}
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
node_modules/
|
||||||
|
uploads/
|
||||||
|
logs/
|
||||||
|
config.js
|
@ -1,2 +1,7 @@
|
|||||||
|
<<<<<<< HEAD
|
||||||
|
# loli-bank
|
||||||
|
Pomf-like image uploading service, written in NodeJS
|
||||||
|
=======
|
||||||
# loli-safe
|
# loli-safe
|
||||||
Pomf-like file uploading service, written in NodeJS
|
Pomf-like file uploading service, written in NodeJS
|
||||||
|
>>>>>>> b285f244150d0eb79376716501a97b9416497344
|
||||||
|
49
controllers/uploadController.js
Normal file
49
controllers/uploadController.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
const path = require('path')
|
||||||
|
const config = require('../config.js')
|
||||||
|
const multer = require('multer')
|
||||||
|
const randomstring = require('randomstring')
|
||||||
|
const db = require('knex')(config.database)
|
||||||
|
|
||||||
|
let uploadsController = {}
|
||||||
|
|
||||||
|
const storage = multer.diskStorage({
|
||||||
|
destination: function (req, file, cb) {
|
||||||
|
cb(null, './' + config.uploads.folder + '/')
|
||||||
|
},
|
||||||
|
filename: function (req, file, cb) {
|
||||||
|
cb(null, randomstring.generate(config.fileLength) + path.extname(file.originalname))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const upload = multer({
|
||||||
|
storage: storage,
|
||||||
|
limits: { fileSize: config.uploads.maxsize }
|
||||||
|
}).single('file')
|
||||||
|
|
||||||
|
uploadsController.upload = function(req, res, next){
|
||||||
|
|
||||||
|
let gallery = req.headers.gallery
|
||||||
|
|
||||||
|
if(!config.privacy.public)
|
||||||
|
if(!config.privacy.IPs.includes(req.ip)) return res.status(401).send('Not Authorized!')
|
||||||
|
|
||||||
|
upload(req, res, function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err)
|
||||||
|
return res.json({ error: err })
|
||||||
|
}
|
||||||
|
|
||||||
|
db.table('files').insert({
|
||||||
|
file: req.file.filename,
|
||||||
|
galleryid: gallery
|
||||||
|
}).then(() => {
|
||||||
|
res.json({
|
||||||
|
'filename': req.file.filename
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = uploadsController
|
31
lolisafe.js
Normal file
31
lolisafe.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const config = require('./config.js')
|
||||||
|
const routes = require('./routes.js')
|
||||||
|
const express = require('express')
|
||||||
|
const db = require('knex')(config.database)
|
||||||
|
const fs = require('fs')
|
||||||
|
const safe = express()
|
||||||
|
|
||||||
|
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
|
||||||
|
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
|
||||||
|
fs.existsSync('db') || fs.writeFile('db', '')
|
||||||
|
|
||||||
|
safe.use('/', express.static('./uploads'))
|
||||||
|
safe.use('/api' , routes)
|
||||||
|
safe.use('/panel', express.static('./dashboard'))
|
||||||
|
|
||||||
|
// Create the tables we need to store galleries and files
|
||||||
|
db.schema.createTableIfNotExists('gallery', function (table) {
|
||||||
|
table.increments()
|
||||||
|
table.string('name')
|
||||||
|
table.timestamps()
|
||||||
|
}).then(() => {})
|
||||||
|
|
||||||
|
db.schema.createTableIfNotExists('files', function (table) {
|
||||||
|
table.increments()
|
||||||
|
table.string('file')
|
||||||
|
table.integer('galleryid')
|
||||||
|
}).then(() => {})
|
||||||
|
|
||||||
|
safe.enable('trust proxy')
|
||||||
|
|
||||||
|
safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
|
25
package.json
Normal file
25
package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "loli-safe",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Pomf-like uploading service, written in NodeJS",
|
||||||
|
"author": "kanadeko",
|
||||||
|
"main": "lolibank.js",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/kanadeko/loli-safe"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/kanadeko/loli-safe/issues"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=7.0.0"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.14.0",
|
||||||
|
"knex": "^0.12.6",
|
||||||
|
"multer": "^1.2.1",
|
||||||
|
"randomstring": "^1.1.5",
|
||||||
|
"sqlite3": "^3.1.8"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user