dkforest

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

commit 0229bf2cb91140e3698e9f856eb23bf6309bb6e0
parent c2cbb2309e4e1f3b999fd77974d1671db29cb879
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 24 Jun 2023 16:36:20 -0700

remove deprecated code

Diffstat:
Mcmd/highlight/main.go | 6+++---
Mpkg/database/tableMemes.go | 3+--
Mpkg/database/tableUploads.go | 11+++++++----
Mpkg/utils/utils.go | 3+--
Mpkg/web/handlers/handlers.go | 5++---
Mpkg/web/handlers/interceptors/uploadInterceptor.go | 4++--
Mpkg/web/handlers/settings.go | 3+--
7 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/cmd/highlight/main.go b/cmd/highlight/main.go @@ -3,7 +3,7 @@ package main import ( "bytes" "flag" - "io/ioutil" + "os" "github.com/alecthomas/chroma/formatters/html" "github.com/alecthomas/chroma/lexers" @@ -14,7 +14,7 @@ func main() { var fileName string flag.StringVar(&fileName, "f", "", "File name") flag.Parse() - by, err := ioutil.ReadFile(fileName) + by, err := os.ReadFile(fileName) if err != nil { panic(err) } @@ -27,5 +27,5 @@ func main() { out := buf.Bytes() out = bytes.ReplaceAll(out, []byte("{{"), []byte("&#123;&#123;")) out = bytes.ReplaceAll(out, []byte("}}"), []byte("&#125;&#125;")) - _ = ioutil.WriteFile("output.html", out, 0644) + _ = os.WriteFile("output.html", out, 0644) } diff --git a/pkg/database/tableMemes.go b/pkg/database/tableMemes.go @@ -5,7 +5,6 @@ import ( "dkforest/pkg/utils" html2 "html" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -85,7 +84,7 @@ func (d *DkfDB) CreateEncryptedMemeWithSize(fileName string, content []byte, siz func (d *DkfDB) createMemeWithSize(fileName string, content []byte, size int64) (*Meme, error) { newFileName := utils.MD5([]byte(utils.GenerateToken32())) - if err := ioutil.WriteFile(filepath.Join(config.Global.ProjectMemesPath(), newFileName), content, 0644); err != nil { + if err := os.WriteFile(filepath.Join(config.Global.ProjectMemesPath(), newFileName), content, 0644); err != nil { return nil, err } meme := Meme{ diff --git a/pkg/database/tableUploads.go b/pkg/database/tableUploads.go @@ -5,7 +5,6 @@ import ( "dkforest/pkg/utils" html2 "html" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -81,7 +80,7 @@ func (d *DkfDB) CreateEncryptedUploadWithSize(fileName string, content []byte, u func (d *DkfDB) createUploadWithSize(fileName string, content []byte, userID UserID, size int64) (*Upload, error) { newFileName := utils.MD5([]byte(utils.GenerateToken32())) - if err := ioutil.WriteFile(filepath.Join(config.Global.ProjectUploadsPath(), newFileName), content, 0644); err != nil { + if err := os.WriteFile(filepath.Join(config.Global.ProjectUploadsPath(), newFileName), content, 0644); err != nil { return nil, err } upload := Upload{ @@ -128,13 +127,17 @@ func (d *DkfDB) DeleteOldUploads() { if err := d.db.Exec(`DELETE FROM uploads WHERE created_at < date('now', '-1 Day')`).Error; err != nil { logrus.Error(err.Error()) } - fileInfo, err := ioutil.ReadDir(config.Global.ProjectUploadsPath()) + entries, err := os.ReadDir(config.Global.ProjectUploadsPath()) if err != nil { logrus.Error(err.Error()) return } now := time.Now() - for _, info := range fileInfo { + for _, entry := range entries { + info, err := entry.Info() + if err != nil { + continue + } if diff := now.Sub(info.ModTime()); diff > 24*time.Hour { if err := os.Remove(filepath.Join(config.Global.ProjectUploadsPath(), info.Name())); err != nil { logrus.Error(err.Error()) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go @@ -34,7 +34,6 @@ import ( "image/jpeg" "image/png" "io" - "io/ioutil" "log" "math/rand" "net" @@ -499,7 +498,7 @@ func PgpDecryptMessage(secretKey, msg string) (string, error) { logrus.Error(err) return "", errors.New("unable to read message") } - by, err := ioutil.ReadAll(md.UnverifiedBody) + by, err := io.ReadAll(md.UnverifiedBody) if err != nil { return "", err } diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -23,7 +23,6 @@ import ( "image" _ "image/gif" "image/png" - "io/ioutil" "net/http" "net/url" "os" @@ -509,7 +508,7 @@ func getDownloadableFiles(folder, fileNamePrefix string) (out []downloadableFile return nil } if !strings.HasSuffix(info.Name(), ".checksum") { - checksumBytes, err := ioutil.ReadFile(path + ".checksum") + checksumBytes, err := os.ReadFile(path + ".checksum") if err != nil { return nil } @@ -542,7 +541,7 @@ func getTorchessDownloadableFiles(folder, fileNamePrefix string) (out []download return nil } if !strings.HasSuffix(info.Name(), ".checksum") { - checksumBytes, err := ioutil.ReadFile(path + ".checksum") + checksumBytes, err := os.ReadFile(path + ".checksum") if err != nil { return nil } diff --git a/pkg/web/handlers/interceptors/uploadInterceptor.go b/pkg/web/handlers/interceptors/uploadInterceptor.go @@ -11,7 +11,7 @@ import ( "github.com/asaskevich/govalidator" "github.com/dustin/go-humanize" "github.com/sirupsen/logrus" - "io/ioutil" + "io" "mime/multipart" ) @@ -52,7 +52,7 @@ func handleUploadedFile(db *database.DkfDB, file multipart.File, handler *multip origFileName = tz1Rgx.ReplaceAllString(origFileName, "xxxx-xx-xx xx-xx-xx") origFileName = tz3Rgx.ReplaceAllString(origFileName, "xxxx-xx-xx xxxxxx") origFileName = tz4Rgx.ReplaceAllString(origFileName, "xxxx-xx-xx_xx_xx_xx") - fileBytes, err := ioutil.ReadAll(file) + fileBytes, err := io.ReadAll(file) if err != nil { return nil, err } diff --git a/pkg/web/handlers/settings.go b/pkg/web/handlers/settings.go @@ -19,7 +19,6 @@ import ( "github.com/sirupsen/logrus" "image" "io" - "io/ioutil" "net/http" "regexp" "sort" @@ -310,7 +309,7 @@ func changeAvatarForm(c echo.Context, data settingsAccountData) error { data.ErrorAvatar = fmt.Sprintf("The maximum file size for avatars is %s", humanize.Bytes(config.MaxAvatarSize)) return c.Render(http.StatusOK, "settings.account", data) } - fileBytes, err := ioutil.ReadAll(file) + fileBytes, err := io.ReadAll(file) if err != nil { data.ErrorAvatar = err.Error() return c.Render(http.StatusOK, "settings.account", data)