8
.dockerignore
Normal file
8
.dockerignore
Normal file
@ -0,0 +1,8 @@
|
||||
staging.bat
|
||||
staging.sh
|
||||
uploads
|
||||
.idea
|
||||
.env
|
||||
tmp
|
||||
log
|
||||
/public/output.css
|
17
.env
17
.env
@ -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
3
.gitignore
vendored
@ -2,6 +2,9 @@
|
||||
/uploads
|
||||
/public/output.css
|
||||
/log
|
||||
/.idea
|
||||
|
||||
.env
|
||||
|
||||
*_templ.txt
|
||||
*_templ.go
|
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@ -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
9
.idea/filekeeper.iml
generated
@ -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>
|
10
.idea/inspectionProfiles/Project_Default.xml
generated
10
.idea/inspectionProfiles/Project_Default.xml
generated
@ -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
8
.idea/modules.xml
generated
@ -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
6
.idea/vcs.xml
generated
@ -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
27
Dockerfile
Normal 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"]
|
@ -2,14 +2,14 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
"gorm.io/driver/mysql"
|
||||
_ "gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
gormLogger "gorm.io/gorm/logger"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var DB *gorm.DB
|
||||
@ -23,11 +23,11 @@ func init() {
|
||||
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
|
||||
})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
panic("failed to connect database" + err.Error())
|
||||
}
|
||||
file, err := os.ReadFile("schema.sql")
|
||||
if err != nil {
|
||||
log.Error("Error opening file: %v", err)
|
||||
log.Error("Error opening file: %s", err.Error())
|
||||
}
|
||||
querys := strings.Split(string(file), "\n")
|
||||
for _, query := range querys {
|
||||
|
@ -2,11 +2,12 @@ package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/google/uuid"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
|
@ -2,6 +2,8 @@ package downloadHandler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/middleware"
|
||||
@ -10,7 +12,6 @@ import (
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
downloadView "github.com/fossyy/filekeeper/view/download"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -1,12 +1,13 @@
|
||||
package downloadFileHandler
|
||||
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -1,9 +1,10 @@
|
||||
package errorHandler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
errorView "github.com/fossyy/filekeeper/view/error"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -5,6 +5,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/email"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
@ -14,9 +19,6 @@ import (
|
||||
emailView "github.com/fossyy/filekeeper/view/email"
|
||||
forgotPasswordView "github.com/fossyy/filekeeper/view/forgotPassword"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ForgotPassword struct {
|
||||
@ -34,7 +36,8 @@ var UserForgotPassword = make(map[string]string)
|
||||
func init() {
|
||||
log = logger.Logger()
|
||||
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)
|
||||
go func() {
|
||||
for {
|
||||
|
@ -1,9 +1,10 @@
|
||||
package indexHandler
|
||||
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/view/index"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
indexView "github.com/fossyy/filekeeper/view/index"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -2,11 +2,12 @@ package logoutHandler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -9,17 +9,5 @@ func Robot(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)
|
||||
}
|
||||
|
@ -2,14 +2,15 @@ package signinHandler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/fossyy/filekeeper/db/model/user"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
signinView "github.com/fossyy/filekeeper/view/signin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -5,6 +5,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/email"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
@ -15,9 +20,6 @@ import (
|
||||
signupView "github.com/fossyy/filekeeper/view/signup"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UnverifiedUser struct {
|
||||
@ -34,7 +36,8 @@ var VerifyEmail map[string]string
|
||||
|
||||
func init() {
|
||||
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)
|
||||
VerifyEmail = make(map[string]string)
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
package signupVerifyHandler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
signupHandler "github.com/fossyy/filekeeper/handler/signup"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
signupView "github.com/fossyy/filekeeper/view/signup"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -3,6 +3,11 @@ package initialisation
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fossyy/filekeeper/db"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/middleware"
|
||||
@ -11,10 +16,6 @@ import (
|
||||
"github.com/fossyy/filekeeper/types/models"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -2,18 +2,19 @@ package uploadHandler
|
||||
|
||||
import (
|
||||
"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"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"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
|
||||
|
@ -2,11 +2,12 @@ package userHandler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/middleware"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
userView "github.com/fossyy/filekeeper/view/user"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
3
main.go
3
main.go
@ -2,10 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/middleware"
|
||||
"github.com/fossyy/filekeeper/routes"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -3,13 +3,14 @@ package middleware
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
errorHandler "github.com/fossyy/filekeeper/handler/error"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var log *logger.AggregatedLogger
|
||||
|
@ -1,6 +1,8 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
downloadHandler "github.com/fossyy/filekeeper/handler/download"
|
||||
downloadFileHandler "github.com/fossyy/filekeeper/handler/download/file"
|
||||
forgotPasswordHandler "github.com/fossyy/filekeeper/handler/forgotPassword"
|
||||
@ -15,7 +17,6 @@ import (
|
||||
"github.com/fossyy/filekeeper/handler/upload/initialisation"
|
||||
userHandler "github.com/fossyy/filekeeper/handler/user"
|
||||
"github.com/fossyy/filekeeper/middleware"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SetupRoutes() *http.ServeMux {
|
||||
|
@ -1,11 +1,12 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/fossyy/filekeeper/utils"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
|
@ -2,9 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/joho/godotenv"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -12,6 +9,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/fossyy/filekeeper/logger"
|
||||
"github.com/joho/godotenv"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type Env struct {
|
||||
@ -109,9 +110,11 @@ func Getenv(key string) string {
|
||||
return val
|
||||
}
|
||||
|
||||
err := godotenv.Load(".env")
|
||||
if err != nil {
|
||||
log.Error("Error loading .env file: %s", err)
|
||||
if os.Getenv("HOSTNAME") == "" {
|
||||
err := godotenv.Load(".env")
|
||||
if err != nil {
|
||||
log.Error("Error loading .env file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
val := os.Getenv(key)
|
||||
|
Reference in New Issue
Block a user