Skip to content

Commit

Permalink
🎉 show text abstract for plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Dec 19, 2022
1 parent 662114c commit 2266542
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var Version = "v0.0.0"
var OptionMap map[string]string

var ItemsPerPage = 10
var AbstractTextLength = 40

var ExplorerCacheEnabled = false // After my test, enable this will make the server slower...
var ExplorerCacheTimeout = 600 // Second
Expand Down
5 changes: 4 additions & 1 deletion controller/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func UploadFile(c *gin.Context) {
c.String(http.StatusInternalServerError, fmt.Sprintf("failed to write text to file: %s", err.Error()))
return
}
description = fmt.Sprintf("纯文本分享,创建于:%s", currentTime)
descriptionRune := []rune(description)
if len(descriptionRune) > common.AbstractTextLength {
description = fmt.Sprintf("内容摘要:%s...", string(descriptionRune[:common.AbstractTextLength]))
}
} else {
if err := c.SaveUploadedFile(file, savePath); err != nil {
c.String(http.StatusInternalServerError, fmt.Sprintf("failed to save uploaded file: %s", err.Error()))
Expand Down

0 comments on commit 2266542

Please sign in to comment.