mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
feat alpha: support sqlite engine
This commit is contained in:
parent
52419e1b2b
commit
4f0390815c
@ -31,7 +31,7 @@ func GenerateDocxFile(target, title, content string) error {
|
|||||||
|
|
||||||
func CreateArticleFile(hash, title, content string) string {
|
func CreateArticleFile(hash, title, content string) string {
|
||||||
target := fmt.Sprintf("addition/article/data/%s/%s.docx", hash, title)
|
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 {
|
if err := GenerateDocxFile(target, title, content); err != nil {
|
||||||
globals.Debug(fmt.Sprintf("[article] error during generate article %s: %s", title, err.Error()))
|
globals.Debug(fmt.Sprintf("[article] error during generate article %s: %s", title, err.Error()))
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ export function setAnnouncement(announcement: string): void {
|
|||||||
*/
|
*/
|
||||||
if (!announcement || announcement.trim() === "") return;
|
if (!announcement || announcement.trim() === "") return;
|
||||||
|
|
||||||
const firstReceived = getMemory("announcement") !== announcement;
|
const firstReceived = getMemory("announcement").trim() !== announcement.trim();
|
||||||
setMemory("announcement", announcement);
|
setMemory("announcement", announcement);
|
||||||
|
|
||||||
announcementEvent.emit({
|
announcementEvent.emit({
|
||||||
|
@ -23,8 +23,8 @@ func InitMySQLSafe() *sql.DB {
|
|||||||
func getConn() *sql.DB {
|
func getConn() *sql.DB {
|
||||||
if viper.GetString("mysql.host") == "" {
|
if viper.GetString("mysql.host") == "" {
|
||||||
globals.SqliteEngine = true
|
globals.SqliteEngine = true
|
||||||
globals.Warn("[connection] mysql host is not set, using sqlite (chatnio.db)")
|
globals.Warn("[connection] mysql host is not set, using sqlite (~/db/chatnio.db)")
|
||||||
db, err := sql.Open("sqlite3", "chatnio.db")
|
db, err := sql.Open("sqlite3", utils.FileSafe("./db/chatnio.db"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func handlePath(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateZipObject(output string, files []string, replacer string) error {
|
func CreateZipObject(output string, files []string, replacer string) error {
|
||||||
CreateFolderOnFile(output)
|
FileDirSafe(output)
|
||||||
file, err := os.Create(output)
|
file, err := os.Create(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -107,7 +107,7 @@ func addFileToZip(zipWriter *zip.Writer, path string, replacer string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CreateGzipObject(output string, files []string, replacer string) error {
|
func CreateGzipObject(output string, files []string, replacer string) error {
|
||||||
CreateFolderOnFile(output)
|
FileDirSafe(output)
|
||||||
tarFile, err := os.Create(output)
|
tarFile, err := os.Create(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
15
utils/fs.go
15
utils/fs.go
@ -23,22 +23,27 @@ func Exists(path string) bool {
|
|||||||
return err != nil && os.IsExist(err)
|
return err != nil && os.IsExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFolderNotExists(path string) string {
|
func DirSafe(path string) string {
|
||||||
CreateFolder(path)
|
CreateFolder(path)
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateFolderOnFile(file string) string {
|
func FileDirSafe(file string) string {
|
||||||
if strings.LastIndex(file, "/") == -1 {
|
if strings.LastIndex(file, "/") == -1 {
|
||||||
return file
|
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 {
|
func WriteFile(path string, data string, folderSafe bool) error {
|
||||||
if folderSafe {
|
if folderSafe {
|
||||||
CreateFolderOnFile(path)
|
FileDirSafe(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.Create(path)
|
file, err := os.Create(path)
|
||||||
@ -152,7 +157,7 @@ func CopyFile(src string, dst string) error {
|
|||||||
}
|
}
|
||||||
}(in)
|
}(in)
|
||||||
|
|
||||||
CreateFolderOnFile(dst)
|
FileDirSafe(dst)
|
||||||
out, err := os.Create(dst)
|
out, err := os.Create(dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user