Merge branch 'github-main' into pr/github

This commit is contained in:
LinkinStar 2022-10-25 10:39:28 +08:00
commit 43cc77f9d4
7 changed files with 170 additions and 36 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ Thumbs*.db
tmp tmp
vendor/ vendor/
.husky .husky
answer-data/

View File

@ -11,7 +11,7 @@ services:
links: links:
- db - db
volumes: volumes:
- ./answer/data:/data - ./answer-data/data:/data
db: db:
image: mariadb:10.4.7 image: mariadb:10.4.7
ports: ports:
@ -26,4 +26,4 @@ services:
retries: 10 retries: 10
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--skip-character-set-client-handshake'] command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--skip-character-set-client-handshake']
volumes: volumes:
- ./answer/mysql:/var/lib/mysql - ./answer-data/mysql:/var/lib/mysql

View File

@ -15,11 +15,156 @@ email:
password: password:
other: "密码" other: "密码"
username_or_password_wrong_error: &username_or_password_wrong email_or_password_wrong_error: &email_or_password_wrong
other: "用户名或密码错误" other: "邮箱或密码错误"
error: error:
user:
username_or_password_wrong: *username_or_password_wrong
admin: admin:
username_or_password_wrong: *username_or_password_wrong email_or_password_wrong: *email_or_password_wrong
answer:
not_found:
other: "答案未找到"
comment:
edit_without_permission:
other: "不允许编辑评论"
not_found:
other: "评论未找到"
email:
duplicate:
other: "邮箱已经存在"
need_to_be_verified:
other: "邮箱需要验证"
verify_url_expired:
other: "邮箱验证的网址已过期,请重新发送邮件"
lang:
not_found:
other: "语言未找到"
object:
captcha_verification_failed:
other: "验证码错误"
disallow_follow:
other: "你不能关注"
disallow_vote:
other: "你不能投票"
disallow_vote_your_self:
other: "你不能为自己的帖子投票!"
not_found:
other: "对象未找到"
verification_failed:
other: "验证失败"
email_or_password_incorrect:
other: "邮箱或密码不正确"
old_password_verification_failed:
other: "旧密码验证失败"
new_password_same_as_previous_setting:
other: "新密码与之前的设置相同"
question:
not_found:
other: "问题未找到"
rank:
fail_to_meet_the_condition:
other: "级别不符合条件"
report:
handle_failed:
other: "报告处理失败"
not_found:
other: "报告未找到"
tag:
not_found:
other: "标签未找到"
theme:
not_found:
other: "主题未找到"
user:
email_or_password_wrong:
other: *email_or_password_wrong
not_found:
other: "用户未找到"
suspended:
other: "用户已被暂停"
username_invalid:
other: "用户名无效"
username_duplicate:
other: "用户名已被使用"
report:
spam:
name:
other: "垃圾信息"
description:
other: "此帖子是一个广告贴,或是破坏性行为。它对当前的主题无用,也不相关。"
rude:
name:
other: "粗鲁或辱骂的"
description:
other: "有理智的人都会发现此内容不适合进行尊重的讨论。"
duplicate:
name:
other: "重复信息"
description:
other: "此问题以前就有人问过,而且已经有了答案。"
not_answer:
name:
other: "不是答案"
description:
other: "此帖子是作为一个答案发布的,但它并没有试图回答这个问题。总之,它可能应该是个编辑,评论,另一个问题或者被删除。"
not_need:
name:
other: "不再需要"
description:
other: "此条评论是过时的,对话性的或与本帖无关。"
other:
name:
other: "其他原因"
description:
other: "此帖子需要工作人员关注,因为是上述所列以外的其他理由。"
question:
close:
duplicate:
name:
other: "垃圾信息"
description:
other: "此问题以前就有人问过,而且已经有了答案。"
guideline:
name:
other: "社区特定原因"
description:
other: "此问题不符合社区准则。"
multiple:
name:
other: "需要细节或澄清"
description:
other: "此问题目前涵盖多个问题。它应该只集中在一个问题上。"
other:
name:
other: "其他原因"
description:
other: "此帖子需要上述所列以外的其他理由。"
notification:
action:
update_question:
other: "更新了问题"
answer_the_question:
other: "回答了问题"
update_answer:
other: "更新了答案"
adopt_answer:
other: "接受了答案"
comment_question:
other: "评论了问题"
comment_answer:
other: "评论了答案"
reply_to_you:
other: "回复了你"
mention_you:
other: "提到了你"
your_question_is_closed:
other: "你的问题已被关闭"
your_question_was_deleted:
other: "你的问题已被删除"
your_answer_was_deleted:
other: "你的答案已被删除"
your_comment_was_deleted:
other: "你的评论已被删除"

View File

@ -44,7 +44,7 @@ func installConfigFile() {
return return
} }
if _, err := dir.CreatePathIsNotExist(ConfigFilePath); err != nil { if err := dir.CreateDirIfNotExist(ConfigFilePath); err != nil {
fmt.Printf("[config-file] create directory fail %s\n", err.Error()) fmt.Printf("[config-file] create directory fail %s\n", err.Error())
return return
} }
@ -59,7 +59,7 @@ func installConfigFile() {
func installUploadDir() { func installUploadDir() {
fmt.Println("[upload-dir] try to install...") fmt.Println("[upload-dir] try to install...")
if _, err := dir.CreatePathIsNotExist(UploadFilePath); err != nil { if err := dir.CreateDirIfNotExist(UploadFilePath); err != nil {
fmt.Printf("[upload-dir] install fail %s\n", err.Error()) fmt.Printf("[upload-dir] install fail %s\n", err.Error())
} else { } else {
fmt.Printf("[upload-dir] install success, upload directory is %s\n", UploadFilePath) fmt.Printf("[upload-dir] install success, upload directory is %s\n", UploadFilePath)
@ -68,7 +68,7 @@ func installUploadDir() {
func installI18nBundle() { func installI18nBundle() {
fmt.Println("[i18n] try to install i18n bundle...") fmt.Println("[i18n] try to install i18n bundle...")
if _, err := dir.CreatePathIsNotExist(I18nPath); err != nil { if err := dir.CreateDirIfNotExist(I18nPath); err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return
} }

View File

@ -6,11 +6,11 @@ import (
) )
func CheckConfigFile(configPath string) bool { func CheckConfigFile(configPath string) bool {
return dir.CheckPathExist(configPath) return dir.CheckFileExist(configPath)
} }
func CheckUploadDir() bool { func CheckUploadDir() bool {
return dir.CheckPathExist(UploadFilePath) return dir.CheckDirExist(UploadFilePath)
} }
func CheckDB(dataConf *data.Database) bool { func CheckDB(dataConf *data.Database) bool {

View File

@ -26,11 +26,11 @@ type UploaderService struct {
// NewUploaderService new upload service // NewUploaderService new upload service
func NewUploaderService(serviceConfig *service_config.ServiceConfig) *UploaderService { func NewUploaderService(serviceConfig *service_config.ServiceConfig) *UploaderService {
_, err := dir.CreatePathIsNotExist(filepath.Join(serviceConfig.UploadPath, avatarSubPath)) err := dir.CreateDirIfNotExist(filepath.Join(serviceConfig.UploadPath, avatarSubPath))
if err != nil { if err != nil {
panic(err) panic(err)
} }
_, err = dir.CreatePathIsNotExist(filepath.Join(serviceConfig.UploadPath, postSubPath)) err = dir.CreateDirIfNotExist(filepath.Join(serviceConfig.UploadPath, postSubPath))
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -2,28 +2,16 @@ package dir
import "os" import "os"
// CreatePathIsNotExist create path is not exists func CreateDirIfNotExist(path string) error {
func CreatePathIsNotExist(path string) (bool, error) { return os.MkdirAll(path, os.ModePerm)
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
// create directory
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return false, err
} else {
return true, nil
}
}
return false, err
} }
// CheckPathExist path if exist func CheckDirExist(path string) bool {
func CheckPathExist(path string) bool { f, err := os.Stat(path)
_, err := os.Stat(path) return err == nil && f.IsDir()
if err == nil { }
return true
} func CheckFileExist(path string) bool {
return false f, err := os.Stat(path)
return err == nil && !f.IsDir()
} }