From 226654290ed98a28ed04111a5f92e2dea4214040 Mon Sep 17 00:00:00 2001 From: JustSong Date: Mon, 19 Dec 2022 17:03:21 +0800 Subject: [PATCH] :tada: show text abstract for plain text --- common/constants.go | 1 + controller/file.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index cd1ccc7..806f45c 100644 --- a/common/constants.go +++ b/common/constants.go @@ -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 diff --git a/controller/file.go b/controller/file.go index 8cb21df..f11596a 100644 --- a/controller/file.go +++ b/controller/file.go @@ -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()))