Skip to content

Commit 37bfbc0

Browse files
committed
fix: some error
1 parent 32088cc commit 37bfbc0

File tree

9 files changed

+47
-66
lines changed

9 files changed

+47
-66
lines changed

ent/envelope/envelope.go

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/envelope_create.go

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/envelope_update.go

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/runtime.go

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/schema/envelope.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func (Envelope) Fields() []ent.Field {
1818
return []ent.Field{
1919
field.String("to").NotEmpty(),
2020
field.String("from").NotEmpty(),
21-
field.String("subject").NotEmpty().Default("no subject"),
22-
field.String("content").NotEmpty().Default("no content"),
21+
field.String("subject").Default("no subject"),
22+
field.String("content").Default("no content"),
2323
field.Time("created_at").Default(time.Now),
2424
}
2525
}

internal/api/report.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func saveAttachment(ctx *Context, attachments []*enmime.Part, to string, ownerID
6666
}
6767

6868
_, err := ctx.ent.Attachment.Create().
69-
SetID(filepath.Base(dir) + name[:16]).
69+
SetID(filepath.Base(dir) + name[:6] + utils.RandomStr(4)).
7070
SetFilename(a.FileName).
7171
SetFilepath(fp).
7272
SetContentType(a.ContentType).

internal/utils/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,29 @@ package utils
33
import (
44
"crypto/md5"
55
"encoding/hex"
6+
"math/rand/v2"
7+
"unsafe"
68
)
79

810
func Md5(str string) string {
911
h := md5.New()
1012
h.Write([]byte(str))
1113
return hex.EncodeToString(h.Sum(nil))
1214
}
15+
16+
func RandomStr(length int) string {
17+
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
18+
b := make([]byte, length)
19+
for i := range b {
20+
b[i] = charset[rand.IntN(len(charset))]
21+
}
22+
return Bytes2Str(b)
23+
}
24+
25+
func Str2Bytes(str string) []byte {
26+
return unsafe.Slice(unsafe.StringData(str), len(str))
27+
}
28+
29+
func Bytes2Str(b []byte) string {
30+
return unsafe.String(unsafe.SliceData(b), len(b))
31+
}

web/bun.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)