chore: update db migration, seed and docker env

This commit is contained in:
Pitu 2021-06-15 00:13:37 +09:00
parent f45cb197e4
commit b2253c7f60
5 changed files with 23 additions and 37 deletions

2
TODO
View File

@ -1,2 +0,0 @@
Remove generate zips from .env as its not used anymore
> Or make it an admin setting to allow users to create zips for their album links or not.

View File

@ -12,14 +12,11 @@ services:
# RATE_LIMIT_WINDOW: 2
# RATE_LIMIT_MAX: 5
# BLOCKED_EXTENSIONS: '.jar,.exe,.msi,.com,.bat,.cmd,.scr,.ps1,.sh'
# UPLOAD_FOLDER: uploads
# MAX_LINKS_PER_ALBUM: 5
# META_THEME_COLOR: '#20222b'
# META_DESCRIPTION: 'Blazing fast file uploader and bunker written in node! 🚀'
# META_KEYWORDS: 'chibisafe,upload,uploader,file,vue,images,ssr,file uploader,free'
# META_TWITTER_HANDLE: ''
# SERVER_PORT: 5000
# WEBSITE_PORT: 5001
# DOMAIN: 'http://chibisafe.moe'
# SERVICE_NAME: chibisafe
# MAX_SIZE: 5000

View File

@ -32,7 +32,6 @@ services:
RATE_LIMIT_WINDOW: 2
RATE_LIMIT_MAX: 5
BLOCKED_EXTENSIONS: ".jar,.exe,.msi,.com,.bat,.cmd,.scr,.ps1,.sh"
UPLOAD_FOLDER: uploads
SECRET: ""
MAX_LINKS_PER_ALBUM: 5
META_THEME_COLOR: "#20222b"
@ -40,8 +39,7 @@ services:
META_KEYWORDS: "chibisafe,upload,uploader,file,vue,images,ssr,file uploader,free"
META_TWITTER_HANDLE: ""
SERVER_PORT: 5000
WEBSITE_PORT: 5001
DOMAIN: "http://chibisafe.moe"
DOMAIN: "http://localhost:5000"
SERVICE_NAME: chibisafe
MAX_SIZE: 5000
GENERATE_THUMBNAILS: "true"

View File

@ -1,27 +1,7 @@
exports.up = async knex => {
await knex.schema.createTable('settings', table => {
table.string('routePrefix');
table.integer('rateLimitWindow');
table.integer('rateLimitMax');
table.string('secret');
table.string('serviceName');
table.string('domain');
table.integer('chunkSize');
table.integer('maxSize');
table.boolean('generateZips');
table.integer('generatedFilenameLength');
table.integer('generatedAlbumLength');
table.integer('maxLinksPerAlbum');
table.string('uploadFolder');
table.json('blockedExtensions');
table.boolean('publicMode');
table.boolean('userAccounts');
table.string('adminAccount');
table.string('adminPassword');
table.string('metaThemeColor');
table.string('metaDescription');
table.string('metaKeywords');
table.string('metaTwitterHandle');
table.string('key');
table.string('value');
});
};

View File

@ -8,21 +8,34 @@ exports.seed = async db => {
// Save environment variables to the database
try {
const settings = await db.table('settings').first();
if (!settings) {
await Util.writeConfigToDb(Util.getEnvironmentDefaults(), false);
const defaults = Util.getEnvironmentDefaults();
const keys = Object.keys(defaults);
for await (const item of keys) {
Util.writeConfigToDb({
key: item,
value: defaults[item]
});
}
} catch (error) {
console.error(error);
}
// Create admin user if it doesnt exist
const user = await db.table('users').where({ username: process.env.ADMIN_ACCOUNT }).first();
if (user) return;
const user = await db.table('users').where({ username: 'admin' }).first();
if (user) {
console.log();
console.log('=========================================================');
console.log('== admin account already exists, skipping. ==');
console.log('=========================================================');
console.log('== Run `pm2 start pm2.json` to start the service ==');
console.log('=========================================================');
console.log();
return;
}
try {
const hash = await bcrypt.hash(process.env.ADMIN_PASSWORD, 10);
const hash = await bcrypt.hash('admin', 10);
await db.table('users').insert({
username: process.env.ADMIN_ACCOUNT,
username: 'admin',
password: hash,
passwordEditedAt: now,
createdAt: now,