More changes

This commit is contained in:
Melon 2024-03-15 15:13:09 +00:00
parent d103f6bcb7
commit 63aa76b63a
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
7 changed files with 63 additions and 29 deletions

View File

@ -61,7 +61,7 @@ func main() {
srv := &http.Server{
Addr: config.Listen,
Handler: routes.Router(db, config.Name, repoBasePath, config.Repository),
Handler: routes.Router(db, config.Name, repoDir, config.Repository),
ReadTimeout: time.Minute,
ReadHeaderTimeout: time.Minute,
WriteTimeout: time.Minute,

View File

@ -0,0 +1,7 @@
package database
import "strings"
func (a Artifact) GetPath() string {
return strings.Replace(a.MvnGroup, ".", "/", -1) + "/" + a.Artifact + "/" + a.Version
}

View File

@ -1,3 +1,22 @@
CREATE TABLE artifacts
(
mvn_group TEXT NOT NULL,
artifact TEXT NOT NULL,
version TEXT NOT NULL,
modified DATETIME NOT NULL
);
CREATE TABLE paths
(
user_id INTEGER UNIQUE,
path TEXT PRIMARY KEY,
deploy TINYINT,
created_at DATETIME,
updated_at DATETIME,
FOREIGN KEY (user_id) REFERENCES users (id)
);
CREATE TABLE users
(
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT,

View File

@ -4,7 +4,25 @@
package database
import ()
import (
"database/sql"
"time"
)
type Artifact struct {
MvnGroup string `json:"mvn_group"`
Artifact string `json:"artifact"`
Version string `json:"version"`
Modified time.Time `json:"modified"`
}
type Path struct {
UserID sql.NullInt64 `json:"user_id"`
Path string `json:"path"`
Deploy sql.NullInt64 `json:"deploy"`
CreatedAt sql.NullTime `json:"created_at"`
UpdatedAt sql.NullTime `json:"updated_at"`
}
type User struct {
ID int64 `json:"id"`

View File

@ -1,10 +0,0 @@
package types
import "time"
type Artifact struct {
MvnGroup string `json:"mvn_group"`
Artifact string `json:"artifact"`
Version string `json:"version"`
Modified time.Time `json:"modified"`
}

View File

@ -1,30 +1,23 @@
package paths
import (
"github.com/1f349/gomvn/database/types"
"github.com/1f349/gomvn/database"
"os"
"path/filepath"
"strings"
"time"
)
func GetRepositories(basePath string, repository []string) map[string][]*types.Artifact {
result := map[string][]*types.Artifact{}
func GetRepositories(basePath string, repository []string) map[string][]*database.Artifact {
result := map[string][]*database.Artifact{}
for _, repo := range repository {
result[repo] = []*types.Artifact{}
result[repo] = []*database.Artifact{}
repoPath := filepath.Join(basePath, repo)
_ = filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
if strings.HasSuffix(path, ".pom") {
path = strings.Replace(path, "\\", "/", -1)
path = strings.Replace(path, repoPath+"/", "", 1)
parts := strings.Split(path, "/")
last := len(parts) - 1
artifact := &types.Artifact{
MvnGroup: strings.Join(parts[0:last-2], "."),
Artifact: parts[last-2],
Version: parts[last-1],
Modified: info.ModTime(),
}
artifact := newArtifact(path, info.ModTime())
result[repo] = append(result[repo], artifact)
}
return nil
@ -32,3 +25,14 @@ func GetRepositories(basePath string, repository []string) map[string][]*types.A
}
return result
}
func newArtifact(p string, mod time.Time) *database.Artifact {
parts := strings.Split(p, "/")
last := len(parts) - 1
return &database.Artifact{
MvnGroup: strings.Join(parts[0:last-2], "."),
Artifact: parts[last-2],
Version: parts[last-1],
Modified: mod,
}
}

View File

@ -114,7 +114,3 @@ func (r *routeCtx) handlePut(rw http.ResponseWriter, req *http.Request, params h
return
}
}
func (r *routeCtx) handleGet(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
}