This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
/
upload.go
120 lines (107 loc) · 3.27 KB
/
upload.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package controller
import (
"net/http"
"net/url"
"os"
"path/filepath"
"github.com/GoAdminGroup/filemanager/guard"
"github.com/GoAdminGroup/filemanager/modules/language"
"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/modules/file"
)
func (h *Handler) Upload(ctx *context.Context) {
param := guard.GetUploadParam(ctx)
for k := range param.Files {
for _, fileObj := range param.Files[k] {
err := file.SaveMultipartFile(fileObj, filepath.FromSlash(param.FullPath+"/"+fileObj.Filename))
if err != nil {
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"code": http.StatusInternalServerError,
"msg": err.Error(),
})
}
}
}
ctx.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"msg": language.GetHTML("upload success"),
})
}
func (h *Handler) CreateDirPopUp(ctx *context.Context) {
var (
popupID = ctx.FormValue("popup_id")
path, _ = url.QueryUnescape(ctx.Query("path"))
prefix = h.Prefix(ctx)
)
popupForm := `<form>
<div class="form-group">
<input type="text" class="form-control" placeholder="` + language.Get("input name") + `" id="dir_name_input">
</div>
</form>
<script>
$('#` + popupID + ` button.btn.btn-primary').on('click', function (event) {
NProgress.start();
$.ajax({
method: 'post',
url: "` + GetUrl(prefix, "/create/dir") + `",
data: {
name: $('#dir_name_input').val(),
path: "` + path + `"
},
success: function (data) {
NProgress.done();
if (typeof (data) === "string") {
data = JSON.parse(data);
}
$('#` + popupID + `').hide();
$('.modal-backdrop.fade.in').hide();
if (data.code === 0) {
swal(data.msg, '', 'success');
$.pjax.reload('#pjax-container');
} else {
swal(data.msg, '', 'error');
}
},
error: function (data) {
NProgress.done();
if (data.responseText !== "") {
swal(data.responseJSON.msg, '', 'error');
} else {
swal('error', '', 'error');
}
setTimeout(function() {
$('#` + popupID + `').hide();
$('.modal-backdrop.fade.in').hide();
}, 500)
},
});
})
</script>`
ctx.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"msg": "ok",
"data": popupForm,
})
}
func (h *Handler) CreateDir(ctx *context.Context) {
param := guard.GetCreateDirParam(ctx)
if param.Error != nil {
ctx.JSON(http.StatusBadRequest, map[string]interface{}{
"code": http.StatusBadRequest,
"msg": param.Error.Error(),
})
return
}
err := os.MkdirAll(filepath.FromSlash(param.Dir), os.ModePerm)
if err != nil {
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"code": http.StatusInternalServerError,
"msg": err.Error(),
})
return
}
ctx.JSON(http.StatusOK, map[string]interface{}{
"code": 0,
"msg": language.Get("create success"),
})
}