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_WINDOW: 2
# RATE_LIMIT_MAX: 5 # RATE_LIMIT_MAX: 5
# BLOCKED_EXTENSIONS: '.jar,.exe,.msi,.com,.bat,.cmd,.scr,.ps1,.sh' # BLOCKED_EXTENSIONS: '.jar,.exe,.msi,.com,.bat,.cmd,.scr,.ps1,.sh'
# UPLOAD_FOLDER: uploads
# MAX_LINKS_PER_ALBUM: 5
# META_THEME_COLOR: '#20222b' # META_THEME_COLOR: '#20222b'
# META_DESCRIPTION: 'Blazing fast file uploader and bunker written in node! 🚀' # META_DESCRIPTION: 'Blazing fast file uploader and bunker written in node! 🚀'
# META_KEYWORDS: 'chibisafe,upload,uploader,file,vue,images,ssr,file uploader,free' # META_KEYWORDS: 'chibisafe,upload,uploader,file,vue,images,ssr,file uploader,free'
# META_TWITTER_HANDLE: '' # META_TWITTER_HANDLE: ''
# SERVER_PORT: 5000 # SERVER_PORT: 5000
# WEBSITE_PORT: 5001
# DOMAIN: 'http://chibisafe.moe' # DOMAIN: 'http://chibisafe.moe'
# SERVICE_NAME: chibisafe # SERVICE_NAME: chibisafe
# MAX_SIZE: 5000 # MAX_SIZE: 5000

View File

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

View File

@ -1,27 +1,7 @@
exports.up = async knex => { exports.up = async knex => {
await knex.schema.createTable('settings', table => { await knex.schema.createTable('settings', table => {
table.string('routePrefix'); table.string('key');
table.integer('rateLimitWindow'); table.string('value');
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');
}); });
}; };

View File

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