mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2024-12-22 10:08:08 +00:00
init
This commit is contained in:
commit
52007d940e
4
.env
Normal file
4
.env
Normal file
@ -0,0 +1,4 @@
|
||||
# something like this ->
|
||||
# https://domain.tld
|
||||
CHIBISAFE_BASEPATH=
|
||||
HOST=
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
uploads
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module github.com/minoplhy/chibisafe_netstorage_middleman
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/joho/godotenv v1.5.1
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
170
src/handler/chibisafe.go
Normal file
170
src/handler/chibisafe.go
Normal file
File diff suppressed because it is too large
Load Diff
60
src/handler/file.go
Normal file
60
src/handler/file.go
Normal file
@ -0,0 +1,60 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetTempFilename(Filename string) string {
|
||||
filename := fmt.Sprintf("./uploads/%d%s", time.Now().UnixNano(), filepath.Ext(Filename))
|
||||
return filename
|
||||
}
|
||||
|
||||
func SaveFile(filename string, file multipart.File) error {
|
||||
err := os.MkdirAll("./uploads", os.ModePerm)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
dst, err := os.Create(filename)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer dst.Close()
|
||||
|
||||
// Copy the uploaded file to the filesystem
|
||||
// at the specified destination
|
||||
_, err = io.Copy(dst, file)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteFile(filePath string) error {
|
||||
err := os.Remove(filePath)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DiscardFile(file multipart.File) error {
|
||||
// Clear the data from memory
|
||||
_, err := io.Copy(io.Discard, file)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user