From 6fc5cbde02f66c16973d820112a136388b9a0b7a Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 4 Feb 2025 12:01:02 +0800 Subject: [PATCH] add publish --- base/web/cache.go | 20 +++++++++------ core/code/publish/client.go | 34 +++++++++++++++++++++++++ core/code/publish/client.js | 14 +++++++++++ core/code/publish/server.go | 49 ++++++++++++++++++++++++++++++++++++ core/code/publish/trans.json | 10 ++++++++ 5 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 core/code/publish/client.go create mode 100644 core/code/publish/client.js create mode 100644 core/code/publish/server.go create mode 100644 core/code/publish/trans.json diff --git a/base/web/cache.go b/base/web/cache.go index 8ed967b2..a4630e10 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -176,11 +176,14 @@ func init() { action.Hand = ice.MergeHand(func(m *ice.Message, arg ...string) { up := Upload(m) m.Assert(len(up) > 1) - if m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Table(func(value ice.Maps) { m.Options(value) }).Length() == 0 { + msg := m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)) + // if m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Table(func(value ice.Maps) { m.Options(value) }).Length() == 0 { + if msg.Length() == 0 { SpideCache(m.Spawn(), m.MergeLink(SHARE_CACHE+up[0])) } - if m.Options(mdb.HASH, up[0], mdb.NAME, up[1]); watch { - m.Cmdy(CACHE, WATCH, m.Option(mdb.HASH), path.Join(m.Option(nfs.PATH), up[1])) + // if m.Options(mdb.HASH, up[0], mdb.NAME, up[1]); watch { + if watch { + m.Cmdy(CACHE, WATCH, up[0], path.Join(msg.Append(nfs.PATH), up[1])) } }, action.Hand) } @@ -188,12 +191,13 @@ func init() { } func Upload(m *ice.Message) []string { if up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)); len(up) == 1 { - if m.Cmdy(CACHE, UPLOAD).Optionv(ice.MSG_UPLOAD, kit.Simple(m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))); m.Option(ice.MSG_USERPOD) != "" { - if nfs.Exists(m, "usr/local/work/"+m.Option(ice.MSG_USERPOD)) { - m.Cmd(nfs.LINK, path.Join("usr/local/work/"+m.Option(ice.MSG_USERPOD), m.Append(nfs.FILE)), m.Append(nfs.FILE)) - m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), CACHE, mdb.CREATE, m.AppendSimple(mdb.NAME, mdb.TEXT, nfs.FILE, nfs.SIZE)) + msg := m.Cmd(CACHE, UPLOAD) + if m.Optionv(ice.MSG_UPLOAD, kit.Simple(msg.Append(mdb.HASH), msg.Append(mdb.NAME), msg.Append(nfs.SIZE))); m.Option(ice.MSG_USERPOD) != "" { + if nfs.Exists(m, nfs.USR_LOCAL_WORK+m.Option(ice.MSG_USERPOD)) { + m.Cmd(nfs.LINK, path.Join(nfs.USR_LOCAL_WORK+m.Option(ice.MSG_USERPOD), msg.Append(nfs.FILE)), msg.Append(nfs.FILE)) + m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), CACHE, mdb.CREATE, msg.AppendSimple(mdb.NAME, mdb.TEXT, nfs.FILE, nfs.SIZE)) } else { - m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, tcp.PublishLocalhost(m, m.MergeLink(PP(SHARE, CACHE, m.Append(mdb.HASH))))) + m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, tcp.PublishLocalhost(m, m.MergeLink(PP(SHARE, CACHE, msg.Append(mdb.HASH))))) } } return kit.Simple(m.Optionv(ice.MSG_UPLOAD)) diff --git a/core/code/publish/client.go b/core/code/publish/client.go new file mode 100644 index 00000000..64295650 --- /dev/null +++ b/core/code/publish/client.go @@ -0,0 +1,34 @@ +package publish + +import ( + "path" + + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + "shylinux.com/x/icebergs/base/web" +) + +type client struct { + list string `name:"list client.name auto" help:"软件包"` +} + +func (s client) List(m *ice.Message, arg ...string) { + if len(arg) == 0 { + m.Cmd(web.SPIDE).Table(func(value ice.Maps) { + if value[web.CLIENT_TYPE] == nfs.REPOS { + m.PushRecord(value, mdb.ICONS, web.CLIENT_NAME) + } + }) + m.Display("") + } else { + m.SplitIndex(m.Cmdx(web.SPIDE, arg[0], "/c/"+m.Prefix("server"))) + m.PushAction(s.Download) + } +} +func (s client) Download(m *ice.Message, arg ...string) { + name := path.Base(m.Option(nfs.PATH)) + m.Cmd(web.SPIDE, m.Option(web.CLIENT_NAME), web.SPIDE_SAVE, nfs.USR+name, "/publish/"+name) +} + +func init() { ice.Cmd("web.code.publish.client", client{}) } diff --git a/core/code/publish/client.js b/core/code/publish/client.js new file mode 100644 index 00000000..ba89489a --- /dev/null +++ b/core/code/publish/client.js @@ -0,0 +1,14 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { + can.ui = can.onappend.layout(can) + msg.Table(function(value) { + can.onimport.item(can, {icons: value.icons, name: value["client.name"]}, function(event, item) { + if (can.onmotion.cache(can, function() { return item.name }, can.ui.content)) { return } + can.run(event, [item.name], function(msg) { + can.onappend.table(can, msg, null, can.ui.content) + + }) + }) + }) + }, +}) \ No newline at end of file diff --git a/core/code/publish/server.go b/core/code/publish/server.go new file mode 100644 index 00000000..260c331d --- /dev/null +++ b/core/code/publish/server.go @@ -0,0 +1,49 @@ +package publish + +import ( + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" +) + +type server struct { + ice.Hash + short string `data:"name"` + field string `data:"time,name*,text,path,version*,compile,runtime,os,cpu"` + list string `name:"list name auto" help:"软件源" role:"void"` +} + +func (s server) Inputs(m *ice.Message, arg ...string) { + switch arg[0] { + case "path": + m.Cmdy(nfs.DIR, nfs.USR_PUBLISH, nfs.PATH) + case "compile": + m.Push(arg[0], "go") + m.Push(arg[0], "javac") + case "runtime": + m.Push(arg[0], "python") + m.Push(arg[0], "java") + m.Push(arg[0], "php") + case "os": + m.Push(arg[0], "Linux") + m.Push(arg[0], "macOS") + m.Push(arg[0], "Windows") + case "cpu": + m.Push(arg[0], "amd64") + m.Push(arg[0], "x86") + m.Push(arg[0], "arm") + m.Push(arg[0], "arm64") + default: + s.Hash.Inputs(m, arg...) + } +} +func (s server) Upload(m *ice.Message, arg ...string) { + s.Modify(m, mdb.NAME, m.Option(mdb.NAME), nfs.PATH, m.UploadSave(nfs.USR_PUBLISH)) +} +func (s server) List(m *ice.Message, arg ...string) { + if s.Hash.List(m, arg...); m.IsTech() { + m.PushAction(s.Detail, s.Upload, s.Remove) + } +} + +func init() { ice.Cmd("web.code.publish.server", server{}) } diff --git a/core/code/publish/trans.json b/core/code/publish/trans.json new file mode 100644 index 00000000..f2365775 --- /dev/null +++ b/core/code/publish/trans.json @@ -0,0 +1,10 @@ +{ + "icons": {}, + "input": { + "compile": "编译器", + "runtime": "运行时", + "os": "操作系统", + "cpu": "芯片架构" + }, + "value": {} +} \ No newline at end of file