...
 
Commits (2)
# Copyright (c) 2017-2018 Tokumei authors.
# This software package is licensed for use under the ISC license.
# See LICENSE for details.
#
# Tokumei is a simple, self-hosted microblogging platform.
# This Makefile simplifies the build and installation process for the software.
BIN = tokumei
.PHONY: all frontend clean test
# build Tokumei and get the front-end dependencies
all: frontend
go build -i -o $(BIN) ./cmd
# install front end dependancies
frontend:
./install.sh
# remove the compiled binary
clean:
rm $(BIN)
# test code coverage of each package in Tokumei
# TODO: add more tests
test:
go test -cover ./mimetype
......@@ -26,7 +26,8 @@ func removePost(id int64) error {
} else if p == nil {
return posts.ErrPostNotFound
}
p.GetNumReports()
fmt.Printf("Found post: %s\n", p.String())
var yn string
fmt.Print("Are you sure you want to remove post? [y/N] ")
......
......@@ -4,18 +4,24 @@
*
* Tokumei is a simple, self-hosted microblogging platform. */
// Package globals constains cross-package constants. It exists as a glue
// between Tokumei packages
package globals
import "path/filepath"
const (
VERSION string = "2.0"
PUBLIC string = "public"
)
// VERSION is the semantic version number of this release of Tokumei
const VERSION string = "2.0.0-dev"
/* constant-ish */
var (
/* constant-ish */
TMPLDIR string = filepath.FromSlash(PUBLIC + "/html") // location of all templates
POSTDIR string = filepath.FromSlash(PUBLIC + "/files") // location of all post media
POSTDB string = "posts.db" // sqlite3 database
// PUBLIC is the location of non-private files for the server.
PUBLIC string = "public"
// TMPLDIR is the location of all templates.
TMPLDIR string = filepath.FromSlash(PUBLIC + "/html")
// POSTDIR is the location of all post media. This directory is subdivided
// into directories by post number.
POSTDIR string = filepath.FromSlash(PUBLIC + "/files")
// POSTDB is the location of the sqlite3 database.
POSTDB string = "posts.db"
)
......@@ -61,9 +61,15 @@ type FileType struct {
}
var (
ErrBadFile = errors.New("mime: file is malformed")
// ErrBadFile is returned if a file does not exist or is otherwise an
// unexpected format for reading.
ErrBadFile = errors.New("mime: file is malformed")
// ErrUnsupportedFile is returned if a file's mimetype cannot be determined
// by any other means than by checking its extension.
ErrUnsupportedFile = errors.New("mime: file type is not supported")
ErrBadExt = errors.New("mime: file has a mismatched extension")
// ErrBadExt is returned if a file's extension does not match that of its
// determined mimetype.
ErrBadExt = errors.New("mime: file has a mismatched extension")
)
// Returns a FileType descriptor for the file located at the supplied path.
......@@ -74,8 +80,6 @@ var (
// erroneous to write PDF data to a web application but supply this file with a
// .txt extension; since this is misleading to users, it is an error.
func GetFileType(path string) (*FileType, error) {
fmt.Println(path)
fmt.Println("here!!")
// verify the file exists and is not a directory
if f, err := os.Stat(path); os.IsNotExist(err) || f.IsDir() {
return nil, ErrBadFile
......
......@@ -164,7 +164,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
/* helper functions for dynamic pages */
// makePostFromReq() mkaes a new post from the form data found in the supplied
// makePostFromReq() makes a new post from the form data found in the supplied
// http request.
func makePostFromReq(r *http.Request) (*posts.Post, error) {
// save all multipart form data to disk
......@@ -192,7 +192,7 @@ func makePostFromReq(r *http.Request) (*posts.Post, error) {
log.Println("post rejected because message has invalid number of attachments")
return nil, errUnprocessableEntity
}
// TODO(krourke/kfarwell) discard original file names; strip metadata
// TODO(krourke/kfarwell) strip metadata from files:
// this is particularly challenging and may require we write a new package
for _, fh := range fhdrs {
fmt.Println(fh.Filename)
......@@ -216,6 +216,8 @@ func makePostFromReq(r *http.Request) (*posts.Post, error) {
attachedFile.Close()
// check file is allowed mimetype and reject unverified files
// possible future feature: allow server conf to specify filetype
// verification
if ftyp, err := mimetype.GetFileType(f.Name()); err != nil {
log.Printf("rejected file %s because file type could not be determined\n", filename)
log.Println(err)
......