Improve environment variable stuff
This commit is contained in:
parent
760ee07a2e
commit
6ba174cff0
16 changed files with 66 additions and 64 deletions
|
@ -1,7 +1,7 @@
|
|||
import moment from 'moment';
|
||||
import { sniff } from './type';
|
||||
|
||||
const fileHost = process.env.FILE_HOST || 'http://localhost:4040';
|
||||
const baseURL = process.env.WEB_BASE_URL;
|
||||
|
||||
export function formatDate(timestamp) {
|
||||
return moment.unix(timestamp).format('D MMM YY [at] h:mm A');
|
||||
|
@ -25,7 +25,7 @@ export function formatFile(file) {
|
|||
added: moment.unix(file.time_added).format(),
|
||||
readableAdded: formatDate(file.time_added),
|
||||
downloads: file.downloads !== undefined ? file.downloads : 0,
|
||||
href: fileHost + '/' + file._id, // eslint-disable-line no-underscore-dangle
|
||||
href: baseURL + '/' + file._id, // eslint-disable-line no-underscore-dangle
|
||||
id: file._id, // eslint-disable-line no-underscore-dangle
|
||||
name: file.file_name,
|
||||
size: file.file_size,
|
||||
|
@ -40,8 +40,8 @@ export function formatFile(file) {
|
|||
formattedFile.width = file.width;
|
||||
const ext = (file.file_name.split('.').pop().toLowerCase() === 'psd' ? '.png' : '');
|
||||
formattedFile.direct = {
|
||||
'150x': fileHost + '/file/150/' + file._id + '/' + file.file_name + ext, // eslint-disable-line no-underscore-dangle
|
||||
'970x': fileHost + '/file/970/' + file._id + '/' + file.file_name + ext, // eslint-disable-line no-underscore-dangle
|
||||
'150x': baseURL + '/file/150/' + file._id + '/' + file.file_name + ext, // eslint-disable-line no-underscore-dangle
|
||||
'970x': baseURL + '/file/970/' + file._id + '/' + file.file_name + ext, // eslint-disable-line no-underscore-dangle
|
||||
};
|
||||
}
|
||||
return formattedFile;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import virustotal from 'virustotal.js';
|
||||
|
||||
virustotal.setKey(process.env.VIRUSTOTAL);
|
||||
virustotal.setKey(process.env.VIRUSTOTAL_KEY);
|
||||
|
||||
const extensions = ['EXE', 'PIF', 'APPLICATION', 'GADGET', 'MSI', 'MSP', 'COM', 'SCR', 'HTA', 'CPL', 'MSC',
|
||||
'JAR', 'BAT', 'CMD', 'VB', 'VBS', 'VBE', 'JS', 'JSE', 'WS', 'WSF', 'WSC', 'WSH', 'PS1', 'PS1XML', 'PS2',
|
||||
|
|
|
@ -3,11 +3,9 @@ const MongoClient = mongodb().MongoClient;
|
|||
import debugname from 'debug';
|
||||
const debug = debugname('hostr:mongo');
|
||||
|
||||
const uristring = process.env.MONGO_URL || process.env.MONGOLAB_URI || 'mongodb://localhost:27017/hostr';
|
||||
|
||||
const configuredClient = new Promise((resolve, reject) => {
|
||||
debug('Connecting to Mongodb');
|
||||
return MongoClient.connect(uristring).then((client) => {
|
||||
return MongoClient.connect(process.env.MONGO_URL).then((client) => {
|
||||
debug('Successfully connected to Mongodb');
|
||||
client.Users = client.collection('users');
|
||||
client.Files = client.collection('files');
|
||||
|
|
|
@ -5,7 +5,7 @@ import session from 'koa-generic-session';
|
|||
import debugname from 'debug';
|
||||
const debug = debugname('hostr:redis');
|
||||
|
||||
const redisUrl = process.env.REDIS_URL || process.env.REDISTOGO_URL || 'redis://localhost:6379';
|
||||
const redisUrl = process.env.REDIS_URL;
|
||||
|
||||
const connection = new Promise((resolve, reject) => {
|
||||
debug('Connecting to Redis');
|
||||
|
|
10
lib/s3.js
10
lib/s3.js
|
@ -3,17 +3,15 @@ import s3UploadStream from 's3-upload-stream';
|
|||
import debugname from 'debug';
|
||||
const debug = debugname('hostr:s3');
|
||||
|
||||
const bucket = process.env.AWS_BUCKET || 'hostrdotcodev';
|
||||
|
||||
const s3 = new aws.S3();
|
||||
const s3Stream = s3UploadStream(s3);
|
||||
|
||||
export function get(key) {
|
||||
debug('fetching file: %s', 'hostr_files/' + key);
|
||||
return s3.getObject({Bucket: bucket, Key: 'hostr_files/' + key}).createReadStream();
|
||||
debug('fetching from s3: %s', 'hostr_files/' + key);
|
||||
return s3.getObject({Bucket: process.env.AWS_BUCKET, Key: 'hostr_files/' + key}).createReadStream();
|
||||
}
|
||||
|
||||
export function upload(key) {
|
||||
debug('Uploading file: %s', 'hostr_files/' + key);
|
||||
return s3Stream.upload({Bucket: bucket, Key: 'hostr_files/' + key});
|
||||
debug('sending to s3: %s', 'hostr_files/' + key);
|
||||
return s3Stream.upload({Bucket: process.env.AWS_BUCKET, Key: 'hostr_files/' + key});
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ function range(start, stop) {
|
|||
return result;
|
||||
}
|
||||
|
||||
const storePath = process.env.FILE_PATH || path.join(process.env.HOME, '.hostr', 'uploads');
|
||||
const storePath = process.env.UPLOAD_STORAGE_PATH;
|
||||
|
||||
const directories = range('A', 'Z').concat(range('a', 'z'), range('0', '9'));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue