Skip to content

Commit

Permalink
Merge pull request #3 from SparkedHost/redesign
Browse files Browse the repository at this point in the history
✨ Redesign ✨
  • Loading branch information
BetTD authored Sep 17, 2021
2 parents f9a34eb + 92198c6 commit 2694c7d
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 201 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright © 2011-2012 John Crepezzi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the ‘Software’), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
58 changes: 15 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Haste
# Sparked Paste

Haste is an open-source pastebin software written in node.js, which is easily
installable in any network. It can be backed by either redis or filesystem,
and has a very easy adapter interface for other stores. A publicly available
version can be found at [hastebin.com](http://hastebin.com)
Sparked Paste is a fork of the open-source project haste-server, modified to
match the Sparked Host brand and with a couple different patches and improvements.

Major design objectives:

Expand All @@ -20,22 +18,19 @@ to do things like:
which will output a URL to share containing the contents of `cat something`'s
STDOUT. Check the README there for more details and usages.

## Tested Browsers

* Firefox 8
* Chrome 17
* Safari 5.3

## Installation

1. Download the package, and expand it
2. Explore the settings inside of config.json, but the defaults should be good
3. `npm install`
4. `npm start` (you may specify an optional `<config-path>` as well)
1. Clone the repository: `git clone https://github.com/SparkedHost/Sparked-Paste`
2. Explore the settings inside of config.js, but the defaults should be good.
3. Run `npm install` to install all the required npm packages.
4. Create the `hastes` directory: `mkdir hastes`
5. `npm start` (you may specify an optional `<config-path>` as well)

Read the wiki for a more in-depth installation guide.

## Settings

* `host` - the host the server runs on (default localhost)
* `host` - the host the server runs on (default 127.0.0.1)
* `port` - the port the server runs on (default 7777)
* `keyLength` - the length of the keys to user (default 10)
* `maxLength` - maximum length of a paste (default 400000)
Expand All @@ -52,7 +47,7 @@ STDOUT. Check the README there for more details and usages.

When present, the `rateLimits` option enables built-in rate limiting courtesy
of `connect-ratelimit`. Any of the options supported by that library can be
used and set in `config.json`.
used and set in `config.js`.

See the README for [connect-ratelimit](https://github.com/dharmafly/connect-ratelimit)
for more information!
Expand Down Expand Up @@ -87,12 +82,12 @@ for the key.

### File

To use file storage (the default) change the storage section in `config.json` to
To use file storage (the default) change the storage section in `config.js` to
something like:

``` json
{
"path": "./data",
"path": "./hastes",
"type": "file"
}
```
Expand Down Expand Up @@ -357,30 +352,7 @@ Here is a list of all the environment variables
## Author

John Crepezzi <[email protected]>

## License

(The MIT License)

Copyright © 2011-2012 John Crepezzi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the ‘Software’), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
Raúl Molina <[email protected]>

### Other components:

Expand Down
2 changes: 1 addition & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

"documents": {
"about": "./about.md",
"howtouse": "howtouse.md"
"howtouse": "./howtouse.md"
}

}
15 changes: 8 additions & 7 deletions howtouse.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# How to use the Sparked Paste service
# Getting Started with [Sparked Paste](https://paste.sparked.host)

1. First navigate to the main page @ https://paste.sparked.host
## What is Sparked Paste?

2. You will be greeted by a dark gray page where you can type text.
Sparked Paste is a service, originally made by [toptal](https://github.com/toptal/haste-server), but has been forked by the [Sparked Host LLC DevOps Team](https://sparkedhost.com/about-us) to include a better looking theme and more features. This website provides the ability for clients to send server logs and configuration files easily with our Support Team and our Community.

3. Paste code, text, log snippets, etc. on that page
## How do I use Sparked Paste?

4. Once you're done, you will see a save button on the top right corner of the page, click on that to save it, or use Control + S.

5. The URL on your browser will update, and syntax highlighting will be applied to your paste. Copy that new URL and send it wherever you want.
1) First, navigate to the main page [here](https://paste.sparked.host).
2) You will be greeted by a dark gray page where you can type (or paste) text, code, or configurations.
3) Once you're done, you will see a save button on the top right corner of the page, click on that to save it, or use Control + S.
4) The URL on your browser will update, and syntax highlighting will be applied to your paste. Copy that new URL and send it wherever you want.
111 changes: 62 additions & 49 deletions lib/document_handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var winston = require('winston');
var Busboy = require('busboy');
const winston = require('winston');
const Busboy = require('busboy');

// For handling serving stored documents

Expand All @@ -21,23 +21,25 @@ DocumentHandler.prototype.handleGet = function(request, response, config) {
const skipExpire = !!config.documents[key];

this.store.get(key, function(ret) {
let responseCode;
let responseBody;

if (ret) {
winston.verbose('retrieved document', { key: key });
response.writeHead(200, { 'content-type': 'application/json' });
if (request.method === 'HEAD') {
response.end();
} else {
response.end(JSON.stringify({ data: ret, key: key }));
}
winston.verbose('Successfully retrieved document:', { client: request.remoteAddress, key: key });
responseCode = 200;
responseBody = JSON.stringify({ data: ret, key: key });
} else {
winston.warn('Document not found:', { client: request.remoteAddress, key: key });
responseCode = 404;
responseBody = JSON.stringify({ message: 'Document not found.' });
}
else {
winston.warn('document not found', { key: key });
response.writeHead(404, { 'content-type': 'application/json' });
if (request.method === 'HEAD') {
response.end();
} else {
response.end(JSON.stringify({ message: 'Document not found.' }));
}

response.writeHead(responseCode, { 'content-type': 'application/json' });

if (request.method === 'HEAD') {
response.end();
} else {
response.end(responseBody);
}
}, skipExpire);
};
Expand All @@ -48,66 +50,77 @@ DocumentHandler.prototype.handleRawGet = function(request, response, config) {
const skipExpire = !!config.documents[key];

this.store.get(key, function(ret) {
// Having responseCode here is pointless as the content-type header changes between conditions too
let responseBody;

if (ret) {
winston.verbose('retrieved raw document', { key: key });
winston.verbose('Successfully retrieved raw document:', { key: key });
responseBody = ret;
response.writeHead(200, { 'content-type': 'text/plain; charset=UTF-8' });
if (request.method === 'HEAD') {
response.end();
} else {
response.end(ret);
}
}
else {
winston.warn('raw document not found', { key: key });
} else {
winston.warn('Raw document not found:', { key: key });
responseBody = JSON.stringify({ message: 'Document not found.' });
response.writeHead(404, { 'content-type': 'application/json' });
if (request.method === 'HEAD') {
response.end();
} else {
response.end(JSON.stringify({ message: 'Document not found.' }));
}
}

if (request.method === 'HEAD') {
response.end();
} else {
response.end(responseBody);
}
}, skipExpire);
};

// Handle adding a new Document
DocumentHandler.prototype.handlePost = function (request, response) {
var _this = this;
var buffer = '';
var cancelled = false;
const _this = this;
let buffer = '';
let cancelled = false;

// What to do when done
var onSuccess = function () {
let onSuccess = function () {
// Check length

/* Patch from https://github.com/zneix/haste-server/commit/04e1f09fedbaa9a83a6d747f033467e1f42f4d53
* "It is no longer possible to make a POST request with no body content and make a "ghost key" - which upon requesting returns 404, but it considered as a taken key"
* Credit: zneix
*/
if (!buffer.length){
cancelled = true;
winston.warn('document with no length was POSTed');
res.status(411).json({ message: 'Length required.' });
return;
}

if (_this.maxLength && buffer.length > _this.maxLength) {
cancelled = true;
winston.warn('document >maxLength', { maxLength: _this.maxLength });
response.writeHead(400, { 'content-type': 'application/json' });
winston.warn('document >maxLength', {maxLength: _this.maxLength});
response.writeHead(400, {'content-type': 'application/json'});
response.end(
JSON.stringify({ message: 'Document exceeds maximum length.' })
JSON.stringify({message: 'Document exceeds maximum length.'})
);
return;
}
// And then save if we should
_this.chooseKey(function (key) {
_this.store.set(key, buffer, function (res) {
if (res) {
winston.verbose('added document', { key: key });
response.writeHead(200, { 'content-type': 'application/json' });
response.end(JSON.stringify({ key: key }));
}
else {
winston.verbose('added document', {key: key});
response.writeHead(200, {'content-type': 'application/json'});
response.end(JSON.stringify({key: key}));
} else {
winston.verbose('error adding document');
response.writeHead(500, { 'content-type': 'application/json' });
response.end(JSON.stringify({ message: 'Error adding document.' }));
response.writeHead(500, {'content-type': 'application/json'});
response.end(JSON.stringify({message: 'Error adding document.'}));
}
});
});
};

// If we should, parse a form to grab the data
var ct = request.headers['content-type'];
const ct = request.headers['content-type'];
if (ct && ct.split(';')[0] === 'multipart/form-data') {
var busboy = new Busboy({ headers: request.headers });
const busboy = new Busboy({headers: request.headers});
busboy.on('field', function (fieldname, val) {
if (fieldname === 'data') {
buffer = val;
Expand Down Expand Up @@ -137,8 +150,8 @@ DocumentHandler.prototype.handlePost = function (request, response) {

// Keep choosing keys until one isn't taken
DocumentHandler.prototype.chooseKey = function(callback) {
var key = this.acceptableKey();
var _this = this;
const key = this.acceptableKey();
const _this = this;
this.store.get(key, function(ret) {
if (ret) {
_this.chooseKey(callback);
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "haste",
"version": "0.1.0",
"name": "Sparked-Paste",
"version": "1.0.0",
"private": true,
"description": "Private Pastebin Server",
"description": "Fork of haste-server",
"keywords": [
"paste",
"pastebin"
],
"author": {
"name": "John Crepezzi",
"email": "john.crepezzi@gmail.com",
"url": "http://seejohncode.com/"
"name": "Raúl Molina",
"email": "raul.m@sparkedhost.com",
"url": "https://bettd.me/"
},
"main": "haste",
"dependencies": {
Expand Down
Loading

0 comments on commit 2694c7d

Please sign in to comment.