Skip to content

Commit

Permalink
complete file and import task
Browse files Browse the repository at this point in the history
modify upload and download

mody: go mod

refine the code

update: make check

motify api

modify return values

rename
  • Loading branch information
veeding committed May 18, 2022
1 parent 673992e commit d208aa2
Show file tree
Hide file tree
Showing 44 changed files with 2,245 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"
29 changes: 29 additions & 0 deletions server-v2/api/studio/internal/common/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package common

import (
"net/http"
"regexp"
"strings"
)

func ReserveRequest(r *http.Request) bool {
if strings.HasPrefix(r.URL.Path, "/api/files") {
return true
}
if strings.HasPrefix(r.URL.Path, "/api/import-tasks") {
return true
}
return false
}

func ReserveResponse(r *http.Request) bool {
if strings.HasPrefix(r.URL.Path, "/api/import-tasks") {
return true
}
return false
}

func IgnoreHandlerBody(r *http.Request) bool {
pattern := regexp.MustCompile(`/api/import-tasks/\d/download.*`)
return pattern.MatchString(r.URL.Path)
}
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(DefaultTasksDir)
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.

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

Loading

0 comments on commit d208aa2

Please sign in to comment.