Compare commits

..

No commits in common. "827e7b51b5a76cbf7e44efe0725068de80224d73" and "0d8aec8d61d2e133312fe05e4ed704f92c959dda" have entirely different histories.

6 changed files with 79 additions and 98 deletions

View File

@ -97,9 +97,7 @@ something like:
} }
``` ```
where `path` represents where you want the files stored. Where `path` represents where you want the files stored
File storage currently does not support paste expiration, you can follow [#191](https://github.com/seejohnrun/haste-server/issues/191) for status updates.
### Redis ### Redis
@ -156,9 +154,9 @@ All of which are optional except `type` with very logical default values.
### Memcached ### Memcached
To use memcache storage you must install the `memcached` package via npm To use memcached storage you must install the `memcache` package via npm
`npm install memcached` `npm install memcache`
Once you've done that, your config section should look like: Once you've done that, your config section should look like:

View File

@ -19,7 +19,7 @@ Most of the time I want to show you some text, it's coming from my current
console session. We should make it really easy to take code from the console console session. We should make it really easy to take code from the console
and send it to people. and send it to people.
`cat something | haste` # https://hastebin.com/1238193 `cat something | haste` # http://hastebin.com/1238193
You can even take this a step further, and cut out the last step of copying the You can even take this a step further, and cut out the last step of copying the
URL with: URL with:

View File

@ -1,16 +1,10 @@
{ {
"host": "0.0.0.0", "host": "0.0.0.0",
"port": 7777, "port": 7777,
"keyLength": 10, "keyLength": 10,
"maxLength": 400000, "maxLength": 400000,
"staticMaxAge": 86400, "staticMaxAge": 86400,
"recompressStaticAssets": true, "recompressStaticAssets": true,
"logging": [ "logging": [
{ {
"level": "verbose", "level": "verbose",
@ -18,11 +12,9 @@
"colorize": true "colorize": true
} }
], ],
"keyGenerator": { "keyGenerator": {
"type": "phonetic" "type": "phonetic"
}, },
"rateLimits": { "rateLimits": {
"categories": { "categories": {
"normal": { "normal": {
@ -31,16 +23,14 @@
} }
} }
}, },
"storage": { "storage": {
"type": "memcached", "type": "redis",
"host": "127.0.0.1", "host": "0.0.0.0",
"port": 11211, "port": 6379,
"db": 2,
"expire": 2592000 "expire": 2592000
}, },
"documents": { "documents": {
"about": "./about.md" "about": "./about.md"
} }
} }

View File

@ -123,7 +123,7 @@ DocumentHandler.prototype.chooseKey = function(callback) {
} else { } else {
callback(key); callback(key);
} }
}, true); // Don't bump expirations when key searching });
}; };
DocumentHandler.prototype.acceptableKey = function() { DocumentHandler.prototype.acceptableKey = function() {

View File

@ -1,52 +1,45 @@
const memcached = require('memcached'); var memcached = require('memcache');
const winston = require('winston'); var winston = require('winston');
class MemcachedDocumentStore { // Create a new store with options
var MemcachedDocumentStore = function(options) {
// Create a new store with options
constructor(options) {
this.expire = options.expire; this.expire = options.expire;
if (!MemcachedDocumentStore.client) {
const host = options.host || '127.0.0.1'; MemcachedDocumentStore.connect(options);
const port = options.port || 11211;
const url = `${host}:${port}`;
this.connect(url);
} }
};
// Create a connection // Create a connection
connect(url) { MemcachedDocumentStore.connect = function(options) {
this.client = new memcached(url); var host = options.host || '127.0.0.1';
var port = options.port || 11211;
winston.info(`connecting to memcached on ${url}`); this.client = new memcached.Client(port, host);
this.client.connect();
this.client.on('failure', function(error) { this.client.on('connect', function() {
winston.info('error connecting to memcached', {error}); winston.info('connected to memcached on ' + host + ':' + port);
}); });
} this.client.on('error', function(e) {
winston.info('error connecting to memcached', { error: e });
// Save file in a key
set(key, data, callback, skipExpire) {
this.client.set(key, data, skipExpire ? 0 : this.expire, (error) => {
callback(!error);
}); });
} };
// Get a file from a key // Save file in a key
get(key, callback, skipExpire) { MemcachedDocumentStore.prototype.set =
this.client.get(key, (error, data) => { function(key, data, callback, skipExpire) {
callback(error ? false : data); MemcachedDocumentStore.client.set(key, data, function(err) {
err ? callback(false) : callback(true);
}, skipExpire ? 0 : this.expire);
};
// Update the key so that the expiration is pushed forward // Get a file from a key
if (!skipExpire) { MemcachedDocumentStore.prototype.get = function(key, callback, skipExpire) {
this.set(key, data, (updateSucceeded) => { var _this = this;
if (!updateSucceeded) { MemcachedDocumentStore.client.get(key, function(err, reply) {
winston.error('failed to update expiration on GET', {key}); callback(err ? false : reply);
} if (_this.expire && !skipExpire) {
}, skipExpire); winston.warn('store does not currently push forward expirations on GET');
} }
}); });
} };
}
module.exports = MemcachedDocumentStore; module.exports = MemcachedDocumentStore;

View File

@ -20,7 +20,7 @@ RethinkDBStore.md5 = (str) => {
RethinkDBStore.prototype.set = (key, data, callback) => { RethinkDBStore.prototype.set = (key, data, callback) => {
try { try {
this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) =? {
if (error) return callback(false); if (error) return callback(false);
callback(true); callback(true);
}); });