- Go 60.6%
- Svelte 20.8%
- TypeScript 12.5%
- JavaScript 2.8%
- CSS 2.6%
- Other 0.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
job 映像(git.1li.tw/1li/ci)已提供 Node.js、Go、gcc 與 chromium。 Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
| .forgejo/workflows | ||
| api | ||
| cmd/lai | ||
| deploy | ||
| docs | ||
| internal | ||
| sdk | ||
| web | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| AGENTS.md | ||
| compose.yaml | ||
| config.example.yaml | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| justfile | ||
| README.md | ||
| REFACTOR.md | ||
| sqlc.yaml | ||
lai-media
專案概況、架構、部署與測試請從文件導覽開始。下文是 SDK 的使用範例。
Go SDK for the server-rendered PHP backend observed at sys.posu.tw.
The SDK models the discovered form-based protocol rather than pretending the backend is a JSON REST API. It supports authenticated reads and the article write operations that were observed during the read-only/API exploration:
- login and session cookies;
- article/news list pages and title/date filters;
- article create and update forms;
- article cover uploads and image-library uploads;
- TinyMCE image and same-paragraph caption HTML generation;
- article sort updates, view-count clearing, and deletion;
- article/news traffic pages and news monthly hot-page queries;
- article/news preview pages;
- generic HTML access for account/profile pages.
ArticleInput.Published defaults to false. Ordinary create/update methods
reject Published=true; publication requires the separately named
PublishArticle method and an explicit confirmation argument.
Example
import (
"context"
"fmt"
"os"
sdk "github.com/simbafs/lai-media/sdk"
)
ctx := context.Background()
client, err := sdk.New("https://sys.posu.tw")
if err != nil {
return err
}
if err := client.Login(ctx, sdk.Credentials{
Username: os.Getenv("POSU_USERNAME"),
Password: os.Getenv("POSU_PASSWORD"),
}); err != nil {
return err
}
articles, err := client.ListArticles(ctx, sdk.ArticleListOptions{Page: 1})
if err != nil {
return err
}
draft, err := client.CreateArticle(ctx, sdk.ArticleInput{
Title: "Mock draft",
Brief: "A draft created by the SDK.",
Content: "<p>Not published.</p>",
Published: false,
Platform: sdk.PlatformNone,
}, nil)
if err != nil {
return err
}
fmt.Println(len(articles.Articles), draft.ID)
The package is intentionally small and uses the standard net/http client.
Inject WithHTTPClient with an httptest.Server in tests; no live-site tests
are included.
News bodies are written as structured blocks; the SDK renders the HTML POSU expects, including the caption styling and alt text:
_, err = client.CreateNews(ctx, sdk.NewsInput{
Title: "標題",
Brief: "摘要",
Body: []sdk.Block{
sdk.BodyImage{URL: "https://uploads.posu.tw/path/image.png", Width: 1920, Height: 1080, Caption: "▲ 圖說"},
sdk.Paragraph{Lines: []string{"第一行", "同一段的第二行"}},
},
}, &cover)
Each paragraph becomes one <p> (lines joined by <br>), and each image its own
<div> containing only the image and its caption. GetNews parses the stored
content back into News.Body, so a write can be verified by comparing blocks.
Selecting an image in the browser's image library is a TinyMCE client-side
action, not a separate server API call.
Test coverage
Run just coverage to test all Go packages and generate coverage.html in the
project root. Open the file in a browser to inspect coverage by source file.
The intermediate coverage profile is written to coverage.out.
Web editor
cmd/lai is the news editor: Codex-assisted writing, SQLite storage, images in
a filesystem or S3 object store, and verified unpublished uploads to POSU. The
SvelteKit frontend in web/ is embedded in the binary. Start with the
documentation index.