Merge pull request #8 from fossyy/staging

Staging
This commit is contained in:
2024-04-27 16:08:55 +07:00
committed by GitHub
29 changed files with 110 additions and 118 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
staging.bat
staging.sh
uploads
.idea
.env
tmp
log
/public/output.css

17
.env
View File

@ -1,17 +0,0 @@
SERVER_HOST=localhost
SERVER_PORT=8000
DOMAIN=filekeeper.fossy.my.id
CORS_PROTO=https
CORS_LIST=filekeeper.fossy.my.id:443,fossy.my.id:443
CORS_METHODS=POST,GET
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=test123
DB_NAME=filekeeper
SESSION_NAME=Session
SESSION_MAX_AGE=604800

3
.gitignore vendored
View File

@ -2,6 +2,9 @@
/uploads /uploads
/public/output.css /public/output.css
/log /log
/.idea
.env
*_templ.txt *_templ.txt
*_templ.go *_templ.go

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

9
.idea/filekeeper.iml generated
View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,10 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="GoDfaErrorMayBeNotNil" enabled="true" level="WARNING" enabled_by_default="true">
<methods>
<method importPath="github.com/fossyy/filekeeper/session" receiver="*StoreSession" name="Get" />
</methods>
</inspection_tool>
</profile>
</component>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/filekeeper.iml" filepath="$PROJECT_DIR$/.idea/filekeeper.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM node:current-alpine3.19 AS tailwind
WORKDIR /src
COPY ./public/input.css ./public/
COPY tailwind.config.js .
COPY ./view ./view
RUN npm install -g tailwindcss
RUN npx tailwindcss -i ./public/input.css -o ./public/output.css
FROM golang:1.22.2-alpine3.19 AS go_builder
WORKDIR /src
COPY . .
COPY --from=tailwind /src/public/output.css ./public/
RUN go install github.com/a-h/templ/cmd/templ@$(go list -m -f '{{ .Version }}' github.com/a-h/templ)
RUN templ generate
RUN go build -o ./tmp/main
FROM scratch
WORKDIR /src
COPY --from=go_builder /src /src
ENTRYPOINT ["./tmp/main"]

View File

@ -2,14 +2,14 @@ package db
import ( import (
"fmt" "fmt"
"os"
"strings"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/utils" "github.com/fossyy/filekeeper/utils"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
_ "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"
gormLogger "gorm.io/gorm/logger" gormLogger "gorm.io/gorm/logger"
"os"
"strings"
) )
var DB *gorm.DB var DB *gorm.DB
@ -23,11 +23,11 @@ func init() {
Logger: gormLogger.Default.LogMode(gormLogger.Silent), Logger: gormLogger.Default.LogMode(gormLogger.Silent),
}) })
if err != nil { if err != nil {
panic("failed to connect database") panic("failed to connect database" + err.Error())
} }
file, err := os.ReadFile("schema.sql") file, err := os.ReadFile("schema.sql")
if err != nil { if err != nil {
log.Error("Error opening file: %v", err) log.Error("Error opening file: %s", err.Error())
} }
querys := strings.Split(string(file), "\n") querys := strings.Split(string(file), "\n")
for _, query := range querys { for _, query := range querys {

View File

@ -2,11 +2,12 @@ package user
import ( import (
"fmt" "fmt"
"sync"
"time"
"github.com/fossyy/filekeeper/db" "github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/google/uuid" "github.com/google/uuid"
"sync"
"time"
) )
type Cache struct { type Cache struct {

View File

@ -2,6 +2,8 @@ package downloadHandler
import ( import (
"errors" "errors"
"net/http"
"github.com/fossyy/filekeeper/db" "github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/middleware" "github.com/fossyy/filekeeper/middleware"
@ -10,7 +12,6 @@ import (
"github.com/fossyy/filekeeper/types/models" "github.com/fossyy/filekeeper/types/models"
"github.com/fossyy/filekeeper/utils" "github.com/fossyy/filekeeper/utils"
downloadView "github.com/fossyy/filekeeper/view/download" downloadView "github.com/fossyy/filekeeper/view/download"
"net/http"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -1,12 +1,13 @@
package downloadFileHandler package downloadFileHandler
import ( import (
"github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/types/models"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/types/models"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -1,9 +1,10 @@
package errorHandler package errorHandler
import ( import (
"net/http"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
errorView "github.com/fossyy/filekeeper/view/error" errorView "github.com/fossyy/filekeeper/view/error"
"net/http"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -5,6 +5,11 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"net/http"
"strconv"
"sync"
"time"
"github.com/fossyy/filekeeper/db" "github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/email" "github.com/fossyy/filekeeper/email"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
@ -14,9 +19,6 @@ import (
emailView "github.com/fossyy/filekeeper/view/email" emailView "github.com/fossyy/filekeeper/view/email"
forgotPasswordView "github.com/fossyy/filekeeper/view/forgotPassword" forgotPasswordView "github.com/fossyy/filekeeper/view/forgotPassword"
"gorm.io/gorm" "gorm.io/gorm"
"net/http"
"sync"
"time"
) )
type ForgotPassword struct { type ForgotPassword struct {
@ -34,7 +36,8 @@ var UserForgotPassword = make(map[string]string)
func init() { func init() {
log = logger.Logger() log = logger.Logger()
ListForgotPassword = make(map[string]*ForgotPassword) ListForgotPassword = make(map[string]*ForgotPassword)
mailServer = email.NewSmtpServer("mail.fossy.my.id", 25, "test@fossy.my.id", "Test123456") smtpPort, _ := strconv.Atoi(utils.Getenv("SMTP_PORT"))
mailServer = email.NewSmtpServer(utils.Getenv("SMTP_HOST"), smtpPort, utils.Getenv("SMTP_USER"), utils.Getenv("SMTP_PASSWORD"))
ticker := time.NewTicker(time.Minute) ticker := time.NewTicker(time.Minute)
go func() { go func() {
for { for {

View File

@ -1,9 +1,10 @@
package indexHandler package indexHandler
import ( import (
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/view/index"
"net/http" "net/http"
"github.com/fossyy/filekeeper/logger"
indexView "github.com/fossyy/filekeeper/view/index"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -2,11 +2,12 @@ package logoutHandler
import ( import (
"errors" "errors"
"net/http"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/session" "github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/types" "github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils" "github.com/fossyy/filekeeper/utils"
"net/http"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -9,17 +9,5 @@ func Robot(w http.ResponseWriter, r *http.Request) {
} }
func Favicon(w http.ResponseWriter, r *http.Request) { func Favicon(w http.ResponseWriter, r *http.Request) {
//currentDir, _ := os.Getwd()
//fmt.Println(currentDir)
//logo := "../../../favicon.ico"
//basePath := filepath.Join(currentDir, "public")
//logoPath := filepath.Join(basePath, logo)
//fmt.Println(filepath.Dir(logoPath))
//if filepath.Dir(logoPath) != basePath {
// log.Print("invalid logo path", logoPath)
// w.WriteHeader(500)
// return
//}
//http.ServeContent()
http.Redirect(w, r, "/public/favicon.ico", http.StatusSeeOther) http.Redirect(w, r, "/public/favicon.ico", http.StatusSeeOther)
} }

View File

@ -2,14 +2,15 @@ package signinHandler
import ( import (
"errors" "errors"
"net/http"
"strings"
"github.com/fossyy/filekeeper/db/model/user" "github.com/fossyy/filekeeper/db/model/user"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/session" "github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/types" "github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils" "github.com/fossyy/filekeeper/utils"
signinView "github.com/fossyy/filekeeper/view/signin" signinView "github.com/fossyy/filekeeper/view/signin"
"net/http"
"strings"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -5,6 +5,11 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"net/http"
"strconv"
"sync"
"time"
"github.com/fossyy/filekeeper/db" "github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/email" "github.com/fossyy/filekeeper/email"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
@ -15,9 +20,6 @@ import (
signupView "github.com/fossyy/filekeeper/view/signup" signupView "github.com/fossyy/filekeeper/view/signup"
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm" "gorm.io/gorm"
"net/http"
"sync"
"time"
) )
type UnverifiedUser struct { type UnverifiedUser struct {
@ -34,7 +36,8 @@ var VerifyEmail map[string]string
func init() { func init() {
log = logger.Logger() log = logger.Logger()
mailServer = email.NewSmtpServer("mail.fossy.my.id", 25, "test@fossy.my.id", "Test123456") smtpPort, _ := strconv.Atoi(utils.Getenv("SMTP_PORT"))
mailServer = email.NewSmtpServer(utils.Getenv("SMTP_HOST"), smtpPort, utils.Getenv("SMTP_USER"), utils.Getenv("SMTP_PASSWORD"))
VerifyUser = make(map[string]*UnverifiedUser) VerifyUser = make(map[string]*UnverifiedUser)
VerifyEmail = make(map[string]string) VerifyEmail = make(map[string]string)

View File

@ -1,12 +1,13 @@
package signupVerifyHandler package signupVerifyHandler
import ( import (
"net/http"
"github.com/fossyy/filekeeper/db" "github.com/fossyy/filekeeper/db"
signupHandler "github.com/fossyy/filekeeper/handler/signup" signupHandler "github.com/fossyy/filekeeper/handler/signup"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/types" "github.com/fossyy/filekeeper/types"
signupView "github.com/fossyy/filekeeper/view/signup" signupView "github.com/fossyy/filekeeper/view/signup"
"net/http"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -3,6 +3,11 @@ package initialisation
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"io"
"net/http"
"os"
"path/filepath"
"github.com/fossyy/filekeeper/db" "github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/middleware" "github.com/fossyy/filekeeper/middleware"
@ -11,10 +16,6 @@ import (
"github.com/fossyy/filekeeper/types/models" "github.com/fossyy/filekeeper/types/models"
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm" "gorm.io/gorm"
"io"
"net/http"
"os"
"path/filepath"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -2,18 +2,19 @@ package uploadHandler
import ( import (
"errors" "errors"
"github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/handler/upload/initialisation"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/middleware"
"github.com/fossyy/filekeeper/session"
filesView "github.com/fossyy/filekeeper/view/upload"
"io" "io"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"sync" "sync"
"github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/handler/upload/initialisation"
"github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/middleware"
"github.com/fossyy/filekeeper/session"
filesView "github.com/fossyy/filekeeper/view/upload"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -2,11 +2,12 @@ package userHandler
import ( import (
"errors" "errors"
"net/http"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/middleware" "github.com/fossyy/filekeeper/middleware"
"github.com/fossyy/filekeeper/session" "github.com/fossyy/filekeeper/session"
userView "github.com/fossyy/filekeeper/view/user" userView "github.com/fossyy/filekeeper/view/user"
"net/http"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -2,10 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"net/http"
"github.com/fossyy/filekeeper/middleware" "github.com/fossyy/filekeeper/middleware"
"github.com/fossyy/filekeeper/routes" "github.com/fossyy/filekeeper/routes"
"github.com/fossyy/filekeeper/utils" "github.com/fossyy/filekeeper/utils"
"net/http"
) )
func main() { func main() {

View File

@ -3,13 +3,14 @@ package middleware
import ( import (
"errors" "errors"
"fmt" "fmt"
"net/http"
"strings"
errorHandler "github.com/fossyy/filekeeper/handler/error" errorHandler "github.com/fossyy/filekeeper/handler/error"
"github.com/fossyy/filekeeper/logger" "github.com/fossyy/filekeeper/logger"
"github.com/fossyy/filekeeper/session" "github.com/fossyy/filekeeper/session"
"github.com/fossyy/filekeeper/types" "github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils" "github.com/fossyy/filekeeper/utils"
"net/http"
"strings"
) )
var log *logger.AggregatedLogger var log *logger.AggregatedLogger

View File

@ -1,6 +1,8 @@
package routes package routes
import ( import (
"net/http"
downloadHandler "github.com/fossyy/filekeeper/handler/download" downloadHandler "github.com/fossyy/filekeeper/handler/download"
downloadFileHandler "github.com/fossyy/filekeeper/handler/download/file" downloadFileHandler "github.com/fossyy/filekeeper/handler/download/file"
forgotPasswordHandler "github.com/fossyy/filekeeper/handler/forgotPassword" forgotPasswordHandler "github.com/fossyy/filekeeper/handler/forgotPassword"
@ -15,7 +17,6 @@ import (
"github.com/fossyy/filekeeper/handler/upload/initialisation" "github.com/fossyy/filekeeper/handler/upload/initialisation"
userHandler "github.com/fossyy/filekeeper/handler/user" userHandler "github.com/fossyy/filekeeper/handler/user"
"github.com/fossyy/filekeeper/middleware" "github.com/fossyy/filekeeper/middleware"
"net/http"
) )
func SetupRoutes() *http.ServeMux { func SetupRoutes() *http.ServeMux {

View File

@ -1,11 +1,12 @@
package session package session
import ( import (
"github.com/fossyy/filekeeper/utils"
"net/http" "net/http"
"strconv" "strconv"
"sync" "sync"
"time" "time"
"github.com/fossyy/filekeeper/utils"
) )
type Session struct { type Session struct {

View File

@ -2,9 +2,6 @@ package utils
import ( import (
"fmt" "fmt"
"github.com/fossyy/filekeeper/logger"
"github.com/joho/godotenv"
"golang.org/x/crypto/bcrypt"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
@ -12,6 +9,10 @@ import (
"sync" "sync"
"time" "time"
"unicode" "unicode"
"github.com/fossyy/filekeeper/logger"
"github.com/joho/godotenv"
"golang.org/x/crypto/bcrypt"
) )
type Env struct { type Env struct {
@ -109,9 +110,11 @@ func Getenv(key string) string {
return val return val
} }
err := godotenv.Load(".env") if os.Getenv("HOSTNAME") == "" {
if err != nil { err := godotenv.Load(".env")
log.Error("Error loading .env file: %s", err) if err != nil {
log.Error("Error loading .env file: %s", err)
}
} }
val := os.Getenv(key) val := os.Getenv(key)