Release 0.3.0 (#37)

* chore(cicd): add build and start script

* fix(client/web): fix fail to reupload same file, avoid default worker

* test(client/web): add case for worker list filtering
This commit is contained in:
Hexxa 2021-01-31 19:37:05 +08:00 committed by GitHub
parent ede6c239f0
commit c8a3f911e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 117 additions and 15 deletions

View file

@ -5,3 +5,7 @@ export function alertMsg(msg: string) {
console.log(msg);
}
}
export function comfirmMsg(msg: string): boolean {
return confirm(msg);
}

View file

@ -4,7 +4,7 @@ import { List, Map } from "immutable";
import FileSize from "filesize";
import { Layouter } from "./layouter";
import { alertMsg } from "../common/env";
import { alertMsg, comfirmMsg } from "../common/env";
import { updater } from "./browser.updater";
import { ICoreState } from "./core_state";
import {
@ -139,6 +139,11 @@ export class Browser extends React.Component<Props, State, {}> {
selectedItems: Map<string, boolean>(),
});
return;
} else {
const filesToDel = this.state.selectedItems.keySeq().join(", ");
if (!comfirmMsg(`do you want to delete ${filesToDel}?`)) {
return;
}
}
updater()

View file

@ -32,7 +32,6 @@ export function initWithWorker(worker: IWorker): ICoreState {
}
export function init(): ICoreState {
const scripts = Array.from(document.querySelectorAll("script"));
const worker = Worker == null ? new FgWorker() : new BgWorker();
initUploadMgr(worker);

View file

@ -62,6 +62,12 @@ describe("upload.worker", () => {
expectedUploaderStartInput: "file1",
currentFilePath: "file0",
},
{
infos: [makeEntry("file1", true)],
expectedUploadingFile: "file1",
expectedUploaderStartInput: "file1",
currentFilePath: "file1",
},
];
for (let i = 0; i < tcs.length; i++) {

View file

@ -57,10 +57,10 @@ export class UploadWorker {
infoArray[i].runnable &&
infoArray[i].uploaded < infoArray[i].size
) {
if (infoArray[i].filePath !== this.filePath) {
this.stopUploader();
this.startUploader(infoArray[i].file, infoArray[i].filePath);
}
// infoArray[i].filePath !== this.filePath, it may re-uploading a deleted file
// and it will stuck or the file will be renamed in the future
this.stopUploader();
this.startUploader(infoArray[i].file, infoArray[i].filePath);
break;
} else if (
!infoArray[i].runnable &&

View file

@ -144,7 +144,7 @@ export class UploadMgr {
};
}
export let uploadMgr = new UploadMgr(new FgWorker());
export let uploadMgr: UploadMgr = undefined;
export const initUploadMgr = (worker: IWorker): UploadMgr => {
uploadMgr = new UploadMgr(worker);
return uploadMgr;

View file

@ -28,6 +28,7 @@ type ServerCfg struct {
ReadTimeout int `json:"readTimeout"`
WriteTimeout int `json:"writeTimeout"`
MaxHeaderBytes int `json:"maxHeaderBytes"`
PublicPath string `json:"publicPath"`
}
type Config struct {
@ -66,6 +67,7 @@ func DefaultConfig() (string, error) {
ReadTimeout: 2000,
WriteTimeout: 1000 * 3600 * 24, // 1 day
MaxHeaderBytes: 512,
PublicPath: "public",
},
}

View file

@ -4,8 +4,10 @@ import (
"context"
"crypto/rand"
"crypto/sha1"
"errors"
"fmt"
"net/http"
"os"
"time"
"github.com/gin-contrib/static"
@ -56,6 +58,22 @@ func NewServer(cfg gocfg.ICfg) (*Server, error) {
}, nil
}
func mkRoot(rootPath string) {
info, err := os.Stat(rootPath)
if err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(rootPath, 0760)
if err != nil {
panic(err)
}
} else {
panic(err)
}
} else if !info.IsDir() {
panic(fmt.Sprintf("can not create %s folder: there is a file with same name", rootPath))
}
}
func initDeps(cfg gocfg.ICfg) *depidx.Deps {
secret, ok := cfg.String("ENV.TOKENSECRET")
if !ok {
@ -64,6 +82,7 @@ func initDeps(cfg gocfg.ICfg) *depidx.Deps {
}
rootPath := cfg.GrabString("Fs.Root")
mkRoot(rootPath)
opensLimit := cfg.GrabInt("Fs.OpensLimit")
openTTL := cfg.GrabInt("Fs.OpenTTL")
@ -121,10 +140,15 @@ func initHandlers(router *gin.Engine, cfg gocfg.ICfg, deps *depidx.Deps) (*gin.E
return nil, err
}
publicPath, ok := cfg.String("Server.PublicPath")
if !ok || publicPath == "" {
return nil, errors.New("publicPath not found or empty")
}
// middleware
router.Use(userHdrs.Auth())
// tmp static server
router.Use(static.Serve("/", static.LocalFile("../public", false)))
router.Use(static.Serve("/", static.LocalFile(publicPath, false)))
// handler
v1 := router.Group("/v1")