package storage import ( "path" "shylinux.com/x/ice" "shylinux.com/x/icebergs/base/cli" kit "shylinux.com/x/toolkits" "shylinux.com/x/operation/src/storage/model" ) type file struct { Table order string `data:"1"` fields string `data:"title,content,size,user_uid"` upload string `name:"upload" role:"leader,worker"` create string `name:"create title* content*" role:"leader,worker"` remove string `name:"remove" role:"leader,worker"` right string `name:"right" role:"void"` } func (s file) Upload(m *ice.Message, arg ...string) { up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)) p := s.path(m, m.Option(model.STORAGE_UID), up[1]) s.ValueCreate(m, model.TITLE, m.UploadSave(p), model.CONTENT, "", model.TYPE, kit.Format(FilePath), model.SIZE, up[2]) s.DashboardUpdate(m) } func (s file) Right(m *ice.Message, arg ...string) { msg := m.Cmd(s.PrefixPortal(m), Portal{}.PlaceList, m.Option(model.USER_UID), arg[0]) m.WarnNotRight(kit.Int(msg.Append(model.USER_STORAGE_ROLE)) == 0) } func (s file) List(m *ice.Message, arg ...string) { if s.ValueList(m, arg).Display(""); len(arg) == 1 { m.Action(s.Upload) if m.Length() == 0 { m.SetResult() s.Button(m, m.Trans("please upload file", "请上传文件"), s.Upload) } } else if len(arg) == 2 { m.PushQRCode(cli.QRCODE, kit.MergeURL2(m.Option(ice.MSG_USERWEB), m.Resource(s.path(m, arg[0], m.Append(model.TITLE))))) m.EchoImages(m.Resource(s.path(m, arg[0], m.Append(model.TITLE)))) } } func init() { ice.TeamCtxCmd(file{}) } func (s file) path(m *ice.Message, arg ...string) string { return path.Join("usr/local/storage/", path.Join(arg...)) } type FileType int const ( FileBlob FileType = iota FilePath FileLink ) var FileTypeList = map[FileType]string{ FileBlob: "blob", FilePath: "path", FileLink: "link", } func (s FileType) String() string { return FileTypeList[s] }