Skip to content

Commit

Permalink
Update posting.go description to reflect changes, add version.go
Browse files Browse the repository at this point in the history
The GochanVersion struct will be used to compare versions, especially for updating
  • Loading branch information
user.email committed Nov 22, 2018
1 parent a865840 commit 6ecfc8e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/building.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// functions for post, thread, board, and page building

package main

import (
Expand Down
18 changes: 9 additions & 9 deletions src/posting.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// functions for handling posting, uploading, and post/thread/board page building
// functions for handling posting, uploading, and bans

package main

Expand Down Expand Up @@ -401,7 +401,7 @@ func makePost(writer http.ResponseWriter, request *http.Request) {
thumbPath := path.Join(config.DocumentRoot, "/"+boardDir+"/thumb/", strings.Replace(post.Filename, "."+filetype, "t."+thumbFiletype, -1))
catalogThumbPath := path.Join(config.DocumentRoot, "/"+boardDir+"/thumb/", strings.Replace(post.Filename, "."+filetype, "c."+thumbFiletype, -1))

if err := ioutil.WriteFile(filePath, data, 0777); err != nil {
if err = ioutil.WriteFile(filePath, data, 0777); err != nil {
handleError(0, "Couldn't write file \""+post.Filename+"\""+err.Error())
serveErrorPage(writer, "Couldn't write file \""+post.FilenameOriginal+"\"")
return
Expand Down Expand Up @@ -451,7 +451,7 @@ func makePost(writer http.ResponseWriter, request *http.Request) {
serveErrorPage(writer, handleError(1, "Error getting video info: "+err.Error()))
return
}
if err == nil && outputBytes != nil {
if outputBytes != nil {
outputStringArr := strings.Split(string(outputBytes), "\n")
for _, line := range outputStringArr {
lineArr := strings.Split(line, "=")
Expand Down Expand Up @@ -574,16 +574,16 @@ func makePost(writer http.ResponseWriter, request *http.Request) {
boards, _ := getBoardArr(nil, "")

if isBanned(banStatus, boards[post.BoardID-1].Dir) {
var banpage_buffer bytes.Buffer
var banpage_html string
banpage_buffer.Write([]byte(""))
if err = banpage_tmpl.Execute(&banpage_buffer, map[string]interface{}{
var banpageBuffer bytes.Buffer

banpageBuffer.Write([]byte(""))
if err = banpage_tmpl.Execute(&banpageBuffer, map[string]interface{}{
"config": config, "ban": banStatus, "banBoards": boards[post.BoardID-1].Dir,
}); err != nil {
fmt.Fprintf(writer, banpage_html+handleError(1, err.Error())+"\n</body>\n</html>")
fmt.Fprintf(writer, handleError(1, err.Error()))
return
}
fmt.Fprintf(writer, banpage_buffer.String())
fmt.Fprintf(writer, banpageBuffer.String())
return
}

Expand Down
55 changes: 55 additions & 0 deletions src/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"fmt"
)

type GochanVersion struct {
Major uint
Minor uint
Revision uint
Extra string
}

func ParseVersion(vStr string) GochanVersion {
var v GochanVersion
fmt.Sscanf(vStr, "%d.%d.%d-%s", &v.Major, &v.Minor, &v.Revision, &v.Extra)
return v
}

func (v *GochanVersion) Compare(v2 GochanVersion) int {
if v.Major > v2.Major {
return 1
}
if v.Major < v2.Major {
return -1
}
if v.Minor > v2.Minor {
return 1
}
if v.Minor < v2.Minor {
return -1
}
if v.Revision > v2.Revision {
return 1
}
if v.Revision < v2.Revision {
return -1
}
return 0
}

func (v *GochanVersion) CompareString(v2 string) int {
return v.Compare(ParseVersion(v2))
}

func (v *GochanVersion) String() string {
str := fmt.Sprintf("%d.%d", v.Major, v.Minor)
if v.Revision > 0 {
str += fmt.Sprintf(".%d", v.Revision)
}
if v.Extra != "" {
str += "-" + v.Extra
}
return str
}

0 comments on commit 6ecfc8e

Please sign in to comment.