Compare commits
10 Commits
0d8aec8d61
...
827e7b51b5
Author | SHA1 | Date |
---|---|---|
![]() |
827e7b51b5 | |
![]() |
ad7702aaf4 | |
![]() |
f5fbc8d19e | |
![]() |
0a8923bf12 | |
![]() |
4d572a2ec0 | |
![]() |
d9a53d3e6e | |
![]() |
8da37ea5de | |
![]() |
ff0fccd6c2 | |
![]() |
63c4576633 | |
![]() |
b31d143bcd |
10
README.md
10
README.md
|
@ -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
|
||||
|
||||
|
@ -154,9 +156,9 @@ All of which are optional except `type` with very logical default values.
|
|||
|
||||
### 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:
|
||||
|
||||
|
@ -228,4 +230,4 @@ SOFTWARE
|
|||
|
||||
* jQuery: MIT/GPL license
|
||||
* highlight.js: Copyright © 2006, Ivan Sagalaev
|
||||
* highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak
|
||||
* highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak
|
||||
|
|
2
about.md
2
about.md
|
@ -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
|
||||
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
|
||||
URL with:
|
||||
|
|
78
config.js
78
config.js
|
@ -1,36 +1,46 @@
|
|||
{
|
||||
"host": "0.0.0.0",
|
||||
"port": 7777,
|
||||
"keyLength": 10,
|
||||
"maxLength": 400000,
|
||||
"staticMaxAge": 86400,
|
||||
"recompressStaticAssets": true,
|
||||
"logging": [
|
||||
{
|
||||
"level": "verbose",
|
||||
"type": "Console",
|
||||
"colorize": true
|
||||
}
|
||||
],
|
||||
"keyGenerator": {
|
||||
"type": "phonetic"
|
||||
},
|
||||
"rateLimits": {
|
||||
"categories": {
|
||||
"normal": {
|
||||
"totalRequests": 500,
|
||||
"every": 60000
|
||||
}
|
||||
}
|
||||
},
|
||||
"storage": {
|
||||
"type": "redis",
|
||||
"host": "0.0.0.0",
|
||||
"port": 6379,
|
||||
"db": 2,
|
||||
"expire": 2592000
|
||||
},
|
||||
"documents": {
|
||||
"about": "./about.md"
|
||||
}
|
||||
|
||||
"host": "0.0.0.0",
|
||||
"port": 7777,
|
||||
|
||||
"keyLength": 10,
|
||||
|
||||
"maxLength": 400000,
|
||||
|
||||
"staticMaxAge": 86400,
|
||||
|
||||
"recompressStaticAssets": true,
|
||||
|
||||
"logging": [
|
||||
{
|
||||
"level": "verbose",
|
||||
"type": "Console",
|
||||
"colorize": true
|
||||
}
|
||||
],
|
||||
|
||||
"keyGenerator": {
|
||||
"type": "phonetic"
|
||||
},
|
||||
|
||||
"rateLimits": {
|
||||
"categories": {
|
||||
"normal": {
|
||||
"totalRequests": 500,
|
||||
"every": 60000
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"storage": {
|
||||
"type": "memcached",
|
||||
"host": "127.0.0.1",
|
||||
"port": 11211,
|
||||
"expire": 2592000
|
||||
},
|
||||
|
||||
"documents": {
|
||||
"about": "./about.md"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ DocumentHandler.prototype.chooseKey = function(callback) {
|
|||
} else {
|
||||
callback(key);
|
||||
}
|
||||
});
|
||||
}, true); // Don't bump expirations when key searching
|
||||
};
|
||||
|
||||
DocumentHandler.prototype.acceptableKey = function() {
|
||||
|
|
|
@ -1,45 +1,52 @@
|
|||
var memcached = require('memcache');
|
||||
var winston = require('winston');
|
||||
const memcached = require('memcached');
|
||||
const winston = require('winston');
|
||||
|
||||
// Create a new store with options
|
||||
var MemcachedDocumentStore = function(options) {
|
||||
this.expire = options.expire;
|
||||
if (!MemcachedDocumentStore.client) {
|
||||
MemcachedDocumentStore.connect(options);
|
||||
class MemcachedDocumentStore {
|
||||
|
||||
// Create a new store with options
|
||||
constructor(options) {
|
||||
this.expire = options.expire;
|
||||
|
||||
const host = options.host || '127.0.0.1';
|
||||
const port = options.port || 11211;
|
||||
const url = `${host}:${port}`;
|
||||
this.connect(url);
|
||||
}
|
||||
};
|
||||
|
||||
// Create a connection
|
||||
MemcachedDocumentStore.connect = function(options) {
|
||||
var host = options.host || '127.0.0.1';
|
||||
var port = options.port || 11211;
|
||||
this.client = new memcached.Client(port, host);
|
||||
this.client.connect();
|
||||
this.client.on('connect', function() {
|
||||
winston.info('connected to memcached on ' + host + ':' + port);
|
||||
});
|
||||
this.client.on('error', function(e) {
|
||||
winston.info('error connecting to memcached', { error: e });
|
||||
});
|
||||
};
|
||||
// Create a connection
|
||||
connect(url) {
|
||||
this.client = new memcached(url);
|
||||
|
||||
// Save file in a key
|
||||
MemcachedDocumentStore.prototype.set =
|
||||
function(key, data, callback, skipExpire) {
|
||||
MemcachedDocumentStore.client.set(key, data, function(err) {
|
||||
err ? callback(false) : callback(true);
|
||||
}, skipExpire ? 0 : this.expire);
|
||||
};
|
||||
winston.info(`connecting to memcached on ${url}`);
|
||||
|
||||
// Get a file from a key
|
||||
MemcachedDocumentStore.prototype.get = function(key, callback, skipExpire) {
|
||||
var _this = this;
|
||||
MemcachedDocumentStore.client.get(key, function(err, reply) {
|
||||
callback(err ? false : reply);
|
||||
if (_this.expire && !skipExpire) {
|
||||
winston.warn('store does not currently push forward expirations on GET');
|
||||
}
|
||||
});
|
||||
};
|
||||
this.client.on('failure', function(error) {
|
||||
winston.info('error connecting to memcached', {error});
|
||||
});
|
||||
}
|
||||
|
||||
// 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
|
||||
get(key, callback, skipExpire) {
|
||||
this.client.get(key, (error, data) => {
|
||||
callback(error ? false : data);
|
||||
|
||||
// Update the key so that the expiration is pushed forward
|
||||
if (!skipExpire) {
|
||||
this.set(key, data, (updateSucceeded) => {
|
||||
if (!updateSucceeded) {
|
||||
winston.error('failed to update expiration on GET', {key});
|
||||
}
|
||||
}, skipExpire);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = MemcachedDocumentStore;
|
||||
|
|
|
@ -20,7 +20,7 @@ RethinkDBStore.md5 = (str) => {
|
|||
|
||||
RethinkDBStore.prototype.set = (key, data, callback) => {
|
||||
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);
|
||||
callback(true);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue