path fixing

This commit is contained in:
Dominic Ferrando
2025-04-24 22:45:23 -04:00
parent 9cdee244f8
commit 53dc923119
3 changed files with 32 additions and 11 deletions
+4 -2
View File
@@ -22,8 +22,10 @@ import (
const FILE_MEM_LIMIT int64 = 10 << 20
const MAX_REQUEST_BYTES int64 = FILE_MEM_LIMIT + (1 << 20)
const POST_MEDIA_FULL_PATH = "web/static/media/posts/full"
const POST_MEDIA_THUMB_PATH = "web/static/media/posts/thumb"
var (
POST_MEDIA_FULL_PATH = "web/static/media/posts/full"
POST_MEDIA_THUMB_PATH = "web/static/media/posts/thumb"
)
const MAX_THREAD_COUNT = 50
+5
View File
@@ -12,6 +12,11 @@ import (
const DevMode = false
var (
STATIC_PATH = "web/static"
DATABASE_PATH = "internal/database/comfychan.db"
)
func FormatBytes(bytes int64) string {
const (
KB = 1 << 10 // 1024
+23 -9
View File
@@ -4,6 +4,16 @@ import (
"database/sql"
"errors"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/dominicf2001/comfychan/internal/database"
"github.com/dominicf2001/comfychan/internal/util"
"github.com/dominicf2001/comfychan/web/views"
@@ -12,14 +22,6 @@ import (
"github.com/go-chi/chi/v5/middleware"
_ "github.com/mattn/go-sqlite3"
"golang.org/x/crypto/bcrypt"
"io"
"log"
"mime/multipart"
"net/http"
"path/filepath"
"strconv"
"strings"
"time"
)
func AdminOnlyMiddleware(next http.Handler) http.Handler {
@@ -66,6 +68,18 @@ func main() {
// SETUP
// -----------------
// init paths
dataDir := os.Getenv("COMFYCHAN_DATA_DIR")
if dataDir == "" {
dataDir = "." // for development
}
util.POST_MEDIA_FULL_PATH = filepath.Join(dataDir, util.POST_MEDIA_FULL_PATH)
util.POST_MEDIA_THUMB_PATH = filepath.Join(dataDir, util.POST_MEDIA_FULL_PATH)
util.DATABASE_PATH = filepath.Join(dataDir, util.DATABASE_PATH)
util.STATIC_PATH = filepath.Join(dataDir, util.STATIC_PATH)
db, err := sql.Open("sqlite3", "internal/database/comfychan.db")
if err != nil {
log.Fatal(err)
@@ -79,7 +93,7 @@ func main() {
r.Handle("/static/*",
disableCacheInDevMode(
http.StripPrefix("/static",
http.FileServer(http.Dir("web/static")))))
http.FileServer(http.Dir(util.STATIC_PATH)))))
// -----------------