Private pastes, systemd unit file, design updates.

It is now possible to create private pastes, just check approriate
checkbox.

Added systemd unit file. Don't forget to fix it for your needs!

Updated design for pastes viewing, now paste information shows in
table. Improves mobile experience at least :).
master
Stanislav Nikitin 4 years ago
parent 64c2d62a49
commit c926a58276
  1. 2
      README.md
  2. 4
      api/http/static/ab0x.go
  3. 6
      api/http/static/b0xfile__index.html.go
  4. 6
      api/http/static/b0xfile__paste.html.go
  5. 35
      api/http/static/b0xfile_static_css_bulma-tooltip-1.0.4.min.css.go
  6. 1
      assets/css/bulma-tooltip-1.0.4.min.css
  7. 6
      assets/index.html
  8. 35
      assets/paste.html
  9. 48
      database/migrations/3_private_pastes.go
  10. 1
      database/migrations/exported.go
  11. 1
      fileb0x.yml
  12. 37
      pastes/api_http.go
  13. 9
      pastes/exported.go
  14. 3
      pastes/model.go
  15. 4
      pastes/queries.go
  16. 11
      systemd/fastpastebin.service

@ -48,7 +48,7 @@ fileb0x fileb0x.yml
```
Also if you're changed list of assets (by creating or deleting them) be sure
to fix files list if ``fileb0x.yml`` file!
to fix files list in ``fileb0x.yml`` file!
The rest is default - use linters, formatters, etc. VSCode with Go plugin is
recommended for developing as it will perform most of linting-formatting

@ -1,5 +1,5 @@
// Code generated by fileb0x at "2018-05-01 18:42:52.800269995 +0500 +05 m=+0.035406927" from config file "fileb0x.yml" DO NOT EDIT.
// modification hash(b2d7b5e4ee752835a7e3a3ee5b9ac079.5c3b355fe5a9e5324e826569a62de332)
// Code generated by fileb0x at "2018-05-01 22:56:15.114143898 +0500 +05 m=+0.020887887" from config file "fileb0x.yml" DO NOT EDIT.
// modification hash(c89aff9b6b6a650f49dd49d615e3d3e0.e30269e2254cb92c4231bb47f2cedf3a)
package static

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fast Paste Bin</title>
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
<link rel="stylesheet" href="/static/css/bulma-tooltip-1.0.4.min.css">
<script defer src="/static/js/fontawesome-5.0.7.js"></script>
<link rel="stylesheet" href="/static/css/style.css">
</head>
@ -72,6 +73,11 @@
</div>
</div>
</div>
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="Should this paste be accessible only with special URL and not shown in pastes list?">
<label class="checkbox">
<input type="checkbox" name="paste-private" id="paste-private"> Private paste with unique URL?
</label>
</div>
<div class="field">
<label for="paste-language">Language:</label>
<div class="control">

@ -32,16 +32,31 @@
</div>
</div>
</nav>
<section class="section paste-header">
<div class="columns content">
<div class="column is-10">
<h2>#{pasteID}, titled '{pasteTitle}'</h2>
<p>Pasted on
<strong>{pasteDate}</strong>, language: {pasteLanguage}</p>
</div>
<div class="column is-2">
<a class="button" href="/paste/{pasteID}/raw">View raw</a>
</div>
<section class="section">
<div class="content">
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Language</th>
<th>Pasted on</th>
</tr>
</thead>
<tbody>
<tr>
<td>{pasteID}</td>
<td>{pasteTitle}</td>
<td>{pasteLanguage}</td>
<td>{pasteDate}</td>
</tr>
<tr>
<td colspan="4">
<a class="button" href="/paste/{pasteID}/raw">View raw</a>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<div class="paste-data">

@ -0,0 +1,48 @@
// Fast Paste Bin - uberfast and easy-to-use pastebin.
//
// Copyright (c) 2018, Stanislav N. aka pztrn and Fast Paste Bin
// developers.
//
// 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.
package migrations
import (
// stdlib
"database/sql"
)
func PrivatePastesUp(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` ADD `private` BOOL NOT NULL DEFAULT false COMMENT 'Private paste? If true - additional URL parameter (UNIX TIMESTAMP) of paste will be required to access.'")
if err != nil {
return err
}
return nil
}
func PrivatePastesDown(tx *sql.Tx) error {
_, err := tx.Exec("ALTER TABLE `pastes` DROP COLUMN `private`")
if err != nil {
return err
}
return nil
}

@ -49,6 +49,7 @@ func Migrate() {
goose.SetDialect("mysql")
goose.AddNamedMigration("1_initial.go", InitialUp, nil)
goose.AddNamedMigration("2_paste_lang.go", PasteLangUp, PasteLangDown)
goose.AddNamedMigration("3_private_pastes.go", PrivatePastesUp, PrivatePastesDown)
// Add new migrations BEFORE this message.
dbConn := c.Database.GetDatabaseConnection()

@ -80,6 +80,7 @@ custom:
# type: array of strings
- files:
- "assets/css/bulma-0.7.0.min.css"
- "assets/css/bulma-tooltip-1.0.4.min.css"
- "assets/css/bulma.css.map"
- "assets/css/style.css"
- "assets/js/fontawesome-5.0.7.js"

@ -53,7 +53,7 @@ var (
regexInts = regexp.MustCompile("[0-9]+")
)
// GET for "/paste/PASTE_ID".
// GET for "/paste/PASTE_ID" and "/paste/PASTE_ID/TIMESTAMP" (private pastes).
func pasteGET(ec echo.Context) error {
errhtml, err := static.ReadFile("error.html")
if err != nil {
@ -74,6 +74,23 @@ func pasteGET(ec echo.Context) error {
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
}
// Check if we have a private paste and it's parameters are correct.
if paste.Private {
tsProvidedStr := ec.Param("timestamp")
tsProvided, err2 := strconv.ParseInt(tsProvidedStr, 10, 64)
if err2 != nil {
c.Logger.Error().Msgf("Invalid timestamp '%s' provided for getting private paste #%d: %s", tsProvidedStr, pasteID, err2.Error())
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
}
pasteTs := paste.CreatedAt.Unix()
if tsProvided != pasteTs {
c.Logger.Error().Msgf("Incorrect timestamp '%v' provided for private paste #%d, waiting for %v", tsProvidedStr, pasteID, strconv.FormatInt(pasteTs, 10))
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
}
}
pasteHTML, err2 := static.ReadFile("paste.html")
if err2 != nil {
return ec.String(http.StatusNotFound, "parse.html wasn't found!")
@ -85,6 +102,12 @@ func pasteGET(ec echo.Context) error {
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteDate}", paste.CreatedAt.Format("2006-01-02 @ 15:04:05"), 1)
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteLanguage}", paste.Language, 1)
if paste.Private {
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{privateMode}", "Private", 1)
} else {
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{privateMode}", "Public", 1)
}
// Highlight.
// Get lexer.
lexer := lexers.Get(paste.Language)
@ -193,6 +216,12 @@ func pastePOST(ec echo.Context) error {
}
}
// Private paste?
paste.Private = false
if params["paste-private"][0] == "on" {
paste.Private = true
}
id, err2 := Save(paste)
if err2 != nil {
c.Logger.Debug().Msgf("Failed to save paste: %s", err2.Error())
@ -202,6 +231,12 @@ func pastePOST(ec echo.Context) error {
newPasteIDAsString := strconv.FormatInt(id, 10)
c.Logger.Debug().Msgf("Paste saved, URL: /paste/" + newPasteIDAsString)
// Private pastes have it's timestamp in URL.
if paste.Private {
return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString+"/"+strconv.FormatInt(paste.CreatedAt.Unix(), 10))
}
return ec.Redirect(http.StatusFound, "/paste/"+newPasteIDAsString)
}

@ -41,11 +41,16 @@ func New(cc *context.Context) {
// New paste.
c.Echo.POST("/paste/", pastePOST)
// Show paste.
// Show public paste.
c.Echo.GET("/paste/:id", pasteGET)
// Show RAW.
// Show RAW representation of public paste.
c.Echo.GET("/paste/:id/raw", pasteRawGET)
// Show private paste.
c.Echo.GET("/paste/:id/:timestamp", pasteGET)
// Show RAW representation of private paste.
c.Echo.GET("/paste/:id/:timestamp/raw", pasteRawGET)
// Pastes list.
c.Echo.GET("/pastes/", pastesGET)
c.Echo.GET("/pastes/:page", pastesGET)

@ -56,6 +56,5 @@ type Paste struct {
KeepFor int `db:"keep_for"`
KeepForUnitType int `db:"keep_for_unit_type"`
Language string `db:"language"`
Private bool `db:"private"`
}
func (p *Paste) Highlight() {}

@ -52,7 +52,7 @@ func GetPagedPastes(page int) ([]Paste, error) {
startPagination = (page - 1) * PAGINATION
}
err := dbConn.Select(&pastes, dbConn.Rebind("SELECT * FROM `pastes` ORDER BY id DESC LIMIT ? OFFSET ?"), PAGINATION, startPagination)
err := dbConn.Select(&pastes, dbConn.Rebind("SELECT * FROM `pastes` WHERE private != true ORDER BY id DESC LIMIT ? OFFSET ?"), PAGINATION, startPagination)
if err != nil {
return nil, err
}
@ -84,7 +84,7 @@ func GetPastesPages() int {
// Save saves paste to database and returns it's ID.
func Save(p *Paste) (int64, error) {
dbConn := c.Database.GetDatabaseConnection()
result, err := dbConn.NamedExec("INSERT INTO `pastes` (title, data, created_at, keep_for, keep_for_unit_type, language) VALUES (:title, :data, :created_at, :keep_for, :keep_for_unit_type, :language)", p)
result, err := dbConn.NamedExec("INSERT INTO `pastes` (title, data, created_at, keep_for, keep_for_unit_type, language, private) VALUES (:title, :data, :created_at, :keep_for, :keep_for_unit_type, :language, :private)", p)
if err != nil {
return 0, err
}

@ -0,0 +1,11 @@
[Unit]
Description=fastpastebin
After=network.target
[Service]
ExecStart=/usr/bin/fastpastebin -config /etc/fastpastebin.yaml
User=paste
Group=paste
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save