diff --git a/src/db/rdb/sqlite/init.go b/src/db/rdb/sqlite/init.go index 60b08fe..67e1596 100644 --- a/src/db/rdb/sqlite/init.go +++ b/src/db/rdb/sqlite/init.go @@ -20,7 +20,7 @@ type SQLite struct { } func NewSQLite(dbPath string) (*SQLite, error) { - db, err := sql.Open("sqlite3", fmt.Sprintf("%s?_sync=FULL&_locking=EXCLUSIVE", dbPath)) + db, err := sql.Open("sqlite3", fmt.Sprintf("%s?_sync=FULL&_vacuum=incremental", dbPath)) if err != nil { return nil, err } diff --git a/src/handlers/fileshdr/handlers.go b/src/handlers/fileshdr/handlers.go index 5c4b81f..3d4311d 100644 --- a/src/handlers/fileshdr/handlers.go +++ b/src/handlers/fileshdr/handlers.go @@ -142,10 +142,11 @@ func (h *FileHandlers) Create(c *gin.Context) { return } + infoId := h.deps.ID().Gen() tmpFilePath := q.UploadPath(userName, fsFilePath) if req.FileSize == 0 { // TODO: limit the number of files with 0 byte - err = h.deps.FileInfos().AddUploadInfos(c, userID, tmpFilePath, fsFilePath, &db.FileInfo{ + err = h.deps.FileInfos().AddUploadInfos(c, infoId, userID, tmpFilePath, fsFilePath, &db.FileInfo{ Size: req.FileSize, }) if err != nil { @@ -157,7 +158,9 @@ func (h *FileHandlers) Create(c *gin.Context) { return } - err = h.deps.FileInfos().MoveUploadingInfos(c, userID, tmpFilePath, fsFilePath) + // it is ok to use same info ID here + // because the upload info is just moved to the right place after creating. + err = h.deps.FileInfos().MoveUploadingInfos(c, infoId, userID, tmpFilePath, fsFilePath) if err != nil { c.JSON(q.ErrResp(c, 500, err)) return @@ -210,7 +213,7 @@ func (h *FileHandlers) Create(c *gin.Context) { return } - err = h.deps.FileInfos().AddUploadInfos(c, userID, tmpFilePath, fsFilePath, &db.FileInfo{ + err = h.deps.FileInfos().AddUploadInfos(c, infoId, userID, tmpFilePath, fsFilePath, &db.FileInfo{ Size: req.FileSize, }) if err != nil { @@ -517,8 +520,9 @@ func (h *FileHandlers) UploadChunk(c *gin.Context) { } // move the file from uploading dir to uploaded dir + infoId := h.deps.ID().Gen() if uploaded+int64(wrote) == fileSize { - err = h.deps.FileInfos().MoveUploadingInfos(c, userId, tmpFilePath, fsFilePath) + err = h.deps.FileInfos().MoveUploadingInfos(c, infoId, userId, tmpFilePath, fsFilePath) if err != nil { return 500, err } @@ -1017,7 +1021,8 @@ func (h *FileHandlers) AddSharing(c *gin.Context) { return } - err = h.deps.FileInfos().AddSharing(c, userId, sharingPath) + infoId := h.deps.ID().Gen() + err = h.deps.FileInfos().AddSharing(c, infoId, userId, sharingPath) if err != nil { c.JSON(q.ErrResp(c, 500, err)) return diff --git a/src/server/config_load_test.go b/src/server/config_load_test.go index 1b3bf69..bc916ff 100644 --- a/src/server/config_load_test.go +++ b/src/server/config_load_test.go @@ -90,7 +90,7 @@ func TestLoadCfg(t *testing.T) { BgColor: "", }, AllowSetBg: false, - AutoTheme: true, + AutoTheme: false, }, } @@ -156,7 +156,7 @@ func TestLoadCfg(t *testing.T) { BgColor: "", }, AllowSetBg: false, - AutoTheme: true, + AutoTheme: false, }, }, Db: &DbConfig{ diff --git a/src/server/testdata/quickshare.sqlite b/src/server/testdata/quickshare.sqlite new file mode 100644 index 0000000..69eac6d Binary files /dev/null and b/src/server/testdata/quickshare.sqlite differ