]> Sergey Matveev's repositories - uploader.git/blobdiff - main.go
Raise copyright years
[uploader.git] / main.go
diff --git a/main.go b/main.go
index e31ae19cbf3839f45cbc5b095e29d3b45a814677..af1add3ffdecb9889168a55aba70f54bf54855a7 100644 (file)
--- a/main.go
+++ b/main.go
@@ -1,19 +1,17 @@
-/*
-uploader -- simplest form file uploader
-Copyright (C) 2018-2022 Sergey Matveev <stargrave@stargrave.org>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// uploader -- simplest form file uploader
+// Copyright (C) 2018-2025 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package main
 
@@ -26,7 +24,6 @@ import (
        "fmt"
        "html/template"
        "io"
-       "io/ioutil"
        "log"
        "mime"
        "net"
@@ -38,10 +35,10 @@ import (
        "sync"
        "time"
 
-       "go.cypherpunks.ru/recfile"
-       "go.cypherpunks.ru/tai64n/v2"
-       "golang.org/x/crypto/blake2b"
+       "go.cypherpunks.su/recfile/v2"
+       "go.cypherpunks.su/tai64n/v4"
        "golang.org/x/net/netutil"
+       "lukechampine.com/blake3"
 )
 
 const (
@@ -58,7 +55,7 @@ var (
 Example command line usage:
 <pre>
 $ curl -F file=@somedata.tar.gpg [-F comment="optional comment"] http://.../upload/
-$ b2sum somedata.tar.gpg # to verify BLAKE2b-512 checksum
+$ b3sum somedata.tar.gpg # to verify BLAKE3-256 checksum
 </pre>
 <form enctype="multipart/form-data" action="/upload/" method="post">
 <label for="file">File to upload:</label><br/>
@@ -94,14 +91,10 @@ func upload(w http.ResponseWriter, r *http.Request) {
                log.Println(r.RemoteAddr, "non file form field")
                return
        }
-       h, err := blake2b.New512(nil)
-       if err != nil {
-               panic(err)
-       }
        t := time.Now()
-       ts := new(tai64n.TAI64N)
+       var ts tai64n.TAI64N
        ts.FromTime(t)
-       tai := tai64n.Encode(ts[:])[1:]
+       tai := ts.Encode()[1:]
        fnOrig := p.FileName()
        fd, err := os.OpenFile(tai+".part", os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666)
        if err != nil {
@@ -109,6 +102,7 @@ func upload(w http.ResponseWriter, r *http.Request) {
                return
        }
        fdBuf := bufio.NewWriterSize(fd, WriteBufSize)
+       h := blake3.New(32, nil)
        mw := io.MultiWriter(fdBuf, h)
        n, err := io.Copy(mw, p)
        if err != nil {
@@ -167,14 +161,14 @@ func upload(w http.ResponseWriter, r *http.Request) {
        var commentLines []string
        p, err = mr.NextPart()
        if err == nil && p.FormName() == CommentFieldName {
-               comment, err := ioutil.ReadAll(p)
+               comment, err := io.ReadAll(p)
                if err == nil && len(comment) > 0 {
                        commentLines = strings.Split(string(comment), "\n")
                        wr.WriteFieldMultiline("Comment", commentLines)
                }
        }
 
-       ioutil.WriteFile(tai+".rec", rec.Bytes(), os.FileMode(0666))
+       os.WriteFile(tai+".rec", rec.Bytes(), os.FileMode(0666))
        if *NotifyToAddr == "" {
                return
        }