Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #213

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ dist/
!app/**/*.js
tmp
server/data
server-v2/api/*/data
assets/
bin/
7 changes: 5 additions & 2 deletions server-v2/api/studio/etc/studio-api.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Name: studio-api
Host: 0.0.0.0
Port: 9000
Port: 7002
MaxBytes: 1073741824
Debug:
Enable: false
Auth:
AccessSecret: "login_secret"
AccessExpire: 1800
File:
UploadDir: "./upload/"
UploadDir: "./data/upload/"
TasksDir: "./data/tasks"
SqliteDbFilePath: "./data/tasks.db"
TaskIdPath: "./data/taskId.data"
37 changes: 37 additions & 0 deletions server-v2/api/studio/internal/common/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package common

import (
"regexp"
"strings"
)

var (
ReserveRequestRoutes = []string{
"/api/files",
"/api/import-tasks",
}
ReserveResponseRoutes = []string{
"/api/import-tasks",
}
IgnoreHandlerBodyPatterns = []*regexp.Regexp{
regexp.MustCompile(`^/api/import-tasks/\d+/download`),
}
)

func PathHasPrefix(path string, routes []string) bool {
for _, route := range routes {
if strings.HasPrefix(path, route) {
return true
}
}
return false
}

func PathMatchPattern(path string, patterns []*regexp.Regexp) bool {
for _, pattern := range patterns {
if pattern.MatchString(path) {
return true
}
}
return false
}
81 changes: 79 additions & 2 deletions server-v2/api/studio/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package config

import "github.com/zeromicro/go-zero/rest"
import (
"io/ioutil"
"os"
"path/filepath"

"github.com/zeromicro/go-zero/rest"
"go.uber.org/zap"
)

type Config struct {
rest.RestConf
Expand All @@ -13,6 +20,76 @@ type Config struct {
}

File struct {
UploadDir string
UploadDir string
TasksDir string
SqliteDbFilePath string
TaskIdPath string
}
}

const (
DefaultFilesDataDir = "data"
DefaultTaskIdPath = "data/taskId.data"
DefaultUploadDir = "data/upload"
DefaultTasksDir = "data/tasks"
DefaultSqliteDbFilePath = "data/tasks.db"
)

func (c *Config) Validate() error {
return nil
}

func (c *Config) Complete() {
if c.File.TaskIdPath == "" {
_, err := os.Stat(DefaultFilesDataDir)
if os.IsNotExist(err) {
os.MkdirAll(DefaultFilesDataDir, 0o766)
}
abs, _ := filepath.Abs(DefaultTaskIdPath)
_, err = ioutil.ReadFile(abs)
if err != nil {
if os.IsNotExist(err) {
_, err := os.Create(abs)
if err != nil {
zap.L().Fatal("DefaultTaskIdPath Init fail", zap.Error(err))
} else {
zap.L().Fatal("DefaultTaskIdPath Init fail", zap.Error(err))
}
}
}
c.File.TaskIdPath = abs
}

if c.File.UploadDir == "" {
abs, _ := filepath.Abs(DefaultUploadDir)
c.File.UploadDir = abs
_, err := os.Stat(abs)
if os.IsNotExist(err) {
os.MkdirAll(abs, 0o776)
}
}

if c.File.TasksDir == "" {
abs, _ := filepath.Abs(DefaultTasksDir)
c.File.TasksDir = abs
_, err := os.Stat(abs)
if os.IsNotExist(err) {
os.MkdirAll(abs, 0o766)
}
}

if c.File.SqliteDbFilePath == "" {
_, err := os.Stat(DefaultFilesDataDir)
if os.IsNotExist(err) {
os.MkdirAll(DefaultFilesDataDir, 0o766)
}
abs, _ := filepath.Abs(DefaultSqliteDbFilePath)
c.File.SqliteDbFilePath = abs
}
}

func (c *Config) InitConfig() error {
c.Complete()

return c.Validate()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading