Skip to content

Commit

Permalink
feat alpha: support sqlite engine
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Mar 8, 2024
1 parent 52419e1 commit 4f03908
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion addition/article/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GenerateDocxFile(target, title, content string) error {

func CreateArticleFile(hash, title, content string) string {
target := fmt.Sprintf("addition/article/data/%s/%s.docx", hash, title)
utils.CreateFolderOnFile(target)
utils.FileDirSafe(target)
if err := GenerateDocxFile(target, title, content); err != nil {
globals.Debug(fmt.Sprintf("[article] error during generate article %s: %s", title, err.Error()))
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/conf/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function setAnnouncement(announcement: string): void {
*/
if (!announcement || announcement.trim() === "") return;

const firstReceived = getMemory("announcement") !== announcement;
const firstReceived = getMemory("announcement").trim() !== announcement.trim();
setMemory("announcement", announcement);

announcementEvent.emit({
Expand Down
4 changes: 2 additions & 2 deletions connection/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func InitMySQLSafe() *sql.DB {
func getConn() *sql.DB {
if viper.GetString("mysql.host") == "" {
globals.SqliteEngine = true
globals.Warn("[connection] mysql host is not set, using sqlite (chatnio.db)")
db, err := sql.Open("sqlite3", "chatnio.db")
globals.Warn("[connection] mysql host is not set, using sqlite (~/db/chatnio.db)")
db, err := sql.Open("sqlite3", utils.FileSafe("./db/chatnio.db"))
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions utils/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func handlePath(path string) string {
}

func CreateZipObject(output string, files []string, replacer string) error {
CreateFolderOnFile(output)
FileDirSafe(output)
file, err := os.Create(output)
if err != nil {
return err
Expand Down Expand Up @@ -107,7 +107,7 @@ func addFileToZip(zipWriter *zip.Writer, path string, replacer string) error {
}

func CreateGzipObject(output string, files []string, replacer string) error {
CreateFolderOnFile(output)
FileDirSafe(output)
tarFile, err := os.Create(output)
if err != nil {
return err
Expand Down
15 changes: 10 additions & 5 deletions utils/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,27 @@ func Exists(path string) bool {
return err != nil && os.IsExist(err)
}

func CreateFolderNotExists(path string) string {
func DirSafe(path string) string {
CreateFolder(path)
return path
}

func CreateFolderOnFile(file string) string {
func FileDirSafe(file string) string {
if strings.LastIndex(file, "/") == -1 {
return file
}

return CreateFolderNotExists(file[:strings.LastIndex(file, "/")])
return DirSafe(file[:strings.LastIndex(file, "/")])
}

func FileSafe(file string) string {
FileDirSafe(file)
return file
}

func WriteFile(path string, data string, folderSafe bool) error {
if folderSafe {
CreateFolderOnFile(path)
FileDirSafe(path)
}

file, err := os.Create(path)
Expand Down Expand Up @@ -152,7 +157,7 @@ func CopyFile(src string, dst string) error {
}
}(in)

CreateFolderOnFile(dst)
FileDirSafe(dst)
out, err := os.Create(dst)
if err != nil {
return err
Expand Down

0 comments on commit 4f03908

Please sign in to comment.