Rename {expiry|access}_expiry config options to {expiry|access}_ttl

This commit is contained in:
Nadav Ivgi 2017-12-17 19:22:42 +02:00
parent c7a3b2897b
commit 6528486931
5 changed files with 26 additions and 26 deletions

View File

@ -63,8 +63,8 @@ directory: /home/shesek/ForSale
default_price: 0.25 USD
# Expiry times
invoice_expiry: 3600 # lock-in exchange rate for 1 hour
download_expiry: 172800 # make download available for 2 days after payment
invoice_ttl: 3600 # lock-in exchange rate for 1 hour
download_ttl: 172800 # make download available for 2 days after payment
# Secret for generating HMAC access tokens (required)
token_secret: SOME_LONG_RANDOM_STRING

View File

@ -23,8 +23,8 @@ env: production
#default_price: 0.25 USD
# Expiry times
#invoice_expiry: 3600 # lock-in exchange rate for 1 hour
#download_expiry: 172800 # make download available for 2 days after payment
#invoice_ttl: 3600 # lock-in exchange rate for 1 hour
#download_ttl: 172800 # make download available for 2 days after payment
# Secret for generating HMAC access tokens (required)
token_secret: $TOKEN_SECRET

4
app.js
View File

@ -4,7 +4,7 @@ import { pwrap, pick, fcurrency, fmsat, pngPixel } from './lib/util'
const app = require('express')()
, conf = require('./lib/config')(process.argv[2] || process.cwd())
, kite = require('lightning-strike-client')(conf.kite_url, conf.kite_token)
, files = require('./lib/files')(conf.directory, conf.default_price, conf.invoice_expiry, conf.files)
, files = require('./lib/files')(conf.directory, conf.default_price, conf.invoice_ttl, conf.files)
, tokenr = require('./lib/token')(conf.token_secret)
, preview = require('./lib/preview')(files, conf.cache_path)
@ -74,7 +74,7 @@ app.get('/:rpath(*)', pwrap(async (req, res) => {
}
else if (invoice) {
if (invoice.completed) res.redirect(escape(file.name) + '?token=' + tokenr.make(invoice, conf.access_expiry))
if (invoice.completed) res.redirect(escape(file.name) + '?token=' + tokenr.make(invoice, conf.access_ttl))
else res.render('file', { ...file, invoice })
}

View File

@ -9,29 +9,29 @@ module.exports = basePath => {
const configPath = fs.statSync(basePath).isFile() ? basePath : path.join(basePath, '_filebazaar.yaml')
, config = fs.existsSync(configPath) ? yaml.safeLoad(fs.readFileSync(configPath)) : {}
config.env = config.env || process.env.NODE_ENV || 'development'
config.host = config.host || process.env.HOST || 'localhost'
config.port = config.port || process.env.PORT || 9678
config.url = config.url || process.env.URL || `http://${config.host}:${config.port}/`
config.proxied = config.proxied || process.env.PROXIED || false
config.env = config.env || process.env.NODE_ENV || 'development'
config.host = config.host || process.env.HOST || 'localhost'
config.port = config.port || process.env.PORT || 9678
config.url = config.url || process.env.URL || `http://${config.host}:${config.port}/`
config.proxied = config.proxied || process.env.PROXIED || false
config.directory = config.directory || process.env.BASE_DIR || path.dirname(configPath)
config.token_secret = config.token_secret || process.env.TOKEN_SECRET || assert(false, 'token_secret is required')
config.cache_path = config.cache_path || process.env.CACHE_PATH || path.join(config.directory, '_filebazaar_cache')
config.directory = config.directory || process.env.BASE_DIR || path.dirname(configPath)
config.token_secret = config.token_secret || process.env.TOKEN_SECRET || assert(false, 'token_secret is required')
config.cache_path = config.cache_path || process.env.CACHE_PATH || path.join(config.directory, '_filebazaar_cache')
config.kite_url = config.kite_url || process.env.KITE_URL || 'http://localhost:9112'
config.kite_token = config.kite_token || process.env.KITE_TOKEN
config.kite_url = config.kite_url || process.env.KITE_URL || 'http://localhost:9112'
config.kite_token = config.kite_token || process.env.KITE_TOKEN
config.invoice_expiry = config.invoice_expiry || +process.env.INVOICE_EXP || 3600 // 1 hour
config.access_expiry = config.access_expiry || +process.env.ACCESS_EXP || 172800 // 2 days
config.invoice_ttl = config.invoice_ttl || +process.env.INVOICE_TTL || 3600 // 1 hour
config.access_ttl = config.access_ttl || +process.env.ACCESS_TTL || 172800 // 2 days
config.views_dir = config.views_dir || process.env.VIEWS_DIR || path.join(__dirname, '..', 'views')
config.static_dir = config.static_dir || process.env.STATIC_DIR || path.join(__dirname, '..', 'static')
config.theme = config.theme || process.env.theme || 'yeti'
config.css = config.css || process.env.CSS
config.views_dir = config.views_dir || process.env.VIEWS_DIR || path.join(__dirname, '..', 'views')
config.static_dir = config.static_dir || process.env.STATIC_DIR || path.join(__dirname, '..', 'static')
config.theme = config.theme || process.env.THEME || 'yeti'
config.css = config.css || process.env.CSS
config.files = parseFiles(config.files || (process.env.FILES_JSON ? JSON.parse(process.env.FILES_JSON) : {}))
config.default_price = parsePrice(config.default_price || process.env.DEFAULT_PRICE || '0.25 USD')
config.files = parseFiles(config.files || (process.env.FILES_JSON ? JSON.parse(process.env.FILES_JSON) : {}))
config.default_price = parsePrice(config.default_price || process.env.DEFAULT_PRICE || '0.25 USD')
fs.ensureDirSync(config.cache_path)

View File

@ -14,7 +14,7 @@ import getExif from './exif'
const reIgnore = /^[._]/
, forbiddenErr = new Error('forbidden')
module.exports = (base, default_price, invoice_expiry, files_attr) => {
module.exports = (base, default_price, invoice_ttl, files_attr) => {
const load = async (_path, basic=false) => {
const fullpath = upath.resolve(base, _path)
@ -60,7 +60,7 @@ module.exports = (base, default_price, invoice_expiry, files_attr) => {
description: `Pay to access ${ file.path }, size=${ prettyb(file.size) }, mime=${ file.mime||'-' }` //, sha256=${ await getHash(file.full.path) }`
, currency: file.price.currency
, amount: file.price.amount
, expiry: invoice_expiry
, expiry: invoice_ttl
, metadata: { path: file.path }
})