2025-01-17 03:41:52 +08:00
|
|
|
The Space API provides functions for interacting with pages, attachments, and files in the space.
|
|
|
|
|
2025-01-17 17:41:02 +08:00
|
|
|
# Page Operations
|
2025-01-17 03:41:52 +08:00
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.listPages()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns a list of all pages in the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local pages = space.listPages()
|
2025-01-17 03:41:52 +08:00
|
|
|
for page in each(pages) do
|
|
|
|
print(page.name)
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.readPage(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Reads the content of a page.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local content = space.readPage("welcome")
|
2025-01-17 03:41:52 +08:00
|
|
|
print(content) -- prints the content of the "welcome" page
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.getPageMeta(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Gets metadata for a specific page.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local meta = space.getPageMeta("welcome")
|
2025-01-17 03:41:52 +08:00
|
|
|
print(meta.name, meta.lastModified) -- prints page name and last modified date
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.writePage(name, text)
|
2025-01-17 03:41:52 +08:00
|
|
|
Writes content to a page.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local meta = space.writePage("notes", "My new note content")
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Page updated at: " .. meta.lastModified)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.deletePage(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Deletes a page from the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
space.deletePage("old-notes")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-01-17 17:41:02 +08:00
|
|
|
# Attachment Operations
|
2025-01-17 03:41:52 +08:00
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.listAttachments()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns a list of all attachments in the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local attachments = space.listAttachments()
|
2025-01-17 03:41:52 +08:00
|
|
|
for att in each(attachments) do
|
|
|
|
print(att.name, att.size)
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.readAttachment(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Reads the content of an attachment.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local data = space.readAttachment("image.png")
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Attachment size: " .. #data .. " bytes")
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.writeAttachment(name, data)
|
2025-01-17 03:41:52 +08:00
|
|
|
Writes binary data to an attachment.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local binaryData = string.char(72, 69, 76, 76, 79) -- "HELLO" in binary
|
|
|
|
local meta = space.writeAttachment("test.bin", binaryData)
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Attachment saved with size: " .. meta.size)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.deleteAttachment(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Deletes an attachment from the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
space.deleteAttachment("old-image.png")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-01-17 17:41:02 +08:00
|
|
|
# File Operations
|
2025-01-17 03:41:52 +08:00
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.listFiles()
|
2025-01-17 03:41:52 +08:00
|
|
|
Returns a list of all files in the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local files = space.listFiles()
|
2025-01-17 03:41:52 +08:00
|
|
|
for _, file in ipairs(files) do
|
|
|
|
print(file.name, file.size)
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.getFileMeta(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Gets metadata for a specific file.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local meta = space.getFileMeta("document.txt")
|
2025-01-17 03:41:52 +08:00
|
|
|
print(meta.name, meta.modified, meta.size)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.readFile(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Reads the content of a file.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
local content = space.readFile("document.txt")
|
2025-01-17 03:41:52 +08:00
|
|
|
print("File size: " .. #content .. " bytes")
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.writeFile(name, data)
|
2025-01-17 03:41:52 +08:00
|
|
|
Writes binary data to a file.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
|
|
|
local text = "Hello, World!"
|
2025-02-06 17:04:45 +08:00
|
|
|
local meta = space.writeFile("greeting.txt", text)
|
2025-01-17 03:41:52 +08:00
|
|
|
print("File written with size: " .. meta.size)
|
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.deleteFile(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Deletes a file from the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
space.deleteFile("old-document.txt")
|
2025-01-17 03:41:52 +08:00
|
|
|
```
|
|
|
|
|
2025-02-06 17:04:45 +08:00
|
|
|
## space.fileExists(name)
|
2025-01-17 03:41:52 +08:00
|
|
|
Checks if a file exists in the space.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```lua
|
2025-02-06 17:04:45 +08:00
|
|
|
if space.fileExists("config.json") then
|
2025-01-17 03:41:52 +08:00
|
|
|
print("Config file exists!")
|
|
|
|
else
|
|
|
|
print("Config file not found")
|
|
|
|
end
|