Documentation
¶
Index ¶
- func HandleWebSocket(w http.ResponseWriter, r *http.Request, password string, hub *WebSocketHub, ...)
- func ReloadConfig() error
- func Start(opts ServeOpts) error
- type APIHandler
- func (h *APIHandler) HandleConfigGet(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleConfigPut(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleDownload(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleLogin(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleLogout(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandlePostDelete(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandlePostDownload(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandlePosts(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleSchedulesCreate(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleSchedulesDelete(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleSchedulesGet(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleSchedulesUpdate(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleTaskCancel(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleTasks(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleUpdate(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleVersion(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) HandleWebSocket(w http.ResponseWriter, r *http.Request)
- type PostInfo
- type ScheduleData
- type ScheduleManager
- func (sm *ScheduleManager) AddSchedule(tid int, authorId int, cronExpr string) (*ScheduleTask, error)
- func (sm *ScheduleManager) DeleteSchedule(id string) error
- func (sm *ScheduleManager) GetAllSchedules() []ScheduleTask
- func (sm *ScheduleManager) Load() error
- func (sm *ScheduleManager) Start() error
- func (sm *ScheduleManager) Stop()
- func (sm *ScheduleManager) UpdateSchedule(id string, cronExpr string, enabled bool) (*ScheduleTask, error)
- type ScheduleTask
- type ServeOpts
- type Session
- type SessionManager
- func (sm *SessionManager) ClearSessionCookie(w http.ResponseWriter)
- func (sm *SessionManager) CreateSession() *Session
- func (sm *SessionManager) DeleteSession(token string)
- func (sm *SessionManager) GetSessionFromRequest(r *http.Request) *Session
- func (sm *SessionManager) SetSessionCookie(w http.ResponseWriter, token string)
- func (sm *SessionManager) ValidateSession(token string) bool
- type TaskManager
- type TaskStatus
- type WSMessage
- type WebSocketHub
- func (h *WebSocketHub) AddClient(conn *websocket.Conn)
- func (h *WebSocketHub) Broadcast(msg WSMessage)
- func (h *WebSocketHub) BroadcastProgress(task *TaskStatus)
- func (h *WebSocketHub) BroadcastTaskComplete(task *TaskStatus)
- func (h *WebSocketHub) BroadcastTaskFailed(task *TaskStatus)
- func (h *WebSocketHub) RemoveClient(conn *websocket.Conn)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleWebSocket ¶
func HandleWebSocket(w http.ResponseWriter, r *http.Request, password string, hub *WebSocketHub, sessionManager *SessionManager)
Types ¶
type APIHandler ¶
type APIHandler struct {
// contains filtered or unexported fields
}
func NewAPIHandler ¶
func NewAPIHandler(taskManager *TaskManager, scheduleManager *ScheduleManager, cfg *ini.File, password string, sessionManager *SessionManager) *APIHandler
func (*APIHandler) HandleConfigGet ¶
func (h *APIHandler) HandleConfigGet(w http.ResponseWriter, r *http.Request)
GET /api/config - 获取配置
func (*APIHandler) HandleConfigPut ¶
func (h *APIHandler) HandleConfigPut(w http.ResponseWriter, r *http.Request)
PUT /api/config - 更新配置
func (*APIHandler) HandleDownload ¶
func (h *APIHandler) HandleDownload(w http.ResponseWriter, r *http.Request)
POST /api/download - 下载帖子
func (*APIHandler) HandleLogin ¶
func (h *APIHandler) HandleLogin(w http.ResponseWriter, r *http.Request)
POST /api/login - 登录
func (*APIHandler) HandleLogout ¶
func (h *APIHandler) HandleLogout(w http.ResponseWriter, r *http.Request)
POST /api/logout - 登出
func (*APIHandler) HandlePostDelete ¶
func (h *APIHandler) HandlePostDelete(w http.ResponseWriter, r *http.Request)
DELETE /api/posts/{tid} - 删除帖子文件夹
func (*APIHandler) HandlePostDownload ¶
func (h *APIHandler) HandlePostDownload(w http.ResponseWriter, r *http.Request)
GET /api/posts/{tid}/download - 下载帖子文件
func (*APIHandler) HandlePosts ¶
func (h *APIHandler) HandlePosts(w http.ResponseWriter, r *http.Request)
GET /api/posts - 获取帖子列表
func (*APIHandler) HandleSchedulesCreate ¶
func (h *APIHandler) HandleSchedulesCreate(w http.ResponseWriter, r *http.Request)
POST /api/schedules - 创建定时任务
func (*APIHandler) HandleSchedulesDelete ¶
func (h *APIHandler) HandleSchedulesDelete(w http.ResponseWriter, r *http.Request)
DELETE /api/schedules/{id} - 删除定时任务
func (*APIHandler) HandleSchedulesGet ¶
func (h *APIHandler) HandleSchedulesGet(w http.ResponseWriter, r *http.Request)
GET /api/schedules - 获取定时任务列表
func (*APIHandler) HandleSchedulesUpdate ¶
func (h *APIHandler) HandleSchedulesUpdate(w http.ResponseWriter, r *http.Request)
PUT /api/schedules/{id} - 更新定时任务
func (*APIHandler) HandleTaskCancel ¶
func (h *APIHandler) HandleTaskCancel(w http.ResponseWriter, r *http.Request)
DELETE /api/tasks/{tid} - 取消任务
func (*APIHandler) HandleTasks ¶
func (h *APIHandler) HandleTasks(w http.ResponseWriter, r *http.Request)
GET /api/tasks - 获取任务列表
func (*APIHandler) HandleUpdate ¶
func (h *APIHandler) HandleUpdate(w http.ResponseWriter, r *http.Request)
POST /api/update - 更新帖子
func (*APIHandler) HandleVersion ¶
func (h *APIHandler) HandleVersion(w http.ResponseWriter, r *http.Request)
GET /api/version - 返回版本号
func (*APIHandler) HandleWebSocket ¶
func (h *APIHandler) HandleWebSocket(w http.ResponseWriter, r *http.Request)
GET /ws - WebSocket 连接
type PostInfo ¶
type PostInfo struct {
Tid int `json:"tid"`
AuthorId int `json:"authorId"`
Title string `json:"title"`
FolderName string `json:"folderName"`
MaxPage int `json:"maxPage"`
MaxFloor int `json:"maxFloor"`
FloorCount int `json:"floorCount,omitempty"`
HasMarkdown bool `json:"hasMarkdown"`
CreatedTime string `json:"createdTime"`
UpdatedTime string `json:"updatedTime"`
}
PostInfo 表示一个已下载的帖子
type ScheduleData ¶
type ScheduleData struct {
Tasks []ScheduleTask `json:"tasks"`
}
type ScheduleManager ¶
type ScheduleManager struct {
// contains filtered or unexported fields
}
func NewScheduleManager ¶
func NewScheduleManager(tm *TaskManager) *ScheduleManager
func (*ScheduleManager) AddSchedule ¶
func (sm *ScheduleManager) AddSchedule(tid int, authorId int, cronExpr string) (*ScheduleTask, error)
func (*ScheduleManager) DeleteSchedule ¶
func (sm *ScheduleManager) DeleteSchedule(id string) error
func (*ScheduleManager) GetAllSchedules ¶
func (sm *ScheduleManager) GetAllSchedules() []ScheduleTask
func (*ScheduleManager) Load ¶
func (sm *ScheduleManager) Load() error
func (*ScheduleManager) Start ¶
func (sm *ScheduleManager) Start() error
func (*ScheduleManager) Stop ¶
func (sm *ScheduleManager) Stop()
func (*ScheduleManager) UpdateSchedule ¶
func (sm *ScheduleManager) UpdateSchedule(id string, cronExpr string, enabled bool) (*ScheduleTask, error)
type ScheduleTask ¶
type ScheduleTask struct {
ID string `json:"id"`
Tid int `json:"tid"`
AuthorId int `json:"authorId"`
Cron string `json:"cron"`
Enabled bool `json:"enabled"`
LastRunTime string `json:"lastRunTime,omitempty"`
NextRunTime string `json:"nextRunTime,omitempty"`
LastRunStatus string `json:"lastRunStatus,omitempty"` // "completed" | "failed" | ""
CreatedTime string `json:"createdTime"`
CronEntryID cron.EntryID // 内部使用,不序列化
}
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager() *SessionManager
func (*SessionManager) ClearSessionCookie ¶
func (sm *SessionManager) ClearSessionCookie(w http.ResponseWriter)
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession() *Session
func (*SessionManager) DeleteSession ¶
func (sm *SessionManager) DeleteSession(token string)
func (*SessionManager) GetSessionFromRequest ¶
func (sm *SessionManager) GetSessionFromRequest(r *http.Request) *Session
func (*SessionManager) SetSessionCookie ¶
func (sm *SessionManager) SetSessionCookie(w http.ResponseWriter, token string)
func (*SessionManager) ValidateSession ¶
func (sm *SessionManager) ValidateSession(token string) bool
type TaskManager ¶
type TaskManager struct {
// contains filtered or unexported fields
}
TaskManager 管理任务队列,每次只执行一个任务
func NewTaskManager ¶
func NewTaskManager(hub *WebSocketHub) *TaskManager
func (*TaskManager) CancelTask ¶
func (tm *TaskManager) CancelTask(tid int) error
CancelTask 取消/移除任务。正在运行的任务无法取消(nga 无取消机制),队列中的任务可以移除。
func (*TaskManager) EnqueueDownload ¶
func (tm *TaskManager) EnqueueDownload(tid int, authorId int, onComplete func(bool)) (*TaskStatus, error)
EnqueueDownload 将下载任务加入队列
func (*TaskManager) EnqueueUpdate ¶
func (tm *TaskManager) EnqueueUpdate(tid int, onComplete func(bool)) (*TaskStatus, error)
EnqueueUpdate 将更新任务加入队列
func (*TaskManager) GetAllTasks ¶
func (tm *TaskManager) GetAllTasks() []TaskStatus
GetAllTasks 返回当前正在运行的任务 + 队列中等待的任务
type TaskStatus ¶
type TaskStatus struct {
Tid int `json:"tid"`
AuthorId int `json:"authorId"`
Type string `json:"type"` // "download" | "update"
Status string `json:"status"` // "queued" | "downloading" | "processing" | "generating_markdown" | "completed" | "failed" | "cancelled"
CurrentPage int `json:"currentPage"`
TotalPage int `json:"totalPage"`
CurrentFloor int `json:"currentFloor"`
TotalFloor int `json:"totalFloor"`
Stage string `json:"stage"`
Error string `json:"error,omitempty"`
StartTime time.Time `json:"startTime,omitempty"`
EndTime time.Time `json:"endTime,omitempty"`
QueueTime time.Time `json:"queueTime"` // 入队时间
OnComplete func(success bool)
}
type WSMessage ¶
type WSMessage struct {
Type string `json:"type"` // "progress" | "task_complete" | "task_failed"
Tid int `json:"tid"`
TaskType string `json:"taskType"`
Status string `json:"status"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
CurrentPage int `json:"currentPage,omitempty"`
TotalPage int `json:"totalPage,omitempty"`
CurrentFloor int `json:"currentFloor,omitempty"`
TotalFloor int `json:"totalFloor,omitempty"`
Stage string `json:"stage,omitempty"`
}
type WebSocketHub ¶
type WebSocketHub struct {
// contains filtered or unexported fields
}
func NewWebSocketHub ¶
func NewWebSocketHub() *WebSocketHub
func (*WebSocketHub) AddClient ¶
func (h *WebSocketHub) AddClient(conn *websocket.Conn)
func (*WebSocketHub) Broadcast ¶
func (h *WebSocketHub) Broadcast(msg WSMessage)
func (*WebSocketHub) BroadcastProgress ¶
func (h *WebSocketHub) BroadcastProgress(task *TaskStatus)
func (*WebSocketHub) BroadcastTaskComplete ¶
func (h *WebSocketHub) BroadcastTaskComplete(task *TaskStatus)
func (*WebSocketHub) BroadcastTaskFailed ¶
func (h *WebSocketHub) BroadcastTaskFailed(task *TaskStatus)
func (*WebSocketHub) RemoveClient ¶
func (h *WebSocketHub) RemoveClient(conn *websocket.Conn)