Skip to content

Commit

Permalink
update: 2024-01-07
Browse files Browse the repository at this point in the history
  • Loading branch information
Light authored and Light committed Jan 6, 2024
1 parent accbf9d commit 61771b5
Show file tree
Hide file tree
Showing 80 changed files with 8,815 additions and 8,088 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.html

# Dependency directories (remove the comment below to include it)
# vendor/
Expand All @@ -21,8 +22,8 @@ internal/assets/favicon.ico
internal/assets/css
internal/templates/html/*
internal/mdi/mdi-cheat-sheets
internal/guide/guide-assets
internal/editor/editor-assets
internal/pages/guide/guide-assets
internal/pages/editor/editor-assets
internal/pages/home/home-assets
internal/weather/icons
.DS_Store
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
1. 生产环境下不再输出 `gin-gonic/gin` 包日志。
1. 首页的搜索框支持实时搜索书签。
1. 添加一个可选的返回顶部按钮。
1. 添加支持使用 [Simple Icons](https://simpleicons.org/)(v10.1.0) 图标,格式为 `si` 前缀 + [slug](https://github.com/simple-icons/simple-icons/blob/master/slugs.md),如:`siGitHub`
1. 添加支持使用 [Simple Icons](https://simpleicons.org/)(v10.4.0) 图标,格式为 `si` 前缀 + [slug](https://github.com/simple-icons/simple-icons/blob/master/slugs.md),如:`siGitHub`
1. 添加可选的侧边栏功能。(_v0.4.0-20230316_)
1. 调整为可选水平(默认)或垂直排列书签。(_v0.4.0-20230326_)
1. 调整基础样式,以优化在移动端下的使用体验。
Expand All @@ -23,7 +23,7 @@
- 名称:
- 环境变量: `FLARE_LOG_LEVEL`
- 启动命令: `log_level`
- 可选值: `TRACE``DEBUG``INFO``WARN``ERROR``PANIC`
- 可选值: `DEBUG``INFO``WARN``ERROR`

#### 示例

Expand All @@ -36,15 +36,18 @@

其他改动主要包含修复在 [Flare](https://github.com/soulteary/flare) 正式发行版本中存在的问题,这些问题理论上会在 [Flare](https://github.com/soulteary/flare) 的后续迭代版本中被处理和修复,所以这些更改基本只会针对特定的发行版本:

- **0.4.3:**
- 修正某些 HTML 标签名错误。
- 更新 [Material Design Icons](https://materialdesignicons.com/) 图标至 v7.3.67 版本。
- **0.5.1**
- 更新 [Material Design Icons](https://materialdesignicons.com/) 图标至 v7.4.47 版本。

---

<details>
<summary>旧版本中的改动</summary>

- **0.4.3:**
- 修正某些 HTML 标签名错误。
- 更新 [Material Design Icons](https://materialdesignicons.com/) 图标至 v7.3.67 版本。

- **0.4.1:**
- 修复加密链接可能无法解码的问题。
- 修复无法读取 .env 文件中所配置值的问题 (_v0.4.1-20230628_)
Expand Down
6 changes: 3 additions & 3 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ func main() {
"embed/assets/vendor/mdi/mdi.js", "internal/resources/mdi/icons.go",
)
builder.TaskForSimpleIcons("embed/assets/vendor/simple-icons/index.js", "internal/resources/simpleicons/icons.go")
builder.TaskForGuideAssets("embed/assets/vendor/guide-assets", "internal/guide/guide-assets")
builder.TaskForEditorAssets("embed/assets/vendor/editor-assets", "internal/editor/editor-assets")
builder.TaskForGuideAssets("embed/assets/vendor/guide-assets", "internal/pages/guide/guide-assets")
builder.TaskForEditorAssets("embed/assets/vendor/editor-assets", "internal/pages/editor/editor-assets")
builder.TaskForHomeAssets("embed/assets/vendor/home-assets", "internal/pages/home/home-assets")
builder.TaskForStyles("internal/state/style.go")
builder.TaskForStyles("config/state/style.go")
builder.TaskForFavicon("embed/assets/favicon.ico", "internal/resources/assets/favicon.ico")
builder.TaskForTemplates("embed/templates", "internal/resources/templates/html")
}
126 changes: 126 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package cmd

import (
"os"
"regexp"
"strings"

"github.com/soulteary/flare/internal/version"
flags "github.com/spf13/pflag"

FlareDefine "github.com/soulteary/flare/config/define"
FlareModel "github.com/soulteary/flare/config/model"
)

func ParseCLI(baseFlags FlareModel.Flags) FlareModel.Flags {

var cliFlags = new(FlareModel.Flags)
options := flags.NewFlagSet("appFlags", flags.ContinueOnError)
options.SortFlags = false

// port
options.IntVarP(&cliFlags.Port, _KEY_PORT, _KEY_PORT_SHORT, FlareDefine.DEFAULT_PORT, "指定监听端口")
// guide
options.BoolVarP(&cliFlags.EnableGuide, _KEY_ENABLE_GUIDE, _KEY_ENABLE_GUIDE_SHORT, FlareDefine.DEFAULT_ENABLE_GUIDE, "启用应用向导")
// visibility
options.StringVarP(&cliFlags.Visibility, _KEY_VISIBILITY, _KEY_VISIBILITY_SHORT, FlareDefine.DEFAULT_VISIBILITY, "调整网站整体可见性")
// mini_request
options.BoolVarP(&cliFlags.EnableMinimumRequest, _KEY_MINI_REQUEST, _KEY_MINI_REQUEST_SHORT, FlareDefine.DEFAULT_ENABLE_MINI_REQUEST, "使用请求最小化模式")
options.BoolVar(&cliFlags.EnableMinimumRequest, _KEY_MINI_REQUEST_OLD, FlareDefine.DEFAULT_ENABLE_MINI_REQUEST, "使用请求最小化模式")
_ = options.MarkDeprecated(_KEY_MINI_REQUEST_OLD, "please use --"+_KEY_MINI_REQUEST+" instead")
// offline
options.BoolVarP(&cliFlags.EnableOfflineMode, _KEY_ENABLE_OFFLINE, _KEY_ENABLE_OFFLINE_SHORT, FlareDefine.DEFAULT_ENABLE_OFFLINE, "启用离线模式")
// disable_login
options.BoolVarP(&cliFlags.DisableLoginMode, _KEY_DISABLE_LOGIN, _KEY_DISABLE_LOGIN_SHORT, FlareDefine.DEFAULT_DISABLE_LOGIN, "禁用账号登陆")
options.BoolVar(&cliFlags.DisableLoginMode, _KEY_DISABLE_LOGIN_OLD, FlareDefine.DEFAULT_DISABLE_LOGIN, "禁用账号登陆")
_ = options.MarkDeprecated(_KEY_DISABLE_LOGIN_OLD, "please use --"+_KEY_DISABLE_LOGIN+" instead")
// 启用废弃日志警告
options.BoolVarP(&cliFlags.EnableDeprecatedNotice, _KEY_ENABLE_DEPRECATED_NOTICE, _KEY_ENABLE_DEPRECATED_NOTICE_SHORT, FlareDefine.DEFAULT_ENABLE_DEPRECATED_NOTICE, "启用废弃日志警告")
options.BoolVarP(&cliFlags.EnableEditor, _KEY_ENABLE_EDITOR, _KEY_ENABLE_EDITOR_SHORT, FlareDefine.DEFAULT_ENABLE_EDITOR, "启用编辑器")
// 禁用 CSP
options.BoolVarP(&cliFlags.DisableCSP, _KEY_DISABLE_CSP, _KEY_DISABLE_CSP_SHORT, FlareDefine.DEFAULT_DISABLE_CSP, "禁用CSP")
// 输出日志级别
options.StringVar(&cliFlags.LogLevel, _KEY_LOG_LEVEL, FlareDefine.DEFAULT_LOG_LEVEL, "输出日志级别")
// 其他
options.BoolVarP(&cliFlags.ShowVersion, "version", "v", false, "显示应用版本号")
options.BoolVarP(&cliFlags.ShowHelp, "help", "h", false, "显示帮助")

_ = options.Parse(os.Args)

exit := ExcuteCLI(cliFlags, options)
if exit {
os.Exit(0)
}
GetVersion(true)

// 用于判断参数是否存在
keys := make(map[string]bool)
trimValue := regexp.MustCompile(`=.*`)
for _, key := range os.Args[1:] {
if key[:2] == "--" {
keys[trimValue.ReplaceAllString(key[2:], "")] = true
} else if key[:1] == "-" {
keys[trimValue.ReplaceAllString(key[1:], "")] = true
}
}

if keys[_KEY_PORT] || keys[_KEY_PORT_SHORT] {
baseFlags.Port = cliFlags.Port
}

if keys[_KEY_MINI_REQUEST] || keys[_KEY_MINI_REQUEST_SHORT] || keys[_KEY_MINI_REQUEST_OLD] {
baseFlags.EnableMinimumRequest = cliFlags.EnableMinimumRequest
}

if keys[_KEY_DISABLE_LOGIN] || keys[_KEY_DISABLE_LOGIN_SHORT] || keys[_KEY_DISABLE_LOGIN_OLD] {
baseFlags.DisableLoginMode = cliFlags.DisableLoginMode
}

if keys[_KEY_DISABLE_CSP] || keys[_KEY_DISABLE_CSP_SHORT] {
baseFlags.DisableCSP = cliFlags.DisableCSP
}

if keys[_KEY_VISIBILITY] || keys[_KEY_VISIBILITY_SHORT] {
baseFlags.Visibility = cliFlags.Visibility
// 判断是否为白名单中的词,以及强制转换内容为大写
if strings.ToUpper(cliFlags.Visibility) != FlareDefine.DEFAULT_VISIBILITY &&
strings.ToUpper(cliFlags.Visibility) != "PRIVATE" {
baseFlags.Visibility = FlareDefine.DEFAULT_VISIBILITY
} else {
baseFlags.Visibility = strings.ToUpper(cliFlags.Visibility)
}
} else {
baseFlags.Visibility = strings.ToUpper(baseFlags.Visibility)
}

if keys[_KEY_ENABLE_OFFLINE] || keys[_KEY_ENABLE_OFFLINE_SHORT] {
baseFlags.EnableOfflineMode = cliFlags.EnableOfflineMode
}

if keys[_KEY_ENABLE_DEPRECATED_NOTICE] || keys[_KEY_ENABLE_DEPRECATED_NOTICE_SHORT] {
baseFlags.EnableDeprecatedNotice = cliFlags.EnableDeprecatedNotice
}

if keys[_KEY_ENABLE_GUIDE] || keys[_KEY_ENABLE_GUIDE_SHORT] {
baseFlags.EnableGuide = cliFlags.EnableGuide
}

if keys[_KEY_ENABLE_EDITOR] || keys[_KEY_ENABLE_EDITOR_SHORT] {
baseFlags.EnableEditor = cliFlags.EnableEditor
}

if keys[_KEY_LOG_LEVEL] {
baseFlags.LogLevel = cliFlags.LogLevel
}

// Forcibly disable `debug mode` in non-development mode
if strings.ToLower(version.Version) != "dev" {
baseFlags.DebugMode = false
} else {
if keys["D"] || keys["debug"] {
baseFlags.DebugMode = true
}
}

return baseFlags
}
78 changes: 58 additions & 20 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,80 @@
package cmd

import (
"github.com/soulteary/flare/pkg/logger"
"fmt"
"log/slog"
"runtime"
"strings"

FlareData "github.com/soulteary/flare/internal/data"
FlareState "github.com/soulteary/flare/internal/state"
)
flags "github.com/spf13/pflag"

func Parse() {
FlareData "github.com/soulteary/flare/config/data"
FlareDefine "github.com/soulteary/flare/config/define"
FlareModel "github.com/soulteary/flare/config/model"
FlareState "github.com/soulteary/flare/config/state"
FlareLogger "github.com/soulteary/flare/internal/logger"
"github.com/soulteary/flare/internal/version"
)

envs := parseEnvFile(parseEnvVars())
flags := parseCLI(envs)
func Parse() FlareModel.Flags {
envs := ParseEnvFile(ParseEnvVars())
flags := ParseCLI(envs)

log := logger.GetLogger(flags.LogLevel)
log.Println()
log.Println("程序服务端口", flags.Port)
log.Println("页面请求合并", flags.EnableMinimumRequest)
log.Println("启用离线模式", flags.EnableOfflineMode)
log := FlareLogger.GetLogger(flags.LogLevel)
log.Info("程序服务端口", slog.Int(_KEY_PORT, flags.Port))
log.Info("页面请求合并", slog.Bool(_KEY_MINI_REQUEST, flags.EnableMinimumRequest))
log.Info("启用离线模式", slog.Bool(_KEY_ENABLE_OFFLINE, flags.EnableOfflineMode))
if flags.DisableLoginMode {
log.Println("已禁用登陆模式,用户可直接调整应用设置。")
log.Info("已禁用登陆模式,用户可直接调整应用设置。")
} else {
log.Println("启用登陆模式,调整应用设置需要先进行登陆。")
log.Println("当前内容整体可见性为:", flags.Visibility)
log.Info("启用登陆模式,调整应用设置需要先进行登陆。")
log.Info("当前内容整体可见性为:", slog.String(_KEY_VISIBILITY, flags.Visibility))

if flags.UserIsGenerated {
log.Println("用户未指定 `FLARE_USER`,使用默认用户名", _DEFAULT_USER_NAME)
log.Info("用户未指定 `FLARE_USER`,使用默认用户名", slog.String("username", FlareDefine.DEFAULT_USER_NAME))
} else {
log.Println("应用用户设置为", flags.User)
log.Info("应用用户设置为", slog.String("username", flags.User))

}

if flags.PassIsGenerated {
log.Println("用户未指定 `FLARE_PASS`,自动生成应用密码", flags.Pass)
log.Info("用户未指定 `FLARE_PASS`,自动生成应用密码", slog.String("password", flags.Pass))
} else {
log.Println("应用登陆密码已设置为", FlareData.MaskTextWithStars(flags.Pass))
log.Info("应用登陆密码已设置为", slog.String("password", FlareData.MaskTextWithStars(flags.Pass)))
}
}

FlareState.AppFlags = flags
startDaemon(&flags)
return flags
}

func ExcuteCLI(cliFlags *FlareModel.Flags, options *flags.FlagSet) (exit bool) {
programVersion := GetVersion(false)
if cliFlags.ShowHelp {
fmt.Println(programVersion)
fmt.Println()
fmt.Println("支持命令:")
options.PrintDefaults()
return true
}
if cliFlags.ShowVersion {
fmt.Println(version.Version)
return true
}
return false
}

func GetVersion(echo bool) string {
programVersion := fmt.Sprintf("Flare v%s-%s %s/%s BuildDate=%s", version.Version, strings.ToUpper(version.Commit), runtime.GOOS, runtime.GOARCH, version.BuildDate)
if echo {
log := FlareLogger.GetLogger(FlareDefine.DEFAULT_LOG_LEVEL)
log.Info("Flare - 🏂 Challenge all bookmarking apps and websites directories, Aim to Be a best performance monster.")
log.Info("程序信息:",
slog.String("version", version.Version),
slog.String("commit", strings.ToUpper(version.Commit)),
slog.String("GOGS/ARCH", fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)),
slog.String("date", version.BuildDate),
)
}
return programVersion
}
Loading

0 comments on commit 61771b5

Please sign in to comment.