feat: folder mapping UI on account add (probe + map modal)

ADD now probes both connections, lists folders on each side, and opens a
mapping modal to route source->destination folders (e.g. Спам -> Spam) so we
append into the existing folder instead of creating a duplicate.

- store: SetTaskFolderMapping (+ round-trip test)
- httpapi: POST /tasks/{id}/probe (test both, return folder lists),
  PUT /tasks/{id}/folder-mapping
- web: FolderMappingModal (reuses Modal, size=lg), submitAccount probes then
  opens the modal; confirm creates the account and saves the task mapping

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
This commit is contained in:
2026-07-02 14:39:31 +07:00
parent 331497aff4
commit 0bb584fe10
9 changed files with 329 additions and 7 deletions
+34
View File
@@ -0,0 +1,34 @@
package store
import (
"context"
"testing"
)
func TestSetTaskFolderMappingRoundTrip(t *testing.T) {
s := testStore(t)
ctx := context.Background()
e1, _ := s.CreateEndpoint(ctx, Endpoint{RoleLabel: "s", Host: "a", Port: 993, TLSMode: "ssl"})
e2, _ := s.CreateEndpoint(ctx, Endpoint{RoleLabel: "d", Host: "b", Port: 993, TLSMode: "ssl"})
taskID, _ := s.CreateTask(ctx, Task{Name: "t", SrcEndpointID: e1, DstEndpointID: e2})
m := map[string]string{"Спам": "Spam", "Отправленные": "Sent"}
if err := s.SetTaskFolderMapping(ctx, taskID, m); err != nil {
t.Fatalf("set mapping: %v", err)
}
got, err := s.GetTask(ctx, taskID)
if err != nil {
t.Fatalf("get: %v", err)
}
if got.FolderMapping["Спам"] != "Spam" || got.FolderMapping["Отправленные"] != "Sent" {
t.Fatalf("mapping round-trip failed: %+v", got.FolderMapping)
}
// nil clears to empty object, not null
if err := s.SetTaskFolderMapping(ctx, taskID, nil); err != nil {
t.Fatalf("clear: %v", err)
}
got, _ = s.GetTask(ctx, taskID)
if got.FolderMapping == nil {
t.Fatal("mapping should be non-nil empty map after clear")
}
}
+8
View File
@@ -57,6 +57,14 @@ func (s *Store) ListTasks(ctx context.Context) ([]Task, error) {
return out, rows.Err()
}
func (s *Store) SetTaskFolderMapping(ctx context.Context, id int64, mapping map[string]string) error {
if mapping == nil {
mapping = map[string]string{}
}
_, err := s.Pool.Exec(ctx, `UPDATE tasks SET folder_mapping=$2 WHERE id=$1`, id, mapping)
return err
}
func (s *Store) SetTaskStatus(ctx context.Context, id int64, status string) error {
_, err := s.Pool.Exec(ctx, `UPDATE tasks SET status=$2 WHERE id=$1`, id, status)
return err