Compare commits

..

10 Commits

Author SHA1 Message Date
John Crepezzi 827e7b51b5 Rewrite the memcached client
* Update syntax to ES6
* Use `memcached` instead of `memcache`
* Fix restrictions where expirations weren't pushed forward on GET
* Fix a bug where we were unnecessarily bumping expirations on key search

Closes #201
2018-02-16 09:52:44 -05:00
John Crepezzi ad7702aaf4
Merge pull request #194 from szepeviktor/patch-1
Change to HTTPS in about.md
2018-01-22 10:30:12 -05:00
Viktor Szépe f5fbc8d19e
Change to HTTPS in about.md
Please also change the repo URL here on GitHub
2018-01-22 14:51:15 +01:00
John Crepezzi 0a8923bf12
Merge pull request #192 from C0rn3j/master
Add note about paste expiration, cosmetic fixes.
2017-12-30 20:24:01 -05:00
Martin 4d572a2ec0
convert relative path to absolute 2017-12-30 17:11:29 +01:00
Martin d9a53d3e6e
Add note about paste expiration, cosmetic fixes. 2017-12-29 20:42:11 +01:00
John Crepezzi 8da37ea5de
Merge pull request #190 from PassTheMayo/patch-1
Oh noes! I didn't even notice that I had a typo...
2017-12-11 10:51:12 -05:00
Jacob Gunther ff0fccd6c2
Oh noes! I didn't even notice that I had a typo... 2017-12-11 09:50:50 -06:00
John Crepezzi 63c4576633
Merge pull request #189 from PassTheMayo/master
Added RethinkDB storage option & fixed config to use proper JSON
2017-12-11 10:46:45 -05:00
Jacob Gunther b31d143bcd
Revert config.js to previous state 2017-12-11 09:45:37 -06:00
6 changed files with 98 additions and 79 deletions

View File

@ -97,7 +97,9 @@ 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
@ -154,9 +156,9 @@ All of which are optional except `type` with very logical default values.
### Memcached ### Memcached
To use memcached storage you must install the `memcache` package via npm To use memcache storage you must install the `memcached` package via npm
`npm install memcache` `npm install memcached`
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` # http://hastebin.com/1238193 `cat something | haste` # https://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,10 +1,16 @@
{ {
"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",
@ -12,9 +18,11 @@
"colorize": true "colorize": true
} }
], ],
"keyGenerator": { "keyGenerator": {
"type": "phonetic" "type": "phonetic"
}, },
"rateLimits": { "rateLimits": {
"categories": { "categories": {
"normal": { "normal": {
@ -23,14 +31,16 @@
} }
} }
}, },
"storage": { "storage": {
"type": "redis", "type": "memcached",
"host": "0.0.0.0", "host": "127.0.0.1",
"port": 6379, "port": 11211,
"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,45 +1,52 @@
var memcached = require('memcache'); const memcached = require('memcached');
var winston = require('winston'); const winston = require('winston');
class MemcachedDocumentStore {
// Create a new store with options // Create a new store with options
var MemcachedDocumentStore = function(options) { constructor(options) {
this.expire = options.expire; this.expire = options.expire;
if (!MemcachedDocumentStore.client) {
MemcachedDocumentStore.connect(options); const host = options.host || '127.0.0.1';
const port = options.port || 11211;
const url = `${host}:${port}`;
this.connect(url);
} }
};
// Create a connection // Create a connection
MemcachedDocumentStore.connect = function(options) { connect(url) {
var host = options.host || '127.0.0.1'; this.client = new memcached(url);
var port = options.port || 11211;
this.client = new memcached.Client(port, host); winston.info(`connecting to memcached on ${url}`);
this.client.connect();
this.client.on('connect', function() { this.client.on('failure', function(error) {
winston.info('connected to memcached on ' + host + ':' + port); winston.info('error connecting to memcached', {error});
}); });
this.client.on('error', function(e) { }
winston.info('error connecting to memcached', { error: e });
});
};
// Save file in a key // Save file in a key
MemcachedDocumentStore.prototype.set = set(key, data, callback, skipExpire) {
function(key, data, callback, skipExpire) { this.client.set(key, data, skipExpire ? 0 : this.expire, (error) => {
MemcachedDocumentStore.client.set(key, data, function(err) { callback(!error);
err ? callback(false) : callback(true); });
}, skipExpire ? 0 : this.expire); }
};
// Get a file from a key // Get a file from a key
MemcachedDocumentStore.prototype.get = function(key, callback, skipExpire) { get(key, callback, skipExpire) {
var _this = this; this.client.get(key, (error, data) => {
MemcachedDocumentStore.client.get(key, function(err, reply) { callback(error ? false : data);
callback(err ? false : reply);
if (_this.expire && !skipExpire) { // Update the key so that the expiration is pushed forward
winston.warn('store does not currently push forward expirations on GET'); if (!skipExpire) {
this.set(key, data, (updateSucceeded) => {
if (!updateSucceeded) {
winston.error('failed to update expiration on GET', {key});
}
}, skipExpire);
} }
}); });
}; }
}
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);
}); });