-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: support import theme from git repo #271
Conversation
@golangboy Well done!
|
主题的下载需要适配多种实现,可以看下MultipartZipThemeFetcher 这个 |
@1379 我发现这个函数的主题是下载到系统的临时目录的 func (t *themeServiceImpl) UploadTheme(ctx context.Context, file *multipart.FileHeader) (*dto.ThemeProperty, error) {
themeProperty, err := t.MultipartZipThemeFetcher.FetchTheme(ctx, file)
if err != nil {
return nil, err
}
return t.addTheme(ctx, themeProperty)
} func (m *multipartZipThemeFetcherImpl) FetchTheme(ctx context.Context, file interface{}) (*dto.ThemeProperty, error) {
themeFileHeader, ok := file.(*multipart.FileHeader)
if !ok {
return nil, xerr.WithStatus(nil, xerr.StatusBadRequest).WithMsg("not support")
}
tempDir := os.TempDir()
... 临时目录是临时存放文件目录的,随时可能被清除,其实可以在上层获取到主题的存放目录 func (t *themeServiceImpl) UploadTheme(ctx context.Context, file *multipart.FileHeader) (*dto.ThemeProperty, error) {
// 这里可以通过t.Config.Sonic.ThemeDir获取主题目录
themeProperty, err := t.MultipartZipThemeFetcher.FetchTheme(ctx, file)
if err != nil {
return nil, err
}
return t.addTheme(ctx, themeProperty)
} |
@golangboy themeFetcher 只负责下载主题,并不关心主题的存放位置。addTheme方法会把临时目录的主题Copy到主题目录下的 |
用策略模式去实现更优吧? |
|
我看到其中有一个lint error是这样的
我查了一下 depguard ,发现是依赖一个文件.depguard.yml 但是项目里似乎是没有的? |
@golangboy 那就先忽略掉这个错误吧。 |
可能是我之前的命名误导你了,抱歉 :) type MultipartZipThemeFetcher interface {
FetchTheme(ctx context.Context, file interface{}) (*dto.ThemeProperty, error)
} 应该改成 type ThemeFetcher interface {
FetchTheme(ctx context.Context, file interface{}) (*dto.ThemeProperty, error)
} 对应的,新的GitThemeFetcher也应该去实现这个接口,你觉得如何。 |
|
||
diskFilePath := filepath.Join(tempDir, fileName) | ||
if util.FileIsExisted(diskFilePath) { | ||
err = os.Remove(diskFilePath) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
} | ||
} | ||
|
||
diskFile, err := os.OpenFile(diskFilePath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o444) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
if err == nil && themeProperty != nil { | ||
return themeProperty, nil | ||
} | ||
dirEntrys, err := os.ReadDir(dest) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression
Bravo! |
Awesome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
use rebase instead of merge |
没理解 |
这里是指git 操作。我来操作也可以的 |
Done! |
支持从git仓库clone主题