diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c43d0c7..ec9890f 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,10 @@
-
+
+
+
@@ -36,33 +38,33 @@
- {
+ "keyToString": {
+ "DefaultGoTemplateProperty": "Go File",
+ "Go Build.Backend.executor": "Debug",
+ "Go 构建.Backend.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.go.formatter.settings.were.checked": "true",
+ "RunOnceActivity.go.migrated.go.modules.settings": "true",
+ "RunOnceActivity.go.modules.automatic.dependencies.download": "true",
+ "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
+ "git-widget-placeholder": "master",
+ "go.import.settings.migrated": "true",
+ "go.sdk.automatically.set": "true",
+ "last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/grpc",
+ "node.js.detected.package.eslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "run.code.analysis.last.selected.profile": "pProject Default",
+ "settings.editor.selected.configurable": "preferences.pluginManager",
+ "vue.rearranger.settings.migration": "true"
},
- "keyToStringList": {
- "DatabaseDriversLRU": [
- "postgresql"
+ "keyToStringList": {
+ "DatabaseDriversLRU": [
+ "postgresql"
]
}
-}]]>
+}
@@ -131,7 +133,8 @@
-
+
+
true
@@ -140,14 +143,9 @@
- file://$PROJECT_DIR$/pkg/internal/services/recycler.go
- 45
-
-
-
- file://$PROJECT_DIR$/pkg/internal/services/recycler.go
- 40
-
+ file://$PROJECT_DIR$/pkg/internal/services/attachments.go
+ 62
+
diff --git a/pkg/internal/services/attachments.go b/pkg/internal/services/attachments.go
index 00cf60c..0415a68 100644
--- a/pkg/internal/services/attachments.go
+++ b/pkg/internal/services/attachments.go
@@ -60,8 +60,8 @@ func CacheAttachment(id uint, item models.Attachment) {
}
func NewAttachmentMetadata(tx *gorm.DB, user models.Account, file *multipart.FileHeader, attachment models.Attachment) (models.Attachment, error) {
- attachment.Rid = RandString(16)
attachment.Uuid = uuid.NewString()
+ attachment.Rid = RandString(16)
attachment.Size = file.Size
attachment.Name = file.Filename
attachment.AccountID = user.ID
diff --git a/pkg/internal/services/random_id.go b/pkg/internal/services/random_id.go
index b341c30..5c44a4d 100644
--- a/pkg/internal/services/random_id.go
+++ b/pkg/internal/services/random_id.go
@@ -2,30 +2,14 @@ package services
import (
"math/rand"
- "strings"
)
-const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
-const (
- letterIdxBits = 6
- letterIdxMask = 1<= 0; {
- if remain == 0 {
- cache, remain = rand.Int63(), letterIdxMax
- }
- if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
- builder.WriteByte(letterBytes[idx])
- idx--
- }
- cache >>= letterIdxBits
- remain--
+ builder := make([]rune, length)
+ for i := range builder {
+ builder[i] = letters[rand.Intn(len(letters))]
}
-
- return builder.String()
+ return string(builder)
}
diff --git a/pkg/internal/services/recycler.go b/pkg/internal/services/recycler.go
index 4134d71..28d4e5f 100644
--- a/pkg/internal/services/recycler.go
+++ b/pkg/internal/services/recycler.go
@@ -51,7 +51,8 @@ func RunMarkDeletionTask() {
for _, pool := range pendingPools {
lifecycle := fmt.Sprintf("%d seconds", *pool.Config.Data().ExistLifecycle)
tx := database.C.
- Where("pool_id = ? AND created_at < NOW() - INTERVAL ?", pool.ID, lifecycle).
+ Where("pool_id = ?", pool.ID).
+ Where("created_at < NOW() - INTERVAL ?", lifecycle).
Updates(&models.Attachment{CleanedAt: lo.ToPtr(time.Now())})
log.Info().
Str("pool", pool.Alias).