~tsileo/blobstash

d62b4924ec016bd250d26f05ac5570f60374e0f2 — Thomas Sileo 2 months ago d875ca6
filetree/lua: add new upload_file Lua function
1 files changed, 12 insertions(+), 0 deletions(-)

M pkg/filetree/lua/lua.go
M pkg/filetree/lua/lua.go => pkg/filetree/lua/lua.go +12 -0
@@ 260,6 260,18 @@ func setupFileTree(ft *filetree.FileTree, bs store.BlobStore, kv store.KvStore) 
				L.Push(lua.LString(node.Hash))
				return 1
			},
			"upload_file": func(L *lua.LState) int {
				uploader := writer.NewUploader(filetree.NewBlobStoreCompat(bs, context.TODO()))
				name := L.ToString(1)
				contents := L.ToString(2)
				node, err := uploader.PutReader(name, strings.NewReader(contents), nil)
				if err != nil {
					panic(err)
				}

				L.Push(lua.LString(node.Hash))
				return 1
			},
			"put_file_at": func(L *lua.LState) int {
				uploader := writer.NewUploader(filetree.NewBlobStoreCompat(bs, context.TODO()))
				snap := toSnap(luautil.TableToMap(L.ToTable(1)))