initial AText
This commit is contained in:
parent
308182cdb3
commit
a8702b617f
|
@ -82,6 +82,9 @@ var AllowedFileExts = StringList{
|
|||
var ImageFileExts = StringList{
|
||||
"png", "jpg", "jpe", "jpeg", "jif", "jfi", "jfif", "svg", "bmp", "gif", "tiff", "tif", "webp", /* "apng", "bpg", */
|
||||
}
|
||||
var TextFileExts = StringList{
|
||||
"txt", "xml", "json", "yaml", "toml", "ini", "md", "html", "rtf", "js", "py", "rb", "css", "scss", "less", "eqcss", "pcss", "java", "ts", "cs", "c", "cc", "cpp", "cxx", "C", "c++", "h", "hh", "hpp", "hxx", "h++", "rs", "rlib", "htaccess", "gitignore", /*"go","php",*/
|
||||
}
|
||||
var VideoFileExts = StringList{
|
||||
"mp4", "avi", "ogg", "ogv", "ogx", "wmv", "webm",
|
||||
}
|
||||
|
|
|
@ -44,6 +44,9 @@ var attachOpen = []byte("<a class='attach'href=\"")
|
|||
var attachClose = []byte("\"download>Attachment</a>")
|
||||
var sidParam = []byte("?sid=")
|
||||
var stypeParam = []byte("&stype=")
|
||||
var textOpen = []byte("<a class='attach'href=\"")
|
||||
var textOpen2 = []byte("\">View</a> / <a class='attach'href=\"")
|
||||
var textClose = []byte("\"download>Download</a>")
|
||||
var urlPattern = `(?s)([ {1}])((http|https|ftp|mailto)*)(:{??)\/\/([\.a-zA-Z\/]+)([ {1}])`
|
||||
var urlReg *regexp.Regexp
|
||||
|
||||
|
@ -713,6 +716,24 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse
|
|||
case EImage:
|
||||
addImage(media.URL)
|
||||
continue
|
||||
case AText:
|
||||
sb.Write(textOpen)
|
||||
sb.WriteString(media.URL)
|
||||
sb.Write(sidParam)
|
||||
sid := strconv.Itoa(sectionID)
|
||||
sb.WriteString(sid)
|
||||
sb.Write(stypeParam)
|
||||
sb.WriteString(sectionType)
|
||||
sb.Write(textOpen2)
|
||||
sb.WriteString(media.URL)
|
||||
sb.Write(sidParam)
|
||||
sb.WriteString(sid)
|
||||
sb.Write(stypeParam)
|
||||
sb.WriteString(sectionType)
|
||||
sb.Write(textClose)
|
||||
i += urlLen
|
||||
lastItem = i
|
||||
continue
|
||||
case AOther:
|
||||
sb.Write(attachOpen)
|
||||
sb.WriteString(media.URL)
|
||||
|
@ -951,6 +972,7 @@ const (
|
|||
AImage
|
||||
AVideo
|
||||
AAudio
|
||||
AText
|
||||
AOther
|
||||
)
|
||||
|
||||
|
@ -1011,6 +1033,8 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
|
|||
media.Type = AVideo
|
||||
case WebAudioFileExts.Contains(ext):
|
||||
media.Type = AAudio
|
||||
case TextFileExts.Contains(ext):
|
||||
media.Type = AText
|
||||
default:
|
||||
media.Type = AOther
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"github.com/Azareal/Gosora/common/phrases"
|
||||
)
|
||||
|
||||
func IPSearch(w http.ResponseWriter, r *http.Request, user *c.User, h *c.Header) c.RouteError {
|
||||
func IPSearch(w http.ResponseWriter, r *http.Request, u *c.User, h *c.Header) c.RouteError {
|
||||
h.Title = phrases.GetTitlePhrase("ip_search")
|
||||
// TODO: How should we handle the permissions if we extend this into an alt detector of sorts?
|
||||
if !user.Perms.ViewIPs {
|
||||
return c.NoPermissions(w, r, user)
|
||||
if !u.Perms.ViewIPs {
|
||||
return c.NoPermissions(w, r, u)
|
||||
}
|
||||
|
||||
// TODO: Reject IP Addresses with illegal characters
|
||||
|
|
|
@ -10,13 +10,13 @@ import (
|
|||
c "github.com/Azareal/Gosora/common"
|
||||
)
|
||||
|
||||
func WordFilters(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
basePage, ferr := buildBasePage(w, r, user, "word_filters", "word-filters")
|
||||
func WordFilters(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||
basePage, ferr := buildBasePage(w, r, u, "word_filters", "word-filters")
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
if !user.Perms.EditSettings {
|
||||
return c.NoPermissions(w, r, user)
|
||||
if !u.Perms.EditSettings {
|
||||
return c.NoPermissions(w, r, u)
|
||||
}
|
||||
|
||||
// TODO: What if this list gets too long?
|
||||
|
@ -29,20 +29,20 @@ func WordFilters(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteEr
|
|||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_word_filters", &pi})
|
||||
}
|
||||
|
||||
func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user *c.User) c.RouteError {
|
||||
_, ferr := c.SimplePanelUserCheck(w, r, user)
|
||||
func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, u *c.User) c.RouteError {
|
||||
_, ferr := c.SimplePanelUserCheck(w, r, u)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
if !user.Perms.EditSettings {
|
||||
return c.NoPermissions(w, r, user)
|
||||
if !u.Perms.EditSettings {
|
||||
return c.NoPermissions(w, r, u)
|
||||
}
|
||||
js := r.PostFormValue("js") == "1"
|
||||
|
||||
// ? - We're not doing a full sanitise here, as it would be useful if admins were able to put down rules for replacing things with HTML, etc.
|
||||
find := strings.TrimSpace(r.PostFormValue("find"))
|
||||
if find == "" {
|
||||
return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, user, js)
|
||||
return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, u, js)
|
||||
}
|
||||
|
||||
// Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement
|
||||
|
@ -52,7 +52,7 @@ func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user *c.Use
|
|||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
err = c.AdminLogs.Create("create", wfid, "word_filter", user.GetIP(), user.ID)
|
||||
err = c.AdminLogs.Create("create", wfid, "word_filter", u.GetIP(), u.ID)
|
||||
if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
}
|
||||
|
@ -61,13 +61,13 @@ func WordFiltersCreateSubmit(w http.ResponseWriter, r *http.Request, user *c.Use
|
|||
}
|
||||
|
||||
// TODO: Implement this as a non-JS fallback
|
||||
func WordFiltersEdit(w http.ResponseWriter, r *http.Request, user *c.User, wfid string) c.RouteError {
|
||||
basePage, ferr := buildBasePage(w, r, user, "edit_word_filter", "word-filters")
|
||||
func WordFiltersEdit(w http.ResponseWriter, r *http.Request, u *c.User, wfid string) c.RouteError {
|
||||
basePage, ferr := buildBasePage(w, r, u, "edit_word_filter", "word-filters")
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
if !user.Perms.EditSettings {
|
||||
return c.NoPermissions(w, r, user)
|
||||
if !u.Perms.EditSettings {
|
||||
return c.NoPermissions(w, r, u)
|
||||
}
|
||||
_ = wfid
|
||||
|
||||
|
@ -75,30 +75,30 @@ func WordFiltersEdit(w http.ResponseWriter, r *http.Request, user *c.User, wfid
|
|||
return renderTemplate("panel", w, r, basePage.Header, c.Panel{basePage, "", "", "panel_word_filters_edit", &pi})
|
||||
}
|
||||
|
||||
func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User, swfid string) c.RouteError {
|
||||
_, ferr := c.SimplePanelUserCheck(w, r, user)
|
||||
func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, u *c.User, swfid string) c.RouteError {
|
||||
_, ferr := c.SimplePanelUserCheck(w, r, u)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
js := r.PostFormValue("js") == "1"
|
||||
if !user.Perms.EditSettings {
|
||||
return c.NoPermissionsJSQ(w, r, user, js)
|
||||
if !u.Perms.EditSettings {
|
||||
return c.NoPermissionsJSQ(w, r, u, js)
|
||||
}
|
||||
|
||||
wfid, err := strconv.Atoi(swfid)
|
||||
if err != nil {
|
||||
return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, user, js)
|
||||
return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, u, js)
|
||||
}
|
||||
find := strings.TrimSpace(r.PostFormValue("find"))
|
||||
if find == "" {
|
||||
return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, user, js)
|
||||
return c.LocalErrorJSQ("You need to specify what word you want to match", w, r, u, js)
|
||||
}
|
||||
// Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement
|
||||
replace := strings.TrimSpace(r.PostFormValue("replace"))
|
||||
|
||||
wf, err := c.WordFilters.Get(wfid)
|
||||
if err == sql.ErrNoRows {
|
||||
return c.LocalErrorJSQ("This word filter doesn't exist.", w, r, user, js)
|
||||
return c.LocalErrorJSQ("This word filter doesn't exist.", w, r, u, js)
|
||||
} else if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User,
|
|||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
err = c.AdminLogs.CreateExtra("edit", wfid, "word_filter", user.GetIP(), user.ID, string(lBytes))
|
||||
err = c.AdminLogs.CreateExtra("edit", wfid, "word_filter", u.GetIP(), u.ID, string(lBytes))
|
||||
if err != nil {
|
||||
return c.InternalErrorJSQ(err, w, r, js)
|
||||
}
|
||||
|
@ -120,25 +120,25 @@ func WordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, user *c.User,
|
|||
return nil
|
||||
}
|
||||
|
||||
func WordFiltersDeleteSubmit(w http.ResponseWriter, r *http.Request, user *c.User, swfid string) c.RouteError {
|
||||
_, ferr := c.SimplePanelUserCheck(w, r, user)
|
||||
func WordFiltersDeleteSubmit(w http.ResponseWriter, r *http.Request, u *c.User, swfid string) c.RouteError {
|
||||
_, ferr := c.SimplePanelUserCheck(w, r, u)
|
||||
if ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
js := r.PostFormValue("js") == "1"
|
||||
if !user.Perms.EditSettings {
|
||||
return c.NoPermissionsJSQ(w, r, user, js)
|
||||
if !u.Perms.EditSettings {
|
||||
return c.NoPermissionsJSQ(w, r, u, js)
|
||||
}
|
||||
|
||||
wfid, err := strconv.Atoi(swfid)
|
||||
if err != nil {
|
||||
return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, user, js)
|
||||
return c.LocalErrorJSQ("The word filter ID must be an integer.", w, r, u, js)
|
||||
}
|
||||
err = c.WordFilters.Delete(wfid)
|
||||
if err == sql.ErrNoRows {
|
||||
return c.LocalErrorJSQ("This word filter doesn't exist", w, r, user, js)
|
||||
return c.LocalErrorJSQ("This word filter doesn't exist", w, r, u, js)
|
||||
}
|
||||
err = c.AdminLogs.Create("delete", wfid, "word_filter", user.GetIP(), user.ID)
|
||||
err = c.AdminLogs.Create("delete", wfid, "word_filter", u.GetIP(), u.ID)
|
||||
if err != nil {
|
||||
return c.InternalError(err, w, r)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
{{template "header.html" . }}
|
||||
<main>
|
||||
|
||||
</main>
|
||||
<main></main>
|
||||
{{template "footer.html" . }}
|
Loading…
Reference in New Issue