diff --git a/routers/api/v1/repo/repo_dashbord.go b/routers/api/v1/repo/repo_dashbord.go index d5d4ceae2..0fcd70a99 100644 --- a/routers/api/v1/repo/repo_dashbord.go +++ b/routers/api/v1/repo/repo_dashbord.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "net/http" + "net/url" "os" "path" "strconv" @@ -169,7 +170,7 @@ func ServeAllProjectsPeriodStatisticsFile(ctx *context.Context) { return } - fileName := getFileName(ctx, beginTime, endTime) + fileName, frontName := getFileName(ctx, beginTime, endTime) if err := os.MkdirAll(setting.RadarMap.Path, os.ModePerm); err != nil { ctx.Error(http.StatusBadRequest, fmt.Errorf("Failed to create dir %s: %v", setting.AvatarUploadPath, err).Error()) @@ -197,20 +198,24 @@ func ServeAllProjectsPeriodStatisticsFile(ctx *context.Context) { } - ctx.ServeFile(fileName) + ctx.ServeFile(fileName, url.QueryEscape(frontName)) } -func getFileName(ctx *context.Context, beginTime time.Time, endTime time.Time) string { - baseName := setting.RadarMap.Path + "/" - if ctx.QueryTrim("type") != "" { - baseName = baseName + ctx.QueryTrim("type") + "_" - } +func getFileName(ctx *context.Context, beginTime time.Time, endTime time.Time) (string, string) { + baseName := setting.RadarMap.Path + "/项目分析_" + if ctx.QueryTrim("q") != "" { baseName = baseName + ctx.QueryTrim("q") + "_" } - baseName = baseName + beginTime.AddDate(0, 0, -1).Format(DATE_FORMAT) + "_to_" + endTime.AddDate(0, 0, -1).Format(DATE_FORMAT) + "_" + strconv.FormatInt(time.Now().Unix(), 10) + ".csv" - return baseName + if ctx.QueryTrim("type") == "all" { + baseName = baseName + "所有" + } else { + baseName = baseName + beginTime.AddDate(0, 0, -1).Format(DATE_FORMAT) + "_" + endTime.AddDate(0, 0, -1).Format(DATE_FORMAT) + } + frontName := baseName + ".csv" + localName := baseName + "_" + strconv.FormatInt(time.Now().Unix(), 10) + ".csv" + return localName, path.Base(frontName) } func ClearUnusedStatisticsFile() { @@ -230,8 +235,8 @@ func ClearUnusedStatisticsFile() { func allProjectsPeroidHeader(ctx *context.Context) []string { - return []string{ctx.Tr("repos.id"), ctx.Tr("repos.projectName"), ctx.Tr("repos.isPrivate"), ctx.Tr("repos.openi"), ctx.Tr("repos.visit"), ctx.Tr("repos.download"), ctx.Tr("repos.pr"), ctx.Tr("repos.commit"), - ctx.Tr("repos.watches"), ctx.Tr("repos.stars"), ctx.Tr("repos.forks"), ctx.Tr("repos.issues"), ctx.Tr("repos.closedIssues"), ctx.Tr("repos.contributor")} + return []string{ctx.Tr("admin.repos.id"), ctx.Tr("admin.repos.projectName"), ctx.Tr("admin.repos.isPrivate"), ctx.Tr("admin.repos.openi"), ctx.Tr("admin.repos.visit"), ctx.Tr("admin.repos.download"), ctx.Tr("admin.repos.pr"), ctx.Tr("admin.repos.commit"), + ctx.Tr("admin.repos.watches"), ctx.Tr("admin.repos.stars"), ctx.Tr("admin.repos.forks"), ctx.Tr("admin.repos.issues"), ctx.Tr("admin.repos.closedIssues"), ctx.Tr("admin.repos.contributor")} } @@ -245,9 +250,9 @@ func allProjectsPeroidValues(rs *models.RepoStatistic, ctx *context.Context) []s func getIsPrivateDisplay(private bool, ctx *context.Context) string { if private { - return ctx.Tr("repos.yes") + return ctx.Tr("admin.repos.yes") } else { - return ctx.Tr("repos.no") + return ctx.Tr("admin.repos.no") } }