Skip to content

Commit

Permalink
complete file and import task (vesoft-inc#213)
Browse files Browse the repository at this point in the history
modify upload and download
mody: go mod
refine the code
update: make check
modify return values
  • Loading branch information
veeding committed Jun 14, 2022
1 parent 472f1e0 commit c2a37b1
Show file tree
Hide file tree
Showing 44 changed files with 2,253 additions and 168 deletions.
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

0 comments on commit c2a37b1

Please sign in to comment.