dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 7938d5efb9c36df047f30e24b36e2d4cbf062d9a
parent e1dd391c69fbeac12434b7a717af714e4595bbf6
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  6 Jun 2023 00:45:07 -0700

move code

Diffstat:
Mpkg/web/handlers/api/v1/topBarHandler.go | 70+++++++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go @@ -1099,6 +1099,27 @@ func extractPGPMessage(html string) (out string) { return out } +func convertNewLines(html string, canUseMultiline bool) string { + if !canUseMultiline { + html = strings.ReplaceAll(html, "\n", "") + } + return html +} + +func convertPGPClearsignToFile(db *database.DkfDB, html string, authUserID database.UserID) string { + if b, _ := clearsign.Decode([]byte(html)); b != nil { + startIdx := strings.Index(html, pgpSignedPrefix) + endIdx := strings.Index(html, pgpSignedSuffix) + tmp := html[startIdx : endIdx+len(pgpSignedSuffix)] + upload, _ := db.CreateUpload("pgp_clearsign.txt", []byte(tmp), authUserID) + msgBefore := html[0:startIdx] + msgAfter := html[endIdx+len(pgpSignedSuffix):] + html = msgBefore + ` [` + upload.GetHTMLLink() + `] ` + msgAfter + html = strings.TrimSpace(html) + } + return html +} + // Auto convert pasted pgp message into uploaded file func convertPGPMessageToFile(db *database.DkfDB, html string, authUserID database.UserID) string { startIdx := strings.Index(html, pgpPrefix) @@ -1137,21 +1158,21 @@ func convertPGPPublicKeyToFile(db *database.DkfDB, html string, authUserID datab return html } -func convertNewLines(html string, canUseMultiline bool) string { - if !canUseMultiline { - html = strings.ReplaceAll(html, "\n", "") - } - return html -} - -func convertPGPClearsignToFile(db *database.DkfDB, html string, authUserID database.UserID) string { - if b, _ := clearsign.Decode([]byte(html)); b != nil { - startIdx := strings.Index(html, pgpSignedPrefix) - endIdx := strings.Index(html, pgpSignedSuffix) - tmp := html[startIdx : endIdx+len(pgpSignedSuffix)] - upload, _ := db.CreateUpload("pgp_clearsign.txt", []byte(tmp), authUserID) +// Auto convert pasted age message into uploaded file +func convertAgeMessageToFile(db *database.DkfDB, html string, authUserID database.UserID) string { + startIdx := strings.Index(html, agePrefix) + endIdx := strings.Index(html, ageSuffix) + if startIdx != -1 && endIdx != -1 { + tmp := html[startIdx : endIdx+len(ageSuffix)] + tmp = strings.TrimSpace(tmp) + tmp = strings.TrimPrefix(tmp, agePrefix) + tmp = strings.TrimSuffix(tmp, ageSuffix) + tmp = strings.Join(strings.Split(tmp, " "), "\n") + tmp = agePrefix + tmp + tmp += ageSuffix + upload, _ := db.CreateUpload("age.txt", []byte(tmp), authUserID) msgBefore := html[0:startIdx] - msgAfter := html[endIdx+len(pgpSignedSuffix):] + msgAfter := html[endIdx+len(ageSuffix):] html = msgBefore + ` [` + upload.GetHTMLLink() + `] ` + msgAfter html = strings.TrimSpace(html) } @@ -1195,24 +1216,3 @@ func convertInlinePGPPublicKey(inlinePKey string) string { inlinePKey = pgpPKeyPrefix + "\n" + commentsStr + key + "\n" + pgpPKeySuffix return inlinePKey } - -// Auto convert pasted age message into uploaded file -func convertAgeMessageToFile(db *database.DkfDB, html string, authUserID database.UserID) string { - startIdx := strings.Index(html, agePrefix) - endIdx := strings.Index(html, ageSuffix) - if startIdx != -1 && endIdx != -1 { - tmp := html[startIdx : endIdx+len(ageSuffix)] - tmp = strings.TrimSpace(tmp) - tmp = strings.TrimPrefix(tmp, agePrefix) - tmp = strings.TrimSuffix(tmp, ageSuffix) - tmp = strings.Join(strings.Split(tmp, " "), "\n") - tmp = agePrefix + tmp - tmp += ageSuffix - upload, _ := db.CreateUpload("age.txt", []byte(tmp), authUserID) - msgBefore := html[0:startIdx] - msgAfter := html[endIdx+len(ageSuffix):] - html = msgBefore + ` [` + upload.GetHTMLLink() + `] ` + msgAfter - html = strings.TrimSpace(html) - } - return html -}