mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
1、实现富文本编辑器
2、实现文档转换为PDF、MOBI、EPUB、Word格式 3、实现登录后跳转到来源地址
This commit is contained in:
@@ -6,11 +6,12 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"log"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"encoding/json"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
@@ -19,14 +20,6 @@ import (
|
||||
"github.com/lifei6671/mindoc/conf"
|
||||
"github.com/lifei6671/mindoc/models"
|
||||
"github.com/lifei6671/mindoc/utils"
|
||||
"log"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigurationFile = "./conf/app.conf"
|
||||
WorkingDirectory = "./"
|
||||
LogFile = "./logs"
|
||||
)
|
||||
|
||||
// RegisterDataBase 注册数据库
|
||||
@@ -54,8 +47,8 @@ func RegisterDataBase() {
|
||||
}
|
||||
} else if adapter == "sqlite3" {
|
||||
database := beego.AppConfig.String("db_database")
|
||||
if strings.HasPrefix(database,"./") {
|
||||
database = filepath.Join(WorkingDirectory,string(database[1:]))
|
||||
if strings.HasPrefix(database, "./") {
|
||||
database = filepath.Join(conf.WorkingDirectory, string(database[1:]))
|
||||
}
|
||||
|
||||
dbPath := filepath.Dir(database)
|
||||
@@ -99,11 +92,11 @@ func RegisterLogger(log string) {
|
||||
|
||||
if f, err := os.Create(logPath); err == nil {
|
||||
f.Close()
|
||||
config := make(map[string]interface{},1)
|
||||
config := make(map[string]interface{}, 1)
|
||||
|
||||
config["filename"] = logPath
|
||||
|
||||
b,_ := json.Marshal(config)
|
||||
b, _ := json.Marshal(config)
|
||||
|
||||
beego.SetLogger("file", string(b))
|
||||
}
|
||||
@@ -133,7 +126,7 @@ func RegisterFunction() {
|
||||
|
||||
beego.AddFuncMap("cdn", func(p string) string {
|
||||
cdn := beego.AppConfig.DefaultString("cdn", "")
|
||||
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
|
||||
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
||||
return p
|
||||
}
|
||||
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
|
||||
@@ -147,7 +140,7 @@ func RegisterFunction() {
|
||||
|
||||
beego.AddFuncMap("cdnjs", func(p string) string {
|
||||
cdn := beego.AppConfig.DefaultString("cdnjs", "")
|
||||
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
|
||||
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
||||
return p
|
||||
}
|
||||
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
|
||||
@@ -160,7 +153,7 @@ func RegisterFunction() {
|
||||
})
|
||||
beego.AddFuncMap("cdncss", func(p string) string {
|
||||
cdn := beego.AppConfig.DefaultString("cdncss", "")
|
||||
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
|
||||
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
||||
return p
|
||||
}
|
||||
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
|
||||
@@ -172,7 +165,7 @@ func RegisterFunction() {
|
||||
return cdn + p
|
||||
})
|
||||
beego.AddFuncMap("cdnimg", func(p string) string {
|
||||
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
|
||||
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
|
||||
return p
|
||||
}
|
||||
cdn := beego.AppConfig.DefaultString("cdnimg", "")
|
||||
@@ -188,62 +181,64 @@ func RegisterFunction() {
|
||||
|
||||
func ResolveCommand(args []string) {
|
||||
flagSet := flag.NewFlagSet("MinDoc command: ", flag.ExitOnError)
|
||||
flagSet.StringVar(&ConfigurationFile, "config", "", "MinDoc configuration file.")
|
||||
flagSet.StringVar(&WorkingDirectory, "dir", "", "MinDoc working directory.")
|
||||
flagSet.StringVar(&LogFile, "log", "", "MinDoc log file path.")
|
||||
flagSet.StringVar(&conf.ConfigurationFile, "config", "", "MinDoc configuration file.")
|
||||
flagSet.StringVar(&conf.WorkingDirectory, "dir", "", "MinDoc working directory.")
|
||||
flagSet.StringVar(&conf.LogFile, "log", "", "MinDoc log file path.")
|
||||
|
||||
flagSet.Parse(args)
|
||||
|
||||
|
||||
if WorkingDirectory == "" {
|
||||
if conf.WorkingDirectory == "" {
|
||||
if p, err := filepath.Abs(os.Args[0]); err == nil {
|
||||
WorkingDirectory = filepath.Dir(p)
|
||||
conf.WorkingDirectory = filepath.Dir(p)
|
||||
}
|
||||
}
|
||||
if LogFile == "" {
|
||||
LogFile = filepath.Join(WorkingDirectory,"logs")
|
||||
if conf.LogFile == "" {
|
||||
conf.LogFile = filepath.Join(conf.WorkingDirectory, "logs")
|
||||
}
|
||||
if ConfigurationFile == "" {
|
||||
ConfigurationFile = filepath.Join(WorkingDirectory,"conf","app.conf")
|
||||
config := filepath.Join(WorkingDirectory,"conf","app.conf.example")
|
||||
if !utils.FileExists(ConfigurationFile) && utils.FileExists(config){
|
||||
utils.CopyFile(ConfigurationFile,config)
|
||||
if conf.ConfigurationFile == "" {
|
||||
conf.ConfigurationFile = filepath.Join(conf.WorkingDirectory, "conf", "app.conf")
|
||||
config := filepath.Join(conf.WorkingDirectory, "conf", "app.conf.example")
|
||||
if !utils.FileExists(conf.ConfigurationFile) && utils.FileExists(config) {
|
||||
utils.CopyFile(conf.ConfigurationFile, config)
|
||||
}
|
||||
}
|
||||
gocaptcha.ReadFonts(filepath.Join(WorkingDirectory,"static","fonts"), ".ttf")
|
||||
gocaptcha.ReadFonts(filepath.Join(conf.WorkingDirectory, "static", "fonts"), ".ttf")
|
||||
|
||||
err := beego.LoadAppConfig("ini", ConfigurationFile)
|
||||
err := beego.LoadAppConfig("ini", conf.ConfigurationFile)
|
||||
|
||||
if err != nil {
|
||||
log.Println("An error occurred:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
uploads := filepath.Join(WorkingDirectory, "uploads")
|
||||
uploads := filepath.Join(conf.WorkingDirectory, "uploads")
|
||||
|
||||
os.MkdirAll(uploads,0666)
|
||||
os.MkdirAll(uploads, 0666)
|
||||
|
||||
beego.BConfig.WebConfig.StaticDir["/static"] = filepath.Join(WorkingDirectory, "static")
|
||||
beego.BConfig.WebConfig.StaticDir["/static"] = filepath.Join(conf.WorkingDirectory, "static")
|
||||
beego.BConfig.WebConfig.StaticDir["/uploads"] = uploads
|
||||
beego.BConfig.WebConfig.ViewsPath = filepath.Join(WorkingDirectory, "views")
|
||||
beego.BConfig.WebConfig.ViewsPath = filepath.Join(conf.WorkingDirectory, "views")
|
||||
|
||||
fonts := filepath.Join(WorkingDirectory, "static", "fonts")
|
||||
fonts := filepath.Join(conf.WorkingDirectory, "static", "fonts")
|
||||
|
||||
if !utils.FileExists(fonts) {
|
||||
log.Fatal("Font path not exist.")
|
||||
}
|
||||
gocaptcha.ReadFonts(filepath.Join(WorkingDirectory, "static", "fonts"), ".ttf")
|
||||
gocaptcha.ReadFonts(filepath.Join(conf.WorkingDirectory, "static", "fonts"), ".ttf")
|
||||
|
||||
RegisterDataBase()
|
||||
RegisterModel()
|
||||
RegisterLogger(LogFile)
|
||||
RegisterLogger(conf.LogFile)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
if configPath ,err := filepath.Abs(conf.ConfigurationFile); err == nil {
|
||||
conf.ConfigurationFile = configPath
|
||||
}
|
||||
gocaptcha.ReadFonts("./static/fonts", ".ttf")
|
||||
gob.Register(models.Member{})
|
||||
|
||||
if p,err := filepath.Abs(os.Args[0]);err == nil{
|
||||
WorkingDirectory = filepath.Dir(p)
|
||||
if p, err := filepath.Abs(os.Args[0]); err == nil {
|
||||
conf.WorkingDirectory = filepath.Dir(p)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ type Daemon struct {
|
||||
func NewDaemon() *Daemon {
|
||||
|
||||
config := &service.Config{
|
||||
Name: "mindocd", //服务显示名称
|
||||
Name: "mindocd", //服务显示名称
|
||||
DisplayName: "MinDoc service", //服务名称
|
||||
Description: "A document online management program.", //服务描述
|
||||
WorkingDirectory: commands.WorkingDirectory,
|
||||
WorkingDirectory: conf.WorkingDirectory,
|
||||
Arguments: os.Args[1:],
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,18 @@ package migrate
|
||||
import (
|
||||
"os"
|
||||
|
||||
"log"
|
||||
"github.com/lifei6671/mindoc/models"
|
||||
"container/list"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/mindoc/models"
|
||||
"log"
|
||||
)
|
||||
|
||||
var (
|
||||
migrationList = &migrationCache{ }
|
||||
migrationList = &migrationCache{}
|
||||
)
|
||||
|
||||
|
||||
type MigrationDatabase interface {
|
||||
//获取当前的版本
|
||||
Version() int64
|
||||
@@ -58,7 +57,7 @@ func RunMigration() {
|
||||
|
||||
if len(os.Args) >= 2 && os.Args[1] == "migrate" {
|
||||
|
||||
migrate,err := models.NewMigration().FindFirst()
|
||||
migrate, err := models.NewMigration().FindFirst()
|
||||
|
||||
if err != nil {
|
||||
//log.Fatalf("migrations table %s", err)
|
||||
@@ -66,10 +65,10 @@ func RunMigration() {
|
||||
}
|
||||
fmt.Println("Start migration databae... ")
|
||||
|
||||
for el := migrationList.items.Front(); el != nil ; el = el.Next() {
|
||||
for el := migrationList.items.Front(); el != nil; el = el.Next() {
|
||||
|
||||
//如果存在比当前版本大的版本,则依次升级
|
||||
if item,ok := el.Value.(MigrationDatabase); ok && item.Version() > migrate.Version {
|
||||
if item, ok := el.Value.(MigrationDatabase); ok && item.Version() > migrate.Version {
|
||||
err := item.ValidUpdate(migrate.Version)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -112,51 +111,53 @@ func RunMigration() {
|
||||
}
|
||||
|
||||
//导出数据库的表结构
|
||||
func ExportDatabaseTable() ([]string,error) {
|
||||
func ExportDatabaseTable() ([]string, error) {
|
||||
db_adapter := beego.AppConfig.String("db_adapter")
|
||||
db_database := beego.AppConfig.String("db_database")
|
||||
tables := make([]string,0)
|
||||
tables := make([]string, 0)
|
||||
|
||||
o := orm.NewOrm()
|
||||
switch db_adapter {
|
||||
case "mysql":{
|
||||
var lists []orm.Params
|
||||
case "mysql":
|
||||
{
|
||||
var lists []orm.Params
|
||||
|
||||
_,err := o.Raw(fmt.Sprintf("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s'",db_database)).Values(&lists)
|
||||
if err != nil {
|
||||
return tables,err
|
||||
}
|
||||
for _,table := range lists {
|
||||
var results []orm.Params
|
||||
|
||||
_,err = o.Raw(fmt.Sprintf("show create table %s",table["TABLE_NAME"])).Values(&results)
|
||||
_, err := o.Raw(fmt.Sprintf("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s'", db_database)).Values(&lists)
|
||||
if err != nil {
|
||||
return tables,err
|
||||
return tables, err
|
||||
}
|
||||
tables = append(tables,results[0]["Create Table"].(string))
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "sqlite3": {
|
||||
var results []orm.Params
|
||||
_,err := o.Raw("SELECT sql FROM sqlite_master WHERE sql IS NOT NULL ORDER BY rootpage ASC").Values(&results)
|
||||
if err != nil {
|
||||
return tables,err
|
||||
}
|
||||
for _,item := range results {
|
||||
if sql,ok := item["sql"]; ok {
|
||||
tables = append(tables,sql.(string))
|
||||
for _, table := range lists {
|
||||
var results []orm.Params
|
||||
|
||||
_, err = o.Raw(fmt.Sprintf("show create table %s", table["TABLE_NAME"])).Values(&results)
|
||||
if err != nil {
|
||||
return tables, err
|
||||
}
|
||||
tables = append(tables, results[0]["Create Table"].(string))
|
||||
}
|
||||
break
|
||||
}
|
||||
case "sqlite3":
|
||||
{
|
||||
var results []orm.Params
|
||||
_, err := o.Raw("SELECT sql FROM sqlite_master WHERE sql IS NOT NULL ORDER BY rootpage ASC").Values(&results)
|
||||
if err != nil {
|
||||
return tables, err
|
||||
}
|
||||
for _, item := range results {
|
||||
if sql, ok := item["sql"]; ok {
|
||||
tables = append(tables, sql.(string))
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
return tables,nil
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
func RegisterMigration() {
|
||||
func RegisterMigration() {
|
||||
migrationList.items = list.New()
|
||||
|
||||
migrationList.items.PushBack(NewMigrationVersion03())
|
||||
}
|
||||
migrationList.items.PushBack(NewMigrationVersion03())
|
||||
}
|
||||
|
||||
@@ -2,21 +2,20 @@ package migrate
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/mindoc/models"
|
||||
"time"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MigrationVersion03 struct {
|
||||
isValid bool
|
||||
tables []string
|
||||
|
||||
tables []string
|
||||
}
|
||||
|
||||
func NewMigrationVersion03() *MigrationVersion03 {
|
||||
return &MigrationVersion03{ isValid: false, tables: make([]string,0)}
|
||||
return &MigrationVersion03{isValid: false, tables: make([]string, 0)}
|
||||
}
|
||||
|
||||
func (m *MigrationVersion03) Version() int64 {
|
||||
@@ -37,8 +36,7 @@ func (m *MigrationVersion03) ValidForBackupTableSchema() error {
|
||||
return errors.New("The current version failed to verify.")
|
||||
}
|
||||
var err error
|
||||
m.tables,err = ExportDatabaseTable()
|
||||
|
||||
m.tables, err = ExportDatabaseTable()
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -72,11 +70,11 @@ func (m *MigrationVersion03) MigrationNewTableData() error {
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
|
||||
_,err := o.Raw("UPDATE md_members SET auth_method = 'local'").Exec()
|
||||
_, err := o.Raw("UPDATE md_members SET auth_method = 'local'").Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_,err = o.Raw("INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用文档历史','ENABLE_DOCUMENT_HISTORY','true' WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLE_DOCUMENT_HISTORY');").Exec()
|
||||
_, err = o.Raw("INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用文档历史','ENABLE_DOCUMENT_HISTORY','true' WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLE_DOCUMENT_HISTORY');").Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -85,24 +83,24 @@ func (m *MigrationVersion03) MigrationNewTableData() error {
|
||||
|
||||
func (m *MigrationVersion03) AddMigrationRecord(version int64) error {
|
||||
o := orm.NewOrm()
|
||||
tables,err := ExportDatabaseTable()
|
||||
tables, err := ExportDatabaseTable()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return err
|
||||
}
|
||||
migration := models.NewMigration()
|
||||
migration.Version = version
|
||||
migration.Status = "update"
|
||||
migration.CreateTime = time.Now()
|
||||
migration.Name = fmt.Sprintf("update_%d",version)
|
||||
migration.Statements = strings.Join(tables,"\r\n")
|
||||
migration.Name = fmt.Sprintf("update_%d", version)
|
||||
migration.Statements = strings.Join(tables, "\r\n")
|
||||
|
||||
_, err = o.Insert(migration)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *MigrationVersion03) MigrationCleanup() error {
|
||||
func (m *MigrationVersion03) MigrationCleanup() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -112,16 +110,16 @@ func (m *MigrationVersion03) RollbackMigration() error {
|
||||
return errors.New("The current version failed to verify.")
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
_,err := o.Raw("ALTER TABLE md_members DROP COLUMN auth_method").Exec()
|
||||
_, err := o.Raw("ALTER TABLE md_members DROP COLUMN auth_method").Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_,err = o.Raw("DROP TABLE md_document_history").Exec()
|
||||
_, err = o.Raw("DROP TABLE md_document_history").Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_,err = o.Raw("DELETE md_options WHERE option_name = 'ENABLE_DOCUMENT_HISTORY'").Exec()
|
||||
_, err = o.Raw("DELETE md_options WHERE option_name = 'ENABLE_DOCUMENT_HISTORY'").Exec()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -129,11 +127,3 @@ func (m *MigrationVersion03) RollbackMigration() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user