The Space API provides functions for interacting with pages, documents, and files in the space.
Returns a list of all pages in the space.
Example:
local pages = space.listPages()
for page in each(pages) do
print(page.name)
end
Reads the content of a page.
Example:
local content = space.readPage("welcome")
print(content) -- prints the content of the "welcome" page
Gets metadata for a specific page.
Example:
local meta = space.getPageMeta("welcome")
print(meta.name, meta.lastModified) -- prints page name and last modified date
Writes content to a page.
Example:
local meta = space.writePage("notes", "My new note content")
print("Page updated at: " .. meta.lastModified)
Deletes a page from the space.
Example:
space.deletePage("old-notes")
Checks if a page exists in the space.
Example:
if space.pageExists("Hello") then
print("Page exists!")
else
print("Page not found")
end
# Document Operations
## space.listDocuments()
Returns a list of all documents in the space.
Example:
```lua
local documents = space.listDocuments()
for doc in each(documents) do
print(doc.name, doc.size)
end
Reads the content of a document.
Example:
local data = space.readDocument("image.png")
print("Document size: " .. #data .. " bytes")
Writes binary data to a document.
Example:
local binaryData = string.char(72, 69, 76, 76, 79) -- "HELLO" in binary
local meta = space.writeDocument("test.bin", binaryData)
print("Document saved with size: " .. meta.size)
Deletes a document from the space.
Example:
space.deleteDocument("old-image.png")
Returns a list of all files in the space.
Example:
local files = space.listFiles()
for _, file in ipairs(files) do
print(file.name, file.size)
end
Gets metadata for a specific file.
Example:
local meta = space.getFileMeta("document.txt")
print(meta.name, meta.modified, meta.size)
Reads the content of a file.
Example:
local content = space.readFile("document.txt")
print("File size: " .. #content .. " bytes")
Writes binary data to a file.
Example:
local text = "Hello, World!"
local meta = space.writeFile("greeting.txt", text)
print("File written with size: " .. meta.size)
Deletes a file from the space.
Example:
space.deleteFile("old-document.txt")
Checks if a file exists in the space.
Example: ```lua if space.fileExists("config.json") then print("Config file exists!") else print("Config file not found") end