/
fsmode.go
46 lines (35 loc) · 928 Bytes
/
fsmode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package filemodes
import (
"fmt"
"log"
"os"
"path"
"github.com/Toyz/GlitchyImageHTTP/core"
"github.com/kataras/iris"
)
type FSMode struct{}
func (fs *FSMode) Setup() {
if _, err := os.Stat(fs.Path()); os.IsNotExist(err) {
os.MkdirAll(fs.Path(), 0644)
}
}
func (fs *FSMode) Write(data []byte, name string) (string, string) {
physicalUploadsFolder := fs.Path()
f, _ := os.Create(path.Join(physicalUploadsFolder, name))
f.Write(data)
f.Close()
return fmt.Sprintf("/uploads/%s", name), ""
}
func (fs *FSMode) Read(path string) []byte {
return make([]byte, 0)
}
func (*FSMode) Path() string {
return core.GetEnv("FS_UPLOADS_FOLDER", fmt.Sprintf("%s%s", core.AssetsFolder(), "uploads"))
}
func (*FSMode) FullPath(_, filename string) string {
return fmt.Sprintf("/uploads/%s", filename)
}
func (fs *FSMode) StaticPath(app *iris.Application) {
log.Printf(fs.Path())
app.StaticWeb("/uploads", fs.Path())
}