mirror of
https://github.com/JustKato/FreePad.git
synced 2026-02-23 15:50:46 +02:00
+ Maximum pad length
+ Configurable maximum pad length + Refresh pad + Archive pad + Archives in local client storage + Download pad
This commit is contained in:
@@ -16,6 +16,28 @@ func GetDomainBase() string {
|
||||
return domainBase
|
||||
}
|
||||
|
||||
func GetMaximumPadSize() int {
|
||||
// Lookup if the maximum pad size variable exists.
|
||||
maxPadSize, exists := os.LookupEnv("MAXIMUM_PAD_SIZE")
|
||||
|
||||
// Check if this environment variable has bee nset
|
||||
if !exists {
|
||||
// Set the variable ourselves to the default string value
|
||||
maxPadSize = "524288"
|
||||
}
|
||||
|
||||
// Try and convert the string into an integer
|
||||
rez, err := strconv.Atoi(maxPadSize)
|
||||
// Check if the conversion has failed
|
||||
if err != nil {
|
||||
// Simply return the default
|
||||
return 524288
|
||||
}
|
||||
|
||||
// Return the resulting value
|
||||
return rez
|
||||
}
|
||||
|
||||
func GetCacheMapLimit() int {
|
||||
cacheMapLimit, domainExists := os.LookupEnv("CACHE_MAP_LIMIT")
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package objects
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/JustKato/FreePad/lib/helper"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
@@ -73,6 +76,11 @@ func GetPost(fileName string) Post {
|
||||
|
||||
func WritePost(p Post) error {
|
||||
|
||||
maximumPadSize := helper.GetMaximumPadSize()
|
||||
if len(p.Content) > maximumPadSize {
|
||||
return errors.New("The pad is too big, please limit to the maximum of " + fmt.Sprint(maximumPadSize) + " characters")
|
||||
}
|
||||
|
||||
// Get the base storage directory and make sure it exists
|
||||
storageDir := getStorageDirectory()
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ func HomeRoutes(router *gin.Engine) {
|
||||
// Get the post we are looking for.
|
||||
postName := c.Param("post")
|
||||
|
||||
// Get the maximum pad size, so that we may notify the client-side to match server-side
|
||||
maximumPadSize := helper.GetMaximumPadSize()
|
||||
|
||||
// Sanitize the postName
|
||||
newPostName, err := url.QueryUnescape(postName)
|
||||
if err == nil {
|
||||
@@ -33,10 +36,11 @@ func HomeRoutes(router *gin.Engine) {
|
||||
post := objects.GetPost(postName)
|
||||
|
||||
c.HTML(200, "page.html", gin.H{
|
||||
"title": postName,
|
||||
"post_content": post.Content,
|
||||
"last_modified": post.LastModified,
|
||||
"domain_base": helper.GetDomainBase(),
|
||||
"title": postName,
|
||||
"post_content": post.Content,
|
||||
"maximumPadSize": maximumPadSize,
|
||||
"last_modified": post.LastModified,
|
||||
"domain_base": helper.GetDomainBase(),
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user