forked from longtao.wu/droboticflow
✨ Replace workgroups with project members and resilient uploads
This commit is contained in:
parent
03fb08e08b
commit
1785697e46
@ -16,9 +16,9 @@ def _run_legacy(
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
template_id = params.get("ANNOTATION_TEMPLATE_ID", "").strip()
|
||||
workgroup_id = params.get("ANNOTATION_WORKGROUP_ID", "").strip()
|
||||
if not template_id or not workgroup_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID 和 ANNOTATION_WORKGROUP_ID")
|
||||
supplier_id = params.get("ANNOTATION_SUPPLIER_ID", "").strip()
|
||||
if not template_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID")
|
||||
payloads = helpers["payloads_from_inputs"](inputs)
|
||||
items = helpers["collect_items"](payloads)
|
||||
if not items:
|
||||
@ -34,7 +34,7 @@ def _run_legacy(
|
||||
"runId": run_id,
|
||||
"nodeId": node_id,
|
||||
"templateId": template_id,
|
||||
"workgroupId": workgroup_id,
|
||||
"supplierId": supplier_id,
|
||||
"itemCount": len(items),
|
||||
"items": items,
|
||||
"interceptedByWorker": False,
|
||||
@ -62,9 +62,9 @@ def _run_multiport(
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
template_id = params.get("ANNOTATION_TEMPLATE_ID", "").strip()
|
||||
workgroup_id = params.get("ANNOTATION_WORKGROUP_ID", "").strip()
|
||||
if not template_id or not workgroup_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID 和 ANNOTATION_WORKGROUP_ID")
|
||||
supplier_id = params.get("ANNOTATION_SUPPLIER_ID", "").strip()
|
||||
if not template_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID")
|
||||
# Only the Qwen ``clips`` port creates human work. HeadPose rendering is
|
||||
# also a video input in v5.7, but it is review evidence, not another clip
|
||||
# to cut, annotate, accept, and package.
|
||||
@ -86,12 +86,12 @@ def _run_multiport(
|
||||
annotations = {
|
||||
"datasetType": "annotation-gate-input",
|
||||
"templateId": template_id,
|
||||
"workgroupId": workgroup_id,
|
||||
"supplierId": supplier_id,
|
||||
"itemCount": len(clips),
|
||||
"items": prelabels,
|
||||
}
|
||||
rejected = {"datasetType": "annotation-gate-rejected", "itemCount": 0, "items": []}
|
||||
summary = {"clipCount": len(clips), "prelabelCount": len(prelabels), "boundaryCount": len(boundaries), "templateId": template_id, "workgroupId": workgroup_id}
|
||||
summary = {"clipCount": len(clips), "prelabelCount": len(prelabels), "boundaryCount": len(boundaries), "templateId": template_id, "supplierId": supplier_id}
|
||||
return [
|
||||
*clips,
|
||||
write(run_id, node_id, output_dir, "annotation-gate-annotations-dataset.json", annotations, output=_output(node_data, helpers, "annotations")),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# No secrets belong in this file. Inject credentials via the platform secret store.
|
||||
FANYU_V5_ANNOTATION_WORKGROUP_ID=
|
||||
FANYU_V5_SUPPLIER_ID=
|
||||
FANYU_HEADPOSE_API_BASE_URL=
|
||||
FANYU_HEADPOSE_SERVICE_IMAGE_ID=
|
||||
FANYU_HEADPOSE_MODEL_SHA256=
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
- `cutter`:只保留历史 v5.7 任务兼容,新建 v5.8 项目不再分配该角色。
|
||||
- `vendor_manager`:只聚合查看所管供应商/工作组的工作量和质量,不能读取任务媒体或执行审核。
|
||||
|
||||
每个成员关系同时绑定 `projectId`、`workgroupId` 和 `vendorId`。除管理员、流程工程师和兼容管理员外,后端只返回当前用户所在分组的任务、模板、分组和工时事件;前端隐藏不是安全边界。
|
||||
每个成员关系绑定 `projectId`、可选 `supplierId` 和三类项目角色。除组织管理员外,后端只返回当前用户所属项目和供应商范围内的任务、模板和工时事件;前端隐藏不是安全边界。
|
||||
|
||||
每个工作台均有“可领取”“我的任务”池;管理员额外拥有“全部任务”,并可通过带乐观锁版本的 `PATCH /api/human-items/{id}/assignment` 将任务改派给符合当前阶段角色和工作组成员关系的用户,或退回共享池。所有领取、释放、改派、提交、审核和打回都会追加 HumanEvent/StageAttempt 审计记录。
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
人工审核节点配置 `REVIEW_MODE=annotation` 后成为原生标注门,另外需要:
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:当前项目中已发布的模板。
|
||||
- `ANNOTATION_WORKGROUP_ID`:目标供应商分组。
|
||||
- `ANNOTATION_SUPPLIER_ID`:可选供应商 ID;留空时按项目成员关系确定。
|
||||
- 新任务不接受 `ANNOTATION_ASSIGNED_USER_ID` 预分配;成员从 HumanItem 待领取池主动领取。
|
||||
|
||||
Worker 到达该节点后不会启动 Kubernetes Job,也不会创建通用 AuditTask。它会从上游真实视频与 Qwen 边界创建 AnnotationTask,并写入 `projectId`、`dataTaskId`、`workflowId`、`runId`、`nodeId`、`artifactId`。Run 保持 `waiting_for_audit`,直到该节点下所有任务依次完成:标注员真实切分与语义标注 → 审核员统一审核 → 最终验收员整包验收。验收通过后系统自动释放 Package child Run。
|
||||
|
||||
@ -77,7 +77,7 @@ export HEADPOSE_SERVICE_IMAGE_ID=ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow/d
|
||||
export HEADPOSE_MODEL_SHA256=sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018
|
||||
# Required to publish the Fanyu v5 left-camera workflow release. Obtain this
|
||||
# from the verified POC annotation workgroup; do not invent an ID.
|
||||
export FANYU_V5_ANNOTATION_WORKGROUP_ID=<published-poc-annotation-workgroup-id>
|
||||
export FANYU_V5_SUPPLIER_ID=<optional-supplier-id>
|
||||
export OPERATOR_GPU_NODE_SELECTOR=accelerator=nvidia
|
||||
export OPERATOR_GPU_TOLERATIONS_JSON='[{"key":"nvidia.com/gpu","operator":"Exists","effect":"NoSchedule"}]'
|
||||
export OPERATOR_GPU_RUNTIME_CLASS=nvidia
|
||||
|
||||
@ -49,5 +49,5 @@ python3 scripts/verify_qwen3vl_model_manifest.py --model-root /workspace/models/
|
||||
1. 独立构建并发布 `directory-scan`、`orbbec-data-normalize`、`orbbec-left-undistort`、`video-face-blur`、`qwen-behavior-rough-cut` 与 `package` 镜像,写入 digest-pinned release manifest;YuNet 资产必须随 `video-face-blur` 镜像离线携带并通过 SHA/size/license 门禁。
|
||||
2. 预置并校验 Qwen3-VL 本地快照;当前无模型或未校验 manifest 即为预期 fail-closed 状态。
|
||||
3. 为 Qwen3-VL 语义粗切腾出 1 张 GPU;目录读取、人工阶段与打包不申请 GPU。
|
||||
4. 提供 `FANYU_V5_ANNOTATION_WORKGROUP_ID`;本版本不读取 `FANYU_HEADPOSE_*`。
|
||||
4. 可选提供 `FANYU_V5_SUPPLIER_ID`;留空时按项目成员关系确定供应商。本版本不读取 `FANYU_HEADPOSE_*`。
|
||||
5. 仅在 `dev/poc` 验收环境中部署 `dev`,S100 使用同一镜像 digest 和以上 PVC/模型配置,不把草稿算子直接标为已发布。
|
||||
|
||||
@ -65,7 +65,7 @@ flowchart LR
|
||||
## 关键超参数
|
||||
|
||||
- `ANNOTATION_TEMPLATE_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。当前项目中已发布的语义模板 ID 通常建议在工作流中显式配置。
|
||||
- `ANNOTATION_WORKGROUP_ID`:类型 `string`,默认值 空字符串或由工作流显式填写。目标供应商工作组 ID 通常建议在工作流中显式配置。
|
||||
- `ANNOTATION_SUPPLIER_ID`:类型 `string`,可选。留空时由项目成员关系确定供应商。
|
||||
- `REQUIRE_PREPACKAGE_ACCEPTANCE`:类型 `boolean`,默认值 `false`。全部切片统一质检通过后创建一个聚合的包前验收任务;验收仅允许确认 可直接使用默认值,也可在节点级覆盖。
|
||||
|
||||
## 执行前准备
|
||||
@ -93,7 +93,7 @@ flowchart LR
|
||||
"category": "HUMAN",
|
||||
"hyperparams": {
|
||||
"ANNOTATION_TEMPLATE_ID": "<按节点填写>",
|
||||
"ANNOTATION_WORKGROUP_ID": "<按节点填写>",
|
||||
"ANNOTATION_SUPPLIER_ID": "<可选供应商 ID>",
|
||||
"REQUIRE_PREPACKAGE_ACCEPTANCE": "false"
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ func annotationManager(principal *authenticatedPrincipal) bool {
|
||||
if principal == nil {
|
||||
return false
|
||||
}
|
||||
return principal.User.Role == domain.UserRoleAdmin
|
||||
return isOrganizationAdmin(principal)
|
||||
}
|
||||
|
||||
func annotationPrincipalUserID(principal *authenticatedPrincipal) string {
|
||||
@ -71,15 +71,43 @@ func (server *server) annotationMembershipsForUser(ctx context.Context, organiza
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
}
|
||||
projectMembers, err := server.store.ListProjectMembers(ctx, organizationID, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, member := range projectMembers {
|
||||
if member.UserID != userID {
|
||||
continue
|
||||
}
|
||||
for _, role := range member.Roles {
|
||||
filtered = append(filtered, domain.ProjectAnnotationMembershipRecord{
|
||||
ID: "project-member:" + member.ID + ":" + string(role),
|
||||
OrganizationID: member.OrganizationID,
|
||||
ProjectID: member.ProjectID,
|
||||
UserID: member.UserID,
|
||||
VendorID: member.SupplierID,
|
||||
AssignmentRole: role,
|
||||
CreatedAt: member.CreatedAt,
|
||||
UpdatedAt: member.UpdatedAt,
|
||||
})
|
||||
}
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func membershipAllowsTask(memberships []domain.ProjectAnnotationMembershipRecord, task domain.AnnotationTaskRecord) bool {
|
||||
for _, membership := range memberships {
|
||||
if membership.ProjectID != task.ProjectID || membership.WorkgroupID != task.WorkgroupID {
|
||||
if membership.ProjectID != task.ProjectID {
|
||||
continue
|
||||
}
|
||||
if membership.VendorID != "" && task.VendorID != "" && membership.VendorID != task.VendorID {
|
||||
taskSupplierID := task.SupplierID
|
||||
if taskSupplierID == "" {
|
||||
taskSupplierID = task.VendorID
|
||||
}
|
||||
if membership.VendorID != "" && taskSupplierID != "" && membership.VendorID != taskSupplierID {
|
||||
continue
|
||||
}
|
||||
if membership.WorkgroupID != "" && task.WorkgroupID != "" && membership.WorkgroupID != task.WorkgroupID {
|
||||
continue
|
||||
}
|
||||
return true
|
||||
@ -764,7 +792,7 @@ func (server *server) handleAnnotationTaskCreate(writer http.ResponseWriter, req
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), item.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: item.OrganizationID, ProjectID: item.ProjectID,
|
||||
TaskID: item.ID, UserID: annotationPrincipalUserID(principal), WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
TaskID: item.ID, UserID: annotationPrincipalUserID(principal), SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
EventType: "created", Mode: taskMode, Temporary: isTemp, TemplateVersion: item.TemplateVersion, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
renderJSON(writer, http.StatusCreated, item)
|
||||
@ -1049,7 +1077,7 @@ func (server *server) handleCombinedAnnotationSubmission(writer http.ResponseWri
|
||||
if annotationRevision.CountsAsOutput {
|
||||
outputDelta = 1
|
||||
}
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "combined_submitted", Mode: taskMode, Temporary: isTemp, Revision: annotationRevision.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: outputDelta, CreatedAt: now})
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "combined_submitted", Mode: taskMode, Temporary: isTemp, Revision: annotationRevision.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: outputDelta, CreatedAt: now})
|
||||
status := http.StatusCreated
|
||||
if resumed {
|
||||
status = http.StatusOK
|
||||
@ -1295,7 +1323,7 @@ func (server *server) handleSliceRevisionCreate(writer http.ResponseWriter, requ
|
||||
_ = server.appendHumanEvent(request.Context(), *item, "submitted", principal.User.ID, map[string]any{"submissionRef": revision.ID, "sliceRevision": revision.Revision})
|
||||
}
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), task.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "slice_submitted", Mode: taskMode, Temporary: isTemp, Revision: revision.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: 0, CreatedAt: nowISO()})
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "slice_submitted", Mode: taskMode, Temporary: isTemp, Revision: revision.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: 0, CreatedAt: nowISO()})
|
||||
renderJSON(writer, http.StatusCreated, map[string]any{"task": task, "sliceRevision": revision})
|
||||
}
|
||||
|
||||
@ -1385,7 +1413,7 @@ func (server *server) handleAnnotationRevisionCreate(writer http.ResponseWriter,
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), task.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID,
|
||||
TaskID: task.ID, UserID: principal.User.ID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
EventType: eventType, Mode: taskMode, Temporary: isTemp, Revision: revisionNumber, TemplateVersion: task.TemplateVersion,
|
||||
DurationSeconds: payload.DurationSeconds, OutputDelta: outputDelta, CreatedAt: nowISO(),
|
||||
})
|
||||
@ -1670,7 +1698,7 @@ func (server *server) handleFanyuV5FourStageReview(writer http.ResponseWriter, r
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), task.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID,
|
||||
UserID: principal.User.ID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
EventType: eventType, Mode: taskMode, Temporary: isTemp, Revision: review.Revision, TemplateVersion: task.TemplateVersion,
|
||||
DurationSeconds: payload.DurationSeconds, OutputDelta: 0, CreatedAt: now,
|
||||
})
|
||||
@ -1777,7 +1805,7 @@ func (server *server) handleFanyuV5CombinedQualityReview(writer http.ResponseWri
|
||||
_ = server.store.UpsertHumanStageAttempt(request.Context(), domain.HumanStageAttemptRecord{OrganizationID: item.OrganizationID, ItemID: item.ID, StageID: "quality_review", Round: item.ReviewRound, Status: item.Status, AssigneeUserID: principal.User.ID, ReviewedRevision: review.Revision, Decision: domain.HumanDecision(payload.Decision), RejectTargets: review.RejectTargets, ReasonCodes: review.ReasonCodes, Comment: review.Comment})
|
||||
_ = server.appendHumanEvent(request.Context(), *item, "combined_quality_"+string(payload.Decision), principal.User.ID, map[string]any{"reviewedRevision": review.Revision, "reasonCodes": review.ReasonCodes, "comment": review.Comment})
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), task.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "quality_" + string(payload.Decision), Mode: taskMode, Temporary: isTemp, Revision: review.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: 0, CreatedAt: now})
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID, TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID, EventType: "quality_" + string(payload.Decision), Mode: taskMode, Temporary: isTemp, Revision: review.Revision, TemplateVersion: task.TemplateVersion, DurationSeconds: payload.DurationSeconds, OutputDelta: 0, CreatedAt: now})
|
||||
if payload.Decision == domain.AnnotationReviewApproved {
|
||||
if err := server.flushHumanReleasePartitions(request.Context(), batch, false); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
@ -1966,7 +1994,7 @@ func (server *server) handleAnnotationReviewCreate(writer http.ResponseWriter, r
|
||||
taskMode, isTemp := server.resolveTaskRunMode(request.Context(), task.RunID)
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: task.OrganizationID, ProjectID: task.ProjectID,
|
||||
TaskID: task.ID, UserID: principal.User.ID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
TaskID: task.ID, UserID: principal.User.ID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID, VendorID: task.VendorID,
|
||||
EventType: eventType, Mode: taskMode, Temporary: isTemp, Revision: task.CurrentRevision, TemplateVersion: task.TemplateVersion,
|
||||
DurationSeconds: payload.DurationSeconds, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
|
||||
@ -520,8 +520,8 @@
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"description": "目标供应商工作组 ID",
|
||||
"key": "ANNOTATION_WORKGROUP_ID",
|
||||
"description": "可选的供应商 ID;留空时按项目成员关系自动确定",
|
||||
"key": "ANNOTATION_SUPPLIER_ID",
|
||||
"type": "string",
|
||||
"value": ""
|
||||
},
|
||||
|
||||
@ -128,7 +128,7 @@ func TestBuiltinCatalogIncludesNativeAnnotationGateContract(t *testing.T) {
|
||||
for _, hyperparam := range item.Hyperparams {
|
||||
keys[hyperparam.Key] = true
|
||||
}
|
||||
for _, key := range []string{"ANNOTATION_TEMPLATE_ID", "ANNOTATION_WORKGROUP_ID", "REQUIRE_PREPACKAGE_ACCEPTANCE"} {
|
||||
for _, key := range []string{"ANNOTATION_TEMPLATE_ID", "ANNOTATION_SUPPLIER_ID", "REQUIRE_PREPACKAGE_ACCEPTANCE"} {
|
||||
if !keys[key] {
|
||||
t.Fatalf("annotation gate is missing hyperparameter %s", key)
|
||||
}
|
||||
|
||||
@ -42,6 +42,9 @@ func normalizeCaptureAutomationConfig(config domain.CaptureAutomationConfig) dom
|
||||
if config.PollIntervalSeconds <= 0 {
|
||||
config.PollIntervalSeconds = 30
|
||||
}
|
||||
if config.StabilityWindowSeconds <= 0 {
|
||||
config.StabilityWindowSeconds = 30
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
@ -51,6 +54,8 @@ func captureAutomationCounts(records []domain.CaptureRecord) domain.CaptureRecor
|
||||
switch record.Status {
|
||||
case domain.CaptureRecordIncomplete:
|
||||
counts.Incomplete++
|
||||
case domain.CaptureRecordStabilizing:
|
||||
counts.Ready++
|
||||
case domain.CaptureRecordReady, domain.CaptureRecordLaunching:
|
||||
counts.Ready++
|
||||
case domain.CaptureRecordRequeueing, domain.CaptureRecordQueued:
|
||||
@ -136,6 +141,9 @@ func validateCaptureAutomationConfig(workflow *domain.WorkflowRecord, config dom
|
||||
if config.PollIntervalSeconds < 5 || config.PollIntervalSeconds > 3600 {
|
||||
issues = append(issues, validationIssue{Field: "captureAutomation.pollIntervalSeconds", Message: "检查间隔必须在5到3600秒之间"})
|
||||
}
|
||||
if config.StabilityWindowSeconds < 5 || config.StabilityWindowSeconds > 3600 {
|
||||
issues = append(issues, validationIssue{Field: "captureAutomation.stabilityWindowSeconds", Message: "稳定等待时间必须在5到3600秒之间"})
|
||||
}
|
||||
for index, pattern := range config.RequiredPatterns {
|
||||
if _, err := regexp.Compile(pattern); err != nil {
|
||||
issues = append(issues, validationIssue{Field: "captureAutomation.requiredPatterns", Message: "第" + strconv.Itoa(index+1) + "个必需文件规则不是有效正则表达式"})
|
||||
|
||||
@ -70,26 +70,20 @@ func (server *server) populateDashboardWorkforce(ctx context.Context, requestOrg
|
||||
return nil
|
||||
}
|
||||
scope := "self"
|
||||
allowedVendors := map[string]struct{}{}
|
||||
if principal == nil || principal.User.Role == domain.UserRoleAdmin {
|
||||
allowedSuppliers := map[string]struct{}{}
|
||||
if principal == nil || isOrganizationAdmin(principal) {
|
||||
scope = "platform"
|
||||
} else if principal.User.Role == domain.UserRoleSupplierManager {
|
||||
scope = "vendor"
|
||||
memberships, err := server.store.ListProjectAnnotationMemberships(ctx, requestOrganizationID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, membership := range memberships {
|
||||
if membership.UserID == principal.User.ID && membership.AssignmentRole == domain.AnnotationRoleVendorManager {
|
||||
allowedVendors[membership.VendorID] = struct{}{}
|
||||
}
|
||||
if principal.User.SupplierID != "" {
|
||||
allowedSuppliers[principal.User.SupplierID] = struct{}{}
|
||||
}
|
||||
}
|
||||
events, err := server.store.ListAnnotationWorklogEvents(ctx, requestOrganizationID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
type aggregateKey struct{ userID, vendorID, workgroupID string }
|
||||
type aggregateKey struct{ userID, supplierID string }
|
||||
aggregates := map[aggregateKey]*domain.DashboardWorkforceMetric{}
|
||||
totals := domain.DashboardWorkforceMetric{}
|
||||
for _, event := range events {
|
||||
@ -104,14 +98,14 @@ func (server *server) populateDashboardWorkforce(ctx context.Context, requestOrg
|
||||
continue
|
||||
}
|
||||
if scope == "vendor" {
|
||||
if _, ok := allowedVendors[event.VendorID]; !ok {
|
||||
if _, ok := allowedSuppliers[event.SupplierID]; !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
key := aggregateKey{event.UserID, event.VendorID, event.WorkgroupID}
|
||||
key := aggregateKey{event.UserID, event.SupplierID}
|
||||
item := aggregates[key]
|
||||
if item == nil {
|
||||
item = &domain.DashboardWorkforceMetric{UserID: event.UserID, VendorID: event.VendorID, WorkgroupID: event.WorkgroupID}
|
||||
item = &domain.DashboardWorkforceMetric{UserID: event.UserID, SupplierID: event.SupplierID}
|
||||
aggregates[key] = item
|
||||
}
|
||||
addDashboardWorkforceEvent(item, event)
|
||||
@ -128,8 +122,8 @@ func (server *server) populateDashboardWorkforce(ctx context.Context, requestOrg
|
||||
items = append(items, *item)
|
||||
}
|
||||
sort.Slice(items, func(left int, right int) bool {
|
||||
leftKey := items[left].VendorID + "\x00" + items[left].WorkgroupID + "\x00" + items[left].UserName + "\x00" + items[left].UserID
|
||||
rightKey := items[right].VendorID + "\x00" + items[right].WorkgroupID + "\x00" + items[right].UserName + "\x00" + items[right].UserID
|
||||
leftKey := items[left].SupplierID + "\x00" + items[left].UserName + "\x00" + items[left].UserID
|
||||
rightKey := items[right].SupplierID + "\x00" + items[right].UserName + "\x00" + items[right].UserID
|
||||
return leftKey < rightKey
|
||||
})
|
||||
finalizeDashboardWorkforceMetric(&totals)
|
||||
|
||||
@ -175,7 +175,7 @@ func (server *server) deliveryPackageReviewer(request *http.Request, item domain
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
return membershipHasRole(memberships, legacy, domain.AnnotationRoleQualityReviewer)
|
||||
}
|
||||
|
||||
@ -386,7 +386,7 @@ func (server *server) handleDeliveryPackageDecision(writer http.ResponseWriter,
|
||||
}
|
||||
_ = server.store.UpsertAnnotationWorklogEvent(request.Context(), domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: item.OrganizationID, ProjectID: item.ProjectID,
|
||||
TaskID: item.ID, UserID: principal.User.ID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
TaskID: item.ID, UserID: principal.User.ID, SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
EventType: "acceptance_" + string(payload.Decision), Mode: item.Mode, Temporary: item.Temporary || item.Mode == domain.RunModeDebug, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
if payload.Decision == domain.HumanDecisionRejected {
|
||||
|
||||
@ -148,6 +148,14 @@ func TestSupplierManagerDashboardIsVendorScopedAndMonitoringIsForbidden(t *testi
|
||||
rootCookie := bootstrapSuperAdminSession(t, handler)
|
||||
organization := adminCreateOrganization(t, handler, rootCookie, "Vendor Dashboard", "vendor-dashboard")
|
||||
manager := adminCreateUser(t, handler, rootCookie, organization.ID, "Supplier Manager", "supplier-manager@example.com", domain.UserRoleSupplierManager, "correct-horse-battery-staple-manager")
|
||||
storedManager, err := dataStore.GetUser(ctx, manager.ID)
|
||||
if err != nil || storedManager == nil {
|
||||
t.Fatalf("load supplier manager: %v", err)
|
||||
}
|
||||
storedManager.SupplierID = "vendor-a"
|
||||
if err := dataStore.UpsertUser(ctx, *storedManager); err != nil {
|
||||
t.Fatalf("set supplier manager scope: %v", err)
|
||||
}
|
||||
managerCookie := loginSession(t, handler, manager.Email, "correct-horse-battery-staple-manager")
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{OrganizationID: organization.ID, Name: "Vendor Project"})
|
||||
if err != nil {
|
||||
@ -175,8 +183,8 @@ func TestSupplierManagerDashboardIsVendorScopedAndMonitoringIsForbidden(t *testi
|
||||
}
|
||||
now := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
for _, event := range []domain.AnnotationWorklogEventRecord{
|
||||
{ID: "event-a", OrganizationID: organization.ID, ProjectID: project.ID, UserID: "worker-a", VendorID: "vendor-a", WorkgroupID: "group-a", EventType: "annotation_submitted", OutputDelta: 1, CreatedAt: now},
|
||||
{ID: "event-b", OrganizationID: organization.ID, ProjectID: project.ID, UserID: "worker-b", VendorID: "vendor-b", WorkgroupID: "group-b", EventType: "annotation_submitted", OutputDelta: 99, CreatedAt: now},
|
||||
{ID: "event-a", OrganizationID: organization.ID, ProjectID: project.ID, UserID: "worker-a", SupplierID: "vendor-a", EventType: "annotation_submitted", OutputDelta: 1, CreatedAt: now},
|
||||
{ID: "event-b", OrganizationID: organization.ID, ProjectID: project.ID, UserID: "worker-b", SupplierID: "vendor-b", EventType: "annotation_submitted", OutputDelta: 99, CreatedAt: now},
|
||||
} {
|
||||
if err := dataStore.UpsertAnnotationWorklogEvent(ctx, event); err != nil {
|
||||
t.Fatalf("create worklog event: %v", err)
|
||||
@ -193,7 +201,7 @@ func TestSupplierManagerDashboardIsVendorScopedAndMonitoringIsForbidden(t *testi
|
||||
if err := json.Unmarshal(dashboard.Body.Bytes(), &summary); err != nil {
|
||||
t.Fatalf("decode dashboard: %v", err)
|
||||
}
|
||||
if summary.AudienceScope != "vendor" || len(summary.Workforce.Items) != 1 || summary.Workforce.Items[0].VendorID != "vendor-a" || summary.Workforce.Totals.OutputCount != 1 {
|
||||
if summary.AudienceScope != "vendor" || len(summary.Workforce.Items) != 1 || summary.Workforce.Items[0].SupplierID != "vendor-a" || summary.Workforce.Totals.OutputCount != 1 {
|
||||
t.Fatalf("vendor scope leaked cross-vendor metrics: %#v", summary.Workforce)
|
||||
}
|
||||
monitoring := serveJSONWithCookie(handler, http.MethodGet, "/api/runs", nil, managerCookie)
|
||||
|
||||
@ -396,7 +396,7 @@ func (server *server) ensureFanyuDeliveryTemplateV58(ctx context.Context, organi
|
||||
node.Position.Y,
|
||||
map[string]string{
|
||||
"ANNOTATION_TEMPLATE_ID": annotationTemplateID,
|
||||
"ANNOTATION_WORKGROUP_ID": strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID")),
|
||||
"ANNOTATION_SUPPLIER_ID": strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID")),
|
||||
"RELEASE_POLICY": "all_accepted",
|
||||
"PARTITION_MAX_ITEMS": "32",
|
||||
"MAX_REWORK_ROUNDS": "5",
|
||||
@ -530,16 +530,6 @@ func (server *server) ensureFanyuDeliveryTemplateV58(ctx context.Context, organi
|
||||
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
return nil
|
||||
}
|
||||
for _, node := range nodes {
|
||||
if node.ID != "fanyu-v56-human" {
|
||||
continue
|
||||
}
|
||||
for _, parameter := range node.Data.Hyperparams {
|
||||
if parameter.Key == "ANNOTATION_WORKGROUP_ID" && strings.TrimSpace(fmt.Sprint(parameter.Value)) == "" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{
|
||||
ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 8, Name: template.Name, Description: template.Description,
|
||||
Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns,
|
||||
@ -580,13 +570,13 @@ func (server *server) ensureFanyuDeliveryTemplateV5(ctx context.Context, organiz
|
||||
operators[operatorID] = *operator
|
||||
}
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", normalizedOrganizationID(organizationID))
|
||||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuNode("fanyu-v5-directory", "目录读取(必填)", operators[operatorIDs[0]], 0, 260),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-normalize", "Orbbec Ego 左相机标准化", operators[operatorIDs[1]], 240, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-face-blur", "人脸脱敏(真实视频)", operators[operatorIDs[2]], 500, 260, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-rough-cut", "Qwen3-VL 手部行为语义粗切", operators[operatorIDs[3]], 760, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "18", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认", operators[operatorIDs[4]], 1040, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_WORKGROUP_ID": annotationWorkgroupID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认", operators[operatorIDs[4]], 1040, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuNodeWithHyperparams("fanyu-v5-package", "人工聚合确认后打包最终 MP4、语义 JSON 与 manifest", operators[operatorIDs[5]], 1320, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
|
||||
}
|
||||
for nodeIndex := range nodes {
|
||||
@ -653,9 +643,6 @@ func (server *server) ensureFanyuDeliveryTemplateV5(ctx context.Context, organiz
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(annotationWorkgroupID) == "" {
|
||||
return nil
|
||||
}
|
||||
if issues := server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction); len(issues) > 0 {
|
||||
return nil
|
||||
}
|
||||
@ -708,13 +695,13 @@ func (server *server) ensureFanyuDeliveryTemplateV54(ctx context.Context, organi
|
||||
}
|
||||
}
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
|
||||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuMultiportNode("fanyu-v54-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 260, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-face-blur", "人脸脱敏(多端口)", operators[operatorIDs[2]], 550, 260, map[string]string{"PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-rough-cut", "Qwen3-VL 手部行为语义粗切(多端口)", operators[operatorIDs[3]], 820, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "18", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[4]], 1110, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_WORKGROUP_ID": annotationWorkgroupID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[4]], 1110, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v54-package", "人工聚合确认后打包(多端口)", operators[operatorIDs[5]], 1400, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
|
||||
}
|
||||
for index := range nodes {
|
||||
@ -771,7 +758,7 @@ func (server *server) ensureFanyuDeliveryTemplateV54(ctx context.Context, organi
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if annotationWorkgroupID == "" || len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
return nil
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 4, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "multiport_artifact_contract", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "v5.4 explicit multiport data contract; PTS-grounded Qwen and four-stage human loop; pose-free direct package", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
|
||||
@ -822,14 +809,14 @@ func (server *server) ensureFanyuDeliveryTemplateV55(ctx context.Context, organi
|
||||
}
|
||||
}
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
|
||||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
nodes := []domain.WorkflowNode{
|
||||
fanyuMultiportNode("fanyu-v55-directory", "目录读取(多端口)", operators[operatorIDs[0]], 0, 260),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-normalize", "Orbbec Ego 左相机标准化(多端口)", operators[operatorIDs[1]], 240, 260, map[string]string{"CAMERA_SIDE": "left", "REQUIRE_STEREO": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-undistort", "左相机 OpenCV 真实去畸变(多端口)", operators[operatorIDs[2]], 480, 260, map[string]string{"UNDISTORT_ALPHA": "0", "REQUIRE_CALIBRATION": "true", "PRESERVE_AUDIO": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-face-blur", "YuNet 人脸真实脱敏(多端口)", operators[operatorIDs[3]], 720, 260, map[string]string{"DETECTION_METHOD": "yunet", "MODEL_PATH": "/app/operator-repos/builtin/video_face_blur/assets/face_detection_yunet_2023mar.onnx", "MODEL_SHA256": "8f2383e4dd3cfbb4553ea8718107fc0423210dc964f9f4280604804ed2552fa4", "CONFIDENCE_THRESHOLD": "0.5", "NMS_THRESHOLD": "0.3", "TOP_K": "5000", "BLUR_TYPE": "mosaic", "BLUR_EXPANSION_RATIO": "1.35", "TRACK_HOLD_FRAMES": "4", "TRACK_IOU_THRESHOLD": "0.2", "PRESERVE_AUDIO": "true", "PRESERVE_PTS": "true", "REQUIRE_PTS": "true", "REQUIRE_DETECTIONS": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-rough-cut", "Qwen3-VL 手部行为语义粗切(多端口)", operators[operatorIDs[4]], 960, 260, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "6", "MAX_NEW_TOKENS": "128", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[5]], 1200, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_WORKGROUP_ID": annotationWorkgroupID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认(多端口)", operators[operatorIDs[5]], 1200, 260, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v55-package", "人工聚合确认后打包(多端口)", operators[operatorIDs[6]], 1440, 260, map[string]string{"REQUIRE_HEADPOSE": "false", "POSE_FREE": "true", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
|
||||
}
|
||||
for index := range nodes {
|
||||
@ -889,7 +876,7 @@ func (server *server) ensureFanyuDeliveryTemplateV55(ctx context.Context, organi
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if annotationWorkgroupID == "" || len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
return nil
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 5, Name: template.Name, Description: template.Description, Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns, WorkflowInputs: workflowInputs, Nodes: nodes, Edges: edges, Capabilities: []string{"directory_input", "multiport_artifact_contract", "left_camera_opencv_undistort", "yunet_face_anonymization", "qwen3vl_behavior_rough_cut", "human_cut_adjustment", "human_cut_review", "human_semantic_annotation", "human_semantic_review", "human_acceptance", "final_segment_package"}, RequiredPluginIDs: []string{pluginregistry.HumanLoopCoreID, pluginregistry.AnnotationQAID}, ContentDigest: workflowReleaseDigest(template), ReleaseNotes: "v5.5 materializes OpenCV rectification and fixed-SHA MIT YuNet face anonymization before PTS rough cutting; virtual cutting and four-stage human loop unchanged", PublishedByUserID: "system", PublishedAt: now, CreatedAt: now}
|
||||
@ -951,7 +938,7 @@ func (server *server) ensureFanyuDeliveryTemplateV56(ctx context.Context, organi
|
||||
}
|
||||
|
||||
annotationTemplateID := fmt.Sprintf("tpl-fanyu-convenience-store-v5-%s", organizationID)
|
||||
annotationWorkgroupID := strings.TrimSpace(os.Getenv("FANYU_V5_ANNOTATION_WORKGROUP_ID"))
|
||||
annotationSupplierID := strings.TrimSpace(os.Getenv("FANYU_V5_SUPPLIER_ID"))
|
||||
headposeOverrides := map[string]string{
|
||||
"HEADPOSE_API_BASE_URL": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_API_BASE_URL")),
|
||||
"HEADPOSE_SERVICE_IMAGE_ID": strings.TrimSpace(os.Getenv("FANYU_HEADPOSE_SERVICE_IMAGE_ID")),
|
||||
@ -985,7 +972,7 @@ func (server *server) ensureFanyuDeliveryTemplateV56(ctx context.Context, organi
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v56-rough-cut", "Qwen3-VL 左相机语义粗切", operators[operatorIDs[4]], 1060, 80, map[string]string{"MODEL_PATH": "/workspace/models/Qwen3-VL-8B-Instruct", "MODEL_REVISION": "0c351dd01ed87e9c1b53cbc748cba10e6187ff3b", "MODEL_MANIFEST_PATH": "/workspace/models/Qwen3-VL-8B-Instruct/MODEL_MANIFEST.json", "MODEL_MANIFEST_SHA256": "3c00bb1b1ada0542de91785001395fc6d4252e3d8a0844ec5fdfe05b306a481a", "TRUST_PREVERIFIED_MODEL": "true", "TECHNICAL_BLOCK_SECONDS": "10", "FRAMES_PER_TECHNICAL_BLOCK": "6", "MAX_NEW_TOKENS": "128", "PTS_OCR_TOLERANCE_FRAMES": "3", "REQUIRE_NON_EMPTY_RESULT": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v56-headpose", "6DRepNet HeadPose(开源)", operators[operatorIDs[6]], 1060, 320, headposeOverrides),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v56-handpose", "WiLoR HandPose(开源)", operators[operatorIDs[7]], 1060, 560, map[string]string{"INPUT_URL": "", "INPUT_PATH": "", "MEDIA_KIND": "video", "FRAME_STRIDE": "3", "MAX_FRAMES": "120", "VIDEO_CHUNK_FRAMES": "119", "REQUIRE_FULL_VIDEO_COVERAGE": "true", "DOWNLOAD_OUTPUTS": "true", "REQUEST_TIMEOUT_SECONDS": "1800"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v56-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认", operators[operatorIDs[5]], 1340, 80, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_WORKGROUP_ID": annotationWorkgroupID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v56-human", "人工调切→剪切审核→语义标注→标注审核→聚合确认", operators[operatorIDs[5]], 1340, 80, map[string]string{"ANNOTATION_TEMPLATE_ID": annotationTemplateID, "ANNOTATION_SUPPLIER_ID": annotationSupplierID, "RELEASE_POLICY": "all_accepted", "PARTITION_MAX_ITEMS": "32", "MAX_REWORK_ROUNDS": "5", "REQUIRE_PREPACKAGE_ACCEPTANCE": "true"}),
|
||||
fanyuMultiportNodeWithHyperparams("fanyu-v56-package", "双目同步裁切 + 姿态结果打包交付", operators[operatorIDs[8]], 1640, 320, map[string]string{"REQUIRE_HEADPOSE": "true", "REQUIRE_HANDPOSE": "true", "REQUIRE_STEREO_DELIVERY": "true", "POSE_FREE": "false", "REQUIRE_FINAL_ACCEPTANCE": "true", "GENERATE_SEGMENT_MP4": "true"}),
|
||||
}
|
||||
edges := []domain.WorkflowEdge{
|
||||
@ -1053,7 +1040,7 @@ func (server *server) ensureFanyuDeliveryTemplateV56(ctx context.Context, organi
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if annotationWorkgroupID == "" || len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
return nil
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{
|
||||
@ -1144,16 +1131,6 @@ func (server *server) ensureFanyuDeliveryTemplateV57(ctx context.Context, organi
|
||||
if len(server.validateWorkflowOperatorPublication(ctx, nodes, domain.WorkflowExecutionScopeProduction)) > 0 {
|
||||
return nil
|
||||
}
|
||||
for _, node := range nodes {
|
||||
if node.ID != "fanyu-v56-human" {
|
||||
continue
|
||||
}
|
||||
for _, parameter := range node.Data.Hyperparams {
|
||||
if parameter.Key == "ANNOTATION_WORKGROUP_ID" && strings.TrimSpace(fmt.Sprint(parameter.Value)) == "" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
release := domain.WorkflowReleaseRecord{
|
||||
ID: releaseID, OrganizationID: organizationID, TemplateID: template.ID, Version: 7, Name: template.Name, Description: template.Description,
|
||||
Type: template.Type, Kind: template.Kind, ExecutionScope: template.ExecutionScope, MaxConcurrentRuns: template.MaxConcurrentRuns,
|
||||
|
||||
@ -408,7 +408,7 @@ func (server *server) canAccessHumanItem(ctx context.Context, request *http.Requ
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
if requiredRole != "" {
|
||||
return membershipHasRole(memberships, legacy, requiredRole)
|
||||
}
|
||||
@ -799,7 +799,7 @@ func (server *server) handleHumanItemRelease(writer http.ResponseWriter, request
|
||||
}
|
||||
|
||||
func userRoleSupportsAnnotationAssignment(role domain.UserRole, assignmentRole domain.AnnotationAssignmentRole) bool {
|
||||
if role == domain.UserRoleAdmin {
|
||||
if role == domain.UserRoleAdmin || role == domain.UserRoleOrganizationAdmin || role == domain.UserRoleMember {
|
||||
return true
|
||||
}
|
||||
switch assignmentRole {
|
||||
@ -879,7 +879,7 @@ func (server *server) handleHumanItemAssignment(writer http.ResponseWriter, requ
|
||||
renderError(writer, http.StatusInternalServerError, membershipErr)
|
||||
return
|
||||
}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
legacy := domain.AnnotationTaskRecord{ProjectID: item.ProjectID, SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID}
|
||||
if !membershipHasRole(memberships, legacy, requiredRole) {
|
||||
renderValidationError(writer, validationIssue{Field: "assignedUserId", Message: "assigned user lacks the required project workgroup role"})
|
||||
return
|
||||
@ -1494,6 +1494,98 @@ func (server *server) handleHumanRejectReopen(writer http.ResponseWriter, reques
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"item": item, "reject": reject})
|
||||
}
|
||||
|
||||
type humanEscalationDecisionRequest struct {
|
||||
Version int `json:"version"`
|
||||
Action string `json:"action"`
|
||||
TargetStageID string `json:"targetStageId,omitempty"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
func (server *server) handleHumanEscalationDecision(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || !isOrganizationAdmin(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "organization admin is required"})
|
||||
return
|
||||
}
|
||||
item, ok := server.loadHumanItemForRequest(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var payload humanEscalationDecisionRequest
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
if payload.Version != item.Version {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "human item version conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
if item.Status != domain.HumanItemEscalated {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "human item is not escalated"})
|
||||
return
|
||||
}
|
||||
payload.Action = strings.ToLower(strings.TrimSpace(payload.Action))
|
||||
payload.Comment = strings.TrimSpace(payload.Comment)
|
||||
if payload.Comment == "" || (payload.Action != "reopen" && payload.Action != "close") {
|
||||
renderValidationError(writer, validationIssue{Field: "escalation", Message: "action (reopen or close) and comment are required"})
|
||||
return
|
||||
}
|
||||
previousVersion := item.Version
|
||||
if payload.Action == "reopen" {
|
||||
batch, err := server.store.GetHumanBatch(request.Context(), item.BatchID)
|
||||
if err != nil || batch == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "human batch not found"})
|
||||
}
|
||||
return
|
||||
}
|
||||
target := strings.TrimSpace(payload.TargetStageID)
|
||||
if target == "" {
|
||||
target = batch.Stages[0].ID
|
||||
}
|
||||
if _, _, exists := humanStage(batch, target); !exists {
|
||||
renderValidationError(writer, validationIssue{Field: "targetStageId", Message: "target stage is not configured for this batch"})
|
||||
return
|
||||
}
|
||||
item.CurrentStageID = target
|
||||
item.Status = domain.HumanItemRework
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
if item.MaxReworkRounds <= item.ReviewRound {
|
||||
item.MaxReworkRounds = item.ReviewRound + 1
|
||||
}
|
||||
batch.Status = domain.HumanBatchActive
|
||||
_ = server.store.UpsertHumanBatch(request.Context(), *batch)
|
||||
} else {
|
||||
item.Status = domain.HumanItemRejected
|
||||
item.RejectedAt = nowISO()
|
||||
}
|
||||
item.Version++
|
||||
updated, err := server.store.UpdateHumanItemVersioned(request.Context(), *item, previousVersion)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if !updated {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "human item version conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
_ = server.appendHumanEvent(request.Context(), *item, "escalation_"+payload.Action, principal.User.ID, map[string]any{"comment": payload.Comment, "targetStageId": item.CurrentStageID})
|
||||
rejects, _ := server.store.ListHumanRejects(request.Context(), item.OrganizationID, domain.HumanRejectQuery{ItemID: item.ID})
|
||||
for _, reject := range rejects {
|
||||
if reject.Status != domain.HumanRejectEscalated {
|
||||
continue
|
||||
}
|
||||
reject.Status = domain.HumanRejectResolved
|
||||
reject.Version++
|
||||
reject.ReopenComment = payload.Comment
|
||||
reject.UpdatedAt = nowISO()
|
||||
_ = server.store.UpsertHumanReject(request.Context(), reject)
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, item)
|
||||
}
|
||||
|
||||
func (server *server) reopenRejectedDeliveryPackage(writer http.ResponseWriter, request *http.Request, reject *domain.HumanRejectRecord, payload humanReopenRequest) {
|
||||
item, err := server.store.GetDeliveryPackage(request.Context(), reject.ItemID)
|
||||
if err != nil {
|
||||
|
||||
496
internal/api/object_storage_upload_sessions.go
Normal file
496
internal/api/object_storage_upload_sessions.go
Normal file
@ -0,0 +1,496 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
const (
|
||||
uploadSessionDirectThresholdBytes int64 = 100 * 1024 * 1024
|
||||
uploadSessionActiveRetention = 7 * 24 * time.Hour
|
||||
uploadSessionCompletedRetention = 30 * 24 * time.Hour
|
||||
)
|
||||
|
||||
type objectStorageUploadSessionCreateInput struct {
|
||||
Bucket string `json:"bucket"`
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
ConflictPolicy string `json:"conflictPolicy,omitempty"`
|
||||
Items []objectStorageUploadSessionCreateItemInput `json:"items"`
|
||||
}
|
||||
|
||||
type objectStorageUploadSessionCreateItemInput struct {
|
||||
RelativePath string `json:"relativePath"`
|
||||
Kind string `json:"kind"`
|
||||
SizeBytes int64 `json:"sizeBytes,omitempty"`
|
||||
ContentType string `json:"contentType,omitempty"`
|
||||
LastModified int64 `json:"lastModified,omitempty"`
|
||||
}
|
||||
|
||||
type objectStorageUploadSessionPartInput struct {
|
||||
PartNumber int `json:"partNumber"`
|
||||
ETag string `json:"eTag"`
|
||||
UploadedBytes int64 `json:"uploadedBytes"`
|
||||
}
|
||||
|
||||
type objectStorageUploadSessionPartURLInput struct {
|
||||
PartNumber int `json:"partNumber"`
|
||||
}
|
||||
|
||||
func uploadSessionExpiry(status domain.ObjectStorageUploadSessionStatus, now time.Time) string {
|
||||
if status == domain.ObjectStorageUploadSessionCompleted || status == domain.ObjectStorageUploadSessionCancelled {
|
||||
return now.Add(uploadSessionCompletedRetention).UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
return now.Add(uploadSessionActiveRetention).UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
|
||||
func (server *server) ensureUploadSessionAccess(writer http.ResponseWriter, request *http.Request, session *domain.ObjectStorageUploadSessionRecord) (*authenticatedPrincipal, bool) {
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || principal == nil {
|
||||
renderJSON(writer, http.StatusUnauthorized, map[string]string{"error": "login is required"})
|
||||
return nil, false
|
||||
}
|
||||
if session == nil {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "upload session not found"})
|
||||
return nil, false
|
||||
}
|
||||
if !server.ensureTenantAccess(writer, request, session.OrganizationID, "Upload session") {
|
||||
return nil, false
|
||||
}
|
||||
if !isOrganizationAdmin(principal) && session.UserID != principal.User.ID {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "upload session access is restricted to its creator"})
|
||||
return nil, false
|
||||
}
|
||||
return principal, true
|
||||
}
|
||||
|
||||
func uploadSessionResponse(session domain.ObjectStorageUploadSessionRecord) domain.ObjectStorageUploadSessionSummary {
|
||||
return domain.SummarizeObjectStorageUploadSession(session)
|
||||
}
|
||||
|
||||
func uploadSessionRefreshStatus(session *domain.ObjectStorageUploadSessionRecord) {
|
||||
if session == nil || session.Status == domain.ObjectStorageUploadSessionPaused || session.Status == domain.ObjectStorageUploadSessionCancelled {
|
||||
return
|
||||
}
|
||||
allResolved := true
|
||||
hasFailure := false
|
||||
for _, item := range session.Items {
|
||||
if item.Status == domain.ObjectStorageUploadItemFailed {
|
||||
hasFailure = true
|
||||
}
|
||||
if item.Status != domain.ObjectStorageUploadItemSuccess && item.Status != domain.ObjectStorageUploadItemSkipped && item.Status != domain.ObjectStorageUploadItemCancelled {
|
||||
allResolved = false
|
||||
}
|
||||
}
|
||||
if allResolved && !hasFailure {
|
||||
session.Status = domain.ObjectStorageUploadSessionCompleted
|
||||
session.CompletedAt = nowISO()
|
||||
} else if hasFailure {
|
||||
session.Status = domain.ObjectStorageUploadSessionFailed
|
||||
} else {
|
||||
session.Status = domain.ObjectStorageUploadSessionRunning
|
||||
}
|
||||
}
|
||||
|
||||
func uploadSessionItem(session *domain.ObjectStorageUploadSessionRecord, itemID string) (*domain.ObjectStorageUploadItemRecord, int) {
|
||||
if session == nil {
|
||||
return nil, -1
|
||||
}
|
||||
for index := range session.Items {
|
||||
if session.Items[index].ID == itemID {
|
||||
return &session.Items[index], index
|
||||
}
|
||||
}
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
func (server *server) saveUploadSession(request *http.Request, session *domain.ObjectStorageUploadSessionRecord) error {
|
||||
if session == nil {
|
||||
return fmt.Errorf("upload session is required")
|
||||
}
|
||||
session.Version++
|
||||
session.UpdatedAt = nowISO()
|
||||
session.ExpiresAt = uploadSessionExpiry(session.Status, time.Now())
|
||||
return server.store.UpsertObjectStorageUploadSession(request.Context(), *session)
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionsList(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || principal == nil {
|
||||
renderJSON(writer, http.StatusUnauthorized, map[string]string{"error": "login is required"})
|
||||
return
|
||||
}
|
||||
userID := principal.User.ID
|
||||
if isOrganizationAdmin(principal) && strings.EqualFold(strings.TrimSpace(request.URL.Query().Get("all")), "true") {
|
||||
userID = ""
|
||||
}
|
||||
items, err := server.store.ListObjectStorageUploadSessions(request.Context(), server.requestOrganizationID(request), userID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
summaries := make([]domain.ObjectStorageUploadSessionSummary, 0, len(items))
|
||||
for _, item := range items {
|
||||
summaries = append(summaries, uploadSessionResponse(item))
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": summaries})
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionGet(writer http.ResponseWriter, request *http.Request) {
|
||||
session, err := server.store.GetObjectStorageUploadSession(request.Context(), chi.URLParam(request, "sessionId"))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if _, ok := server.ensureUploadSessionAccess(writer, request, session); !ok {
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionCreate(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, ok := currentPrincipal(request)
|
||||
if !ok || principal == nil {
|
||||
renderJSON(writer, http.StatusUnauthorized, map[string]string{"error": "login is required"})
|
||||
return
|
||||
}
|
||||
var payload objectStorageUploadSessionCreateInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
batchInput := domain.ObjectStorageBatchUploadPrepareInput{Bucket: payload.Bucket, Prefix: payload.Prefix, ConflictPolicy: payload.ConflictPolicy, Items: make([]domain.ObjectStorageBatchUploadItemInput, 0, len(payload.Items))}
|
||||
for _, item := range payload.Items {
|
||||
batchInput.Items = append(batchInput.Items, domain.ObjectStorageBatchUploadItemInput{RelativePath: item.RelativePath, Kind: item.Kind, SizeBytes: item.SizeBytes, ContentType: item.ContentType})
|
||||
}
|
||||
prepared, prefix, policy, issue := prepareObjectStorageBatchItems(batchInput)
|
||||
if issue != nil {
|
||||
renderValidationError(writer, *issue)
|
||||
return
|
||||
}
|
||||
connectionID := strings.TrimSpace(request.URL.Query().Get("connectionId"))
|
||||
browser, connection, cleanup, err := server.resolveObjectStorageBrowser(request.Context(), connectionID)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if browser == nil || connection == nil {
|
||||
renderValidationError(writer, validationIssue{Field: "connectionId", Message: "connectionId is required"})
|
||||
return
|
||||
}
|
||||
bucket, err := resolveObjectStorageBucket(connection, payload.Bucket)
|
||||
if err != nil || bucket == "" {
|
||||
renderValidationError(writer, validationIssue{Field: "bucket", Message: "bucket is required"})
|
||||
return
|
||||
}
|
||||
if err := inspectObjectStorageBatchConflicts(request.Context(), browser, bucket, prepared); err != nil {
|
||||
renderObjectStorageWriteError(writer, err)
|
||||
return
|
||||
}
|
||||
plan := finalizeObjectStorageBatchPlan(prepared, policy)
|
||||
now := time.Now()
|
||||
session := domain.ObjectStorageUploadSessionRecord{ID: domain.NewID("upload-session"), OrganizationID: server.requestOrganizationID(request), UserID: principal.User.ID, ConnectionID: connectionID, Bucket: bucket, Prefix: prefix, ConflictPolicy: policy, Status: domain.ObjectStorageUploadSessionPrepared, Version: 1, CreatedAt: now.UTC().Format(time.RFC3339Nano), ExpiresAt: uploadSessionExpiry(domain.ObjectStorageUploadSessionPrepared, now)}
|
||||
for index, item := range plan.Items {
|
||||
input := payload.Items[index]
|
||||
status := domain.ObjectStorageUploadItemPending
|
||||
if item.Action == "skip" {
|
||||
status = domain.ObjectStorageUploadItemSkipped
|
||||
}
|
||||
if item.Action == "conflict" {
|
||||
status = domain.ObjectStorageUploadItemFailed
|
||||
}
|
||||
session.Items = append(session.Items, domain.ObjectStorageUploadItemRecord{ID: domain.NewID("upload-item"), RelativePath: item.RelativePath, Key: item.Key, Kind: item.Kind, ContentType: item.ContentType, SizeBytes: item.SizeBytes, LastModified: input.LastModified, Action: item.Action, Status: status, Error: item.Message, UpdatedAt: session.CreatedAt})
|
||||
}
|
||||
uploadSessionRefreshStatus(&session)
|
||||
if len(session.Items) > 0 && session.Status == domain.ObjectStorageUploadSessionCompleted {
|
||||
session.CompletedAt = session.CreatedAt
|
||||
}
|
||||
if err := server.store.UpsertObjectStorageUploadSession(request.Context(), session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusCreated, uploadSessionResponse(session))
|
||||
}
|
||||
|
||||
func (server *server) mutateObjectStorageUploadSession(writer http.ResponseWriter, request *http.Request, target domain.ObjectStorageUploadSessionStatus) {
|
||||
session, err := server.store.GetObjectStorageUploadSession(request.Context(), chi.URLParam(request, "sessionId"))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if _, ok := server.ensureUploadSessionAccess(writer, request, session); !ok {
|
||||
return
|
||||
}
|
||||
if target == domain.ObjectStorageUploadSessionCancelled {
|
||||
browser, _, cleanup, resolveErr := server.resolveObjectStorageBrowser(request.Context(), session.ConnectionID)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
if resolveErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, resolveErr)
|
||||
return
|
||||
}
|
||||
for index := range session.Items {
|
||||
item := &session.Items[index]
|
||||
if item.Status == domain.ObjectStorageUploadItemSuccess || item.Status == domain.ObjectStorageUploadItemSkipped {
|
||||
continue
|
||||
}
|
||||
if browser != nil && item.UploadID != "" {
|
||||
_ = browser.AbortMultipartUpload(request.Context(), session.Bucket, item.Key, item.UploadID)
|
||||
}
|
||||
item.Status = domain.ObjectStorageUploadItemCancelled
|
||||
item.UpdatedAt = nowISO()
|
||||
}
|
||||
session.CancelledAt = nowISO()
|
||||
}
|
||||
if target == domain.ObjectStorageUploadSessionRunning && session.Status != domain.ObjectStorageUploadSessionPaused && session.Status != domain.ObjectStorageUploadSessionFailed && session.Status != domain.ObjectStorageUploadSessionPrepared {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "upload session cannot be resumed from its current state"})
|
||||
return
|
||||
}
|
||||
session.Status = target
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionPause(writer http.ResponseWriter, request *http.Request) {
|
||||
server.mutateObjectStorageUploadSession(writer, request, domain.ObjectStorageUploadSessionPaused)
|
||||
}
|
||||
func (server *server) handleObjectStorageUploadSessionResume(writer http.ResponseWriter, request *http.Request) {
|
||||
server.mutateObjectStorageUploadSession(writer, request, domain.ObjectStorageUploadSessionRunning)
|
||||
}
|
||||
func (server *server) handleObjectStorageUploadSessionCancel(writer http.ResponseWriter, request *http.Request) {
|
||||
server.mutateObjectStorageUploadSession(writer, request, domain.ObjectStorageUploadSessionCancelled)
|
||||
}
|
||||
|
||||
func (server *server) loadUploadSessionItem(writer http.ResponseWriter, request *http.Request) (*domain.ObjectStorageUploadSessionRecord, *domain.ObjectStorageUploadItemRecord, bool) {
|
||||
session, err := server.store.GetObjectStorageUploadSession(request.Context(), chi.URLParam(request, "sessionId"))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return nil, nil, false
|
||||
}
|
||||
if _, ok := server.ensureUploadSessionAccess(writer, request, session); !ok {
|
||||
return nil, nil, false
|
||||
}
|
||||
item, _ := uploadSessionItem(session, chi.URLParam(request, "itemId"))
|
||||
if item == nil {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "upload item not found"})
|
||||
return nil, nil, false
|
||||
}
|
||||
return session, item, true
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionItemStart(writer http.ResponseWriter, request *http.Request) {
|
||||
session, item, ok := server.loadUploadSessionItem(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if session.Status == domain.ObjectStorageUploadSessionPaused || session.Status == domain.ObjectStorageUploadSessionCancelled || session.Status == domain.ObjectStorageUploadSessionCompleted {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "upload session is not runnable"})
|
||||
return
|
||||
}
|
||||
if item.Status == domain.ObjectStorageUploadItemSkipped || item.Status == domain.ObjectStorageUploadItemSuccess {
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
return
|
||||
}
|
||||
browser, _, cleanup, err := server.resolveObjectStorageBrowser(request.Context(), session.ConnectionID)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
if err != nil || browser == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusBadRequest, map[string]string{"error": "storage connection unavailable"})
|
||||
}
|
||||
return
|
||||
}
|
||||
if item.Kind == "directory" {
|
||||
result, putErr := browser.PutObject(request.Context(), session.Bucket, item.Key, []byte{}, "application/x-directory")
|
||||
if putErr != nil {
|
||||
renderObjectStorageWriteError(writer, putErr)
|
||||
return
|
||||
}
|
||||
item.Status, item.UploadedBytes, item.ETag, item.UpdatedAt = domain.ObjectStorageUploadItemSuccess, 0, result.ETag, nowISO()
|
||||
uploadSessionRefreshStatus(session)
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
return
|
||||
}
|
||||
session.Status = domain.ObjectStorageUploadSessionRunning
|
||||
item.Status, item.Error, item.UpdatedAt = domain.ObjectStorageUploadItemUploading, "", nowISO()
|
||||
if item.SizeBytes >= uploadSessionDirectThresholdBytes {
|
||||
if item.UploadID == "" {
|
||||
initiated, initiateErr := browser.InitiateMultipartUpload(request.Context(), session.Bucket, item.Key, item.ContentType, objectStoragePresignDefaultExpires)
|
||||
if initiateErr != nil {
|
||||
renderObjectStorageWriteError(writer, initiateErr)
|
||||
return
|
||||
}
|
||||
item.UploadID, item.Mode = initiated.UploadID, "multipart"
|
||||
}
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"session": uploadSessionResponse(*session), "mode": "multipart", "uploadId": item.UploadID})
|
||||
return
|
||||
}
|
||||
presigned, presignErr := browser.PresignPutObject(request.Context(), session.Bucket, item.Key, item.ContentType, objectStoragePresignDefaultExpires)
|
||||
if presignErr != nil {
|
||||
renderObjectStorageWriteError(writer, presignErr)
|
||||
return
|
||||
}
|
||||
item.Mode = "direct"
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"session": uploadSessionResponse(*session), "mode": "direct", "upload": presigned})
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionPartURL(writer http.ResponseWriter, request *http.Request) {
|
||||
session, item, ok := server.loadUploadSessionItem(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if session.Status != domain.ObjectStorageUploadSessionRunning || item.UploadID == "" {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "multipart upload is not running"})
|
||||
return
|
||||
}
|
||||
var payload objectStorageUploadSessionPartURLInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
if payload.PartNumber < 1 || payload.PartNumber > 10000 {
|
||||
renderValidationError(writer, validationIssue{Field: "partNumber", Message: "partNumber must be between 1 and 10000"})
|
||||
return
|
||||
}
|
||||
browser, _, cleanup, err := server.resolveObjectStorageBrowser(request.Context(), session.ConnectionID)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
if err != nil || browser == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusBadRequest, map[string]string{"error": "storage connection unavailable"})
|
||||
}
|
||||
return
|
||||
}
|
||||
result, err := browser.PresignMultipartUploadPart(request.Context(), session.Bucket, item.Key, item.UploadID, payload.PartNumber, objectStoragePresignDefaultExpires)
|
||||
if err != nil {
|
||||
renderObjectStorageWriteError(writer, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionPartComplete(writer http.ResponseWriter, request *http.Request) {
|
||||
session, item, ok := server.loadUploadSessionItem(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var payload objectStorageUploadSessionPartInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
parts := append([]domain.ObjectStorageMultipartUploadPart(nil), item.UploadedParts...)
|
||||
parts = append(parts, domain.ObjectStorageMultipartUploadPart{PartNumber: payload.PartNumber, ETag: strings.Trim(payload.ETag, `"`)})
|
||||
normalized, err := normalizeObjectStorageMultipartParts(parts)
|
||||
if err != nil {
|
||||
renderValidationError(writer, validationIssue{Field: "part", Message: err.Error()})
|
||||
return
|
||||
}
|
||||
item.UploadedParts = normalized
|
||||
if payload.UploadedBytes > item.UploadedBytes {
|
||||
item.UploadedBytes = payload.UploadedBytes
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionItemComplete(writer http.ResponseWriter, request *http.Request) {
|
||||
session, item, ok := server.loadUploadSessionItem(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
browser, _, cleanup, err := server.resolveObjectStorageBrowser(request.Context(), session.ConnectionID)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
if err != nil || browser == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusBadRequest, map[string]string{"error": "storage connection unavailable"})
|
||||
}
|
||||
return
|
||||
}
|
||||
if item.Mode == "multipart" {
|
||||
parts, partsErr := normalizeObjectStorageMultipartParts(item.UploadedParts)
|
||||
if partsErr != nil {
|
||||
renderValidationError(writer, validationIssue{Field: "parts", Message: partsErr.Error()})
|
||||
return
|
||||
}
|
||||
result, completeErr := browser.CompleteMultipartUpload(request.Context(), session.Bucket, item.Key, item.UploadID, parts)
|
||||
if completeErr != nil {
|
||||
renderObjectStorageWriteError(writer, completeErr)
|
||||
return
|
||||
}
|
||||
item.ETag = result.ETag
|
||||
} else {
|
||||
result, summaryErr := browser.GetObjectSummary(request.Context(), session.Bucket, item.Key)
|
||||
if summaryErr != nil {
|
||||
renderObjectStorageWriteError(writer, summaryErr)
|
||||
return
|
||||
}
|
||||
if result.SizeBytes != item.SizeBytes {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "uploaded object size does not match the selected file"})
|
||||
return
|
||||
}
|
||||
item.ETag = result.ETag
|
||||
}
|
||||
item.Status, item.UploadedBytes, item.Error, item.UpdatedAt = domain.ObjectStorageUploadItemSuccess, item.SizeBytes, "", nowISO()
|
||||
uploadSessionRefreshStatus(session)
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
}
|
||||
|
||||
func (server *server) handleObjectStorageUploadSessionItemFailure(writer http.ResponseWriter, request *http.Request) {
|
||||
session, item, ok := server.loadUploadSessionItem(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var payload struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
item.Status, item.Error, item.UpdatedAt = domain.ObjectStorageUploadItemFailed, strings.TrimSpace(payload.Error), nowISO()
|
||||
uploadSessionRefreshStatus(session)
|
||||
if err := server.saveUploadSession(request, session); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, uploadSessionResponse(*session))
|
||||
}
|
||||
67
internal/api/object_storage_upload_sessions_test.go
Normal file
67
internal/api/object_storage_upload_sessions_test.go
Normal file
@ -0,0 +1,67 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
"droboticflow/internal/store"
|
||||
)
|
||||
|
||||
func TestObjectStorageUploadSessionPersistsSkipAndMultipartResumeState(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
organization, err := dataStore.EnsureDefaultOrganization(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
passwordHash, err := hashPassword("upload-admin-password")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
admin, err := dataStore.CreateUser(ctx, domain.CreateUserInput{OrganizationID: organization.ID, Name: "Upload Admin", Email: "upload-admin@example.com", Role: domain.UserRoleAdmin, PasswordHash: passwordHash})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
connection, err := dataStore.CreateStorageConnection(ctx, domain.CreateStorageConnectionInput{Name: "BOS", Provider: domain.StorageProviderBOS, Endpoint: "https://bos.example.test", Bucket: "datastorage", AccessKeyID: "ak", SecretAccessKey: "sk"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fakeBrowser := newFakeObjectStorageBrowser()
|
||||
fakeBrowser.objects["datastorage|dataset/already.bin"] = domain.ObjectStorageObjectSummary{Bucket: "datastorage", Key: "dataset/already.bin", SizeBytes: 10}
|
||||
original := storageConnectionBrowserResolver
|
||||
storageConnectionBrowserResolver = func(context.Context, *domain.StorageConnectionRecord) (objectStorageBrowser, func(), error) {
|
||||
return fakeBrowser, func() {}, nil
|
||||
}
|
||||
t.Cleanup(func() { storageConnectionBrowserResolver = original })
|
||||
handler := NewHandler(dataStore, nil)
|
||||
cookie := loginSession(t, handler, admin.Email, "upload-admin-password")
|
||||
body := `{"bucket":"datastorage","prefix":"dataset","conflictPolicy":"skip","items":[{"relativePath":"already.bin","kind":"file","sizeBytes":10},{"relativePath":"large.bin","kind":"file","sizeBytes":104857600,"contentType":"application/octet-stream"}]}`
|
||||
created := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions?connectionId="+connection.ID, []byte(body), cookie)
|
||||
if created.Code != http.StatusCreated {
|
||||
t.Fatalf("create=%d body=%s", created.Code, created.Body.String())
|
||||
}
|
||||
var summary domain.ObjectStorageUploadSessionSummary
|
||||
if err := json.Unmarshal(created.Body.Bytes(), &summary); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if summary.SkippedCount != 1 || summary.ProcessedBytes != 10 || len(summary.Session.Items) != 2 {
|
||||
t.Fatalf("summary=%#v", summary)
|
||||
}
|
||||
itemID := summary.Session.Items[1].ID
|
||||
started := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions/"+summary.Session.ID+"/items/"+itemID+"/start", nil, cookie)
|
||||
if started.Code != http.StatusOK || !strings.Contains(started.Body.String(), `"mode":"multipart"`) {
|
||||
t.Fatalf("start=%d body=%s", started.Code, started.Body.String())
|
||||
}
|
||||
paused := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions/"+summary.Session.ID+"/pause", nil, cookie)
|
||||
if paused.Code != http.StatusOK || !strings.Contains(paused.Body.String(), `"status":"paused"`) {
|
||||
t.Fatalf("pause=%d body=%s", paused.Code, paused.Body.String())
|
||||
}
|
||||
cancelled := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions/"+summary.Session.ID+"/cancel", nil, cookie)
|
||||
if cancelled.Code != http.StatusOK || !strings.Contains(cancelled.Body.String(), `"status":"cancelled"`) {
|
||||
t.Fatalf("cancel=%d body=%s", cancelled.Code, cancelled.Body.String())
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ func (server *server) migrateLegacyAnnotationHumanItems(ctx context.Context, org
|
||||
}
|
||||
batch = domain.HumanBatchRecord{
|
||||
ID: legacyHumanBatchID(task), OrganizationID: task.OrganizationID, PluginID: pluginregistry.AnnotationQAID,
|
||||
ProjectID: task.ProjectID, WorkflowID: task.WorkflowID, RunID: task.RunID, GateNodeID: task.NodeID,
|
||||
ProjectID: task.ProjectID, SupplierID: task.SupplierID, WorkflowID: task.WorkflowID, RunID: task.RunID, GateNodeID: task.NodeID,
|
||||
Status: domain.HumanBatchActive, Stages: stages,
|
||||
ReleasePolicy: pluginReleasePolicy(config),
|
||||
PartitionMaxItems: pluginConfigInt(config, "partitionMaxItems", 32),
|
||||
@ -205,7 +205,7 @@ func (server *server) migrateLegacyAnnotationHumanItems(ctx context.Context, org
|
||||
Subject: domain.HumanSubjectRef{ArtifactID: task.ArtifactID, ItemKey: task.ID, MediaType: "video/mp4", Payload: map[string]any{
|
||||
"sourceVideo": task.SourceVideo, "clipStart": task.ClipStart, "clipEnd": task.ClipEnd, "sourceIsFullVideo": task.SourceIsFullVideo, "sourceDurationSeconds": task.SourceDurationSeconds, "templateId": task.TemplateID,
|
||||
}},
|
||||
CurrentStageID: stageID, Status: status, AssignedUserID: task.AssignedUserID, WorkgroupID: task.WorkgroupID,
|
||||
CurrentStageID: stageID, Status: status, AssignedUserID: task.AssignedUserID, SupplierID: task.SupplierID, WorkgroupID: task.WorkgroupID,
|
||||
VendorID: task.VendorID, CurrentRevision: task.CurrentRevision, MaxReworkRounds: batch.MaxReworkRounds,
|
||||
Version: 1, LatestAuthorUserID: authorID, CreatedAt: task.CreatedAt,
|
||||
}
|
||||
@ -432,6 +432,23 @@ func (server *server) handleOrganizationPluginUpdate(writer http.ResponseWriter,
|
||||
return
|
||||
}
|
||||
config = normalized
|
||||
if !payload.Enabled {
|
||||
items, err := server.store.ListHumanItems(request.Context(), organizationID, domain.HumanItemQuery{PluginID: pluginregistry.AnnotationQAID})
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
active := 0
|
||||
for _, item := range items {
|
||||
if humanItemPending(item.Status) || item.Status == domain.HumanItemEscalated {
|
||||
active++
|
||||
}
|
||||
}
|
||||
if active > 0 {
|
||||
renderJSON(writer, http.StatusConflict, map[string]any{"error": "插件仍有未完成的人工任务,不能关闭", "code": "plugin_has_active_human_work", "activeItemCount": active})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
updatedBy := ""
|
||||
|
||||
333
internal/api/project_members.go
Normal file
333
internal/api/project_members.go
Normal file
@ -0,0 +1,333 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type supplierInput struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type projectMemberInput struct {
|
||||
UserID string `json:"userId"`
|
||||
SupplierID string `json:"supplierId,omitempty"`
|
||||
Roles []domain.AnnotationAssignmentRole `json:"roles"`
|
||||
}
|
||||
|
||||
type projectMemberBulkInput struct {
|
||||
Action string `json:"action"`
|
||||
MemberIDs []string `json:"memberIds"`
|
||||
Roles []domain.AnnotationAssignmentRole `json:"roles,omitempty"`
|
||||
}
|
||||
|
||||
func isOrganizationAdmin(principal *authenticatedPrincipal) bool {
|
||||
return principal != nil && (principal.User.IsSuperAdmin || principal.User.Role == domain.UserRoleAdmin || principal.User.Role == domain.UserRoleOrganizationAdmin)
|
||||
}
|
||||
|
||||
func normalizedMemberRoles(values []domain.AnnotationAssignmentRole) ([]domain.AnnotationAssignmentRole, bool) {
|
||||
roles := domain.NormalizeProjectMemberRoles(values)
|
||||
return roles, len(roles) > 0
|
||||
}
|
||||
|
||||
func (server *server) projectMemberVisibleTo(principal *authenticatedPrincipal, member domain.ProjectMemberRecord) bool {
|
||||
if isOrganizationAdmin(principal) {
|
||||
return true
|
||||
}
|
||||
if principal == nil {
|
||||
return false
|
||||
}
|
||||
if principal.User.Role == domain.UserRoleSupplierManager {
|
||||
return strings.TrimSpace(principal.User.SupplierID) != "" && principal.User.SupplierID == member.SupplierID
|
||||
}
|
||||
return principal.User.ID == member.UserID
|
||||
}
|
||||
|
||||
func (server *server) handleSuppliersList(writer http.ResponseWriter, request *http.Request) {
|
||||
items, err := server.store.ListSuppliers(request.Context(), server.requestOrganizationID(request))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
if principal != nil && principal.User.Role == domain.UserRoleSupplierManager {
|
||||
filtered := items[:0]
|
||||
for _, item := range items {
|
||||
if item.ID == principal.User.SupplierID {
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
}
|
||||
items = filtered
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
func (server *server) handleSupplierCreate(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !isOrganizationAdmin(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "organization admin is required"})
|
||||
return
|
||||
}
|
||||
var payload supplierInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
payload.Name = strings.TrimSpace(payload.Name)
|
||||
if payload.Name == "" {
|
||||
renderValidationError(writer, validationIssue{Field: "name", Message: "name is required"})
|
||||
return
|
||||
}
|
||||
item := domain.SupplierRecord{ID: domain.NewID("supplier"), OrganizationID: server.requestOrganizationID(request), Name: payload.Name, Status: "active", CreatedAt: nowISO()}
|
||||
if err := server.store.UpsertSupplier(request.Context(), item); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusCreated, item)
|
||||
}
|
||||
|
||||
func (server *server) handleProjectMembersList(writer http.ResponseWriter, request *http.Request) {
|
||||
projectID := strings.TrimSpace(chi.URLParam(request, "id"))
|
||||
project, err := server.store.GetProject(request.Context(), projectID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if project == nil || !server.filterByTenant(request, project.OrganizationID) {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project not found"})
|
||||
return
|
||||
}
|
||||
items, err := server.store.ListProjectMembers(request.Context(), project.OrganizationID, project.ID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
principal, _ := currentPrincipal(request)
|
||||
filtered := items[:0]
|
||||
for _, item := range items {
|
||||
if server.projectMemberVisibleTo(principal, item) {
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
}
|
||||
sort.Slice(filtered, func(left, right int) bool { return filtered[left].CreatedAt < filtered[right].CreatedAt })
|
||||
renderJSON(writer, http.StatusOK, map[string]any{"items": filtered})
|
||||
}
|
||||
|
||||
func (server *server) saveProjectMember(writer http.ResponseWriter, request *http.Request, project *domain.ProjectRecord, member *domain.ProjectMemberRecord, payload projectMemberInput, created bool) {
|
||||
payload.UserID = strings.TrimSpace(payload.UserID)
|
||||
payload.SupplierID = strings.TrimSpace(payload.SupplierID)
|
||||
roles, valid := normalizedMemberRoles(payload.Roles)
|
||||
if payload.UserID == "" || !valid {
|
||||
renderValidationError(writer, validationIssue{Field: "member", Message: "userId and at least one project role are required"})
|
||||
return
|
||||
}
|
||||
user, err := server.store.GetUser(request.Context(), payload.UserID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if user == nil || !annotationOrganizationEqual(user.OrganizationID, project.OrganizationID) {
|
||||
renderValidationError(writer, validationIssue{Field: "userId", Message: "user must exist in the current organization"})
|
||||
return
|
||||
}
|
||||
if payload.SupplierID == "" {
|
||||
payload.SupplierID = strings.TrimSpace(user.SupplierID)
|
||||
}
|
||||
if payload.SupplierID != "" {
|
||||
supplier, supplierErr := server.store.GetSupplier(request.Context(), payload.SupplierID)
|
||||
if supplierErr != nil {
|
||||
renderError(writer, http.StatusInternalServerError, supplierErr)
|
||||
return
|
||||
}
|
||||
if supplier == nil || !annotationOrganizationEqual(supplier.OrganizationID, project.OrganizationID) {
|
||||
renderValidationError(writer, validationIssue{Field: "supplierId", Message: "supplier must exist in the current organization"})
|
||||
return
|
||||
}
|
||||
}
|
||||
if member == nil {
|
||||
member = &domain.ProjectMemberRecord{ID: domain.NewID("project-member"), OrganizationID: project.OrganizationID, ProjectID: project.ID, UserID: user.ID, CreatedAt: nowISO()}
|
||||
}
|
||||
member.SupplierID = payload.SupplierID
|
||||
member.Roles = roles
|
||||
if err := server.store.UpsertProjectMember(request.Context(), *member); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if created {
|
||||
renderJSON(writer, http.StatusCreated, member)
|
||||
return
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, member)
|
||||
}
|
||||
|
||||
func (server *server) handleProjectMemberCreate(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !isOrganizationAdmin(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "organization admin is required"})
|
||||
return
|
||||
}
|
||||
projectID := strings.TrimSpace(chi.URLParam(request, "id"))
|
||||
project, err := server.store.GetProject(request.Context(), projectID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if project == nil || !server.filterByTenant(request, project.OrganizationID) {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project not found"})
|
||||
return
|
||||
}
|
||||
var payload projectMemberInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
existing, err := server.store.GetProjectMemberByProjectUser(request.Context(), project.OrganizationID, project.ID, strings.TrimSpace(payload.UserID))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if existing != nil {
|
||||
renderJSON(writer, http.StatusConflict, map[string]any{"error": "project member already exists", "member": existing})
|
||||
return
|
||||
}
|
||||
server.saveProjectMember(writer, request, project, nil, payload, true)
|
||||
}
|
||||
|
||||
func (server *server) handleProjectMemberUpdate(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !isOrganizationAdmin(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "organization admin is required"})
|
||||
return
|
||||
}
|
||||
member, err := server.store.GetProjectMember(request.Context(), strings.TrimSpace(chi.URLParam(request, "memberId")))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if member == nil || !server.filterByTenant(request, member.OrganizationID) || member.ProjectID != strings.TrimSpace(chi.URLParam(request, "id")) {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project member not found"})
|
||||
return
|
||||
}
|
||||
project, err := server.store.GetProject(request.Context(), member.ProjectID)
|
||||
if err != nil || project == nil {
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project not found"})
|
||||
}
|
||||
return
|
||||
}
|
||||
var payload projectMemberInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
payload.UserID = member.UserID
|
||||
server.saveProjectMember(writer, request, project, member, payload, false)
|
||||
}
|
||||
|
||||
func (server *server) releaseProjectMemberTasks(ctx context.Context, organizationID string, member domain.ProjectMemberRecord, actorID string) (int, error) {
|
||||
items, err := server.store.ListHumanItems(ctx, organizationID, domain.HumanItemQuery{ProjectID: member.ProjectID})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
released := 0
|
||||
for _, item := range items {
|
||||
if item.AssignedUserID != member.UserID || (member.SupplierID != "" && item.SupplierID != "" && item.SupplierID != member.SupplierID) || !humanItemPending(item.Status) {
|
||||
continue
|
||||
}
|
||||
expectedVersion := item.Version
|
||||
item.AssignedUserID = ""
|
||||
item.ClaimedAt = ""
|
||||
item.Version++
|
||||
if item.Status == domain.HumanItemClaimed || item.Status == domain.HumanItemInProgress {
|
||||
item.Status = domain.HumanItemReady
|
||||
}
|
||||
updated, updateErr := server.store.UpdateHumanItemVersioned(ctx, item, expectedVersion)
|
||||
if updateErr != nil {
|
||||
return released, updateErr
|
||||
}
|
||||
if !updated {
|
||||
return released, nil
|
||||
}
|
||||
_ = server.store.AppendHumanEvent(ctx, domain.HumanEventRecord{OrganizationID: item.OrganizationID, BatchID: item.BatchID, ItemID: item.ID, StageID: item.CurrentStageID, Round: item.ReviewRound, EventType: "project_member_removed_release", ActorUserID: actorID, ItemVersion: item.Version, Payload: map[string]any{"projectMemberId": member.ID}, CreatedAt: nowISO()})
|
||||
released++
|
||||
}
|
||||
return released, nil
|
||||
}
|
||||
|
||||
func (server *server) handleProjectMemberDelete(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !isOrganizationAdmin(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "organization admin is required"})
|
||||
return
|
||||
}
|
||||
member, err := server.store.GetProjectMember(request.Context(), strings.TrimSpace(chi.URLParam(request, "memberId")))
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if member == nil || member.ProjectID != strings.TrimSpace(chi.URLParam(request, "id")) || !server.filterByTenant(request, member.OrganizationID) {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project member not found"})
|
||||
return
|
||||
}
|
||||
releaseTasks := strings.EqualFold(strings.TrimSpace(request.URL.Query().Get("releaseTasks")), "true")
|
||||
if releaseTasks {
|
||||
if _, err := server.releaseProjectMemberTasks(request.Context(), member.OrganizationID, *member, principal.User.ID); err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
deleted, err := server.store.DeleteProjectMember(request.Context(), member.ID)
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if !deleted {
|
||||
renderJSON(writer, http.StatusNotFound, map[string]string{"error": "project member not found"})
|
||||
return
|
||||
}
|
||||
writer.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (server *server) handleProjectMembersBulk(writer http.ResponseWriter, request *http.Request) {
|
||||
principal, _ := currentPrincipal(request)
|
||||
if !isOrganizationAdmin(principal) {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "organization admin is required"})
|
||||
return
|
||||
}
|
||||
projectID := strings.TrimSpace(chi.URLParam(request, "id"))
|
||||
var payload projectMemberBulkInput
|
||||
if !decodeJSON(writer, request, &payload) {
|
||||
return
|
||||
}
|
||||
roles, valid := normalizedMemberRoles(payload.Roles)
|
||||
if len(payload.MemberIDs) == 0 || (payload.Action == "set_roles" && !valid) || (payload.Action != "set_roles" && payload.Action != "remove") {
|
||||
renderValidationError(writer, validationIssue{Field: "bulk", Message: "memberIds and a valid bulk action are required"})
|
||||
return
|
||||
}
|
||||
updated := 0
|
||||
for _, id := range payload.MemberIDs {
|
||||
member, err := server.store.GetProjectMember(request.Context(), strings.TrimSpace(id))
|
||||
if err != nil || member == nil || member.ProjectID != projectID || !server.filterByTenant(request, member.OrganizationID) {
|
||||
continue
|
||||
}
|
||||
if payload.Action == "remove" {
|
||||
if _, err = server.releaseProjectMemberTasks(request.Context(), member.OrganizationID, *member, principal.User.ID); err == nil {
|
||||
_, err = server.store.DeleteProjectMember(request.Context(), member.ID)
|
||||
}
|
||||
} else {
|
||||
member.Roles = roles
|
||||
err = server.store.UpsertProjectMember(request.Context(), *member)
|
||||
}
|
||||
if err != nil {
|
||||
renderError(writer, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
updated++
|
||||
}
|
||||
renderJSON(writer, http.StatusOK, map[string]int{"updated": updated})
|
||||
}
|
||||
62
internal/api/project_members_test.go
Normal file
62
internal/api/project_members_test.go
Normal file
@ -0,0 +1,62 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
"droboticflow/internal/store"
|
||||
)
|
||||
|
||||
func TestProjectMemberEndpointsUseProjectRolesWithoutWorkgroups(t *testing.T) {
|
||||
t.Setenv("DROBOTICFLOW_REQUIRE_SESSION_AUTH", "true")
|
||||
ctx := context.Background()
|
||||
dataStore := store.NewMemoryStore()
|
||||
handler := NewHandler(dataStore, nil)
|
||||
rootCookie := bootstrapSuperAdminSession(t, handler)
|
||||
organization := adminCreateOrganization(t, handler, rootCookie, "Project members", "project-members")
|
||||
admin := adminCreateUser(t, handler, rootCookie, organization.ID, "Org Admin", "org-admin@example.com", domain.UserRoleAdmin, "org-admin-password")
|
||||
member := adminCreateUser(t, handler, rootCookie, organization.ID, "Worker", "worker@example.com", domain.UserRoleMember, "worker-password")
|
||||
adminCookie := loginSession(t, handler, admin.Email, "org-admin-password")
|
||||
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{OrganizationID: organization.ID, Name: "测试项目"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, _ := json.Marshal(map[string]any{"userId": member.ID, "roles": []string{"annotator", "quality_reviewer"}})
|
||||
created := serveJSONWithCookie(handler, http.MethodPost, "/api/projects/"+project.ID+"/members", body, adminCookie)
|
||||
if created.Code != http.StatusCreated {
|
||||
t.Fatalf("create member=%d body=%s", created.Code, created.Body.String())
|
||||
}
|
||||
var stored domain.ProjectMemberRecord
|
||||
if err := json.Unmarshal(created.Body.Bytes(), &stored); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(stored.Roles) != 2 || stored.SupplierID != "" {
|
||||
t.Fatalf("member=%#v", stored)
|
||||
}
|
||||
memberCookie := loginSession(t, handler, member.Email, "worker-password")
|
||||
listed := serveJSONWithCookie(handler, http.MethodGet, "/api/projects/"+project.ID+"/members", nil, memberCookie)
|
||||
if listed.Code != http.StatusOK || !jsonContains(listed.Body.String(), member.ID) {
|
||||
t.Fatalf("member list=%d body=%s", listed.Code, listed.Body.String())
|
||||
}
|
||||
updatedBody, _ := json.Marshal(map[string]any{"roles": []string{"acceptance_reviewer"}})
|
||||
updated := serveJSONWithCookie(handler, http.MethodPatch, "/api/projects/"+project.ID+"/members/"+stored.ID, updatedBody, adminCookie)
|
||||
if updated.Code != http.StatusOK || !jsonContains(updated.Body.String(), "acceptance_reviewer") {
|
||||
t.Fatalf("update=%d body=%s", updated.Code, updated.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func jsonContains(value string, expected string) bool {
|
||||
return len(expected) == 0 || (len(value) >= len(expected) && containsText(value, expected))
|
||||
}
|
||||
|
||||
func containsText(value string, expected string) bool {
|
||||
for index := 0; index+len(expected) <= len(value); index++ {
|
||||
if value[index:index+len(expected)] == expected {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -1348,6 +1348,7 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Post("/api/human-items/{id}/release", instance.handleHumanItemRelease)
|
||||
router.Post("/api/human-items/{id}/submissions", instance.handleHumanItemSubmission)
|
||||
router.Post("/api/human-items/{id}/decisions", instance.handleHumanItemDecision)
|
||||
router.Post("/api/human-items/{id}/escalation", instance.handleHumanEscalationDecision)
|
||||
})
|
||||
router.Group(func(router chi.Router) {
|
||||
router.Use(instance.requireBusinessRole(domain.UserRoleAdmin))
|
||||
@ -1366,8 +1367,6 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Get("/api/annotation-tasks", deprecatedAnnotationEndpoint(instance.handleAnnotationTasksList))
|
||||
router.Get("/api/annotation-tasks/{id}", deprecatedAnnotationEndpoint(instance.handleAnnotationTaskGet))
|
||||
router.Get("/api/annotation-workload-summary", deprecatedAnnotationEndpoint(instance.handleAnnotationWorkloadSummary))
|
||||
router.Get("/api/plugins/annotation-qa/workgroups", instance.handleAnnotationWorkgroupsList)
|
||||
router.Get("/api/plugins/annotation-qa/memberships", instance.handleAnnotationMembershipsList)
|
||||
router.Get("/api/plugins/annotation-qa/templates", instance.handleAnnotationTemplatesList)
|
||||
router.Get("/api/plugins/annotation-qa/tasks", instance.handleAnnotationTasksList)
|
||||
router.Get("/api/plugins/annotation-qa/tasks/{id}", instance.handleAnnotationTaskGet)
|
||||
@ -1394,9 +1393,6 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Post("/api/annotation-memberships", deprecatedAnnotationEndpoint(instance.handleAnnotationMembershipCreate))
|
||||
router.Post("/api/annotation-templates", deprecatedAnnotationEndpoint(instance.handleAnnotationTemplateCreate))
|
||||
router.Post("/api/annotation-templates/{id}/publish", deprecatedAnnotationEndpoint(instance.handleAnnotationTemplatePublish))
|
||||
router.Post("/api/plugins/annotation-qa/workgroups", instance.handleAnnotationWorkgroupCreate)
|
||||
router.Post("/api/plugins/annotation-qa/memberships", instance.handleAnnotationMembershipCreate)
|
||||
router.Delete("/api/plugins/annotation-qa/memberships/{id}", instance.handleAnnotationMembershipDelete)
|
||||
router.Post("/api/plugins/annotation-qa/templates", instance.handleAnnotationTemplateCreate)
|
||||
router.Post("/api/plugins/annotation-qa/templates/{id}/publish", instance.handleAnnotationTemplatePublish)
|
||||
})
|
||||
@ -1412,6 +1408,7 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
|
||||
router.Get("/api/projects", instance.handleProjectsList)
|
||||
router.Get("/api/projects/{id}", instance.handleProjectsGet)
|
||||
router.Get("/api/projects/{id}/members", instance.handleProjectMembersList)
|
||||
router.Get("/api/projects/{id}/storage-path-favorites", instance.handleProjectStoragePathFavoritesGet)
|
||||
router.Get("/api/projects/{id}/workflows", instance.handleProjectWorkflowsList)
|
||||
router.Get("/api/projects/{id}/workflow-instances", instance.handleProjectWorkflowInstancesList)
|
||||
@ -1453,6 +1450,15 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Delete("/api/scan-configs/{id}", instance.handleScanConfigsDelete)
|
||||
router.Post("/api/scan-configs/{id}/run", instance.handleScanConfigsRun)
|
||||
})
|
||||
router.Group(func(router chi.Router) {
|
||||
router.Use(instance.requireBusinessRole(domain.UserRoleAdmin, domain.UserRoleOrganizationAdmin))
|
||||
router.Post("/api/suppliers", instance.handleSupplierCreate)
|
||||
router.Post("/api/projects/{id}/members", instance.handleProjectMemberCreate)
|
||||
router.Patch("/api/projects/{id}/members/{memberId}", instance.handleProjectMemberUpdate)
|
||||
router.Delete("/api/projects/{id}/members/{memberId}", instance.handleProjectMemberDelete)
|
||||
router.Post("/api/projects/{id}/members/bulk", instance.handleProjectMembersBulk)
|
||||
})
|
||||
router.Get("/api/suppliers", instance.handleSuppliersList)
|
||||
|
||||
router.Get("/api/source-data/collections", instance.handleSourceCollectionsList)
|
||||
router.Get("/api/source-data/collections/{runId}/{collectionId}", instance.handleSourceCollectionDetail)
|
||||
@ -1618,6 +1624,17 @@ func NewHandlerWithConfig(dataStore store.Store, aiService ai.Service, appConfig
|
||||
router.Post("/api/object-storage/objects", instance.handleObjectStorageObjectCreate)
|
||||
router.Post("/api/object-storage/objects/upload", instance.handleObjectStorageObjectUpload)
|
||||
router.Post("/api/object-storage/uploads/presign-put", instance.handleObjectStoragePresignPut)
|
||||
router.Get("/api/object-storage/upload-sessions", instance.handleObjectStorageUploadSessionsList)
|
||||
router.Post("/api/object-storage/upload-sessions", instance.handleObjectStorageUploadSessionCreate)
|
||||
router.Get("/api/object-storage/upload-sessions/{sessionId}", instance.handleObjectStorageUploadSessionGet)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/pause", instance.handleObjectStorageUploadSessionPause)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/resume", instance.handleObjectStorageUploadSessionResume)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/cancel", instance.handleObjectStorageUploadSessionCancel)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/items/{itemId}/start", instance.handleObjectStorageUploadSessionItemStart)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/items/{itemId}/part-url", instance.handleObjectStorageUploadSessionPartURL)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/items/{itemId}/parts", instance.handleObjectStorageUploadSessionPartComplete)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/items/{itemId}/complete", instance.handleObjectStorageUploadSessionItemComplete)
|
||||
router.Post("/api/object-storage/upload-sessions/{sessionId}/items/{itemId}/failed", instance.handleObjectStorageUploadSessionItemFailure)
|
||||
router.Post("/api/object-storage/uploads/batch/prepare", instance.handleObjectStorageBatchUploadPrepare)
|
||||
router.Post("/api/object-storage/uploads/multipart/initiate", instance.handleObjectStorageMultipartInitiate)
|
||||
router.Post("/api/object-storage/uploads/multipart/part-url", instance.handleObjectStorageMultipartPartURL)
|
||||
@ -8071,6 +8088,8 @@ type userPatch struct {
|
||||
func validUserRole(value domain.UserRole) bool {
|
||||
switch value {
|
||||
case domain.UserRoleAdmin,
|
||||
domain.UserRoleOrganizationAdmin,
|
||||
domain.UserRoleMember,
|
||||
domain.UserRoleCutter,
|
||||
domain.UserRoleAnnotator,
|
||||
domain.UserRoleQualityReviewer,
|
||||
|
||||
@ -379,7 +379,19 @@ func (server *server) requireBusinessRole(roles ...domain.UserRole) func(http.Ha
|
||||
renderJSON(writer, http.StatusUnauthorized, map[string]string{"error": "login is required"})
|
||||
return
|
||||
}
|
||||
if _, ok := allowed[principal.User.Role]; !ok {
|
||||
_, permitted := allowed[principal.User.Role]
|
||||
if !permitted && principal.User.Role == domain.UserRoleOrganizationAdmin {
|
||||
_, permitted = allowed[domain.UserRoleAdmin]
|
||||
}
|
||||
if !permitted && principal.User.Role == domain.UserRoleMember {
|
||||
for _, humanRole := range []domain.UserRole{domain.UserRoleCutter, domain.UserRoleAnnotator, domain.UserRoleQualityReviewer, domain.UserRoleAcceptanceReviewer} {
|
||||
if _, enabled := allowed[humanRole]; enabled {
|
||||
permitted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !permitted {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "insufficient role permissions"})
|
||||
return
|
||||
}
|
||||
@ -399,7 +411,7 @@ func (server *server) requireAdminMonitoringAccess(next http.Handler) http.Handl
|
||||
renderJSON(writer, http.StatusUnauthorized, map[string]string{"error": "login is required"})
|
||||
return
|
||||
}
|
||||
if principal.User.Role != domain.UserRoleAdmin {
|
||||
if principal.User.Role != domain.UserRoleAdmin && principal.User.Role != domain.UserRoleOrganizationAdmin {
|
||||
renderJSON(writer, http.StatusForbidden, map[string]string{"error": "run monitoring is restricted to administrators"})
|
||||
return
|
||||
}
|
||||
|
||||
@ -142,29 +142,33 @@ type SliceRevisionRecord struct {
|
||||
type SemanticAnnotationRevisionRecord = AnnotationRevisionRecord
|
||||
|
||||
type AnnotationTaskRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId,omitempty" bson:"organizationId,omitempty"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
DataTaskID string `json:"dataTaskId,omitempty" bson:"dataTaskId,omitempty"`
|
||||
WorkflowID string `json:"workflowId,omitempty" bson:"workflowId,omitempty"`
|
||||
RunID string `json:"runId,omitempty" bson:"runId,omitempty"`
|
||||
NodeID string `json:"nodeId,omitempty" bson:"nodeId,omitempty"`
|
||||
ArtifactID string `json:"artifactId,omitempty" bson:"artifactId,omitempty"`
|
||||
SourceVideo string `json:"sourceVideo" bson:"sourceVideo"`
|
||||
ClipStart float64 `json:"clipStart" bson:"clipStart"`
|
||||
ClipEnd float64 `json:"clipEnd" bson:"clipEnd"`
|
||||
SourceIsFullVideo bool `json:"sourceIsFullVideo,omitempty" bson:"sourceIsFullVideo,omitempty"`
|
||||
SourceDurationSeconds float64 `json:"sourceDurationSeconds,omitempty" bson:"sourceDurationSeconds,omitempty"`
|
||||
CoverageStartSecond float64 `json:"coverageStartSecond,omitempty" bson:"coverageStartSecond,omitempty"`
|
||||
CoverageEndSecond float64 `json:"coverageEndSecond,omitempty" bson:"coverageEndSecond,omitempty"`
|
||||
CoverageMode string `json:"coverageMode,omitempty" bson:"coverageMode,omitempty"`
|
||||
TemplateID string `json:"templateId" bson:"templateId"`
|
||||
TemplateVersion int `json:"templateVersion" bson:"templateVersion"`
|
||||
WorkgroupID string `json:"workgroupId" bson:"workgroupId"`
|
||||
VendorID string `json:"vendorId" bson:"vendorId"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty" bson:"assignedUserId,omitempty"`
|
||||
Status AnnotationTaskStatus `json:"status" bson:"status"`
|
||||
CurrentRevision int `json:"currentRevision" bson:"currentRevision"`
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId,omitempty" bson:"organizationId,omitempty"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
DataTaskID string `json:"dataTaskId,omitempty" bson:"dataTaskId,omitempty"`
|
||||
WorkflowID string `json:"workflowId,omitempty" bson:"workflowId,omitempty"`
|
||||
RunID string `json:"runId,omitempty" bson:"runId,omitempty"`
|
||||
NodeID string `json:"nodeId,omitempty" bson:"nodeId,omitempty"`
|
||||
ArtifactID string `json:"artifactId,omitempty" bson:"artifactId,omitempty"`
|
||||
SourceVideo string `json:"sourceVideo" bson:"sourceVideo"`
|
||||
ClipStart float64 `json:"clipStart" bson:"clipStart"`
|
||||
ClipEnd float64 `json:"clipEnd" bson:"clipEnd"`
|
||||
SourceIsFullVideo bool `json:"sourceIsFullVideo,omitempty" bson:"sourceIsFullVideo,omitempty"`
|
||||
SourceDurationSeconds float64 `json:"sourceDurationSeconds,omitempty" bson:"sourceDurationSeconds,omitempty"`
|
||||
CoverageStartSecond float64 `json:"coverageStartSecond,omitempty" bson:"coverageStartSecond,omitempty"`
|
||||
CoverageEndSecond float64 `json:"coverageEndSecond,omitempty" bson:"coverageEndSecond,omitempty"`
|
||||
CoverageMode string `json:"coverageMode,omitempty" bson:"coverageMode,omitempty"`
|
||||
TemplateID string `json:"templateId" bson:"templateId"`
|
||||
TemplateVersion int `json:"templateVersion" bson:"templateVersion"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
// Deprecated compatibility fields. Mongo migration copies their historical
|
||||
// value into LegacyAssignment and unsets them for production records.
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty" bson:"assignedUserId,omitempty"`
|
||||
Status AnnotationTaskStatus `json:"status" bson:"status"`
|
||||
CurrentRevision int `json:"currentRevision" bson:"currentRevision"`
|
||||
// PoseSummary is evidence copied from real upstream Headpose/Handpose
|
||||
// manifests for the v5 aggregate acceptance workbench. It contains only
|
||||
// scoped references/counts, never whole untrimmed pose data.
|
||||
@ -209,21 +213,23 @@ type AnnotationReviewRecord struct {
|
||||
}
|
||||
|
||||
type AnnotationWorklogEventRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId,omitempty" bson:"organizationId,omitempty"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
TaskID string `json:"taskId" bson:"taskId"`
|
||||
UserID string `json:"userId" bson:"userId"`
|
||||
WorkgroupID string `json:"workgroupId" bson:"workgroupId"`
|
||||
VendorID string `json:"vendorId" bson:"vendorId"`
|
||||
EventType string `json:"eventType" bson:"eventType"`
|
||||
Mode RunMode `json:"mode,omitempty" bson:"mode,omitempty"`
|
||||
Temporary bool `json:"temporary,omitempty" bson:"temporary,omitempty"`
|
||||
Revision int `json:"revision,omitempty" bson:"revision,omitempty"`
|
||||
TemplateVersion int `json:"templateVersion,omitempty" bson:"templateVersion,omitempty"`
|
||||
DurationSeconds int64 `json:"durationSeconds,omitempty" bson:"durationSeconds,omitempty"`
|
||||
OutputDelta int64 `json:"outputDelta" bson:"outputDelta"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId,omitempty" bson:"organizationId,omitempty"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
TaskID string `json:"taskId" bson:"taskId"`
|
||||
UserID string `json:"userId" bson:"userId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
EventType string `json:"eventType" bson:"eventType"`
|
||||
Mode RunMode `json:"mode,omitempty" bson:"mode,omitempty"`
|
||||
Temporary bool `json:"temporary,omitempty" bson:"temporary,omitempty"`
|
||||
Revision int `json:"revision,omitempty" bson:"revision,omitempty"`
|
||||
TemplateVersion int `json:"templateVersion,omitempty" bson:"templateVersion,omitempty"`
|
||||
DurationSeconds int64 `json:"durationSeconds,omitempty" bson:"durationSeconds,omitempty"`
|
||||
OutputDelta int64 `json:"outputDelta" bson:"outputDelta"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
}
|
||||
|
||||
type AnnotationWorkloadAggregate struct {
|
||||
|
||||
@ -1,34 +1,36 @@
|
||||
package domain
|
||||
|
||||
type CaptureAutomationConfig struct {
|
||||
Enabled bool `json:"enabled" bson:"enabled"`
|
||||
ConnectionID string `json:"connectionId" bson:"connectionId"`
|
||||
Bucket string `json:"bucket" bson:"bucket"`
|
||||
Prefix string `json:"prefix" bson:"prefix"`
|
||||
Schema string `json:"schema,omitempty" bson:"schema,omitempty"`
|
||||
CompletionMode string `json:"completionMode,omitempty" bson:"completionMode,omitempty"`
|
||||
ManifestName string `json:"manifestName,omitempty" bson:"manifestName,omitempty"`
|
||||
WorkflowInputID string `json:"workflowInputId,omitempty" bson:"workflowInputId,omitempty"`
|
||||
PollIntervalSeconds int `json:"pollIntervalSeconds,omitempty" bson:"pollIntervalSeconds,omitempty"`
|
||||
RequiredPatterns []string `json:"requiredPatterns,omitempty" bson:"requiredPatterns,omitempty"`
|
||||
MaxRetryAttempts int `json:"maxRetryAttempts,omitempty" bson:"maxRetryAttempts,omitempty"`
|
||||
RetryBackoffSeconds int `json:"retryBackoffSeconds,omitempty" bson:"retryBackoffSeconds,omitempty"`
|
||||
Enabled bool `json:"enabled" bson:"enabled"`
|
||||
ConnectionID string `json:"connectionId" bson:"connectionId"`
|
||||
Bucket string `json:"bucket" bson:"bucket"`
|
||||
Prefix string `json:"prefix" bson:"prefix"`
|
||||
Schema string `json:"schema,omitempty" bson:"schema,omitempty"`
|
||||
CompletionMode string `json:"completionMode,omitempty" bson:"completionMode,omitempty"`
|
||||
ManifestName string `json:"manifestName,omitempty" bson:"manifestName,omitempty"`
|
||||
WorkflowInputID string `json:"workflowInputId,omitempty" bson:"workflowInputId,omitempty"`
|
||||
PollIntervalSeconds int `json:"pollIntervalSeconds,omitempty" bson:"pollIntervalSeconds,omitempty"`
|
||||
StabilityWindowSeconds int `json:"stabilityWindowSeconds,omitempty" bson:"stabilityWindowSeconds,omitempty"`
|
||||
RequiredPatterns []string `json:"requiredPatterns,omitempty" bson:"requiredPatterns,omitempty"`
|
||||
MaxRetryAttempts int `json:"maxRetryAttempts,omitempty" bson:"maxRetryAttempts,omitempty"`
|
||||
RetryBackoffSeconds int `json:"retryBackoffSeconds,omitempty" bson:"retryBackoffSeconds,omitempty"`
|
||||
}
|
||||
|
||||
type CaptureRecordStatus string
|
||||
|
||||
const (
|
||||
CaptureRecordIncomplete CaptureRecordStatus = "incomplete"
|
||||
CaptureRecordReady CaptureRecordStatus = "ready"
|
||||
CaptureRecordLaunching CaptureRecordStatus = "launching"
|
||||
CaptureRecordRequeueing CaptureRecordStatus = "requeueing"
|
||||
CaptureRecordQueued CaptureRecordStatus = "queued"
|
||||
CaptureRecordRunning CaptureRecordStatus = "running"
|
||||
CaptureRecordWaiting CaptureRecordStatus = "waiting_for_human"
|
||||
CaptureRecordCompleted CaptureRecordStatus = "completed"
|
||||
CaptureRecordFailed CaptureRecordStatus = "failed"
|
||||
CaptureRecordCancelled CaptureRecordStatus = "cancelled"
|
||||
CaptureRecordDiscarded CaptureRecordStatus = "discarded"
|
||||
CaptureRecordIncomplete CaptureRecordStatus = "incomplete"
|
||||
CaptureRecordStabilizing CaptureRecordStatus = "stabilizing"
|
||||
CaptureRecordReady CaptureRecordStatus = "ready"
|
||||
CaptureRecordLaunching CaptureRecordStatus = "launching"
|
||||
CaptureRecordRequeueing CaptureRecordStatus = "requeueing"
|
||||
CaptureRecordQueued CaptureRecordStatus = "queued"
|
||||
CaptureRecordRunning CaptureRecordStatus = "running"
|
||||
CaptureRecordWaiting CaptureRecordStatus = "waiting_for_human"
|
||||
CaptureRecordCompleted CaptureRecordStatus = "completed"
|
||||
CaptureRecordFailed CaptureRecordStatus = "failed"
|
||||
CaptureRecordCancelled CaptureRecordStatus = "cancelled"
|
||||
CaptureRecordDiscarded CaptureRecordStatus = "discarded"
|
||||
)
|
||||
|
||||
type CaptureActionType string
|
||||
@ -65,6 +67,8 @@ type CaptureRecord struct {
|
||||
Fingerprint string `json:"fingerprint,omitempty" bson:"fingerprint,omitempty"`
|
||||
Status CaptureRecordStatus `json:"status" bson:"status"`
|
||||
MissingTypes []string `json:"missingTypes,omitempty" bson:"missingTypes,omitempty"`
|
||||
StabilityChecks int `json:"stabilityChecks,omitempty" bson:"stabilityChecks,omitempty"`
|
||||
StabilityObservedAt string `json:"stabilityObservedAt,omitempty" bson:"stabilityObservedAt,omitempty"`
|
||||
FileCount int `json:"fileCount" bson:"fileCount"`
|
||||
TotalBytes int64 `json:"totalBytes" bson:"totalBytes"`
|
||||
RunID string `json:"runId,omitempty" bson:"runId,omitempty"`
|
||||
|
||||
@ -28,6 +28,8 @@ type DeliveryPackageRecord struct {
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
ParentRunID string `json:"parentRunId" bson:"parentRunId"`
|
||||
|
||||
@ -109,6 +109,7 @@ type HumanBatchRecord struct {
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
PluginID string `json:"pluginId" bson:"pluginId"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
RunID string `json:"runId" bson:"runId"`
|
||||
GateNodeID string `json:"gateNodeId" bson:"gateNodeId"`
|
||||
@ -134,6 +135,7 @@ type HumanItemRecord struct {
|
||||
PluginID string `json:"pluginId" bson:"pluginId"`
|
||||
BatchID string `json:"batchId" bson:"batchId"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
WorkflowID string `json:"workflowId" bson:"workflowId"`
|
||||
RunID string `json:"runId" bson:"runId"`
|
||||
GateNodeID string `json:"gateNodeId" bson:"gateNodeId"`
|
||||
@ -143,6 +145,7 @@ type HumanItemRecord struct {
|
||||
CurrentStageID string `json:"currentStageId" bson:"currentStageId"`
|
||||
Status HumanItemStatus `json:"status" bson:"status"`
|
||||
AssignedUserID string `json:"assignedUserId,omitempty" bson:"assignedUserId,omitempty"`
|
||||
LegacyAssignment map[string]string `json:"legacyAssignment,omitempty" bson:"legacyAssignment,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty" bson:"workgroupId,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty" bson:"vendorId,omitempty"`
|
||||
CurrentRevision int `json:"currentRevision" bson:"currentRevision"`
|
||||
|
||||
77
internal/domain/project_members.go
Normal file
77
internal/domain/project_members.go
Normal file
@ -0,0 +1,77 @@
|
||||
package domain
|
||||
|
||||
import "strings"
|
||||
|
||||
// AccountRole scopes organization-wide administration. Human production duties
|
||||
// are deliberately assigned on ProjectMember instead of being global user roles.
|
||||
type AccountRole string
|
||||
|
||||
const (
|
||||
AccountRoleOrganizationAdmin AccountRole = "organization_admin"
|
||||
AccountRoleSupplierManager AccountRole = "supplier_manager"
|
||||
AccountRoleMember AccountRole = "member"
|
||||
)
|
||||
|
||||
type SupplierRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
Status string `json:"status" bson:"status"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
type ProjectMemberRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
ProjectID string `json:"projectId" bson:"projectId"`
|
||||
UserID string `json:"userId" bson:"userId"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
Roles []AnnotationAssignmentRole `json:"roles" bson:"roles"`
|
||||
LegacySnapshot map[string]string `json:"legacySnapshot,omitempty" bson:"legacySnapshot,omitempty"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
func NormalizeProjectMemberRoles(values []AnnotationAssignmentRole) []AnnotationAssignmentRole {
|
||||
seen := map[AnnotationAssignmentRole]struct{}{}
|
||||
roles := make([]AnnotationAssignmentRole, 0, len(values))
|
||||
for _, role := range values {
|
||||
switch role {
|
||||
case AnnotationRoleCutter:
|
||||
role = AnnotationRoleAnnotator
|
||||
case AnnotationRoleAnnotator, AnnotationRoleQualityReviewer, AnnotationRoleAcceptanceReviewer:
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if _, exists := seen[role]; exists {
|
||||
continue
|
||||
}
|
||||
seen[role] = struct{}{}
|
||||
roles = append(roles, role)
|
||||
}
|
||||
return roles
|
||||
}
|
||||
|
||||
func (member ProjectMemberRecord) HasRole(role AnnotationAssignmentRole) bool {
|
||||
for _, assigned := range member.Roles {
|
||||
if assigned == role {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func AccountRoleForUser(user UserRecord) AccountRole {
|
||||
if user.IsSuperAdmin || user.Role == UserRoleAdmin || user.Role == UserRoleOrganizationAdmin {
|
||||
return AccountRoleOrganizationAdmin
|
||||
}
|
||||
if user.Role == UserRoleSupplierManager {
|
||||
return AccountRoleSupplierManager
|
||||
}
|
||||
return AccountRoleMember
|
||||
}
|
||||
|
||||
func NormalizedSupplierID(value string) string {
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
21
internal/domain/project_members_test.go
Normal file
21
internal/domain/project_members_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package domain
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeProjectMemberRolesMapsLegacyCutterAndDeduplicates(t *testing.T) {
|
||||
roles := NormalizeProjectMemberRoles([]AnnotationAssignmentRole{AnnotationRoleCutter, AnnotationRoleAnnotator, AnnotationRoleQualityReviewer, AnnotationRoleVendorManager})
|
||||
if len(roles) != 2 || roles[0] != AnnotationRoleAnnotator || roles[1] != AnnotationRoleQualityReviewer {
|
||||
t.Fatalf("roles = %#v", roles)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUploadSessionSummaryCountsSkippedAsProcessedWithoutAddingNetworkBytes(t *testing.T) {
|
||||
summary := SummarizeObjectStorageUploadSession(ObjectStorageUploadSessionRecord{Items: []ObjectStorageUploadItemRecord{
|
||||
{SizeBytes: 100, Status: ObjectStorageUploadItemSkipped},
|
||||
{SizeBytes: 200, UploadedBytes: 200, Status: ObjectStorageUploadItemSuccess},
|
||||
{SizeBytes: 50, Status: ObjectStorageUploadItemPending},
|
||||
}})
|
||||
if summary.TotalBytes != 350 || summary.ProcessedBytes != 300 || summary.UploadedBytes != 200 || summary.SkippedCount != 1 || summary.SuccessCount != 1 || summary.PendingCount != 1 {
|
||||
t.Fatalf("summary = %#v", summary)
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,8 @@ const (
|
||||
UserRoleQualityReviewer UserRole = "quality_reviewer"
|
||||
UserRoleAcceptanceReviewer UserRole = "acceptance_reviewer"
|
||||
UserRoleSupplierManager UserRole = "supplier_manager"
|
||||
UserRoleOrganizationAdmin UserRole = "organization_admin"
|
||||
UserRoleMember UserRole = "member"
|
||||
)
|
||||
|
||||
type UserStatus string
|
||||
@ -961,6 +963,7 @@ type UserRecord struct {
|
||||
Name string `json:"name" bson:"name"`
|
||||
Email string `json:"email" bson:"email"`
|
||||
Role UserRole `json:"role" bson:"role"`
|
||||
SupplierID string `json:"supplierId,omitempty" bson:"supplierId,omitempty"`
|
||||
IsSuperAdmin bool `json:"isSuperAdmin,omitempty" bson:"isSuperAdmin,omitempty"`
|
||||
PasswordHash string `json:"passwordHash,omitempty" bson:"passwordHash,omitempty"`
|
||||
Status UserStatus `json:"status,omitempty" bson:"status,omitempty"`
|
||||
@ -1166,8 +1169,7 @@ type DashboardSummary struct {
|
||||
type DashboardWorkforceMetric struct {
|
||||
UserID string `json:"userId,omitempty"`
|
||||
UserName string `json:"userName,omitempty"`
|
||||
VendorID string `json:"vendorId,omitempty"`
|
||||
WorkgroupID string `json:"workgroupId,omitempty"`
|
||||
SupplierID string `json:"supplierId,omitempty"`
|
||||
OutputCount int64 `json:"outputCount"`
|
||||
SubmittedCount int64 `json:"submittedCount"`
|
||||
ReworkCount int64 `json:"reworkCount"`
|
||||
@ -1386,6 +1388,7 @@ type CreateUserInput struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Role UserRole `json:"role"`
|
||||
SupplierID string `json:"supplierId,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
PasswordHash string `json:"passwordHash,omitempty"`
|
||||
IsSuperAdmin bool `json:"isSuperAdmin,omitempty"`
|
||||
|
||||
92
internal/domain/upload_sessions.go
Normal file
92
internal/domain/upload_sessions.go
Normal file
@ -0,0 +1,92 @@
|
||||
package domain
|
||||
|
||||
type ObjectStorageUploadSessionStatus string
|
||||
|
||||
const (
|
||||
ObjectStorageUploadSessionPrepared ObjectStorageUploadSessionStatus = "prepared"
|
||||
ObjectStorageUploadSessionRunning ObjectStorageUploadSessionStatus = "running"
|
||||
ObjectStorageUploadSessionPaused ObjectStorageUploadSessionStatus = "paused"
|
||||
ObjectStorageUploadSessionCompleted ObjectStorageUploadSessionStatus = "completed"
|
||||
ObjectStorageUploadSessionFailed ObjectStorageUploadSessionStatus = "failed"
|
||||
ObjectStorageUploadSessionCancelled ObjectStorageUploadSessionStatus = "cancelled"
|
||||
)
|
||||
|
||||
type ObjectStorageUploadItemStatus string
|
||||
|
||||
const (
|
||||
ObjectStorageUploadItemPending ObjectStorageUploadItemStatus = "pending"
|
||||
ObjectStorageUploadItemUploading ObjectStorageUploadItemStatus = "uploading"
|
||||
ObjectStorageUploadItemSuccess ObjectStorageUploadItemStatus = "success"
|
||||
ObjectStorageUploadItemSkipped ObjectStorageUploadItemStatus = "skipped"
|
||||
ObjectStorageUploadItemFailed ObjectStorageUploadItemStatus = "failed"
|
||||
ObjectStorageUploadItemCancelled ObjectStorageUploadItemStatus = "cancelled"
|
||||
)
|
||||
|
||||
type ObjectStorageUploadItemRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
RelativePath string `json:"relativePath" bson:"relativePath"`
|
||||
Key string `json:"key" bson:"key"`
|
||||
Kind string `json:"kind" bson:"kind"`
|
||||
ContentType string `json:"contentType,omitempty" bson:"contentType,omitempty"`
|
||||
SizeBytes int64 `json:"sizeBytes" bson:"sizeBytes"`
|
||||
LastModified int64 `json:"lastModified,omitempty" bson:"lastModified,omitempty"`
|
||||
Action string `json:"action" bson:"action"`
|
||||
Status ObjectStorageUploadItemStatus `json:"status" bson:"status"`
|
||||
Mode string `json:"mode,omitempty" bson:"mode,omitempty"`
|
||||
UploadID string `json:"uploadId,omitempty" bson:"uploadId,omitempty"`
|
||||
UploadedParts []ObjectStorageMultipartUploadPart `json:"uploadedParts,omitempty" bson:"uploadedParts,omitempty"`
|
||||
UploadedBytes int64 `json:"uploadedBytes,omitempty" bson:"uploadedBytes,omitempty"`
|
||||
ETag string `json:"eTag,omitempty" bson:"eTag,omitempty"`
|
||||
Error string `json:"error,omitempty" bson:"error,omitempty"`
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
type ObjectStorageUploadSessionRecord struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
OrganizationID string `json:"organizationId" bson:"organizationId"`
|
||||
UserID string `json:"userId" bson:"userId"`
|
||||
ConnectionID string `json:"connectionId" bson:"connectionId"`
|
||||
Bucket string `json:"bucket" bson:"bucket"`
|
||||
Prefix string `json:"prefix,omitempty" bson:"prefix,omitempty"`
|
||||
ConflictPolicy string `json:"conflictPolicy" bson:"conflictPolicy"`
|
||||
Status ObjectStorageUploadSessionStatus `json:"status" bson:"status"`
|
||||
Items []ObjectStorageUploadItemRecord `json:"items" bson:"items"`
|
||||
Version int `json:"version" bson:"version"`
|
||||
ExpiresAt string `json:"expiresAt" bson:"expiresAt"`
|
||||
CompletedAt string `json:"completedAt,omitempty" bson:"completedAt,omitempty"`
|
||||
CancelledAt string `json:"cancelledAt,omitempty" bson:"cancelledAt,omitempty"`
|
||||
CreatedAt string `json:"createdAt" bson:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt" bson:"updatedAt"`
|
||||
}
|
||||
|
||||
type ObjectStorageUploadSessionSummary struct {
|
||||
Session ObjectStorageUploadSessionRecord `json:"session"`
|
||||
TotalBytes int64 `json:"totalBytes"`
|
||||
ProcessedBytes int64 `json:"processedBytes"`
|
||||
UploadedBytes int64 `json:"uploadedBytes"`
|
||||
SuccessCount int `json:"successCount"`
|
||||
SkippedCount int `json:"skippedCount"`
|
||||
FailedCount int `json:"failedCount"`
|
||||
PendingCount int `json:"pendingCount"`
|
||||
}
|
||||
|
||||
func SummarizeObjectStorageUploadSession(session ObjectStorageUploadSessionRecord) ObjectStorageUploadSessionSummary {
|
||||
summary := ObjectStorageUploadSessionSummary{Session: session}
|
||||
for _, item := range session.Items {
|
||||
summary.TotalBytes += item.SizeBytes
|
||||
summary.UploadedBytes += item.UploadedBytes
|
||||
switch item.Status {
|
||||
case ObjectStorageUploadItemSuccess:
|
||||
summary.SuccessCount++
|
||||
summary.ProcessedBytes += item.SizeBytes
|
||||
case ObjectStorageUploadItemSkipped:
|
||||
summary.SkippedCount++
|
||||
summary.ProcessedBytes += item.SizeBytes
|
||||
case ObjectStorageUploadItemFailed:
|
||||
summary.FailedCount++
|
||||
default:
|
||||
summary.PendingCount++
|
||||
}
|
||||
}
|
||||
return summary
|
||||
}
|
||||
@ -22,17 +22,17 @@ var builtin = map[string]domain.PluginManifest{
|
||||
AnnotationQAID: {
|
||||
ID: AnnotationQAID, Name: "Annotation QA", Version: "1.0.0", RequiredCoreVersion: ">=0.1.0",
|
||||
Routes: []domain.PluginRouteContribution{
|
||||
{ID: "clip", Path: "/plugins/annotation-qa/workflows/:workflowId/clip", Label: "人工调切", RequiredRoles: []string{"admin", "cutter"}},
|
||||
{ID: "clip-quality", Path: "/plugins/annotation-qa/workflows/:workflowId/clip-quality", Label: "剪切审核", RequiredRoles: []string{"admin", "annotator"}},
|
||||
{ID: "annotate", Path: "/plugins/annotation-qa/workflows/:workflowId/annotate", Label: "真实切分与语义标注", RequiredRoles: []string{"admin", "annotator"}},
|
||||
{ID: "quality", Path: "/plugins/annotation-qa/workflows/:workflowId/quality", Label: "切分与标注审核", RequiredRoles: []string{"admin", "quality_reviewer"}},
|
||||
{ID: "acceptance", Path: "/plugins/annotation-qa/workflows/:workflowId/acceptance", Label: "最终验收", RequiredRoles: []string{"admin", "acceptance_reviewer"}},
|
||||
{ID: "clip", Path: "/plugins/annotation-qa/workflows/:workflowId/clip", Label: "人工调切", RequiredRoles: []string{"admin", "organization_admin", "member", "cutter"}},
|
||||
{ID: "clip-quality", Path: "/plugins/annotation-qa/workflows/:workflowId/clip-quality", Label: "剪切审核", RequiredRoles: []string{"admin", "organization_admin", "member", "annotator"}},
|
||||
{ID: "annotate", Path: "/plugins/annotation-qa/workflows/:workflowId/annotate", Label: "真实切分与语义标注", RequiredRoles: []string{"admin", "organization_admin", "member", "annotator"}},
|
||||
{ID: "quality", Path: "/plugins/annotation-qa/workflows/:workflowId/quality", Label: "切分与标注审核", RequiredRoles: []string{"admin", "organization_admin", "member", "quality_reviewer"}},
|
||||
{ID: "acceptance", Path: "/plugins/annotation-qa/workflows/:workflowId/acceptance", Label: "最终验收", RequiredRoles: []string{"admin", "organization_admin", "member", "acceptance_reviewer"}},
|
||||
{ID: "item", Path: "/plugins/annotation-qa/items/:itemId", Label: "标注任务详情"},
|
||||
},
|
||||
Navigation: []domain.PluginNavigationContribution{
|
||||
{ID: "annotate", Label: "切分与语义标注", Path: "/plugins/annotation-qa/workflows/all/annotate", Icon: "tags", Order: 10, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "annotator"}},
|
||||
{ID: "quality", Label: "切分与标注审核", Path: "/plugins/annotation-qa/workflows/all/quality", Icon: "clipboard-check", Order: 20, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "quality_reviewer"}},
|
||||
{ID: "acceptance", Label: "最终验收", Path: "/plugins/annotation-qa/workflows/all/acceptance", Icon: "shield-check", Order: 50, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "acceptance_reviewer"}},
|
||||
{ID: "annotate", Label: "切分与语义标注", Path: "/plugins/annotation-qa/workflows/all/annotate", Icon: "tags", Order: 10, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "organization_admin", "member", "annotator"}},
|
||||
{ID: "quality", Label: "切分与标注审核", Path: "/plugins/annotation-qa/workflows/all/quality", Icon: "clipboard-check", Order: 20, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "organization_admin", "member", "quality_reviewer"}},
|
||||
{ID: "acceptance", Label: "最终验收", Path: "/plugins/annotation-qa/workflows/all/acceptance", Icon: "shield-check", Order: 50, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "organization_admin", "member", "acceptance_reviewer"}},
|
||||
},
|
||||
WorkflowCapabilities: []string{"human_cut_adjustment", "human_cut_review", "human_annotation", "human_quality_review", "human_acceptance"},
|
||||
OperatorIDs: []string{
|
||||
|
||||
@ -6,6 +6,15 @@ import (
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func stringSliceContains(values []string, expected string) bool {
|
||||
for _, value := range values {
|
||||
if value == expected {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestAnnotationCapabilitiesAreDerivedFromGateNode(t *testing.T) {
|
||||
workflow := domain.WorkflowRecord{ID: "workflow-1", Nodes: []domain.WorkflowNode{{
|
||||
ID: "gate",
|
||||
@ -62,8 +71,8 @@ func TestAnnotationManifestContributesWorkbenchesAndOperators(t *testing.T) {
|
||||
for _, item := range manifest.Navigation {
|
||||
rolesByID[item.ID] = item.RequiredRoles
|
||||
}
|
||||
if len(rolesByID["acceptance"]) != 2 || rolesByID["acceptance"][1] != "acceptance_reviewer" {
|
||||
t.Fatalf("final acceptance must belong only to the independent acceptance reviewer: %#v", rolesByID["acceptance"])
|
||||
if !stringSliceContains(rolesByID["acceptance"], "acceptance_reviewer") || !stringSliceContains(rolesByID["acceptance"], "member") {
|
||||
t.Fatalf("final acceptance must be exposed to project-scoped members and independently enforced by membership role: %#v", rolesByID["acceptance"])
|
||||
}
|
||||
wanted := map[string]bool{
|
||||
"operator-builtin-annotation-gate": true,
|
||||
|
||||
@ -31,6 +31,8 @@ type MemoryStore struct {
|
||||
samplingTasks map[string]domain.SamplingTaskRecord
|
||||
annotationWorkgroups map[string]domain.AnnotationWorkgroupRecord
|
||||
annotationMemberships map[string]domain.ProjectAnnotationMembershipRecord
|
||||
suppliers map[string]domain.SupplierRecord
|
||||
projectMembers map[string]domain.ProjectMemberRecord
|
||||
annotationTemplates map[string]domain.AnnotationTemplateRecord
|
||||
annotationTasks map[string]domain.AnnotationTaskRecord
|
||||
annotationRevisions map[string]domain.AnnotationRevisionRecord
|
||||
@ -48,6 +50,7 @@ type MemoryStore struct {
|
||||
users map[string]domain.UserRecord
|
||||
sessions map[string]domain.SessionRecord
|
||||
storageConnections map[string]domain.StorageConnectionRecord
|
||||
uploadSessions map[string]domain.ObjectStorageUploadSessionRecord
|
||||
mongoConnections map[string]domain.MongoConnectionRecord
|
||||
objectSyncSpaces map[string]domain.ObjectSyncSpaceRecord
|
||||
objectSyncDevices map[string]domain.ObjectSyncDeviceRecord
|
||||
@ -91,6 +94,8 @@ func NewMemoryStore() *MemoryStore {
|
||||
samplingTasks: map[string]domain.SamplingTaskRecord{},
|
||||
annotationWorkgroups: map[string]domain.AnnotationWorkgroupRecord{},
|
||||
annotationMemberships: map[string]domain.ProjectAnnotationMembershipRecord{},
|
||||
suppliers: map[string]domain.SupplierRecord{},
|
||||
projectMembers: map[string]domain.ProjectMemberRecord{},
|
||||
annotationTemplates: map[string]domain.AnnotationTemplateRecord{},
|
||||
annotationTasks: map[string]domain.AnnotationTaskRecord{},
|
||||
annotationRevisions: map[string]domain.AnnotationRevisionRecord{},
|
||||
@ -108,6 +113,7 @@ func NewMemoryStore() *MemoryStore {
|
||||
users: map[string]domain.UserRecord{},
|
||||
sessions: map[string]domain.SessionRecord{},
|
||||
storageConnections: map[string]domain.StorageConnectionRecord{},
|
||||
uploadSessions: map[string]domain.ObjectStorageUploadSessionRecord{},
|
||||
mongoConnections: map[string]domain.MongoConnectionRecord{},
|
||||
objectSyncSpaces: map[string]domain.ObjectSyncSpaceRecord{},
|
||||
objectSyncDevices: map[string]domain.ObjectSyncDeviceRecord{},
|
||||
@ -389,6 +395,16 @@ func (store *MemoryStore) DeleteOrganizationCascade(_ context.Context, id string
|
||||
delete(store.annotationMemberships, key)
|
||||
}
|
||||
}
|
||||
for key, item := range store.suppliers {
|
||||
if organizationMatches(item.OrganizationID, organizationID) {
|
||||
delete(store.suppliers, key)
|
||||
}
|
||||
}
|
||||
for key, item := range store.projectMembers {
|
||||
if organizationMatches(item.OrganizationID, organizationID) {
|
||||
delete(store.projectMembers, key)
|
||||
}
|
||||
}
|
||||
for key, item := range store.annotationTemplates {
|
||||
if organizationMatches(item.OrganizationID, organizationID) {
|
||||
delete(store.annotationTemplates, key)
|
||||
@ -449,6 +465,11 @@ func (store *MemoryStore) DeleteOrganizationCascade(_ context.Context, id string
|
||||
delete(store.storageConnections, key)
|
||||
}
|
||||
}
|
||||
for key, item := range store.uploadSessions {
|
||||
if organizationMatches(item.OrganizationID, organizationID) {
|
||||
delete(store.uploadSessions, key)
|
||||
}
|
||||
}
|
||||
for key, item := range store.mongoConnections {
|
||||
if organizationMatches(item.OrganizationID, organizationID) {
|
||||
delete(store.mongoConnections, key)
|
||||
@ -1924,6 +1945,7 @@ func (store *MemoryStore) CreateUser(_ context.Context, input domain.CreateUserI
|
||||
Name: input.Name,
|
||||
Email: strings.TrimSpace(strings.ToLower(input.Email)),
|
||||
Role: input.Role,
|
||||
SupplierID: strings.TrimSpace(input.SupplierID),
|
||||
IsSuperAdmin: input.IsSuperAdmin,
|
||||
PasswordHash: input.PasswordHash,
|
||||
Status: status,
|
||||
|
||||
@ -38,6 +38,8 @@ type MongoStore struct {
|
||||
samplingTasks *mongo.Collection
|
||||
annotationWorkgroups *mongo.Collection
|
||||
annotationMemberships *mongo.Collection
|
||||
suppliers *mongo.Collection
|
||||
projectMembers *mongo.Collection
|
||||
annotationTemplates *mongo.Collection
|
||||
annotationTasks *mongo.Collection
|
||||
annotationRevisions *mongo.Collection
|
||||
@ -55,6 +57,7 @@ type MongoStore struct {
|
||||
users *mongo.Collection
|
||||
sessions *mongo.Collection
|
||||
storageConnections *mongo.Collection
|
||||
uploadSessions *mongo.Collection
|
||||
mongoConnections *mongo.Collection
|
||||
objectSyncSpaces *mongo.Collection
|
||||
objectSyncDevices *mongo.Collection
|
||||
@ -97,6 +100,8 @@ func NewMongoStore(db *mongo.Database) *MongoStore {
|
||||
samplingTasks: db.Collection("samplingTasks"),
|
||||
annotationWorkgroups: db.Collection("annotationWorkgroups"),
|
||||
annotationMemberships: db.Collection("annotationMemberships"),
|
||||
suppliers: db.Collection("suppliers"),
|
||||
projectMembers: db.Collection("projectMembers"),
|
||||
annotationTemplates: db.Collection("annotationTemplates"),
|
||||
annotationTasks: db.Collection("annotationTasks"),
|
||||
annotationRevisions: db.Collection("annotationRevisions"),
|
||||
@ -114,6 +119,7 @@ func NewMongoStore(db *mongo.Database) *MongoStore {
|
||||
users: db.Collection("users"),
|
||||
sessions: db.Collection("sessions"),
|
||||
storageConnections: db.Collection("storageConnections"),
|
||||
uploadSessions: db.Collection("objectStorageUploadSessions"),
|
||||
mongoConnections: db.Collection("mongoConnections"),
|
||||
objectSyncSpaces: db.Collection("objectSyncSpaces"),
|
||||
objectSyncDevices: db.Collection("objectSyncDevices"),
|
||||
@ -274,6 +280,8 @@ func (store *MongoStore) DeleteOrganizationCascade(ctx context.Context, id strin
|
||||
store.samplingTasks,
|
||||
store.annotationWorkgroups,
|
||||
store.annotationMemberships,
|
||||
store.suppliers,
|
||||
store.projectMembers,
|
||||
store.annotationTemplates,
|
||||
store.annotationTasks,
|
||||
store.annotationRevisions,
|
||||
@ -289,6 +297,7 @@ func (store *MongoStore) DeleteOrganizationCascade(ctx context.Context, id strin
|
||||
store.releasePartitions,
|
||||
store.deliveryPackages,
|
||||
store.storageConnections,
|
||||
store.uploadSessions,
|
||||
store.mongoConnections,
|
||||
store.objectSyncSpaces,
|
||||
store.objectSyncDevices,
|
||||
@ -398,6 +407,9 @@ func (store *MongoStore) DeleteProject(ctx context.Context, id string) (bool, er
|
||||
if _, err := store.samplingTasks.DeleteMany(ctx, bson.M{"projectId": id}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if _, err := store.projectMembers.DeleteMany(ctx, bson.M{"projectId": id}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(workflowIDs) > 0 {
|
||||
if _, err := store.sourceStates.DeleteMany(ctx, bson.M{"workflowId": bson.M{"$in": workflowIDs}}); err != nil {
|
||||
return false, err
|
||||
@ -1863,6 +1875,7 @@ func (store *MongoStore) CreateUser(ctx context.Context, input domain.CreateUser
|
||||
Name: input.Name,
|
||||
Email: strings.TrimSpace(strings.ToLower(input.Email)),
|
||||
Role: input.Role,
|
||||
SupplierID: strings.TrimSpace(input.SupplierID),
|
||||
IsSuperAdmin: input.IsSuperAdmin,
|
||||
PasswordHash: input.PasswordHash,
|
||||
Status: input.Status,
|
||||
|
||||
@ -146,14 +146,14 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
index("status_createdAt", bson.D{{Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("workflowId_createdAt", bson.D{{Key: "workflowId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
},
|
||||
store.annotationWorkgroups: {
|
||||
store.suppliers: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
index("organizationId_vendorId_name", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "name", Value: 1}}),
|
||||
index("organizationId_name", bson.D{{Key: "organizationId", Value: 1}, {Key: "name", Value: 1}}),
|
||||
},
|
||||
store.annotationMemberships: {
|
||||
store.projectMembers: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
uniqueIndex("organizationId_projectId_userId_role_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "userId", Value: 1}, {Key: "assignmentRole", Value: 1}}),
|
||||
index("organizationId_projectId_workgroupId", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "workgroupId", Value: 1}}),
|
||||
uniqueIndex("organizationId_projectId_userId_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "userId", Value: 1}}),
|
||||
index("organizationId_projectId_supplierId", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "supplierId", Value: 1}}),
|
||||
},
|
||||
store.annotationTemplates: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
@ -161,7 +161,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
},
|
||||
store.annotationTasks: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
index("organizationId_projectId_workgroupId_status", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "status", Value: 1}}),
|
||||
index("organizationId_projectId_supplierId_status", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "supplierId", Value: 1}, {Key: "status", Value: 1}}),
|
||||
index("runId_artifactId", bson.D{{Key: "runId", Value: 1}, {Key: "artifactId", Value: 1}}),
|
||||
},
|
||||
store.annotationRevisions: {
|
||||
@ -179,7 +179,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
store.annotationWorklogEvents: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
index("organizationId_projectId_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_vendorId_workgroupId_userId_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "userId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_supplierId_userId_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "supplierId", Value: 1}, {Key: "userId", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
},
|
||||
store.organizationPlugins: {
|
||||
uniqueIndex("organizationId_pluginId_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "pluginId", Value: 1}}),
|
||||
@ -194,7 +194,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
uniqueIndex("organizationId_batchId_subjectItemKey_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "batchId", Value: 1}, {Key: "subject.itemKey", Value: 1}}),
|
||||
index("organizationId_workflowId_stage_status", bson.D{{Key: "organizationId", Value: 1}, {Key: "workflowId", Value: 1}, {Key: "currentStageId", Value: 1}, {Key: "status", Value: 1}}),
|
||||
index("organizationId_vendorId_workgroupId_stage_status_assignee", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "currentStageId", Value: 1}, {Key: "status", Value: 1}, {Key: "assignedUserId", Value: 1}}),
|
||||
index("organizationId_supplierId_stage_status_assignee", bson.D{{Key: "organizationId", Value: 1}, {Key: "supplierId", Value: 1}, {Key: "currentStageId", Value: 1}, {Key: "status", Value: 1}, {Key: "assignedUserId", Value: 1}}),
|
||||
},
|
||||
store.humanStageAttempts: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
@ -218,7 +218,7 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
uniqueIndex("organizationId_releasePartitionId_unique", bson.D{{Key: "organizationId", Value: 1}, {Key: "releasePartitionId", Value: 1}}),
|
||||
index("organizationId_projectId_status_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_vendorId_workgroupId_status_assignee", bson.D{{Key: "organizationId", Value: 1}, {Key: "vendorId", Value: 1}, {Key: "workgroupId", Value: 1}, {Key: "status", Value: 1}, {Key: "assignedUserId", Value: 1}}),
|
||||
index("organizationId_supplierId_status_assignee", bson.D{{Key: "organizationId", Value: 1}, {Key: "supplierId", Value: 1}, {Key: "status", Value: 1}, {Key: "assignedUserId", Value: 1}}),
|
||||
index("organizationId_mode_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "mode", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_projectId_mode_status_createdAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "projectId", Value: 1}, {Key: "mode", Value: 1}, {Key: "status", Value: 1}, {Key: "createdAt", Value: -1}}),
|
||||
index("organizationId_parentRunId", bson.D{{Key: "organizationId", Value: 1}, {Key: "parentRunId", Value: 1}}),
|
||||
@ -240,6 +240,11 @@ func (store *MongoStore) EnsureIndexes(ctx context.Context) error {
|
||||
index("organizationId_name", bson.D{{Key: "organizationId", Value: 1}, {Key: "name", Value: 1}}),
|
||||
index("name", bson.D{{Key: "name", Value: 1}}),
|
||||
},
|
||||
store.uploadSessions: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
index("organizationId_userId_updatedAt", bson.D{{Key: "organizationId", Value: 1}, {Key: "userId", Value: 1}, {Key: "updatedAt", Value: -1}}),
|
||||
index("expiresAt", bson.D{{Key: "expiresAt", Value: 1}}),
|
||||
},
|
||||
store.mongoConnections: {
|
||||
uniqueIndex("id_unique", bson.D{{Key: "id", Value: 1}}),
|
||||
index("organizationId_name", bson.D{{Key: "organizationId", Value: 1}, {Key: "name", Value: 1}}),
|
||||
|
||||
@ -2,6 +2,8 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
@ -35,6 +37,12 @@ func (store *MongoStore) RunMigrations(ctx context.Context) error {
|
||||
if err := store.backfillRunCaptureDirectories(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := store.migrateLegacyWorkgroupsToProjectMembers(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := store.DeleteExpiredObjectStorageUploadSessions(ctx, nowISO()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := store.deduplicateOperatorRecordsByID(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -44,6 +52,311 @@ func (store *MongoStore) RunMigrations(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func legacySupplierID(group domain.AnnotationWorkgroupRecord) string {
|
||||
if value := strings.TrimSpace(group.VendorID); value != "" {
|
||||
return value
|
||||
}
|
||||
return "supplier-legacy-" + strings.TrimSpace(group.ID)
|
||||
}
|
||||
|
||||
func legacyProjectMemberID(organizationID string, projectID string, userID string) string {
|
||||
sum := sha256.Sum256([]byte(normalizedOrganizationID(organizationID) + "\x00" + strings.TrimSpace(projectID) + "\x00" + strings.TrimSpace(userID)))
|
||||
return "project-member-migrated-" + hex.EncodeToString(sum[:12])
|
||||
}
|
||||
|
||||
// migrateLegacyWorkgroupsToProjectMembers is deliberately additive. The
|
||||
// legacy records remain readable until the rollout has proved every human item
|
||||
// and audit event is scoped by supplierId; API responses already omit the old
|
||||
// fields for new records.
|
||||
func (store *MongoStore) migrateLegacyWorkgroupsToProjectMembers(ctx context.Context) error {
|
||||
groupCursor, err := store.annotationWorkgroups.Find(ctx, bson.M{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groups, err := decodeMany[domain.AnnotationWorkgroupRecord](ctx, groupCursor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupSupplier := map[string]string{}
|
||||
for _, group := range groups {
|
||||
supplierID := legacySupplierID(group)
|
||||
groupSupplier[group.ID] = supplierID
|
||||
if supplier, getErr := store.GetSupplier(ctx, supplierID); getErr != nil {
|
||||
return getErr
|
||||
} else if supplier == nil {
|
||||
if err := store.UpsertSupplier(ctx, domain.SupplierRecord{
|
||||
ID: supplierID, OrganizationID: normalizedOrganizationID(group.OrganizationID),
|
||||
Name: strings.TrimSpace(group.Name), Status: "active", CreatedAt: group.CreatedAt,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
membershipCursor, err := store.annotationMemberships.Find(ctx, bson.M{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
legacyMemberships, err := decodeMany[domain.ProjectAnnotationMembershipRecord](ctx, membershipCursor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
byProjectUser := map[string]domain.ProjectMemberRecord{}
|
||||
for _, legacy := range legacyMemberships {
|
||||
if legacy.AssignmentRole == domain.AnnotationRoleVendorManager {
|
||||
if user, userErr := store.GetUser(ctx, legacy.UserID); userErr != nil {
|
||||
return userErr
|
||||
} else if user != nil && user.SupplierID == "" {
|
||||
user.SupplierID = strings.TrimSpace(legacy.VendorID)
|
||||
if user.SupplierID == "" {
|
||||
user.SupplierID = groupSupplier[legacy.WorkgroupID]
|
||||
}
|
||||
if err := store.UpsertUser(ctx, *user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
key := normalizedOrganizationID(legacy.OrganizationID) + "\x00" + legacy.ProjectID + "\x00" + legacy.UserID
|
||||
member, exists := byProjectUser[key]
|
||||
if !exists {
|
||||
member = domain.ProjectMemberRecord{
|
||||
ID: legacyProjectMemberID(legacy.OrganizationID, legacy.ProjectID, legacy.UserID), OrganizationID: normalizedOrganizationID(legacy.OrganizationID),
|
||||
ProjectID: legacy.ProjectID, UserID: legacy.UserID, SupplierID: strings.TrimSpace(legacy.VendorID),
|
||||
LegacySnapshot: map[string]string{"workgroupId": legacy.WorkgroupID, "vendorId": legacy.VendorID}, CreatedAt: legacy.CreatedAt,
|
||||
}
|
||||
if member.SupplierID == "" {
|
||||
member.SupplierID = groupSupplier[legacy.WorkgroupID]
|
||||
}
|
||||
}
|
||||
member.Roles = append(member.Roles, legacy.AssignmentRole)
|
||||
byProjectUser[key] = member
|
||||
}
|
||||
for _, member := range byProjectUser {
|
||||
member.Roles = domain.NormalizeProjectMemberRoles(member.Roles)
|
||||
if len(member.Roles) == 0 {
|
||||
continue
|
||||
}
|
||||
existing, err := store.GetProjectMemberByProjectUser(ctx, member.OrganizationID, member.ProjectID, member.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if existing != nil {
|
||||
member.ID = existing.ID
|
||||
member.CreatedAt = existing.CreatedAt
|
||||
if member.SupplierID == "" {
|
||||
member.SupplierID = existing.SupplierID
|
||||
}
|
||||
}
|
||||
if err := store.UpsertProjectMember(ctx, member); err != nil {
|
||||
return err
|
||||
}
|
||||
if user, userErr := store.GetUser(ctx, member.UserID); userErr != nil {
|
||||
return userErr
|
||||
} else if user != nil && user.SupplierID == "" && member.SupplierID != "" {
|
||||
user.SupplierID = member.SupplierID
|
||||
if user.Role == domain.UserRoleCutter || user.Role == domain.UserRoleAnnotator || user.Role == domain.UserRoleQualityReviewer || user.Role == domain.UserRoleAcceptanceReviewer {
|
||||
user.Role = domain.UserRoleMember
|
||||
}
|
||||
if err := store.UpsertUser(ctx, *user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := store.migrateAnnotationSupplierHyperparams(ctx, groupSupplier); err != nil {
|
||||
return err
|
||||
}
|
||||
collections := []*mongo.Collection{store.annotationTasks, store.annotationWorklogEvents, store.humanItems, store.deliveryPackages}
|
||||
for _, collection := range collections {
|
||||
pipeline := mongo.Pipeline{bson.D{{Key: "$set", Value: bson.D{
|
||||
{Key: "supplierId", Value: bson.D{{Key: "$ifNull", Value: bson.A{"$vendorId", ""}}}},
|
||||
{Key: "legacyAssignment", Value: bson.D{{Key: "workgroupId", Value: "$workgroupId"}, {Key: "vendorId", Value: "$vendorId"}}},
|
||||
}}}}
|
||||
if _, err := collection.UpdateMany(ctx, bson.M{"$or": bson.A{
|
||||
bson.M{"supplierId": bson.M{"$exists": false}},
|
||||
bson.M{"supplierId": ""},
|
||||
}}, pipeline); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// A few older records only carried a workgroup id. Resolve them through the
|
||||
// archived group mapping before the legacy columns are removed.
|
||||
for workgroupID, supplierID := range groupSupplier {
|
||||
if strings.TrimSpace(workgroupID) == "" || strings.TrimSpace(supplierID) == "" {
|
||||
continue
|
||||
}
|
||||
for _, collection := range collections {
|
||||
if _, err := collection.UpdateMany(ctx, bson.M{
|
||||
"workgroupId": workgroupID,
|
||||
"$or": bson.A{bson.M{"supplierId": ""}, bson.M{"supplierId": bson.M{"$exists": false}}},
|
||||
}, bson.M{"$set": bson.M{"supplierId": supplierID}}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, collection := range collections {
|
||||
legacyAssignmentPipeline := mongo.Pipeline{
|
||||
bson.D{{Key: "$set", Value: bson.D{
|
||||
{Key: "legacyAssignment", Value: bson.D{{Key: "workgroupId", Value: "$workgroupId"}, {Key: "vendorId", Value: "$vendorId"}}},
|
||||
}}},
|
||||
}
|
||||
if _, err := collection.UpdateMany(ctx, bson.M{
|
||||
"workgroupId": bson.M{"$exists": true},
|
||||
"legacyAssignment": bson.M{"$exists": false},
|
||||
}, legacyAssignmentPipeline); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
itemCursor, err := store.humanItems.Find(ctx, bson.M{"supplierId": bson.M{"$ne": ""}}, options.Find().SetProjection(bson.M{"batchId": 1, "supplierId": 1}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
items, err := decodeMany[domain.HumanItemRecord](ctx, itemCursor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, item := range items {
|
||||
if item.BatchID == "" || item.SupplierID == "" {
|
||||
continue
|
||||
}
|
||||
_, err := store.humanBatches.UpdateOne(ctx, bson.M{"id": item.BatchID, "supplierId": bson.M{"$in": bson.A{"", nil}}}, bson.M{"$set": bson.M{"supplierId": item.SupplierID}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := store.users.UpdateMany(ctx, bson.M{"role": bson.M{"$in": bson.A{domain.UserRoleCutter, domain.UserRoleAnnotator, domain.UserRoleQualityReviewer, domain.UserRoleAcceptanceReviewer}}}, bson.M{"$set": bson.M{"role": domain.UserRoleMember}}); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(groups) > 0 || len(legacyMemberships) > 0 {
|
||||
if err := store.archiveAndDropLegacyWorkgroupCollections(ctx, groups, legacyMemberships); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := store.dropLegacyWorkgroupIndexes(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, collection := range collections {
|
||||
if _, err := collection.UpdateMany(ctx, bson.M{}, bson.M{"$unset": bson.M{"workgroupId": "", "vendorId": ""}}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) dropLegacyWorkgroupIndexes(ctx context.Context) error {
|
||||
legacyIndexes := map[*mongo.Collection][]string{
|
||||
store.annotationTasks: {"organizationId_projectId_workgroupId_status"},
|
||||
store.annotationWorklogEvents: {"organizationId_vendorId_workgroupId_userId_createdAt"},
|
||||
store.humanItems: {"organizationId_vendorId_workgroupId_stage_status_assignee"},
|
||||
store.deliveryPackages: {"organizationId_vendorId_workgroupId_status_assignee"},
|
||||
}
|
||||
for collection, names := range legacyIndexes {
|
||||
for _, name := range names {
|
||||
if _, err := collection.Indexes().DropOne(ctx, name); err != nil && !strings.Contains(strings.ToLower(err.Error()), "index not found") {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateAnnotationSupplierNodes(nodes []domain.WorkflowNode, groupSupplier map[string]string) (bool, []domain.WorkflowNode) {
|
||||
changed := false
|
||||
copy := append([]domain.WorkflowNode(nil), nodes...)
|
||||
for nodeIndex := range copy {
|
||||
params := copy[nodeIndex].Data.Hyperparams
|
||||
for paramIndex := range params {
|
||||
if params[paramIndex].Key != "ANNOTATION_WORKGROUP_ID" {
|
||||
continue
|
||||
}
|
||||
legacyID := strings.TrimSpace(fmt.Sprint(params[paramIndex].Value))
|
||||
params[paramIndex].Key = "ANNOTATION_SUPPLIER_ID"
|
||||
if supplierID := groupSupplier[legacyID]; supplierID != "" {
|
||||
params[paramIndex].Value = supplierID
|
||||
}
|
||||
changed = true
|
||||
}
|
||||
copy[nodeIndex].Data.Hyperparams = params
|
||||
}
|
||||
return changed, copy
|
||||
}
|
||||
|
||||
func (store *MongoStore) migrateAnnotationSupplierHyperparams(ctx context.Context, groupSupplier map[string]string) error {
|
||||
workflowCursor, err := store.workflows.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 1, "nodes": 1}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for workflowCursor.Next(ctx) {
|
||||
var item struct {
|
||||
DocumentID any `bson:"_id"`
|
||||
Nodes []domain.WorkflowNode `bson:"nodes"`
|
||||
}
|
||||
if err := workflowCursor.Decode(&item); err != nil {
|
||||
workflowCursor.Close(ctx)
|
||||
return err
|
||||
}
|
||||
if changed, nodes := migrateAnnotationSupplierNodes(item.Nodes, groupSupplier); changed {
|
||||
if _, err := store.workflows.UpdateOne(ctx, bson.M{"_id": item.DocumentID}, bson.M{"$set": bson.M{"nodes": nodes, "updatedAt": nowISO()}}); err != nil {
|
||||
workflowCursor.Close(ctx)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := workflowCursor.Err(); err != nil {
|
||||
workflowCursor.Close(ctx)
|
||||
return err
|
||||
}
|
||||
workflowCursor.Close(ctx)
|
||||
templateCursor, err := store.templates.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 1, "nodes": 1}))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer templateCursor.Close(ctx)
|
||||
for templateCursor.Next(ctx) {
|
||||
var item struct {
|
||||
DocumentID any `bson:"_id"`
|
||||
Nodes []domain.WorkflowNode `bson:"nodes"`
|
||||
}
|
||||
if err := templateCursor.Decode(&item); err != nil {
|
||||
return err
|
||||
}
|
||||
if changed, nodes := migrateAnnotationSupplierNodes(item.Nodes, groupSupplier); changed {
|
||||
if _, err := store.templates.UpdateOne(ctx, bson.M{"_id": item.DocumentID}, bson.M{"$set": bson.M{"nodes": nodes, "updatedAt": nowISO()}}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return templateCursor.Err()
|
||||
}
|
||||
|
||||
func (store *MongoStore) archiveAndDropLegacyWorkgroupCollections(ctx context.Context, groups []domain.AnnotationWorkgroupRecord, memberships []domain.ProjectAnnotationMembershipRecord) error {
|
||||
audit := store.db.Collection("legacyWorkgroupAudit")
|
||||
archive := func(source string, id string, payload any) error {
|
||||
_, err := audit.UpdateOne(ctx, bson.M{"source": source, "sourceId": id}, bson.M{"$set": bson.M{"source": source, "sourceId": id, "payload": payload, "archivedAt": nowISO()}}, options.Update().SetUpsert(true))
|
||||
return err
|
||||
}
|
||||
for _, group := range groups {
|
||||
if err := archive("annotationWorkgroups", group.ID, group); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, membership := range memberships {
|
||||
if err := archive("annotationMemberships", membership.ID, membership); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(groups) > 0 {
|
||||
if err := store.annotationWorkgroups.Drop(ctx); err != nil && !strings.Contains(strings.ToLower(err.Error()), "namespace") {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(memberships) > 0 {
|
||||
if err := store.annotationMemberships.Drop(ctx); err != nil && !strings.Contains(strings.ToLower(err.Error()), "namespace") {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) backfillRunCaptureDirectories(ctx context.Context) error {
|
||||
cursor, err := store.runs.Find(
|
||||
ctx,
|
||||
|
||||
15
internal/store/mongo_migrations_test.go
Normal file
15
internal/store/mongo_migrations_test.go
Normal file
@ -0,0 +1,15 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestMigrateAnnotationSupplierNodesReplacesLegacyWorkgroupHyperparameter(t *testing.T) {
|
||||
nodes := []domain.WorkflowNode{{ID: "human", Data: domain.WorkflowNodeData{Hyperparams: []domain.HyperParam{{Key: "ANNOTATION_WORKGROUP_ID", Value: "legacy-group"}}}}}
|
||||
changed, migrated := migrateAnnotationSupplierNodes(nodes, map[string]string{"legacy-group": "supplier-a"})
|
||||
if !changed || migrated[0].Data.Hyperparams[0].Key != "ANNOTATION_SUPPLIER_ID" || migrated[0].Data.Hyperparams[0].Value != "supplier-a" {
|
||||
t.Fatalf("migrated nodes = %#v", migrated)
|
||||
}
|
||||
}
|
||||
217
internal/store/project_members.go
Normal file
217
internal/store/project_members.go
Normal file
@ -0,0 +1,217 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func (store *MemoryStore) ListSuppliers(_ context.Context, organizationID string) ([]domain.SupplierRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
items := make([]domain.SupplierRecord, 0)
|
||||
for _, item := range store.suppliers {
|
||||
if annotationOrganizationMatches(item.OrganizationID, organizationID) {
|
||||
items = append(items, clone(item))
|
||||
}
|
||||
}
|
||||
sort.Slice(items, func(left, right int) bool { return items[left].Name < items[right].Name })
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) GetSupplier(_ context.Context, id string) (*domain.SupplierRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
item, ok := store.suppliers[strings.TrimSpace(id)]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
copy := clone(item)
|
||||
return ©, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) UpsertSupplier(_ context.Context, item domain.SupplierRecord) error {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
if item.ID == "" {
|
||||
item.ID = domain.NewID("supplier")
|
||||
}
|
||||
item.OrganizationID = normalizedOrganizationID(item.OrganizationID)
|
||||
if item.Status == "" {
|
||||
item.Status = "active"
|
||||
}
|
||||
if item.CreatedAt == "" {
|
||||
item.CreatedAt = nowISO()
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
store.suppliers[item.ID] = clone(item)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) ListProjectMembers(_ context.Context, organizationID string, projectID string) ([]domain.ProjectMemberRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
items := make([]domain.ProjectMemberRecord, 0)
|
||||
for _, item := range store.projectMembers {
|
||||
if annotationOrganizationMatches(item.OrganizationID, organizationID) && (projectID == "" || item.ProjectID == projectID) {
|
||||
items = append(items, clone(item))
|
||||
}
|
||||
}
|
||||
sort.Slice(items, func(left, right int) bool {
|
||||
if items[left].ProjectID != items[right].ProjectID {
|
||||
return items[left].ProjectID < items[right].ProjectID
|
||||
}
|
||||
return items[left].CreatedAt < items[right].CreatedAt
|
||||
})
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) GetProjectMember(_ context.Context, id string) (*domain.ProjectMemberRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
item, ok := store.projectMembers[strings.TrimSpace(id)]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
copy := clone(item)
|
||||
return ©, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) GetProjectMemberByProjectUser(_ context.Context, organizationID string, projectID string, userID string) (*domain.ProjectMemberRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
for _, item := range store.projectMembers {
|
||||
if annotationOrganizationMatches(item.OrganizationID, organizationID) && item.ProjectID == projectID && item.UserID == userID {
|
||||
copy := clone(item)
|
||||
return ©, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) UpsertProjectMember(_ context.Context, item domain.ProjectMemberRecord) error {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
if item.ID == "" {
|
||||
item.ID = domain.NewID("project-member")
|
||||
}
|
||||
item.OrganizationID = normalizedOrganizationID(item.OrganizationID)
|
||||
item.Roles = domain.NormalizeProjectMemberRoles(item.Roles)
|
||||
if item.CreatedAt == "" {
|
||||
item.CreatedAt = nowISO()
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
store.projectMembers[item.ID] = clone(item)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) DeleteProjectMember(_ context.Context, id string) (bool, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
id = strings.TrimSpace(id)
|
||||
if _, exists := store.projectMembers[id]; !exists {
|
||||
return false, nil
|
||||
}
|
||||
delete(store.projectMembers, id)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) ListSuppliers(ctx context.Context, organizationID string) ([]domain.SupplierRecord, error) {
|
||||
cursor, err := store.suppliers.Find(ctx, orgCompatibilityFilter(organizationID), options.Find().SetSort(bson.D{{Key: "name", Value: 1}}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeMany[domain.SupplierRecord](ctx, cursor)
|
||||
}
|
||||
|
||||
func (store *MongoStore) GetSupplier(ctx context.Context, id string) (*domain.SupplierRecord, error) {
|
||||
var item domain.SupplierRecord
|
||||
err := store.suppliers.FindOne(ctx, bson.M{"id": strings.TrimSpace(id)}).Decode(&item)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) UpsertSupplier(ctx context.Context, item domain.SupplierRecord) error {
|
||||
if item.ID == "" {
|
||||
item.ID = domain.NewID("supplier")
|
||||
}
|
||||
item.OrganizationID = normalizedOrganizationID(item.OrganizationID)
|
||||
if item.Status == "" {
|
||||
item.Status = "active"
|
||||
}
|
||||
if item.CreatedAt == "" {
|
||||
item.CreatedAt = nowISO()
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
_, err := store.suppliers.UpdateOne(ctx, bson.M{"id": item.ID}, bson.M{"$set": item}, options.Update().SetUpsert(true))
|
||||
return err
|
||||
}
|
||||
|
||||
func (store *MongoStore) ListProjectMembers(ctx context.Context, organizationID string, projectID string) ([]domain.ProjectMemberRecord, error) {
|
||||
filter := orgCompatibilityFilter(organizationID)
|
||||
if strings.TrimSpace(projectID) != "" {
|
||||
filter["projectId"] = strings.TrimSpace(projectID)
|
||||
}
|
||||
cursor, err := store.projectMembers.Find(ctx, filter, options.Find().SetSort(bson.D{{Key: "createdAt", Value: 1}}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeMany[domain.ProjectMemberRecord](ctx, cursor)
|
||||
}
|
||||
|
||||
func (store *MongoStore) GetProjectMember(ctx context.Context, id string) (*domain.ProjectMemberRecord, error) {
|
||||
var item domain.ProjectMemberRecord
|
||||
err := store.projectMembers.FindOne(ctx, bson.M{"id": strings.TrimSpace(id)}).Decode(&item)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) GetProjectMemberByProjectUser(ctx context.Context, organizationID string, projectID string, userID string) (*domain.ProjectMemberRecord, error) {
|
||||
filter := orgCompatibilityFilter(organizationID)
|
||||
filter["projectId"] = strings.TrimSpace(projectID)
|
||||
filter["userId"] = strings.TrimSpace(userID)
|
||||
var item domain.ProjectMemberRecord
|
||||
err := store.projectMembers.FindOne(ctx, filter).Decode(&item)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) UpsertProjectMember(ctx context.Context, item domain.ProjectMemberRecord) error {
|
||||
if item.ID == "" {
|
||||
item.ID = domain.NewID("project-member")
|
||||
}
|
||||
item.OrganizationID = normalizedOrganizationID(item.OrganizationID)
|
||||
item.Roles = domain.NormalizeProjectMemberRoles(item.Roles)
|
||||
if item.CreatedAt == "" {
|
||||
item.CreatedAt = nowISO()
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
_, err := store.projectMembers.UpdateOne(ctx, bson.M{"id": item.ID}, bson.M{"$set": item}, options.Update().SetUpsert(true))
|
||||
return err
|
||||
}
|
||||
|
||||
func (store *MongoStore) DeleteProjectMember(ctx context.Context, id string) (bool, error) {
|
||||
result, err := store.projectMembers.DeleteOne(ctx, bson.M{"id": strings.TrimSpace(id)})
|
||||
return result != nil && result.DeletedCount == 1, err
|
||||
}
|
||||
21
internal/store/project_members_test.go
Normal file
21
internal/store/project_members_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
)
|
||||
|
||||
func TestMemoryStoreProjectMemberUpsertNormalizesRolesAndFindsByProjectUser(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
dataStore := NewMemoryStore()
|
||||
member := domain.ProjectMemberRecord{ID: "member-a", OrganizationID: "org-a", ProjectID: "project-a", UserID: "user-a", Roles: []domain.AnnotationAssignmentRole{domain.AnnotationRoleCutter, domain.AnnotationRoleQualityReviewer}}
|
||||
if err := dataStore.UpsertProjectMember(ctx, member); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stored, err := dataStore.GetProjectMemberByProjectUser(ctx, "org-a", "project-a", "user-a")
|
||||
if err != nil || stored == nil || len(stored.Roles) != 2 || stored.Roles[0] != domain.AnnotationRoleAnnotator {
|
||||
t.Fatalf("member = %#v err=%v", stored, err)
|
||||
}
|
||||
}
|
||||
@ -146,6 +146,14 @@ type Store interface {
|
||||
ListProjectAnnotationMemberships(context.Context, string, string) ([]domain.ProjectAnnotationMembershipRecord, error)
|
||||
UpsertProjectAnnotationMembership(context.Context, domain.ProjectAnnotationMembershipRecord) error
|
||||
DeleteProjectAnnotationMembership(context.Context, string) (bool, error)
|
||||
ListSuppliers(context.Context, string) ([]domain.SupplierRecord, error)
|
||||
GetSupplier(context.Context, string) (*domain.SupplierRecord, error)
|
||||
UpsertSupplier(context.Context, domain.SupplierRecord) error
|
||||
ListProjectMembers(context.Context, string, string) ([]domain.ProjectMemberRecord, error)
|
||||
GetProjectMember(context.Context, string) (*domain.ProjectMemberRecord, error)
|
||||
GetProjectMemberByProjectUser(context.Context, string, string, string) (*domain.ProjectMemberRecord, error)
|
||||
UpsertProjectMember(context.Context, domain.ProjectMemberRecord) error
|
||||
DeleteProjectMember(context.Context, string) (bool, error)
|
||||
ListAnnotationTemplates(context.Context, string, string) ([]domain.AnnotationTemplateRecord, error)
|
||||
GetAnnotationTemplate(context.Context, string) (*domain.AnnotationTemplateRecord, error)
|
||||
UpsertAnnotationTemplate(context.Context, domain.AnnotationTemplateRecord) error
|
||||
@ -207,6 +215,10 @@ type Store interface {
|
||||
CreateStorageConnection(context.Context, domain.CreateStorageConnectionInput) (*domain.StorageConnectionRecord, error)
|
||||
DeleteStorageConnection(context.Context, string) (bool, error)
|
||||
UpsertStorageConnection(context.Context, domain.StorageConnectionRecord) error
|
||||
ListObjectStorageUploadSessions(context.Context, string, string) ([]domain.ObjectStorageUploadSessionRecord, error)
|
||||
GetObjectStorageUploadSession(context.Context, string) (*domain.ObjectStorageUploadSessionRecord, error)
|
||||
UpsertObjectStorageUploadSession(context.Context, domain.ObjectStorageUploadSessionRecord) error
|
||||
DeleteExpiredObjectStorageUploadSessions(context.Context, string) (int64, error)
|
||||
|
||||
ListMongoConnections(context.Context) ([]domain.MongoConnectionRecord, error)
|
||||
ListMongoConnectionsByOrganization(context.Context, string) ([]domain.MongoConnectionRecord, error)
|
||||
|
||||
110
internal/store/upload_sessions.go
Normal file
110
internal/store/upload_sessions.go
Normal file
@ -0,0 +1,110 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"droboticflow/internal/domain"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func (store *MemoryStore) ListObjectStorageUploadSessions(_ context.Context, organizationID string, userID string) ([]domain.ObjectStorageUploadSessionRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
items := make([]domain.ObjectStorageUploadSessionRecord, 0)
|
||||
for _, item := range store.uploadSessions {
|
||||
if annotationOrganizationMatches(item.OrganizationID, organizationID) && (strings.TrimSpace(userID) == "" || item.UserID == userID) {
|
||||
items = append(items, clone(item))
|
||||
}
|
||||
}
|
||||
sort.Slice(items, func(left, right int) bool { return items[left].UpdatedAt > items[right].UpdatedAt })
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) GetObjectStorageUploadSession(_ context.Context, id string) (*domain.ObjectStorageUploadSessionRecord, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
item, ok := store.uploadSessions[strings.TrimSpace(id)]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
copy := clone(item)
|
||||
return ©, nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) UpsertObjectStorageUploadSession(_ context.Context, item domain.ObjectStorageUploadSessionRecord) error {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
if item.ID == "" {
|
||||
item.ID = domain.NewID("upload-session")
|
||||
}
|
||||
item.OrganizationID = normalizedOrganizationID(item.OrganizationID)
|
||||
if item.CreatedAt == "" {
|
||||
item.CreatedAt = nowISO()
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
store.uploadSessions[item.ID] = clone(item)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *MemoryStore) DeleteExpiredObjectStorageUploadSessions(_ context.Context, before string) (int64, error) {
|
||||
store.mu.Lock()
|
||||
defer store.mu.Unlock()
|
||||
deleted := int64(0)
|
||||
for id, item := range store.uploadSessions {
|
||||
if item.ExpiresAt != "" && item.ExpiresAt < before {
|
||||
delete(store.uploadSessions, id)
|
||||
deleted++
|
||||
}
|
||||
}
|
||||
return deleted, nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) ListObjectStorageUploadSessions(ctx context.Context, organizationID string, userID string) ([]domain.ObjectStorageUploadSessionRecord, error) {
|
||||
filter := orgCompatibilityFilter(organizationID)
|
||||
if strings.TrimSpace(userID) != "" {
|
||||
filter["userId"] = strings.TrimSpace(userID)
|
||||
}
|
||||
cursor, err := store.uploadSessions.Find(ctx, filter, options.Find().SetSort(bson.D{{Key: "updatedAt", Value: -1}}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return decodeMany[domain.ObjectStorageUploadSessionRecord](ctx, cursor)
|
||||
}
|
||||
|
||||
func (store *MongoStore) GetObjectStorageUploadSession(ctx context.Context, id string) (*domain.ObjectStorageUploadSessionRecord, error) {
|
||||
var item domain.ObjectStorageUploadSessionRecord
|
||||
err := store.uploadSessions.FindOne(ctx, bson.M{"id": strings.TrimSpace(id)}).Decode(&item)
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
func (store *MongoStore) UpsertObjectStorageUploadSession(ctx context.Context, item domain.ObjectStorageUploadSessionRecord) error {
|
||||
if item.ID == "" {
|
||||
item.ID = domain.NewID("upload-session")
|
||||
}
|
||||
item.OrganizationID = normalizedOrganizationID(item.OrganizationID)
|
||||
if item.CreatedAt == "" {
|
||||
item.CreatedAt = nowISO()
|
||||
}
|
||||
item.UpdatedAt = nowISO()
|
||||
_, err := store.uploadSessions.UpdateOne(ctx, bson.M{"id": item.ID}, bson.M{"$set": item}, options.Update().SetUpsert(true))
|
||||
return err
|
||||
}
|
||||
|
||||
func (store *MongoStore) DeleteExpiredObjectStorageUploadSessions(ctx context.Context, before string) (int64, error) {
|
||||
result, err := store.uploadSessions.DeleteMany(ctx, bson.M{"expiresAt": bson.M{"$lt": before}})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.DeletedCount, nil
|
||||
}
|
||||
@ -18,7 +18,10 @@ import (
|
||||
)
|
||||
|
||||
type annotationGateConfig struct {
|
||||
TemplateID string
|
||||
TemplateID string
|
||||
SupplierID string
|
||||
// WorkgroupID is retained only to read pre-v6 workflow definitions during
|
||||
// migration. New templates must use ANNOTATION_SUPPLIER_ID or project members.
|
||||
WorkgroupID string
|
||||
ReleasePolicy domain.HumanReleasePolicy
|
||||
PartitionMaxItems int
|
||||
@ -78,6 +81,7 @@ func annotationGateConfigFromNode(node domain.WorkflowNode) annotationGateConfig
|
||||
}
|
||||
return annotationGateConfig{
|
||||
TemplateID: strings.TrimSpace(params["ANNOTATION_TEMPLATE_ID"]),
|
||||
SupplierID: strings.TrimSpace(params["ANNOTATION_SUPPLIER_ID"]),
|
||||
WorkgroupID: strings.TrimSpace(params["ANNOTATION_WORKGROUP_ID"]),
|
||||
ReleasePolicy: releasePolicy,
|
||||
PartitionMaxItems: positiveAnnotationGateInt(params["PARTITION_MAX_ITEMS"], 32),
|
||||
@ -87,6 +91,42 @@ func annotationGateConfigFromNode(node domain.WorkflowNode) annotationGateConfig
|
||||
}
|
||||
}
|
||||
|
||||
func (runtime *Runtime) annotationGateSupplierID(ctx context.Context, run *domain.RunRecord, config *annotationGateConfig) (string, error) {
|
||||
if config == nil || run == nil {
|
||||
return "", nil
|
||||
}
|
||||
if config.SupplierID != "" {
|
||||
return config.SupplierID, nil
|
||||
}
|
||||
if config.WorkgroupID != "" {
|
||||
group, err := runtime.store.GetAnnotationWorkgroup(ctx, config.WorkgroupID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if group != nil {
|
||||
config.SupplierID = strings.TrimSpace(group.VendorID)
|
||||
return config.SupplierID, nil
|
||||
}
|
||||
}
|
||||
members, err := runtime.store.ListProjectMembers(ctx, run.OrganizationID, run.ProjectID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
suppliers := map[string]struct{}{}
|
||||
for _, member := range members {
|
||||
if strings.TrimSpace(member.SupplierID) != "" {
|
||||
suppliers[member.SupplierID] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(suppliers) == 1 {
|
||||
for supplierID := range suppliers {
|
||||
config.SupplierID = supplierID
|
||||
return supplierID, nil
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func annotationNumber(value any) (float64, bool) {
|
||||
switch typed := value.(type) {
|
||||
case float64:
|
||||
@ -585,20 +625,19 @@ func (runtime *Runtime) createAnnotationGateTasks(
|
||||
} else if pluginConfig != nil && pluginConfig.Enabled {
|
||||
config = applyAnnotationPluginConfig(config, pluginConfig.Config)
|
||||
}
|
||||
if config.TemplateID == "" || config.WorkgroupID == "" {
|
||||
return nil, fmt.Errorf("annotation gate requires ANNOTATION_TEMPLATE_ID and ANNOTATION_WORKGROUP_ID")
|
||||
if config.TemplateID == "" {
|
||||
return nil, fmt.Errorf("annotation gate requires ANNOTATION_TEMPLATE_ID")
|
||||
}
|
||||
template, err := runtime.store.GetAnnotationTemplate(ctx, config.TemplateID)
|
||||
if err != nil || template == nil {
|
||||
return nil, fmt.Errorf("load annotation template %s: %w", config.TemplateID, err)
|
||||
}
|
||||
config.HumanStages = template.HumanStages
|
||||
group, err := runtime.store.GetAnnotationWorkgroup(ctx, config.WorkgroupID)
|
||||
if err != nil || group == nil {
|
||||
return nil, fmt.Errorf("load annotation workgroup %s: %w", config.WorkgroupID, err)
|
||||
if (template.ProjectID != "" && template.ProjectID != run.ProjectID) || template.Status != domain.AnnotationTemplatePublished || template.OrganizationID != run.OrganizationID {
|
||||
return nil, fmt.Errorf("annotation gate template does not belong to the run project and organization")
|
||||
}
|
||||
if (template.ProjectID != "" && template.ProjectID != run.ProjectID) || template.Status != domain.AnnotationTemplatePublished || template.OrganizationID != run.OrganizationID || group.OrganizationID != run.OrganizationID {
|
||||
return nil, fmt.Errorf("annotation gate template/workgroup does not belong to the run project and organization")
|
||||
if _, err := runtime.annotationGateSupplierID(ctx, run, &config); err != nil {
|
||||
return nil, fmt.Errorf("resolve annotation supplier: %w", err)
|
||||
}
|
||||
existing, err := annotationGateTasksForRun(ctx, runtime, run, node)
|
||||
if err != nil {
|
||||
@ -632,7 +671,7 @@ func (runtime *Runtime) createAnnotationGateTasks(
|
||||
if duration <= 0 {
|
||||
return nil, fmt.Errorf("human gate cannot resolve full source duration for %s", artifact.Name)
|
||||
}
|
||||
task := domain.AnnotationTaskRecord{ID: domain.NewID("annotation-task"), OrganizationID: run.OrganizationID, ProjectID: run.ProjectID, DataTaskID: run.TaskID, WorkflowID: run.WorkflowID, RunID: run.ID, NodeID: node.ID, ArtifactID: artifact.ID, SourceVideo: fmt.Sprintf("/api/runs/%s/artifacts/%s/content", url.PathEscape(run.ID), url.PathEscape(artifact.ID)), ClipStart: 0, ClipEnd: duration, SourceIsFullVideo: true, SourceDurationSeconds: duration, CoverageStartSecond: 0, CoverageEndSecond: duration, CoverageMode: "full_source_pending_common_range", TemplateID: template.ID, TemplateVersion: template.Version, WorkgroupID: group.ID, VendorID: group.VendorID, Status: domain.AnnotationTaskStatusPendingAnnotation, PoseSummary: poseSummary, CreatedAt: nowISO(), UpdatedAt: nowISO()}
|
||||
task := domain.AnnotationTaskRecord{ID: domain.NewID("annotation-task"), OrganizationID: run.OrganizationID, ProjectID: run.ProjectID, DataTaskID: run.TaskID, WorkflowID: run.WorkflowID, RunID: run.ID, NodeID: node.ID, ArtifactID: artifact.ID, SourceVideo: fmt.Sprintf("/api/runs/%s/artifacts/%s/content", url.PathEscape(run.ID), url.PathEscape(artifact.ID)), ClipStart: 0, ClipEnd: duration, SourceIsFullVideo: true, SourceDurationSeconds: duration, CoverageStartSecond: 0, CoverageEndSecond: duration, CoverageMode: "full_source_pending_common_range", TemplateID: template.ID, TemplateVersion: template.Version, SupplierID: config.SupplierID, Status: domain.AnnotationTaskStatusPendingAnnotation, PoseSummary: poseSummary, CreatedAt: nowISO(), UpdatedAt: nowISO()}
|
||||
if err := runtime.store.UpsertAnnotationTask(ctx, task); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -713,8 +752,7 @@ func (runtime *Runtime) createAnnotationGateTasks(
|
||||
}(),
|
||||
TemplateID: template.ID,
|
||||
TemplateVersion: template.Version,
|
||||
WorkgroupID: group.ID,
|
||||
VendorID: group.VendorID,
|
||||
SupplierID: config.SupplierID,
|
||||
AssignedUserID: "",
|
||||
Status: domain.AnnotationTaskStatusPendingAnnotation,
|
||||
CurrentRevision: 0,
|
||||
@ -740,7 +778,7 @@ func (runtime *Runtime) createAnnotationGateTasks(
|
||||
}
|
||||
_ = runtime.store.UpsertAnnotationWorklogEvent(ctx, domain.AnnotationWorklogEventRecord{
|
||||
ID: domain.NewID("annotation-worklog"), OrganizationID: run.OrganizationID, ProjectID: run.ProjectID,
|
||||
TaskID: task.ID, UserID: "system", WorkgroupID: group.ID, VendorID: group.VendorID,
|
||||
TaskID: task.ID, UserID: "system", SupplierID: config.SupplierID,
|
||||
EventType: "created", Mode: eventMode, Temporary: eventMode == domain.RunModeDebug, TemplateVersion: template.Version, OutputDelta: 0, CreatedAt: nowISO(),
|
||||
})
|
||||
tasks = append(tasks, task)
|
||||
@ -789,6 +827,7 @@ func (runtime *Runtime) ensureAnnotationHumanBatch(
|
||||
OrganizationID: run.OrganizationID,
|
||||
PluginID: "annotation-qa",
|
||||
ProjectID: run.ProjectID,
|
||||
SupplierID: config.SupplierID,
|
||||
WorkflowID: run.WorkflowID,
|
||||
RunID: run.ID,
|
||||
GateNodeID: node.ID,
|
||||
@ -868,8 +907,7 @@ func (runtime *Runtime) ensureAnnotationHumanBatch(
|
||||
CurrentStageID: initialStageID,
|
||||
Status: domain.HumanItemReady,
|
||||
AssignedUserID: "",
|
||||
WorkgroupID: task.WorkgroupID,
|
||||
VendorID: task.VendorID,
|
||||
SupplierID: task.SupplierID,
|
||||
MaxReworkRounds: batch.MaxReworkRounds,
|
||||
Version: 1,
|
||||
}
|
||||
|
||||
@ -84,6 +84,9 @@ func normalizedCaptureAutomation(config *domain.CaptureAutomationConfig) domain.
|
||||
if next.PollIntervalSeconds < 5 {
|
||||
next.PollIntervalSeconds = 5
|
||||
}
|
||||
if next.StabilityWindowSeconds <= 0 {
|
||||
next.StabilityWindowSeconds = 30
|
||||
}
|
||||
return next
|
||||
}
|
||||
|
||||
@ -538,14 +541,29 @@ func (runtime *Runtime) processCaptureAutomation(ctx context.Context, workflow d
|
||||
newCount++
|
||||
}
|
||||
if len(missing) == 0 {
|
||||
record.Status = domain.CaptureRecordReady
|
||||
if existing != nil && existing.ReadyAt != "" {
|
||||
record.ReadyAt = existing.ReadyAt
|
||||
if existing == nil || existing.Fingerprint != group.Fingerprint {
|
||||
record.Status = domain.CaptureRecordStabilizing
|
||||
record.StabilityChecks = 1
|
||||
record.StabilityObservedAt = nowText
|
||||
} else {
|
||||
record.ReadyAt = nowText
|
||||
record.StabilityChecks = existing.StabilityChecks + 1
|
||||
record.StabilityObservedAt = existing.StabilityObservedAt
|
||||
if record.StabilityObservedAt == "" {
|
||||
record.StabilityObservedAt = nowText
|
||||
}
|
||||
stableSince, stableSinceOK := parseRFC3339Nano(record.StabilityObservedAt)
|
||||
stableEnough := stableSinceOK && now.Sub(stableSince) >= time.Duration(config.StabilityWindowSeconds)*time.Second
|
||||
if record.StabilityChecks >= 2 && stableEnough {
|
||||
record.Status = domain.CaptureRecordReady
|
||||
record.ReadyAt = nowText
|
||||
} else {
|
||||
record.Status = domain.CaptureRecordStabilizing
|
||||
}
|
||||
}
|
||||
} else {
|
||||
record.Status = domain.CaptureRecordIncomplete
|
||||
record.StabilityChecks = 0
|
||||
record.StabilityObservedAt = ""
|
||||
}
|
||||
if err := runtime.store.UpsertCaptureRecord(ctx, record); err != nil {
|
||||
return err
|
||||
|
||||
@ -205,3 +205,10 @@ func TestLaunchCaptureRunBindsOneCompleteDirectory(t *testing.T) {
|
||||
t.Fatalf("unexpected directory binding: %#v", input)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizedCaptureAutomationDefaultsToThirtySecondStabilityWindow(t *testing.T) {
|
||||
config := normalizedCaptureAutomation(&domain.CaptureAutomationConfig{Enabled: true, PollIntervalSeconds: 10})
|
||||
if config.StabilityWindowSeconds != 30 {
|
||||
t.Fatalf("stability window = %d", config.StabilityWindowSeconds)
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,15 +221,15 @@ func (runtime *Runtime) syncDeliveryPackage(ctx context.Context, batch domain.Hu
|
||||
if len(packages) > 0 {
|
||||
item = packages[0]
|
||||
} else {
|
||||
workgroupID, vendorID := "", ""
|
||||
workgroupID, vendorID, supplierID := "", "", ""
|
||||
if len(partition.ItemIDs) > 0 {
|
||||
if humanItem, itemErr := runtime.store.GetHumanItem(ctx, partition.ItemIDs[0]); itemErr == nil && humanItem != nil {
|
||||
workgroupID, vendorID = humanItem.WorkgroupID, humanItem.VendorID
|
||||
workgroupID, vendorID, supplierID = humanItem.WorkgroupID, humanItem.VendorID, humanItem.SupplierID
|
||||
}
|
||||
}
|
||||
item = domain.DeliveryPackageRecord{
|
||||
ID: "delivery-package-" + partition.ID, OrganizationID: batch.OrganizationID, ProjectID: batch.ProjectID,
|
||||
WorkflowID: batch.WorkflowID, WorkgroupID: workgroupID, VendorID: vendorID, ParentRunID: batch.RunID, ChildRunID: partition.ChildRunID,
|
||||
WorkflowID: batch.WorkflowID, SupplierID: supplierID, WorkgroupID: workgroupID, VendorID: vendorID, ParentRunID: batch.RunID, ChildRunID: partition.ChildRunID,
|
||||
ReleasePartitionID: partition.ID, ManifestDigest: partition.ManifestDigest, ItemIDs: partition.ItemIDs,
|
||||
Status: domain.DeliveryPackageBuilding, Mode: mode, Temporary: mode == domain.RunModeDebug, Version: 1, CreatedAt: nowISO(), UpdatedAt: nowISO(),
|
||||
}
|
||||
@ -386,7 +386,7 @@ func (runtime *Runtime) ensureDeliveryPackageAcceptanceItem(ctx context.Context,
|
||||
ProjectID: item.ProjectID, WorkflowID: item.WorkflowID, RunID: item.ChildRunID, GateNodeID: "delivery-package-acceptance",
|
||||
Subject: domain.HumanSubjectRef{ArtifactID: artifactID, ItemKey: item.ID, MediaType: "application/json", Payload: map[string]any{
|
||||
"deliveryPackageId": item.ID, "artifactIds": item.ArtifactIDs, "manifestDigest": item.ManifestDigest,
|
||||
}}, CurrentStageID: "acceptance", Status: status, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
}}, CurrentStageID: "acceptance", Status: status, SupplierID: item.SupplierID, WorkgroupID: item.WorkgroupID, VendorID: item.VendorID,
|
||||
Version: 1, MaxReworkRounds: sourceBatch.MaxReworkRounds, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
if err := runtime.store.UpsertHumanItem(ctx, *humanItem); err != nil {
|
||||
|
||||
@ -175,7 +175,7 @@ data:
|
||||
FANYU_HEADPOSE_LICENSE_ID: "MIT"
|
||||
# Empty keeps the v5 template draft/fail-closed. Set the real published
|
||||
# annotation workgroup ID in the POC deployment environment before release.
|
||||
FANYU_V5_ANNOTATION_WORKGROUP_ID: "__FANYU_V5_ANNOTATION_WORKGROUP_ID__"
|
||||
FANYU_V5_SUPPLIER_ID: "__FANYU_V5_SUPPLIER_ID__"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
@ -371,11 +371,11 @@ spec:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_HEADPOSE_LICENSE_ID
|
||||
- name: FANYU_V5_ANNOTATION_WORKGROUP_ID
|
||||
- name: FANYU_V5_SUPPLIER_ID
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: droboticflow-config
|
||||
key: FANYU_V5_ANNOTATION_WORKGROUP_ID
|
||||
key: FANYU_V5_SUPPLIER_ID
|
||||
- name: AI_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
||||
@ -16,9 +16,9 @@ def _run_legacy(
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
template_id = params.get("ANNOTATION_TEMPLATE_ID", "").strip()
|
||||
workgroup_id = params.get("ANNOTATION_WORKGROUP_ID", "").strip()
|
||||
if not template_id or not workgroup_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID 和 ANNOTATION_WORKGROUP_ID")
|
||||
supplier_id = params.get("ANNOTATION_SUPPLIER_ID", "").strip()
|
||||
if not template_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID")
|
||||
payloads = helpers["payloads_from_inputs"](inputs)
|
||||
items = helpers["collect_items"](payloads)
|
||||
if not items:
|
||||
@ -34,7 +34,7 @@ def _run_legacy(
|
||||
"runId": run_id,
|
||||
"nodeId": node_id,
|
||||
"templateId": template_id,
|
||||
"workgroupId": workgroup_id,
|
||||
"supplierId": supplier_id,
|
||||
"itemCount": len(items),
|
||||
"items": items,
|
||||
"interceptedByWorker": False,
|
||||
@ -62,9 +62,9 @@ def _run_multiport(
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
template_id = params.get("ANNOTATION_TEMPLATE_ID", "").strip()
|
||||
workgroup_id = params.get("ANNOTATION_WORKGROUP_ID", "").strip()
|
||||
if not template_id or not workgroup_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID 和 ANNOTATION_WORKGROUP_ID")
|
||||
supplier_id = params.get("ANNOTATION_SUPPLIER_ID", "").strip()
|
||||
if not template_id:
|
||||
raise RuntimeError("原生视频标注 Gate 需要 ANNOTATION_TEMPLATE_ID")
|
||||
# Only the Qwen ``clips`` port creates human work. HeadPose rendering is
|
||||
# also a video input in v5.7, but it is review evidence, not another clip
|
||||
# to cut, annotate, accept, and package.
|
||||
@ -86,12 +86,12 @@ def _run_multiport(
|
||||
annotations = {
|
||||
"datasetType": "annotation-gate-input",
|
||||
"templateId": template_id,
|
||||
"workgroupId": workgroup_id,
|
||||
"supplierId": supplier_id,
|
||||
"itemCount": len(clips),
|
||||
"items": prelabels,
|
||||
}
|
||||
rejected = {"datasetType": "annotation-gate-rejected", "itemCount": 0, "items": []}
|
||||
summary = {"clipCount": len(clips), "prelabelCount": len(prelabels), "boundaryCount": len(boundaries), "templateId": template_id, "workgroupId": workgroup_id}
|
||||
summary = {"clipCount": len(clips), "prelabelCount": len(prelabels), "boundaryCount": len(boundaries), "templateId": template_id, "supplierId": supplier_id}
|
||||
return [
|
||||
*clips,
|
||||
write(run_id, node_id, output_dir, "annotation-gate-annotations-dataset.json", annotations, output=_output(node_data, helpers, "annotations")),
|
||||
|
||||
@ -45,7 +45,6 @@ REQUIRED_VALUES = {
|
||||
"FANYU_S100_MODE",
|
||||
"FANYU_REMOTE_API_BASE_URL",
|
||||
"FANYU_REMOTE_BOS_ENDPOINT",
|
||||
"FANYU_V5_ANNOTATION_WORKGROUP_ID",
|
||||
"FANYU_HEADPOSE_API_BASE_URL",
|
||||
"FANYU_HEADPOSE_SERVICE_IMAGE_ID",
|
||||
"FANYU_HEADPOSE_MODEL_SHA256",
|
||||
|
||||
@ -57,4 +57,4 @@ export AI_MODEL="${AI_MODEL:-}"
|
||||
export HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
# Required only to publish/run the Fanyu v5 release. Keep blank until the
|
||||
# live POC annotation workgroup has been created and verified.
|
||||
export FANYU_V5_ANNOTATION_WORKGROUP_ID="${FANYU_V5_ANNOTATION_WORKGROUP_ID:-}"
|
||||
export FANYU_V5_SUPPLIER_ID="${FANYU_V5_SUPPLIER_ID:-}"
|
||||
|
||||
@ -56,7 +56,7 @@ fi
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-droboticflow-headpose-service:latest}"
|
||||
HEADPOSE_SERVICE_IMAGE_ID="${HEADPOSE_SERVICE_IMAGE_ID:-}"
|
||||
HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
FANYU_V5_ANNOTATION_WORKGROUP_ID="${FANYU_V5_ANNOTATION_WORKGROUP_ID:-}"
|
||||
FANYU_V5_SUPPLIER_ID="${FANYU_V5_SUPPLIER_ID:-}"
|
||||
DROBOTICFLOW_BUILD_COMMIT="${DROBOTICFLOW_BUILD_COMMIT:-$(git -C "$ROOT_DIR" rev-parse HEAD)}"
|
||||
DROBOTICFLOW_BUILD_TIME="${DROBOTICFLOW_BUILD_TIME:-}"
|
||||
OPERATOR_RUNNER_BUILD_COMMIT="${OPERATOR_RUNNER_BUILD_COMMIT:-$DROBOTICFLOW_BUILD_COMMIT}"
|
||||
@ -226,7 +226,7 @@ env \
|
||||
HEADPOSE_SERVICE_IMAGE="$HEADPOSE_SERVICE_IMAGE" \
|
||||
HEADPOSE_SERVICE_IMAGE_ID="$HEADPOSE_SERVICE_IMAGE_ID" \
|
||||
HEADPOSE_MODEL_SHA256="$HEADPOSE_MODEL_SHA256" \
|
||||
FANYU_V5_ANNOTATION_WORKGROUP_ID="$FANYU_V5_ANNOTATION_WORKGROUP_ID" \
|
||||
FANYU_V5_SUPPLIER_ID="$FANYU_V5_SUPPLIER_ID" \
|
||||
OPERATOR_RUNNER_BUILD_COMMIT="$OPERATOR_RUNNER_BUILD_COMMIT" \
|
||||
OPERATOR_RUNNER_BUILD_TIME="$OPERATOR_RUNNER_BUILD_TIME" \
|
||||
DROBOTICFLOW_BUILD_COMMIT="$DROBOTICFLOW_BUILD_COMMIT" \
|
||||
|
||||
@ -153,7 +153,7 @@ validate_manifest_startup_configuration() {
|
||||
validate_http_service_url WORKER_API_BASE_URL "$WORKER_API_BASE_URL"
|
||||
validate_ai_runtime_configuration
|
||||
validate_optional_http_service_url BOS_ENDPOINT "$BOS_ENDPOINT"
|
||||
validate_optional_token_value FANYU_V5_ANNOTATION_WORKGROUP_ID "${FANYU_V5_ANNOTATION_WORKGROUP_ID:-}"
|
||||
validate_optional_token_value FANYU_V5_SUPPLIER_ID "${FANYU_V5_SUPPLIER_ID:-}"
|
||||
validate_integer_min MONGO_CONNECT_RETRIES "$MONGO_CONNECT_RETRIES" 1
|
||||
validate_integer_min MONGO_CONNECT_RETRY_DELAY_MS "$MONGO_CONNECT_RETRY_DELAY_MS" 1
|
||||
validate_integer_min WORKER_POLL_INTERVAL_MS "$WORKER_POLL_INTERVAL_MS" 1
|
||||
|
||||
@ -70,7 +70,7 @@ DROBOTICFLOW_TRUSTED_PROXY_CIDRS="${DROBOTICFLOW_TRUSTED_PROXY_CIDRS:-}"
|
||||
HEADPOSE_SERVICE_IMAGE="${HEADPOSE_SERVICE_IMAGE:-droboticflow-headpose-service:latest}"
|
||||
HEADPOSE_SERVICE_IMAGE_ID="${HEADPOSE_SERVICE_IMAGE_ID:-}"
|
||||
HEADPOSE_MODEL_SHA256="${HEADPOSE_MODEL_SHA256:-sha256:9bdcd0e072df0d21e92288b40ea1d1b3cf7173c44728ab9c45c4d673f361e018}"
|
||||
FANYU_V5_ANNOTATION_WORKGROUP_ID="${FANYU_V5_ANNOTATION_WORKGROUP_ID:-}"
|
||||
FANYU_V5_SUPPLIER_ID="${FANYU_V5_SUPPLIER_ID:-}"
|
||||
# shellcheck source=scripts/lib/image-config.sh
|
||||
source "$ROOT_DIR/scripts/lib/image-config.sh"
|
||||
REGISTRY_HOST="${REGISTRY_HOST:-}"
|
||||
@ -178,7 +178,7 @@ export \
|
||||
HEADPOSE_SERVICE_IMAGE \
|
||||
HEADPOSE_SERVICE_IMAGE_ID \
|
||||
HEADPOSE_MODEL_SHA256 \
|
||||
FANYU_V5_ANNOTATION_WORKGROUP_ID
|
||||
FANYU_V5_SUPPLIER_ID
|
||||
|
||||
python3 - <<'PY'
|
||||
import os
|
||||
@ -242,7 +242,7 @@ replacements = {
|
||||
"__HEADPOSE_SERVICE_IMAGE__": os.environ["HEADPOSE_SERVICE_IMAGE"],
|
||||
"__HEADPOSE_SERVICE_IMAGE_ID__": os.environ["HEADPOSE_SERVICE_IMAGE_ID"],
|
||||
"__HEADPOSE_MODEL_SHA256__": os.environ["HEADPOSE_MODEL_SHA256"],
|
||||
"__FANYU_V5_ANNOTATION_WORKGROUP_ID__": os.environ["FANYU_V5_ANNOTATION_WORKGROUP_ID"],
|
||||
"__FANYU_V5_SUPPLIER_ID__": os.environ["FANYU_V5_SUPPLIER_ID"],
|
||||
}
|
||||
|
||||
rendered = template
|
||||
|
||||
@ -3,6 +3,7 @@ import { Blocks, Loader2 } from "lucide-react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { usePlugins } from "../context/PluginContext";
|
||||
import { useUser } from "../context/UserContext";
|
||||
import { isOrganizationAdminRole } from "../lib/user-roles";
|
||||
|
||||
export function PluginRouteGuard({ pluginId, children }: { pluginId: string; children: React.ReactNode }) {
|
||||
const { loading, isEnabled } = usePlugins();
|
||||
@ -23,7 +24,7 @@ export function PluginRouteGuard({ pluginId, children }: { pluginId: string; chi
|
||||
<p className="mt-2 text-sm leading-6 text-gray-400">
|
||||
当前组织未安装 {pluginId},相关工作台、路由和算子均不可用。
|
||||
</p>
|
||||
{role === "admin" ? (
|
||||
{isOrganizationAdminRole(role) ? (
|
||||
<Link className="mt-5 inline-flex rounded-lg bg-violet-600 px-4 py-2 text-sm text-white" to="/settings">
|
||||
前往系统配置安装
|
||||
</Link>
|
||||
|
||||
@ -1,25 +1,42 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Blocks, Loader2, Save } from "lucide-react";
|
||||
import { AlertTriangle, Blocks, CheckCircle2, Loader2, Save } from "lucide-react";
|
||||
import { useUser } from "../context/UserContext";
|
||||
import { pluginsApi } from "../services/api/plugins";
|
||||
import type { PluginStatus } from "../types";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
import { usePlugins } from "../context/PluginContext";
|
||||
import { humanLoopApi } from "../services/api/human-loop";
|
||||
import type { HumanItem } from "../types";
|
||||
|
||||
const inputClass = "rounded-md border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white";
|
||||
|
||||
export default function PluginSettingsPanel() {
|
||||
const { organization } = useUser();
|
||||
const { organization, role } = useUser();
|
||||
const { statuses, loading, error: loadError, refresh: refreshPlugins } = usePlugins();
|
||||
const [status, setStatus] = useState<PluginStatus | null>(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [escalated, setEscalated] = useState<HumanItem[]>([]);
|
||||
const [escalationComment, setEscalationComment] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
const annotationStatus = statuses.find((item) => item.manifest.id === "annotation-qa");
|
||||
if (annotationStatus) setStatus(annotationStatus);
|
||||
}, [statuses]);
|
||||
|
||||
const refreshEscalations = async () => {
|
||||
if (role !== "admin" && role !== "organization_admin") return;
|
||||
try {
|
||||
setEscalated(await humanLoopApi.listItems({ pluginId: "annotation-qa", status: "escalated", pool: "all" }));
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "加载升级任务失败"));
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void refreshEscalations();
|
||||
}, [role]);
|
||||
|
||||
if (!organization || !status) {
|
||||
if (error || loadError) return <div className="text-sm text-red-300">{error || loadError}</div>;
|
||||
return loading ? (
|
||||
@ -111,6 +128,104 @@ export default function PluginSettingsPanel() {
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid gap-3 border-t border-[#2a2b2f] bg-[#101114] p-5 text-xs text-gray-400 md:grid-cols-3">
|
||||
<div>
|
||||
<div className="font-medium text-white">通过条目分区释放</div>
|
||||
<p className="mt-1 leading-5">达到条数或等待时间后,已通过条目会先进入下游,未完成任务不会阻塞它们。</p>
|
||||
</div>
|
||||
<div>
|
||||
<div className="font-medium text-white">全批通过后释放</div>
|
||||
<p className="mt-1 leading-5">所有任务完成并通过后一次释放;有未解决任务时整批保持等待。</p>
|
||||
</div>
|
||||
<div>
|
||||
<div className="font-medium text-white">最大返工轮次</div>
|
||||
<p className="mt-1 leading-5">超过限制后任务进入升级区并阻塞批次,必须由组织管理员强制重开或关闭。</p>
|
||||
</div>
|
||||
</div>
|
||||
{role === "admin" || role === "organization_admin" ? (
|
||||
<div className="border-t border-[#2a2b2f] p-5">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2 font-medium text-white">
|
||||
<AlertTriangle className="h-4 w-4 text-amber-300" />
|
||||
升级任务({escalated.length})
|
||||
</div>
|
||||
<button type="button" onClick={() => void refreshEscalations()} className="text-xs text-blue-300">
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
<textarea
|
||||
value={escalationComment}
|
||||
onChange={(event) => setEscalationComment(event.target.value)}
|
||||
rows={2}
|
||||
placeholder="管理员处置说明;强制重开或关闭时必填"
|
||||
className="mt-3 w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-3 text-sm text-white"
|
||||
/>
|
||||
<div className="mt-3 space-y-2">
|
||||
{escalated.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-amber-500/20 bg-amber-500/5 p-3 text-xs"
|
||||
>
|
||||
<div>
|
||||
<div className="font-mono text-amber-100">
|
||||
{item.display?.captureDirectories?.join("、") || item.id}
|
||||
</div>
|
||||
<div className="mt-1 text-gray-400">
|
||||
{item.display?.projectName} / {item.display?.workflowName} · 第 {item.reviewRound} 轮返工
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving || !escalationComment.trim()}
|
||||
onClick={() =>
|
||||
humanLoopApi
|
||||
.decideEscalation(item.id, {
|
||||
version: item.version,
|
||||
action: "reopen",
|
||||
comment: escalationComment.trim(),
|
||||
})
|
||||
.then(refreshEscalations)
|
||||
.catch((cause) => setError(getActionErrorMessage(cause, "强制重开失败")))
|
||||
}
|
||||
className="rounded border border-blue-500/30 px-2 py-1 text-blue-200 disabled:opacity-40"
|
||||
>
|
||||
强制重开
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving || !escalationComment.trim()}
|
||||
onClick={() =>
|
||||
humanLoopApi
|
||||
.decideEscalation(item.id, {
|
||||
version: item.version,
|
||||
action: "close",
|
||||
comment: escalationComment.trim(),
|
||||
})
|
||||
.then(refreshEscalations)
|
||||
.catch((cause) => setError(getActionErrorMessage(cause, "关闭升级任务失败")))
|
||||
}
|
||||
className="rounded border border-red-500/30 px-2 py-1 text-red-200 disabled:opacity-40"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{escalated.length === 0 ? (
|
||||
<div className="rounded-lg border border-dashed border-[#2a2b2f] px-3 py-4 text-gray-500">
|
||||
当前没有需要管理员处置的升级任务。
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{escalated.length > 0 && escalationComment.trim() ? (
|
||||
<div className="mt-2 flex items-center gap-1 text-[11px] text-emerald-300">
|
||||
<CheckCircle2 className="h-3.5 w-3.5" />
|
||||
处置说明已填写
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex items-center justify-between border-t border-[#2a2b2f] px-6 py-3">
|
||||
<span className="text-xs text-red-300">{error}</span>
|
||||
<button
|
||||
|
||||
388
src/components/ProjectMembersPanel.tsx
Normal file
388
src/components/ProjectMembersPanel.tsx
Normal file
@ -0,0 +1,388 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Check, Edit3, Loader2, Search, Trash2, UserPlus, Users } from "lucide-react";
|
||||
import type { ProjectMember, ProjectMemberRole, Supplier, User } from "../types";
|
||||
import { projectsApi } from "../services/api/projects";
|
||||
import { suppliersApi } from "../services/api/suppliers";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
|
||||
const roleOptions: Array<{ value: ProjectMemberRole; label: string; description: string }> = [
|
||||
{ value: "annotator", label: "标注员", description: "真实切分校正与语义标注" },
|
||||
{ value: "quality_reviewer", label: "审核员", description: "审核切分、双目同步与语义标注" },
|
||||
{ value: "acceptance_reviewer", label: "最终验收员", description: "独立完成整包最终验收" },
|
||||
];
|
||||
|
||||
function rolesText(roles: ProjectMemberRole[]) {
|
||||
return roles.map((role) => roleOptions.find((item) => item.value === role)?.label || role).join("、");
|
||||
}
|
||||
|
||||
export function ProjectMembersPanel({
|
||||
projectId,
|
||||
users,
|
||||
canManage,
|
||||
}: {
|
||||
projectId: string;
|
||||
users: User[];
|
||||
canManage: boolean;
|
||||
}) {
|
||||
const [members, setMembers] = useState<ProjectMember[]>([]);
|
||||
const [suppliers, setSuppliers] = useState<Supplier[]>([]);
|
||||
const [query, setQuery] = useState("");
|
||||
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [addOpen, setAddOpen] = useState(false);
|
||||
const [draft, setDraft] = useState<{ userId: string; supplierId: string; roles: ProjectMemberRole[] }>({
|
||||
userId: "",
|
||||
supplierId: "",
|
||||
roles: ["annotator"],
|
||||
});
|
||||
const [editing, setEditing] = useState<ProjectMember | null>(null);
|
||||
|
||||
const reload = async () => {
|
||||
try {
|
||||
const [nextMembers, nextSuppliers] = await Promise.all([projectsApi.listMembers(projectId), suppliersApi.list()]);
|
||||
setMembers(nextMembers);
|
||||
setSuppliers(nextSuppliers);
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "加载项目成员失败"));
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void reload();
|
||||
}, [projectId]);
|
||||
|
||||
const visibleMembers = useMemo(() => {
|
||||
const normalized = query.trim().toLowerCase();
|
||||
if (!normalized) return members;
|
||||
return members.filter((member) => {
|
||||
const user = users.find((item) => item.id === member.userId);
|
||||
const supplier = suppliers.find((item) => item.id === member.supplierId);
|
||||
return `${user?.name || ""} ${user?.email || ""} ${supplier?.name || ""} ${rolesText(member.roles)}`
|
||||
.toLowerCase()
|
||||
.includes(normalized);
|
||||
});
|
||||
}, [members, query, suppliers, users]);
|
||||
|
||||
const toggleRole = (role: ProjectMemberRole, target = draft, setTarget = setDraft) => {
|
||||
setTarget((current) => ({
|
||||
...current,
|
||||
roles: current.roles.includes(role) ? current.roles.filter((item) => item !== role) : [...current.roles, role],
|
||||
}));
|
||||
};
|
||||
|
||||
const saveNew = async () => {
|
||||
if (!draft.userId || draft.roles.length === 0) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await projectsApi.createMember(projectId, draft);
|
||||
setAddOpen(false);
|
||||
setDraft({ userId: "", supplierId: "", roles: ["annotator"] });
|
||||
await reload();
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "添加项目成员失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveEdit = async () => {
|
||||
if (!editing || editing.roles.length === 0) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await projectsApi.updateMember(projectId, editing.id, { supplierId: editing.supplierId, roles: editing.roles });
|
||||
setEditing(null);
|
||||
await reload();
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "更新项目角色失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (member: ProjectMember) => {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await projectsApi.removeMember(projectId, member.id, true);
|
||||
await reload();
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "移出项目成员失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const bulk = async (action: "set_roles" | "remove") => {
|
||||
if (!selectedIds.length) return;
|
||||
const roles = editing?.roles || draft.roles;
|
||||
if (action === "set_roles" && roles.length === 0) {
|
||||
setError("请至少保留一个项目角色。");
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await projectsApi.bulkMembers(projectId, {
|
||||
action,
|
||||
memberIds: selectedIds,
|
||||
roles: action === "set_roles" ? roles : undefined,
|
||||
});
|
||||
setSelectedIds([]);
|
||||
await reload();
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "批量更新项目成员失败"));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="space-y-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-[#2a2b2f] bg-[#151619] p-5">
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-lg font-semibold text-white">
|
||||
<Users className="h-5 w-5 text-blue-400" />
|
||||
项目成员与角色
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-gray-500">任务按项目、阶段和供应商隔离;不再使用工作组。</p>
|
||||
</div>
|
||||
{canManage ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setAddOpen(true)}
|
||||
className="inline-flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white"
|
||||
>
|
||||
<UserPlus className="h-4 w-4" />
|
||||
添加项目成员
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<label className="relative min-w-64 flex-1">
|
||||
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500" />
|
||||
<input
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="搜索姓名、账号、供应商或角色"
|
||||
className="w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] py-2 pl-9 pr-3 text-sm text-white"
|
||||
/>
|
||||
</label>
|
||||
{canManage && selectedIds.length > 0 ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void bulk("set_roles")}
|
||||
disabled={saving}
|
||||
className="rounded-lg border border-blue-500/30 px-3 py-2 text-xs text-blue-200"
|
||||
>
|
||||
批量设为当前角色
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void bulk("remove")}
|
||||
disabled={saving}
|
||||
className="rounded-lg border border-red-500/30 px-3 py-2 text-xs text-red-200"
|
||||
>
|
||||
批量移出
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
{error ? (
|
||||
<div className="rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-200">{error}</div>
|
||||
) : null}
|
||||
<div className="overflow-hidden rounded-xl border border-[#2a2b2f] bg-[#151619]">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="bg-[#111214] text-xs uppercase tracking-wider text-gray-500">
|
||||
<tr>
|
||||
{canManage ? (
|
||||
<th className="px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={visibleMembers.length > 0 && visibleMembers.every((item) => selectedIds.includes(item.id))}
|
||||
onChange={(event) =>
|
||||
setSelectedIds(event.target.checked ? visibleMembers.map((item) => item.id) : [])
|
||||
}
|
||||
/>
|
||||
</th>
|
||||
) : null}
|
||||
<th className="px-5 py-3">成员</th>
|
||||
<th className="px-5 py-3">供应商</th>
|
||||
<th className="px-5 py-3">项目角色</th>
|
||||
<th className="px-5 py-3 text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-[#2a2b2f]">
|
||||
{visibleMembers.map((member) => {
|
||||
const user = users.find((item) => item.id === member.userId);
|
||||
const supplier = suppliers.find((item) => item.id === member.supplierId);
|
||||
return (
|
||||
<tr key={member.id} className="hover:bg-white/[0.02]">
|
||||
{canManage ? (
|
||||
<td className="px-4 py-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selectedIds.includes(member.id)}
|
||||
onChange={(event) =>
|
||||
setSelectedIds((current) =>
|
||||
event.target.checked ? [...current, member.id] : current.filter((id) => id !== member.id),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
) : null}
|
||||
<td className="px-5 py-4">
|
||||
<div className="font-medium text-white">{user?.name || member.userId}</div>
|
||||
<div className="mt-0.5 text-xs text-gray-500">{user?.email || member.userId}</div>
|
||||
</td>
|
||||
<td className="px-5 py-4 text-gray-300">{supplier?.name || "内部成员"}</td>
|
||||
<td className="px-5 py-4">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{member.roles.map((role) => (
|
||||
<span
|
||||
key={role}
|
||||
className="rounded-md border border-blue-500/25 bg-blue-500/10 px-2 py-1 text-xs text-blue-200"
|
||||
>
|
||||
{roleOptions.find((item) => item.value === role)?.label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-5 py-4 text-right">
|
||||
{canManage ? (
|
||||
<div className="inline-flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing({ ...member, roles: [...member.roles] })}
|
||||
className="rounded border border-[#2a2b2f] p-1.5 text-gray-300"
|
||||
>
|
||||
<Edit3 className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void remove(member)}
|
||||
disabled={saving}
|
||||
className="rounded border border-red-500/20 p-1.5 text-red-300"
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
{visibleMembers.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={canManage ? 5 : 4} className="px-6 py-12 text-center text-gray-500">
|
||||
当前项目还没有成员。
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{addOpen || editing ? (
|
||||
<div className="rounded-xl border border-blue-500/30 bg-[#151619] p-5">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="font-semibold text-white">{editing ? "编辑项目角色" : "添加项目成员"}</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setAddOpen(false);
|
||||
setEditing(null);
|
||||
}}
|
||||
className="text-xs text-gray-400"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
{!editing ? (
|
||||
<label className="mt-4 block text-xs text-gray-400">
|
||||
用户
|
||||
<select
|
||||
value={draft.userId}
|
||||
onChange={(event) => setDraft((current) => ({ ...current, userId: event.target.value }))}
|
||||
className="mt-1 w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-2 text-sm text-white"
|
||||
>
|
||||
<option value="">选择用户</option>
|
||||
{users
|
||||
.filter((user) => user.status !== "disabled")
|
||||
.map((user) => (
|
||||
<option key={user.id} value={user.id}>
|
||||
{user.name} · {user.email}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
) : (
|
||||
<div className="mt-4 text-sm text-gray-300">
|
||||
{users.find((user) => user.id === editing.userId)?.name || editing.userId}
|
||||
</div>
|
||||
)}
|
||||
<label className="mt-4 block text-xs text-gray-400">
|
||||
供应商
|
||||
<select
|
||||
value={editing ? editing.supplierId || "" : draft.supplierId}
|
||||
onChange={(event) =>
|
||||
editing
|
||||
? setEditing({ ...editing, supplierId: event.target.value })
|
||||
: setDraft((current) => ({ ...current, supplierId: event.target.value }))
|
||||
}
|
||||
className="mt-1 w-full rounded-lg border border-[#2a2b2f] bg-[#0a0a0a] p-2 text-sm text-white"
|
||||
>
|
||||
<option value="">内部成员 / 不限定供应商</option>
|
||||
{suppliers.map((supplier) => (
|
||||
<option key={supplier.id} value={supplier.id}>
|
||||
{supplier.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<div className="mt-4 grid gap-2">
|
||||
{roleOptions.map((option) => {
|
||||
const roles = editing?.roles || draft.roles;
|
||||
const checked = roles.includes(option.value);
|
||||
return (
|
||||
<label
|
||||
key={option.value}
|
||||
className={`flex items-start gap-3 rounded-lg border p-3 ${checked ? "border-blue-500/40 bg-blue-500/10" : "border-[#2a2b2f]"}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={() =>
|
||||
editing
|
||||
? setEditing({
|
||||
...editing,
|
||||
roles: checked
|
||||
? editing.roles.filter((role) => role !== option.value)
|
||||
: [...editing.roles, option.value],
|
||||
})
|
||||
: toggleRole(option.value)
|
||||
}
|
||||
/>
|
||||
<span>
|
||||
<span className="block text-sm text-white">{option.label}</span>
|
||||
<span className="text-xs text-gray-500">{option.description}</span>
|
||||
</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void (editing ? saveEdit() : saveNew())}
|
||||
disabled={saving}
|
||||
className="mt-4 inline-flex items-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm text-white"
|
||||
>
|
||||
{saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Check className="h-4 w-4" />} 保存
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@ -1,31 +1,28 @@
|
||||
import React, { useMemo, useRef, useState } from "react";
|
||||
import { AlertCircle, CheckCircle2, FolderUp, Loader2, RefreshCw, Upload } from "lucide-react";
|
||||
import React, { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { AlertCircle, CheckCircle2, FolderUp, Loader2, Pause, Play, RefreshCw, Square, Upload } from "lucide-react";
|
||||
import type { ObjectStorageUploadSessionItem, ObjectStorageUploadSessionSummary } from "../../types";
|
||||
import { objectStorageApi, type ObjectStorageBatchConflictPolicy } from "../../services/api/object-storage";
|
||||
import {
|
||||
DIRECTORY_UPLOAD_CONCURRENCY,
|
||||
directoryUploadBatchItems,
|
||||
directoryUploadEmptyDirectories,
|
||||
directoryUploadFiles,
|
||||
findDirectoryUploadKeyOverflow,
|
||||
OBJECT_STORAGE_KEY_MAX_UTF8_BYTES,
|
||||
runDirectoryUploadTasks,
|
||||
} from "../../lib/object-storage-directory-upload.js";
|
||||
MULTIPART_CONCURRENCY,
|
||||
MULTIPART_PART_BYTES,
|
||||
objectStorageMultipartParts,
|
||||
parseObjectStorageUploadETag,
|
||||
uploadObjectStoragePresignedURL,
|
||||
} from "../../lib/object-storage-upload.js";
|
||||
import {
|
||||
directoryHandlePermission,
|
||||
filesByRelativePath,
|
||||
filesFromDirectoryHandle,
|
||||
loadUploadDirectoryHandle,
|
||||
saveUploadDirectoryHandle,
|
||||
supportsPersistentDirectoryHandle,
|
||||
uploadSessionNeedsLocalFile,
|
||||
} from "../../lib/object-storage-upload-sessions.js";
|
||||
import { getActionErrorMessage } from "../../lib/action-errors.js";
|
||||
import {
|
||||
objectStorageApi,
|
||||
type ObjectStorageBatchConflictPolicy,
|
||||
type ObjectStorageBatchUploadPreparedItem,
|
||||
} from "../../services/api/object-storage";
|
||||
|
||||
type SelectedDirectoryFile = { relativePath: string; file: File };
|
||||
type UploadState = "pending" | "uploading" | "success" | "skipped" | "conflict" | "failed";
|
||||
type UploadRecord = {
|
||||
item: ObjectStorageBatchUploadPreparedItem;
|
||||
file?: File;
|
||||
state: UploadState;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
const formatBytes = (value: number) => {
|
||||
const formatBytes = (value = 0) => {
|
||||
if (value < 1024) return `${value} B`;
|
||||
const units = ["KB", "MB", "GB", "TB"];
|
||||
let current = value / 1024;
|
||||
@ -37,6 +34,40 @@ const formatBytes = (value: number) => {
|
||||
return `${current.toFixed(current >= 10 ? 0 : 1)} ${units[unit]}`;
|
||||
};
|
||||
|
||||
const itemTone: Record<string, string> = {
|
||||
success: "text-emerald-300",
|
||||
skipped: "text-sky-300",
|
||||
failed: "text-red-300",
|
||||
cancelled: "text-gray-400",
|
||||
uploading: "text-amber-300",
|
||||
pending: "text-gray-300",
|
||||
};
|
||||
|
||||
const itemLabel: Record<string, string> = {
|
||||
success: "已上传",
|
||||
skipped: "已跳过",
|
||||
failed: "失败",
|
||||
cancelled: "已取消",
|
||||
uploading: "上传中",
|
||||
pending: "等待上传",
|
||||
};
|
||||
|
||||
function relativeFiles(fileList: FileList | null): SelectedDirectoryFile[] {
|
||||
return Array.from(fileList || [])
|
||||
.map((file) => ({
|
||||
relativePath: String(file.webkitRelativePath || file.name || "").replace(/^\/+|\/+$/g, ""),
|
||||
file,
|
||||
}))
|
||||
.filter((item) => item.relativePath && !item.relativePath.split("/").some((part) => part === "." || part === ".."))
|
||||
.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
||||
}
|
||||
|
||||
function uploadItemMatchesFile(item: ObjectStorageUploadSessionItem, file: File | undefined) {
|
||||
return (
|
||||
Boolean(file) && item.sizeBytes === file?.size && (!item.lastModified || item.lastModified === file?.lastModified)
|
||||
);
|
||||
}
|
||||
|
||||
export function DirectoryUploadPanel({
|
||||
connectionId,
|
||||
bucket,
|
||||
@ -51,167 +82,306 @@ export function DirectoryUploadPanel({
|
||||
onUploaded: () => void | Promise<void>;
|
||||
}) {
|
||||
const [selectedFiles, setSelectedFiles] = useState<SelectedDirectoryFile[]>([]);
|
||||
const [emptyDirectoriesText, setEmptyDirectoriesText] = useState("");
|
||||
const [directoryHandle, setDirectoryHandle] = useState<any>(null);
|
||||
const [conflictPolicy, setConflictPolicy] = useState<ObjectStorageBatchConflictPolicy>("overwrite");
|
||||
const [records, setRecords] = useState<UploadRecord[]>([]);
|
||||
const [summary, setSummary] = useState<ObjectStorageUploadSessionSummary | null>(null);
|
||||
const [knownSessions, setKnownSessions] = useState<ObjectStorageUploadSessionSummary[]>([]);
|
||||
const [running, setRunning] = useState(false);
|
||||
const [message, setMessage] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [progress, setProgress] = useState({ loadedBytes: 0, totalBytes: 0, completed: 0, total: 0 });
|
||||
const loadedByKeyRef = useRef(new Map<string, number>());
|
||||
const progressFrameRef = useRef<number | null>(null);
|
||||
const pendingProgressRef = useRef<{ completed?: number; total?: number; totalBytes?: number }>({});
|
||||
const [filter, setFilter] = useState("");
|
||||
const abortRef = useRef<AbortController | null>(null);
|
||||
const pausedRef = useRef(false);
|
||||
const cancelledRef = useRef(false);
|
||||
const activeBytesRef = useRef<Map<string, number>>(new Map<string, number>());
|
||||
const partWriteQueueRef = useRef<Promise<void>>(Promise.resolve());
|
||||
const [activeBytes, setActiveBytes] = useState(0);
|
||||
|
||||
const emptyDirectories = useMemo(() => directoryUploadEmptyDirectories(emptyDirectoriesText), [emptyDirectoriesText]);
|
||||
const session = summary?.session || null;
|
||||
const selectedBytes = useMemo(
|
||||
() => selectedFiles.reduce((total, item) => total + item.file.size, 0),
|
||||
[selectedFiles],
|
||||
);
|
||||
const failedCount = records.filter((record) => record.state === "failed").length;
|
||||
const successCount = records.filter((record) => record.state === "success").length;
|
||||
const skippedCount = records.filter((record) => record.state === "skipped").length;
|
||||
const conflictCount = records.filter((record) => record.state === "conflict").length;
|
||||
const percent =
|
||||
progress.totalBytes > 0
|
||||
? Math.round((progress.loadedBytes / progress.totalBytes) * 100)
|
||||
: progress.total > 0
|
||||
? Math.round((progress.completed / progress.total) * 100)
|
||||
: 0;
|
||||
const handledPercent =
|
||||
summary && summary.totalBytes > 0 ? Math.round((summary.processedBytes / summary.totalBytes) * 100) : 0;
|
||||
const networkPercent =
|
||||
summary && summary.totalBytes > 0
|
||||
? Math.round((Math.min(summary.uploadedBytes + activeBytes, summary.totalBytes) / summary.totalBytes) * 100)
|
||||
: 0;
|
||||
const filteredItems = useMemo(() => {
|
||||
const query = filter.trim().toLowerCase();
|
||||
return (session?.items || []).filter(
|
||||
(item) => !query || `${item.relativePath} ${item.key} ${item.status}`.toLowerCase().includes(query),
|
||||
);
|
||||
}, [filter, session?.items]);
|
||||
|
||||
const flushProgress = (completed?: number, total?: number, totalBytes?: number) => {
|
||||
pendingProgressRef.current = {
|
||||
completed: completed ?? pendingProgressRef.current.completed,
|
||||
total: total ?? pendingProgressRef.current.total,
|
||||
totalBytes: totalBytes ?? pendingProgressRef.current.totalBytes,
|
||||
};
|
||||
if (progressFrameRef.current !== null) return;
|
||||
progressFrameRef.current = window.requestAnimationFrame(() => {
|
||||
progressFrameRef.current = null;
|
||||
const pending = pendingProgressRef.current;
|
||||
pendingProgressRef.current = {};
|
||||
const loadedBytes = (Array.from(loadedByKeyRef.current.values()) as number[]).reduce<number>(
|
||||
(sum, value) => sum + value,
|
||||
0,
|
||||
const refreshSessions = async (preferredSessionId = "") => {
|
||||
if (!connectionId || !bucket) return;
|
||||
try {
|
||||
const sessions = await objectStorageApi.listUploadSessions();
|
||||
const relevant = sessions.filter(
|
||||
(item) =>
|
||||
item.session.connectionId === connectionId &&
|
||||
item.session.bucket === bucket &&
|
||||
(item.session.prefix || "") === (prefix || ""),
|
||||
);
|
||||
setProgress((current) => ({
|
||||
loadedBytes,
|
||||
totalBytes: pending.totalBytes ?? current.totalBytes,
|
||||
completed: pending.completed ?? current.completed,
|
||||
total: pending.total ?? current.total,
|
||||
}));
|
||||
});
|
||||
setKnownSessions(relevant);
|
||||
const preferred =
|
||||
relevant.find((item) => item.session.id === preferredSessionId) ||
|
||||
relevant.find((item) => ["prepared", "running", "paused", "failed"].includes(item.session.status));
|
||||
if (preferred) setSummary(preferred);
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "加载可恢复上传会话失败"));
|
||||
}
|
||||
};
|
||||
|
||||
const executeRecords = async (initialRecords: UploadRecord[]) => {
|
||||
const runnable = initialRecords.filter((record) => record.state === "pending" || record.state === "failed");
|
||||
if (runnable.length === 0) return;
|
||||
useEffect(() => {
|
||||
void refreshSessions();
|
||||
}, [connectionId, bucket, prefix]);
|
||||
|
||||
const setProgress = (itemId: string, value: number) => {
|
||||
activeBytesRef.current.set(itemId, value);
|
||||
setActiveBytes(
|
||||
(Array.from(activeBytesRef.current.values()) as number[]).reduce((total, bytes) => total + bytes, 0),
|
||||
);
|
||||
};
|
||||
|
||||
const resolveFiles = async (target: ObjectStorageUploadSessionSummary): Promise<Map<string, File>> => {
|
||||
if (selectedFiles.length > 0) return filesByRelativePath(selectedFiles);
|
||||
const storedHandle = directoryHandle || (await loadUploadDirectoryHandle(target.session.id));
|
||||
if (!storedHandle) throw new Error("请重新选择原目录后继续上传。Chrome/Edge 会在授权后恢复未完成分片。");
|
||||
const permission = await directoryHandlePermission(storedHandle, true);
|
||||
if (permission !== "granted") throw new Error("未授予原目录读取权限,无法恢复上传。");
|
||||
const restored = await filesFromDirectoryHandle(storedHandle);
|
||||
setDirectoryHandle(storedHandle);
|
||||
setSelectedFiles(restored);
|
||||
return filesByRelativePath(restored);
|
||||
};
|
||||
|
||||
const exportItems = () => {
|
||||
if (!session) return;
|
||||
const rows = [
|
||||
["relativePath", "key", "status", "sizeBytes", "uploadedBytes", "eTag", "error"],
|
||||
...session.items.map((item) => [
|
||||
item.relativePath,
|
||||
item.key,
|
||||
item.status,
|
||||
String(item.sizeBytes),
|
||||
String(item.uploadedBytes || 0),
|
||||
item.eTag || "",
|
||||
item.error || "",
|
||||
]),
|
||||
];
|
||||
const blob = new Blob(
|
||||
[rows.map((row) => row.map((value) => `"${String(value).replaceAll('"', '""')}"`).join(",")).join("\n")],
|
||||
{ type: "text/csv;charset=utf-8" },
|
||||
);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = url;
|
||||
anchor.download = `upload-session-${session.id}.csv`;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const processItem = async (
|
||||
current: ObjectStorageUploadSessionSummary,
|
||||
item: ObjectStorageUploadSessionItem,
|
||||
files: Map<string, File>,
|
||||
) => {
|
||||
if (!uploadSessionNeedsLocalFile(item)) {
|
||||
if (item.kind === "directory" && item.status === "pending") {
|
||||
const result = await objectStorageApi.startUploadSessionItem(current.session.id, item.id);
|
||||
setSummary(result.session);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const file = files.get(item.relativePath);
|
||||
if (!uploadItemMatchesFile(item, file))
|
||||
throw new Error(`本地文件不匹配:${item.relativePath}。请重新选择同一目录。`);
|
||||
const started = await objectStorageApi.startUploadSessionItem(current.session.id, item.id);
|
||||
setSummary(started.session);
|
||||
const signal = abortRef.current?.signal;
|
||||
if (started.mode === "direct") {
|
||||
if (!started.upload) throw new Error("服务端没有返回直传地址。");
|
||||
const response = await uploadObjectStoragePresignedURL(
|
||||
started.upload.url,
|
||||
file,
|
||||
started.upload.headers,
|
||||
(loadedBytes) => setProgress(item.id, loadedBytes),
|
||||
undefined,
|
||||
signal,
|
||||
);
|
||||
if (!parseObjectStorageUploadETag(response.headers.get("ETag")))
|
||||
throw new Error(`对象存储未返回 ETag:${item.relativePath}`);
|
||||
activeBytesRef.current.delete(item.id);
|
||||
setActiveBytes(
|
||||
(Array.from(activeBytesRef.current.values()) as number[]).reduce((total, bytes) => total + bytes, 0),
|
||||
);
|
||||
const completed = await objectStorageApi.completeUploadSessionItem(current.session.id, item.id);
|
||||
setSummary(completed);
|
||||
return;
|
||||
}
|
||||
const latestItem = started.session.session.items.find((candidate) => candidate.id === item.id) || item;
|
||||
const completedPartNumbers = new Set((latestItem.uploadedParts || []).map((part) => part.partNumber));
|
||||
const parts = objectStorageMultipartParts(file.size, MULTIPART_PART_BYTES).filter(
|
||||
(part) => !completedPartNumbers.has(part.partNumber),
|
||||
);
|
||||
let committedBytes = latestItem.uploadedBytes || 0;
|
||||
const persistPart = async (partNumber: number, eTag: string, partSize: number) => {
|
||||
const write = partWriteQueueRef.current.then(async () => {
|
||||
committedBytes = Math.min(file.size, committedBytes + partSize);
|
||||
const partSummary = await objectStorageApi.completeUploadSessionPart(
|
||||
current.session.id,
|
||||
item.id,
|
||||
partNumber,
|
||||
eTag,
|
||||
committedBytes,
|
||||
);
|
||||
setSummary(partSummary);
|
||||
});
|
||||
partWriteQueueRef.current = write.catch(() => undefined);
|
||||
await write;
|
||||
};
|
||||
let next = 0;
|
||||
const workers = Array.from({ length: Math.min(MULTIPART_CONCURRENCY, parts.length || 1) }, async () => {
|
||||
while (next < parts.length) {
|
||||
const part = parts[next++];
|
||||
const url = await objectStorageApi.uploadSessionPartURL(current.session.id, item.id, part.partNumber);
|
||||
const partSize = part.end - part.start;
|
||||
const response = await uploadObjectStoragePresignedURL(
|
||||
url.url,
|
||||
file.slice(part.start, part.end),
|
||||
url.headers,
|
||||
(loadedBytes) => setProgress(`${item.id}:${part.partNumber}`, loadedBytes),
|
||||
undefined,
|
||||
signal,
|
||||
);
|
||||
const eTag = parseObjectStorageUploadETag(response.headers.get("ETag"));
|
||||
if (!eTag) throw new Error(`对象存储未返回分片 ETag:${item.relativePath} #${part.partNumber}`);
|
||||
activeBytesRef.current.delete(`${item.id}:${part.partNumber}`);
|
||||
setActiveBytes(
|
||||
(Array.from(activeBytesRef.current.values()) as number[]).reduce((total, bytes) => total + bytes, 0),
|
||||
);
|
||||
await persistPart(part.partNumber, eTag, partSize);
|
||||
}
|
||||
});
|
||||
await Promise.all(workers);
|
||||
const completed = await objectStorageApi.completeUploadSessionItem(current.session.id, item.id);
|
||||
setSummary(completed);
|
||||
};
|
||||
|
||||
const runSession = async (target: ObjectStorageUploadSessionSummary) => {
|
||||
setRunning(true);
|
||||
setError("");
|
||||
setMessage("");
|
||||
loadedByKeyRef.current = new Map();
|
||||
const totalBytes = runnable.reduce(
|
||||
(total, record) => total + (record.item.action === "upload" ? record.file?.size || 0 : 0),
|
||||
0,
|
||||
);
|
||||
let completed = 0;
|
||||
setProgress({ loadedBytes: 0, totalBytes, completed: 0, total: runnable.length });
|
||||
const currentRecords = records.length > 0 ? [...records] : [...initialRecords];
|
||||
const updateRecord = (key: string, update: Partial<UploadRecord>) => {
|
||||
const index = currentRecords.findIndex((record) => record.item.key === key);
|
||||
if (index >= 0) currentRecords[index] = { ...currentRecords[index], ...update };
|
||||
setRecords([...currentRecords]);
|
||||
};
|
||||
await runDirectoryUploadTasks(
|
||||
runnable,
|
||||
async (record) => {
|
||||
updateRecord(record.item.key, { state: "uploading", error: undefined });
|
||||
if (record.item.action === "create_placeholder") {
|
||||
await objectStorageApi.putObject(
|
||||
{ bucket, key: record.item.key, content: "", contentType: "application/x-directory" },
|
||||
{ connectionId },
|
||||
);
|
||||
} else {
|
||||
if (!record.file) throw new Error("未找到该条目的本地文件,请重新选择目录。");
|
||||
await objectStorageApi.uploadObject(
|
||||
record.file,
|
||||
{ connectionId, bucket, key: record.item.key, contentType: record.item.contentType },
|
||||
(uploadProgress) => {
|
||||
loadedByKeyRef.current.set(record.item.key, uploadProgress.loadedBytes);
|
||||
flushProgress(undefined, undefined, totalBytes);
|
||||
},
|
||||
);
|
||||
loadedByKeyRef.current.set(record.item.key, record.file.size);
|
||||
}
|
||||
return record.item.key;
|
||||
},
|
||||
{
|
||||
concurrency: DIRECTORY_UPLOAD_CONCURRENCY,
|
||||
onSettled: (result, record) => {
|
||||
completed += 1;
|
||||
if (result.status === "fulfilled") {
|
||||
updateRecord(record.item.key, { state: "success", error: undefined });
|
||||
} else {
|
||||
updateRecord(record.item.key, { state: "failed", error: getActionErrorMessage(result.reason) });
|
||||
}
|
||||
flushProgress(completed, runnable.length, totalBytes);
|
||||
},
|
||||
},
|
||||
);
|
||||
const finalFailed = currentRecords.filter((record) => record.state === "failed").length;
|
||||
setRunning(false);
|
||||
if (finalFailed > 0) {
|
||||
setError(`${finalFailed} 个条目上传失败,可仅重试失败项。`);
|
||||
} else {
|
||||
setMessage("目录上传完成。");
|
||||
await onUploaded();
|
||||
}
|
||||
};
|
||||
|
||||
const prepareAndUpload = async () => {
|
||||
const batchItems = directoryUploadBatchItems(selectedFiles, emptyDirectories);
|
||||
if (batchItems.length === 0) {
|
||||
setError("请先选择一个目录,或填写需要保留的空目录。");
|
||||
return;
|
||||
}
|
||||
const oversizedKey = findDirectoryUploadKeyOverflow(batchItems, prefix);
|
||||
if (oversizedKey) {
|
||||
setError(
|
||||
`路径过长:${oversizedKey.relativePath}。最终对象键为 ${oversizedKey.bytes} 个 UTF-8 字节,BOS 最多允许 ${OBJECT_STORAGE_KEY_MAX_UTF8_BYTES} 字节。请缩短目录层级、目录名、文件名或目标路径。`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
setRunning(true);
|
||||
setError("");
|
||||
setMessage("正在检查路径和冲突…");
|
||||
pausedRef.current = false;
|
||||
cancelledRef.current = false;
|
||||
abortRef.current = new AbortController();
|
||||
try {
|
||||
const plan = await objectStorageApi.prepareBatchUpload(
|
||||
{ bucket, prefix, conflictPolicy, items: batchItems },
|
||||
{ connectionId },
|
||||
);
|
||||
const filesByPath = new Map<string, File>(selectedFiles.map((item) => [item.relativePath, item.file] as const));
|
||||
const nextRecords: UploadRecord[] = plan.items.map((item) => ({
|
||||
item,
|
||||
file: filesByPath.get(item.relativePath),
|
||||
state: item.action === "skip" ? "skipped" : item.action === "conflict" ? "conflict" : "pending",
|
||||
}));
|
||||
setRecords(nextRecords);
|
||||
if (plan.conflictCount > 0) {
|
||||
setMessage("");
|
||||
setError(`检测到 ${plan.conflictCount} 个冲突。请选择“跳过”或“覆盖”后重新上传。`);
|
||||
return;
|
||||
let current = target;
|
||||
if (["prepared", "paused", "failed"].includes(current.session.status)) {
|
||||
current = await objectStorageApi.resumeUploadSession(current.session.id);
|
||||
setSummary(current);
|
||||
}
|
||||
const files = await resolveFiles(current);
|
||||
for (const item of current.session.items) {
|
||||
if (pausedRef.current || cancelledRef.current) break;
|
||||
try {
|
||||
await processItem(current, item, files);
|
||||
current = await objectStorageApi.getUploadSession(current.session.id);
|
||||
setSummary(current);
|
||||
} catch (cause) {
|
||||
if (pausedRef.current || cancelledRef.current) break;
|
||||
const failed = await objectStorageApi.failUploadSessionItem(
|
||||
current.session.id,
|
||||
item.id,
|
||||
getActionErrorMessage(cause),
|
||||
);
|
||||
current = failed;
|
||||
setSummary(failed);
|
||||
}
|
||||
}
|
||||
const final = await objectStorageApi.getUploadSession(current.session.id);
|
||||
setSummary(final);
|
||||
await refreshSessions(final.session.id);
|
||||
if (final.session.status === "completed") {
|
||||
setMessage("目录上传完成,成功与跳过的文件均已记录。");
|
||||
await onUploaded();
|
||||
} else if (final.failedCount > 0) {
|
||||
setError(`${final.failedCount} 个文件失败,可重新选择目录后继续未完成项。`);
|
||||
}
|
||||
setMessage("");
|
||||
await executeRecords(nextRecords);
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause));
|
||||
if (!pausedRef.current && !cancelledRef.current) setError(getActionErrorMessage(cause, "恢复上传失败"));
|
||||
} finally {
|
||||
activeBytesRef.current.clear();
|
||||
setActiveBytes(0);
|
||||
abortRef.current = null;
|
||||
setRunning(false);
|
||||
}
|
||||
};
|
||||
|
||||
const visibleRecords = records
|
||||
.filter((record) => record.state === "failed" || record.state === "conflict")
|
||||
.slice(0, 50);
|
||||
const createAndRun = async () => {
|
||||
if (!selectedFiles.length) {
|
||||
setError("请先选择需要上传的目录。");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const created = await objectStorageApi.createUploadSession(
|
||||
{
|
||||
bucket,
|
||||
prefix,
|
||||
conflictPolicy,
|
||||
items: selectedFiles.map((item) => ({
|
||||
relativePath: item.relativePath,
|
||||
kind: "file",
|
||||
sizeBytes: item.file.size,
|
||||
contentType: item.file.type,
|
||||
lastModified: item.file.lastModified,
|
||||
})),
|
||||
},
|
||||
{ connectionId },
|
||||
);
|
||||
if (directoryHandle && supportsPersistentDirectoryHandle())
|
||||
await saveUploadDirectoryHandle(created.session.id, directoryHandle);
|
||||
setSummary(created);
|
||||
await refreshSessions(created.session.id);
|
||||
await runSession(created);
|
||||
} catch (cause) {
|
||||
setError(getActionErrorMessage(cause, "创建上传会话失败"));
|
||||
}
|
||||
};
|
||||
|
||||
const choosePersistentDirectory = async () => {
|
||||
try {
|
||||
const handle = await (window as any).showDirectoryPicker({ mode: "read" });
|
||||
const files = await filesFromDirectoryHandle(handle);
|
||||
setDirectoryHandle(handle);
|
||||
setSelectedFiles(files);
|
||||
setError("");
|
||||
setMessage("已选择可恢复目录;刷新页面后可授权继续未完成上传。");
|
||||
} catch (cause) {
|
||||
if ((cause as Error)?.name !== "AbortError") setError(getActionErrorMessage(cause, "选择目录失败"));
|
||||
}
|
||||
};
|
||||
|
||||
const pause = async () => {
|
||||
if (!session) return;
|
||||
pausedRef.current = true;
|
||||
abortRef.current?.abort();
|
||||
const paused = await objectStorageApi.pauseUploadSession(session.id);
|
||||
setSummary(paused);
|
||||
setMessage("已暂停。已完成的分片会被保留,继续时只传未完成分片。");
|
||||
};
|
||||
|
||||
const cancel = async () => {
|
||||
if (!session) return;
|
||||
cancelledRef.current = true;
|
||||
abortRef.current?.abort();
|
||||
const cancelled = await objectStorageApi.cancelUploadSession(session.id);
|
||||
setSummary(cancelled);
|
||||
setMessage("已取消未完成上传;已成功写入的对象会保留。");
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
@ -222,17 +392,18 @@ export function DirectoryUploadPanel({
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-white">
|
||||
<FolderUp className="h-4 w-4 text-blue-400" />
|
||||
上传目录
|
||||
可恢复目录上传
|
||||
</div>
|
||||
<p className="mt-1 text-xs leading-5 text-gray-500">
|
||||
保留 webkitRelativePath,4 个文件并发;大文件自动复用分片上传。纯空目录请在下方补充,将写入 .keep。
|
||||
上传目标:
|
||||
<span className="font-mono text-gray-300">
|
||||
{bucket}/{prefix || ""}
|
||||
</span>
|
||||
。成功、跳过和失败都会保留明细;Chrome/Edge 可在刷新后恢复。
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right text-xs text-gray-500">
|
||||
<div>
|
||||
{selectedFiles.length} 个文件 · {formatBytes(selectedBytes)}
|
||||
</div>
|
||||
{emptyDirectories.length > 0 && <div>{emptyDirectories.length} 个空目录</div>}
|
||||
{selectedFiles.length} 个文件 · {formatBytes(selectedBytes)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -245,26 +416,25 @@ export function DirectoryUploadPanel({
|
||||
multiple
|
||||
{...({ webkitdirectory: "", directory: "" } as React.InputHTMLAttributes<HTMLInputElement>)}
|
||||
onChange={(event) => {
|
||||
setSelectedFiles(directoryUploadFiles(event.target.files) as SelectedDirectoryFile[]);
|
||||
setRecords([]);
|
||||
setDirectoryHandle(null);
|
||||
setSelectedFiles(relativeFiles(event.target.files));
|
||||
setError("");
|
||||
setMessage("");
|
||||
}}
|
||||
disabled={disabled || running}
|
||||
className="block w-full rounded-xl border border-[#2a2b2f] bg-[#0b0c10] px-3 py-[10px] text-sm text-gray-300 file:mr-3 file:rounded-md file:border-0 file:bg-blue-600 file:px-3 file:py-1.5 file:text-xs file:text-white"
|
||||
/>
|
||||
</label>
|
||||
<label className="space-y-2">
|
||||
<span className="block text-xs uppercase tracking-[0.2em] text-gray-500">额外空目录</span>
|
||||
<textarea
|
||||
data-testid="directory-upload-empty-directories"
|
||||
value={emptyDirectoriesText}
|
||||
onChange={(event) => setEmptyDirectoriesText(event.target.value)}
|
||||
disabled={disabled || running}
|
||||
rows={2}
|
||||
className="w-full rounded-xl border border-[#2a2b2f] bg-[#0b0c10] px-3 py-2 text-xs text-white focus:border-blue-500 focus:outline-none"
|
||||
placeholder={"每行一个相对路径\n例如 dataset/labels-empty"}
|
||||
/>
|
||||
{supportsPersistentDirectoryHandle() ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void choosePersistentDirectory()}
|
||||
disabled={disabled || running}
|
||||
className="text-xs text-blue-300 hover:text-blue-200"
|
||||
>
|
||||
选择可恢复目录(Chrome/Edge)
|
||||
</button>
|
||||
) : (
|
||||
<div className="text-[11px] text-gray-600">当前浏览器刷新后需要重新选择目录。</div>
|
||||
)}
|
||||
</label>
|
||||
<label className="space-y-2">
|
||||
<span className="block text-xs uppercase tracking-[0.2em] text-gray-500">同名冲突</span>
|
||||
@ -273,75 +443,164 @@ export function DirectoryUploadPanel({
|
||||
value={conflictPolicy}
|
||||
onChange={(event) => setConflictPolicy(event.target.value as ObjectStorageBatchConflictPolicy)}
|
||||
disabled={disabled || running}
|
||||
className="w-full rounded-xl border border-[#2a2b2f] bg-[#0b0c10] px-3 py-3 text-sm text-white focus:border-blue-500 focus:outline-none"
|
||||
className="w-full rounded-xl border border-[#2a2b2f] bg-[#0b0c10] px-3 py-3 text-sm text-white"
|
||||
>
|
||||
<option value="overwrite">覆盖已有对象</option>
|
||||
<option value="skip">跳过已有对象</option>
|
||||
<option value="error">发现冲突即停止</option>
|
||||
</select>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="directory-upload-button"
|
||||
onClick={prepareAndUpload}
|
||||
disabled={disabled || running || (!selectedFiles.length && !emptyDirectories.length)}
|
||||
className="inline-flex items-center justify-center gap-2 rounded-xl bg-blue-600 px-4 py-3 text-sm font-medium text-white hover:bg-blue-500 disabled:opacity-60 lg:self-end"
|
||||
>
|
||||
{running ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />}
|
||||
{running ? "上传中" : "上传目录"}
|
||||
</button>
|
||||
<label className="space-y-2">
|
||||
<span className="block text-xs uppercase tracking-[0.2em] text-gray-500">文件明细</span>
|
||||
<input
|
||||
value={filter}
|
||||
onChange={(event) => setFilter(event.target.value)}
|
||||
placeholder="搜索文件"
|
||||
className="w-full rounded-xl border border-[#2a2b2f] bg-[#0b0c10] px-3 py-3 text-sm text-white"
|
||||
/>
|
||||
</label>
|
||||
<div className="flex items-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
data-testid="directory-upload-button"
|
||||
onClick={() => void createAndRun()}
|
||||
disabled={disabled || running || !selectedFiles.length}
|
||||
className="inline-flex flex-1 items-center justify-center gap-2 rounded-xl bg-blue-600 px-4 py-3 text-sm font-medium text-white hover:bg-blue-500 disabled:opacity-60"
|
||||
>
|
||||
{running ? <Loader2 className="h-4 w-4 animate-spin" /> : <Upload className="h-4 w-4" />}
|
||||
{running ? "上传中" : "开始上传"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(progress.total > 0 || running) && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-gray-400">
|
||||
<span>
|
||||
总体进度 {progress.completed}/{progress.total}
|
||||
{session ? (
|
||||
<div
|
||||
className="space-y-3 rounded-xl border border-[#2a2b2f] bg-[#0b0c10] p-3"
|
||||
data-testid="directory-upload-session"
|
||||
>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs">
|
||||
<span className="text-gray-300">
|
||||
会话 {session.id} · {session.status}
|
||||
</span>
|
||||
<span>
|
||||
{formatBytes(progress.loadedBytes)} / {formatBytes(progress.totalBytes)} · {percent}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-2 overflow-hidden rounded-full bg-[#202126]">
|
||||
<div className="h-full bg-blue-500 transition-all" style={{ width: `${percent}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(message || error || records.length > 0) && (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-xl border border-[#2a2b2f] bg-[#0b0c10] px-3 py-2 text-xs">
|
||||
<div className="flex items-center gap-2">
|
||||
{error ? (
|
||||
<AlertCircle className="h-4 w-4 text-red-400" />
|
||||
) : (
|
||||
<CheckCircle2 className="h-4 w-4 text-emerald-400" />
|
||||
)}
|
||||
<span className={error ? "text-red-200" : "text-gray-300"}>
|
||||
{error || message || `成功 ${successCount} · 跳过 ${skippedCount} · 冲突 ${conflictCount}`}
|
||||
</span>
|
||||
</div>
|
||||
{failedCount > 0 && !running && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => executeRecords(records)}
|
||||
className="inline-flex items-center gap-1 rounded-lg border border-red-500/30 px-2 py-1 text-red-200 hover:bg-red-500/10"
|
||||
>
|
||||
<RefreshCw className="h-3.5 w-3.5" /> 仅重试失败项
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{visibleRecords.length > 0 && (
|
||||
<div className="max-h-40 space-y-1 overflow-auto text-xs text-red-200">
|
||||
{visibleRecords.map((record) => (
|
||||
<div key={record.item.key} className="rounded-lg bg-red-500/5 px-3 py-2">
|
||||
<div className="font-mono">{record.item.key}</div>
|
||||
<div className="mt-1 text-red-300/80">{record.error || record.item.message || "目标对象冲突"}</div>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void runSession(summary!)}
|
||||
disabled={running || !["prepared", "paused", "failed"].includes(session.status)}
|
||||
className="inline-flex items-center gap-1 rounded-lg border border-blue-500/30 px-2 py-1 text-blue-200 disabled:opacity-40"
|
||||
>
|
||||
<Play className="h-3.5 w-3.5" />
|
||||
继续
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void pause()}
|
||||
disabled={!running && session.status !== "running"}
|
||||
className="inline-flex items-center gap-1 rounded-lg border border-amber-500/30 px-2 py-1 text-amber-200 disabled:opacity-40"
|
||||
>
|
||||
<Pause className="h-3.5 w-3.5" />
|
||||
暂停
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void cancel()}
|
||||
disabled={session.status === "completed" || session.status === "cancelled"}
|
||||
className="inline-flex items-center gap-1 rounded-lg border border-red-500/30 px-2 py-1 text-red-200"
|
||||
>
|
||||
<Square className="h-3.5 w-3.5" />
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={exportItems}
|
||||
className="rounded-lg border border-[#2a2b2f] px-2 py-1 text-gray-300"
|
||||
>
|
||||
导出 CSV
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid gap-2 md:grid-cols-2">
|
||||
<div>
|
||||
<div className="flex justify-between text-xs text-gray-400">
|
||||
<span>处理进度(成功 + 跳过)</span>
|
||||
<span>
|
||||
{formatBytes(summary.processedBytes)} / {formatBytes(summary.totalBytes)} · {handledPercent}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1 h-2 overflow-hidden rounded-full bg-[#202126]">
|
||||
<div className="h-full bg-emerald-500 transition-all" style={{ width: `${handledPercent}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex justify-between text-xs text-gray-400">
|
||||
<span>实际上传流量</span>
|
||||
<span>
|
||||
{formatBytes(summary.uploadedBytes + activeBytes)} / {formatBytes(summary.totalBytes)} ·{" "}
|
||||
{networkPercent}%
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-1 h-2 overflow-hidden rounded-full bg-[#202126]">
|
||||
<div className="h-full bg-blue-500 transition-all" style={{ width: `${networkPercent}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-xs text-gray-400">
|
||||
成功 {summary.successCount} · 跳过 {summary.skippedCount} · 失败 {summary.failedCount} · 待处理{" "}
|
||||
{summary.pendingCount}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
) : null}
|
||||
|
||||
{message || error ? (
|
||||
<div
|
||||
className={`flex items-center gap-2 rounded-xl border px-3 py-2 text-xs ${error ? "border-red-500/30 bg-red-500/10 text-red-200" : "border-emerald-500/30 bg-emerald-500/10 text-emerald-100"}`}
|
||||
>
|
||||
{error ? <AlertCircle className="h-4 w-4" /> : <CheckCircle2 className="h-4 w-4" />}
|
||||
{error || message}
|
||||
</div>
|
||||
) : null}
|
||||
{knownSessions.length > 1 ? (
|
||||
<div className="flex flex-wrap gap-2 text-xs text-gray-500">
|
||||
其它可恢复会话:
|
||||
{knownSessions
|
||||
.filter((item) => item.session.id !== session?.id)
|
||||
.map((item) => (
|
||||
<button
|
||||
key={item.session.id}
|
||||
type="button"
|
||||
onClick={() => setSummary(item)}
|
||||
className="rounded border border-[#2a2b2f] px-2 py-1 hover:text-white"
|
||||
>
|
||||
{item.session.status} · {item.session.id.slice(-8)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{session ? (
|
||||
<div className="max-h-64 overflow-auto rounded-xl border border-[#202126] bg-black/10">
|
||||
<div className="divide-y divide-[#202126]">
|
||||
{filteredItems.map((item) => (
|
||||
<div key={item.id} className="flex items-center justify-between gap-3 px-3 py-2 text-xs">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-gray-200" title={item.key}>
|
||||
{item.relativePath}
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-[10px] text-gray-600">{item.key}</div>
|
||||
{item.error ? <div className="mt-1 text-red-300">{item.error}</div> : null}
|
||||
</div>
|
||||
<div className="shrink-0 text-right">
|
||||
<div className={itemTone[item.status] || "text-gray-300"}>
|
||||
{itemLabel[item.status] || item.status}
|
||||
</div>
|
||||
<div className="mt-0.5 text-gray-600">
|
||||
{formatBytes(item.uploadedBytes || 0)} / {formatBytes(item.sizeBytes)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState, ReactNode } from "react";
|
||||
import { authApi } from "../services/api/auth";
|
||||
import { isOrganizationAdminRole } from "../lib/user-roles";
|
||||
import { usersApi } from "../services/api/users";
|
||||
import type { Organization, User, UserRole } from "../types";
|
||||
|
||||
@ -68,7 +69,7 @@ export function UserProvider({ children }: { children: ReactNode }) {
|
||||
try {
|
||||
const session = await authApi.me();
|
||||
setOrganization(session.organization);
|
||||
if (session.user.role === "admin" && !session.user.isSuperAdmin) {
|
||||
if (isOrganizationAdminRole(session.user.role) && !session.user.isSuperAdmin) {
|
||||
const adminVisibleUsers = await usersApi.list();
|
||||
const resolvedCurrentUser = resolveCurrentUser(adminVisibleUsers, session.user.id) || session.user;
|
||||
setUsers(adminVisibleUsers);
|
||||
|
||||
88
src/lib/object-storage-upload-sessions.js
Normal file
88
src/lib/object-storage-upload-sessions.js
Normal file
@ -0,0 +1,88 @@
|
||||
const DB_NAME = "droboticflow-upload-sessions";
|
||||
const DB_VERSION = 1;
|
||||
const STORE_NAME = "directory-handles";
|
||||
|
||||
function openDatabase() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
||||
request.onerror = () => reject(request.error || new Error("无法打开本地上传恢复存储"));
|
||||
request.onupgradeneeded = () => request.result.createObjectStore(STORE_NAME);
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
});
|
||||
}
|
||||
|
||||
export function supportsPersistentDirectoryHandle() {
|
||||
return (
|
||||
typeof window !== "undefined" &&
|
||||
typeof window.showDirectoryPicker === "function" &&
|
||||
typeof indexedDB !== "undefined"
|
||||
);
|
||||
}
|
||||
|
||||
export async function saveUploadDirectoryHandle(sessionId, handle) {
|
||||
const database = await openDatabase();
|
||||
await new Promise((resolve, reject) => {
|
||||
const transaction = database.transaction(STORE_NAME, "readwrite");
|
||||
transaction.objectStore(STORE_NAME).put(handle, String(sessionId));
|
||||
transaction.oncomplete = resolve;
|
||||
transaction.onerror = () => reject(transaction.error || new Error("保存目录访问授权失败"));
|
||||
});
|
||||
database.close();
|
||||
}
|
||||
|
||||
export async function loadUploadDirectoryHandle(sessionId) {
|
||||
const database = await openDatabase();
|
||||
const result = await new Promise((resolve, reject) => {
|
||||
const request = database.transaction(STORE_NAME, "readonly").objectStore(STORE_NAME).get(String(sessionId));
|
||||
request.onsuccess = () => resolve(request.result || null);
|
||||
request.onerror = () => reject(request.error || new Error("读取目录访问授权失败"));
|
||||
});
|
||||
database.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function clearUploadDirectoryHandle(sessionId) {
|
||||
const database = await openDatabase();
|
||||
await new Promise((resolve, reject) => {
|
||||
const transaction = database.transaction(STORE_NAME, "readwrite");
|
||||
transaction.objectStore(STORE_NAME).delete(String(sessionId));
|
||||
transaction.oncomplete = resolve;
|
||||
transaction.onerror = () => reject(transaction.error || new Error("清理目录访问授权失败"));
|
||||
});
|
||||
database.close();
|
||||
}
|
||||
|
||||
export async function directoryHandlePermission(handle, request = false) {
|
||||
if (!handle?.queryPermission) return "denied";
|
||||
const options = { mode: "read" };
|
||||
let permission = await handle.queryPermission(options);
|
||||
if (permission !== "granted" && request && handle.requestPermission)
|
||||
permission = await handle.requestPermission(options);
|
||||
return permission;
|
||||
}
|
||||
|
||||
export async function filesFromDirectoryHandle(handle) {
|
||||
const items = [];
|
||||
async function walk(current, prefix = "") {
|
||||
for await (const [name, child] of current.entries()) {
|
||||
const relativePath = prefix ? `${prefix}/${name}` : name;
|
||||
if (child.kind === "directory") await walk(child, relativePath);
|
||||
else {
|
||||
const file = await child.getFile();
|
||||
items.push({ relativePath, file });
|
||||
}
|
||||
}
|
||||
}
|
||||
await walk(handle);
|
||||
return items.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
||||
}
|
||||
|
||||
export function filesByRelativePath(items) {
|
||||
return new Map((items || []).map((item) => [item.relativePath, item.file]));
|
||||
}
|
||||
|
||||
export function uploadSessionNeedsLocalFile(item) {
|
||||
return (
|
||||
item?.kind === "file" && ["pending", "uploading", "failed"].includes(item?.status) && item?.action === "upload"
|
||||
);
|
||||
}
|
||||
@ -52,9 +52,22 @@ function objectStorageUploadNetworkError(url) {
|
||||
* @param {(() => XMLHttpRequest) | undefined} createRequest
|
||||
* @returns {Promise<{status: number, headers: {get(name: string): string | null}}>}
|
||||
*/
|
||||
export function uploadObjectStoragePresignedURL(url, body, headers, onProgress, createRequest = undefined) {
|
||||
export function uploadObjectStoragePresignedURL(
|
||||
url,
|
||||
body,
|
||||
headers,
|
||||
onProgress,
|
||||
createRequest = undefined,
|
||||
signal = undefined,
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = createRequest ? createRequest() : new XMLHttpRequest();
|
||||
const abort = () => request.abort();
|
||||
if (signal?.aborted) {
|
||||
reject(new Error("对象存储直传已取消。"));
|
||||
return;
|
||||
}
|
||||
signal?.addEventListener?.("abort", abort, { once: true });
|
||||
request.open("PUT", url, true);
|
||||
request.withCredentials = false;
|
||||
|
||||
@ -70,6 +83,7 @@ export function uploadObjectStoragePresignedURL(url, body, headers, onProgress,
|
||||
onProgress?.(Math.min(event.loaded, totalBytes), totalBytes);
|
||||
};
|
||||
request.onload = () => {
|
||||
signal?.removeEventListener?.("abort", abort);
|
||||
if (request.status >= 200 && request.status < 300) {
|
||||
resolve({
|
||||
status: request.status,
|
||||
@ -83,7 +97,10 @@ export function uploadObjectStoragePresignedURL(url, body, headers, onProgress,
|
||||
reject(new Error(responseText || `Object storage upload failed: ${request.status}`));
|
||||
};
|
||||
request.onerror = () => reject(objectStorageUploadNetworkError(url));
|
||||
request.onabort = () => reject(new Error("对象存储直传已取消。"));
|
||||
request.onabort = () => {
|
||||
signal?.removeEventListener?.("abort", abort);
|
||||
reject(new Error("对象存储直传已取消。"));
|
||||
};
|
||||
request.ontimeout = () => reject(new Error("对象存储直传超时,请重试。"));
|
||||
request.send(body);
|
||||
});
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export function resolvePluginNavigationRole(role) {
|
||||
if (role === "organization_admin") return "admin";
|
||||
if (role === "data_operator") return "annotator";
|
||||
if (role === "acceptance_reviewer") return "acceptance_reviewer";
|
||||
if (role === "qa_reviewer" || role === "auditor" || role === "compliance_auditor") {
|
||||
|
||||
@ -7,8 +7,18 @@ export const USER_ROLE_OPTIONS: Array<{
|
||||
}> = [
|
||||
{
|
||||
value: "admin",
|
||||
label: "平台管理员",
|
||||
description: "账号、系统配置、数据库、对象存储与全局治理",
|
||||
label: "组织管理员(兼容)",
|
||||
description: "旧账号类型;会迁移为组织管理员",
|
||||
},
|
||||
{
|
||||
value: "organization_admin",
|
||||
label: "组织管理员",
|
||||
description: "管理本组织的项目、用户、配置与数据治理",
|
||||
},
|
||||
{
|
||||
value: "member",
|
||||
label: "普通成员",
|
||||
description: "通过项目成员角色领取标注、审核或最终验收任务",
|
||||
},
|
||||
{
|
||||
value: "cutter",
|
||||
@ -37,6 +47,10 @@ export const USER_ROLE_OPTIONS: Array<{
|
||||
},
|
||||
];
|
||||
|
||||
export const ACCOUNT_ROLE_OPTIONS = USER_ROLE_OPTIONS.filter((item) =>
|
||||
["admin", "organization_admin", "member", "supplier_manager"].includes(item.value),
|
||||
);
|
||||
|
||||
const legacyLabels: Partial<Record<UserRole, string>> = {
|
||||
operator: "旧版操作员",
|
||||
auditor: "旧版审核员",
|
||||
@ -55,5 +69,9 @@ export function getUserRoleDescription(role: UserRole) {
|
||||
}
|
||||
|
||||
export function canManagePipelineDesign(role: UserRole | null | undefined) {
|
||||
return role === "admin";
|
||||
return role === "admin" || role === "organization_admin";
|
||||
}
|
||||
|
||||
export function isOrganizationAdminRole(role: UserRole | null | undefined) {
|
||||
return role === "admin" || role === "organization_admin";
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ export function workflowCapabilityTone(capabilityId) {
|
||||
}
|
||||
|
||||
export function canAccessWorkflowCapability(role, capabilityId) {
|
||||
if (role === "admin") return true;
|
||||
if (role === "admin" || role === "organization_admin") return true;
|
||||
if (capabilityId === "human_cut_adjustment") {
|
||||
return role === "cutter";
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ import type {
|
||||
ExecutionRun,
|
||||
Project,
|
||||
ProjectAnnotationMembership,
|
||||
ProjectMember,
|
||||
SliceOperation,
|
||||
SliceSegment,
|
||||
Workflow,
|
||||
@ -67,6 +68,7 @@ import { ManifestMemberBrowser } from "../components/ManifestMemberBrowser";
|
||||
import { usePlugins } from "../context/PluginContext";
|
||||
import { buildBrowserPlayableVideoURL } from "../lib/video-preview.js";
|
||||
import { getPluginNavigationContributions } from "../lib/plugin-navigation.js";
|
||||
import { isOrganizationAdminRole } from "../lib/user-roles";
|
||||
import { captureDirectoriesFromHumanTask, uniqueCaptureDirectories } from "../lib/business-display.js";
|
||||
import { BusinessExecutionPath } from "../components/BusinessExecutionPath";
|
||||
|
||||
@ -314,6 +316,7 @@ export default function AnnotationOperations() {
|
||||
const [projectId, setProjectId] = useState("");
|
||||
const [workgroups, setWorkgroups] = useState<AnnotationWorkgroup[]>([]);
|
||||
const [memberships, setMemberships] = useState<ProjectAnnotationMembership[]>([]);
|
||||
const [projectMembers, setProjectMembers] = useState<ProjectMember[]>([]);
|
||||
const [templates, setTemplates] = useState<AnnotationTemplate[]>([]);
|
||||
const [tasks, setTasks] = useState<AnnotationTaskRecord[]>([]);
|
||||
const [humanPools, setHumanPools] = useState<HumanPools>(emptyHumanPools);
|
||||
@ -361,7 +364,7 @@ export default function AnnotationOperations() {
|
||||
|
||||
const [previewTab, setPreviewTab] = useState<"video" | "rerun">("video");
|
||||
|
||||
const isManager = role === "admin";
|
||||
const isManager = isOrganizationAdminRole(role);
|
||||
|
||||
useEffect(() => {
|
||||
setTaskPoolView((current) => (!isManager && current === "all" ? "available" : current));
|
||||
@ -390,12 +393,8 @@ export default function AnnotationOperations() {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
try {
|
||||
const [nextProjects, nextGroups] = await Promise.all([
|
||||
projectsApi.list(),
|
||||
annotationOperationsApi.listWorkgroups(),
|
||||
]);
|
||||
const nextProjects = await projectsApi.list();
|
||||
setProjects(nextProjects);
|
||||
setWorkgroups(nextGroups);
|
||||
setProjectId(
|
||||
(current) =>
|
||||
current || nextProjects.find((item) => item.id === requestedProjectId)?.id || nextProjects[0]?.id || "",
|
||||
@ -411,6 +410,7 @@ export default function AnnotationOperations() {
|
||||
if (!projectId) {
|
||||
setWorkflows([]);
|
||||
setMemberships([]);
|
||||
setProjectMembers([]);
|
||||
setTemplates([]);
|
||||
setTasks([]);
|
||||
setHumanPools(emptyHumanPools);
|
||||
@ -422,7 +422,7 @@ export default function AnnotationOperations() {
|
||||
setError("");
|
||||
try {
|
||||
const [
|
||||
nextMemberships,
|
||||
nextProjectMembers,
|
||||
nextWorkflows,
|
||||
nextTemplates,
|
||||
nextTasks,
|
||||
@ -434,7 +434,7 @@ export default function AnnotationOperations() {
|
||||
nextPackages,
|
||||
nextScopedRun,
|
||||
] = await Promise.all([
|
||||
annotationOperationsApi.listMemberships(projectId),
|
||||
projectsApi.listMembers(projectId),
|
||||
projectsApi.listWorkflows(projectId),
|
||||
annotationOperationsApi.listTemplates(projectId),
|
||||
annotationOperationsApi.listTasks({
|
||||
@ -481,7 +481,7 @@ export default function AnnotationOperations() {
|
||||
}),
|
||||
isManager && requestedRunId ? runsApi.get(requestedRunId) : Promise.resolve(null),
|
||||
]);
|
||||
setMemberships(nextMemberships);
|
||||
setProjectMembers(nextProjectMembers);
|
||||
setWorkflows(nextWorkflows);
|
||||
setTemplates(nextTemplates);
|
||||
setTasks(nextTasks);
|
||||
@ -695,34 +695,31 @@ export default function AnnotationOperations() {
|
||||
const selectedRequiredRole = assignmentRoleForStage(selectedHumanItem?.currentStageId || annotationStage);
|
||||
const eligibleAssigneesForScope = useCallback(
|
||||
(
|
||||
workgroupId: string | undefined,
|
||||
vendorId: string | undefined,
|
||||
supplierId: string | undefined,
|
||||
requiredRole: ProjectAnnotationMembership["assignmentRole"],
|
||||
currentAssigneeId = "",
|
||||
) => {
|
||||
if (!isManager) return [];
|
||||
const eligibleIds = new Set(
|
||||
memberships
|
||||
projectMembers
|
||||
.filter(
|
||||
(membership) =>
|
||||
assignmentRoleMatches(membership.assignmentRole, requiredRole) &&
|
||||
membership.workgroupId === workgroupId &&
|
||||
(!membership.vendorId || !vendorId || membership.vendorId === vendorId),
|
||||
(member) =>
|
||||
member.roles.includes(requiredRole as ProjectMember["roles"][number]) &&
|
||||
(!member.supplierId || !supplierId || member.supplierId === supplierId),
|
||||
)
|
||||
.map((membership) => membership.userId),
|
||||
.map((member) => member.userId),
|
||||
);
|
||||
if (currentUser?.id) eligibleIds.add(currentUser.id);
|
||||
if (currentAssigneeId) eligibleIds.add(currentAssigneeId);
|
||||
return users.filter((user) => eligibleIds.has(user.id) && user.status !== "disabled");
|
||||
},
|
||||
[currentUser?.id, isManager, memberships, users],
|
||||
[currentUser?.id, isManager, projectMembers, users],
|
||||
);
|
||||
const eligibleAssignees = useMemo(
|
||||
() =>
|
||||
selectedHumanItem
|
||||
? eligibleAssigneesForScope(
|
||||
selectedHumanItem.workgroupId,
|
||||
selectedHumanItem.vendorId,
|
||||
selectedHumanItem.supplierId,
|
||||
selectedRequiredRole,
|
||||
selectedHumanItem.assignedUserId,
|
||||
)
|
||||
@ -1377,7 +1374,6 @@ export default function AnnotationOperations() {
|
||||
<option value="queue">{queueTabLabel}</option>
|
||||
<option value="rejects">拒绝区</option>
|
||||
<option value="templates">模板版本</option>
|
||||
<option value="groups">供应商与角色</option>
|
||||
<option value="workload">工时统计</option>
|
||||
</select>
|
||||
{isManager ? (
|
||||
@ -1579,8 +1575,7 @@ export default function AnnotationOperations() {
|
||||
const acceptanceStatistics = prepackageAcceptanceDrafts[item.id] || emptyPrepackageAcceptanceStatistics;
|
||||
const strictThreeRole = payload.strictThreeRole === true;
|
||||
const acceptanceAssignees = eligibleAssigneesForScope(
|
||||
item.workgroupId,
|
||||
item.vendorId,
|
||||
item.supplierId,
|
||||
strictThreeRole ? "acceptance_reviewer" : "quality_reviewer",
|
||||
item.assignedUserId,
|
||||
);
|
||||
@ -1653,7 +1648,7 @@ export default function AnnotationOperations() {
|
||||
: "缺失"}
|
||||
</div>
|
||||
<div className="rounded-lg bg-[#101114] p-3 text-xs text-gray-300">
|
||||
供应商隔离:{item.vendorId || "-"}
|
||||
供应商隔离:{item.supplierId || "内部成员"}
|
||||
</div>
|
||||
<div className="rounded-lg bg-[#101114] p-3 text-xs text-gray-300">状态:{item.status}</div>
|
||||
</div>
|
||||
@ -1875,8 +1870,7 @@ export default function AnnotationOperations() {
|
||||
prePackageAcceptance?.statistics?.overallGrade || item.acceptanceReviews?.at(-1)?.overallGrade || "-";
|
||||
const assignedToMe = item.assignedUserId === currentUser?.id;
|
||||
const packageAssignees = eligibleAssigneesForScope(
|
||||
item.workgroupId,
|
||||
item.vendorId,
|
||||
item.supplierId,
|
||||
"quality_reviewer",
|
||||
item.assignedUserId,
|
||||
);
|
||||
@ -2221,69 +2215,6 @@ export default function AnnotationOperations() {
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isManager && (workspaceMode === "clip" || workspaceMode === "annotate") ? (
|
||||
<div className={`${panelClass} space-y-3 p-4`}>
|
||||
<div className="text-sm font-semibold text-white">创建标注任务</div>
|
||||
<input
|
||||
className={inputClass}
|
||||
placeholder="视频或 artifact 路径 (.mp4 / .rrd)"
|
||||
value={taskDraft.sourceVideo}
|
||||
onChange={(event) => setTaskDraft((current) => ({ ...current, sourceVideo: event.target.value }))}
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
className={inputClass}
|
||||
type="number"
|
||||
value={taskDraft.clipStart}
|
||||
onChange={(event) => setTaskDraft((current) => ({ ...current, clipStart: event.target.value }))}
|
||||
/>
|
||||
<input
|
||||
className={inputClass}
|
||||
type="number"
|
||||
value={taskDraft.clipEnd}
|
||||
onChange={(event) => setTaskDraft((current) => ({ ...current, clipEnd: event.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<select
|
||||
className={inputClass}
|
||||
value={taskDraft.templateId}
|
||||
onChange={(event) => setTaskDraft((current) => ({ ...current, templateId: event.target.value }))}
|
||||
>
|
||||
<option value="">已发布模板</option>
|
||||
{templates
|
||||
.filter((item) => item.status === "published")
|
||||
.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name} v{item.version}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className={inputClass}
|
||||
value={taskDraft.workgroupId}
|
||||
onChange={(event) => setTaskDraft((current) => ({ ...current, workgroupId: event.target.value }))}
|
||||
>
|
||||
<option value="">供应商分组</option>
|
||||
{workgroups.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.vendorId} / {item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="rounded-lg border border-blue-500/20 bg-blue-500/10 px-3 py-2 text-xs text-blue-100">
|
||||
任务创建后进入供应商工作组待领取池,不指定人员、不发送推送。
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void createTask()}
|
||||
disabled={saving}
|
||||
className="w-full rounded-lg bg-blue-600 px-3 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
创建任务
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className={`${panelClass} min-h-[640px] p-5`}>
|
||||
@ -2307,7 +2238,7 @@ export default function AnnotationOperations() {
|
||||
模板 v{detail.task.templateVersion} · {statusLabels[detail.task.status]}
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-3 text-xs text-gray-500">
|
||||
{detail.task.runId && role === "admin" ? (
|
||||
{detail.task.runId && isOrganizationAdminRole(role) ? (
|
||||
<Link
|
||||
className="text-blue-300 hover:text-blue-200"
|
||||
to={`/monitoring?runId=${encodeURIComponent(detail.task.runId)}`}
|
||||
@ -2423,7 +2354,7 @@ export default function AnnotationOperations() {
|
||||
<ManifestMemberBrowser
|
||||
runId={selectedMaterialization.runId || ""}
|
||||
artifact={materializedDirectoryArtifact}
|
||||
allowTechnicalDownload={role === "admin"}
|
||||
allowTechnicalDownload={isOrganizationAdminRole(role)}
|
||||
humanItemId={selectedHumanItem.id}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -22,6 +22,7 @@ import { useTimeZone } from "../context/TimeZoneContext";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
import { formatCompactDateTime } from "../lib/datetime";
|
||||
import { cn } from "../lib/utils";
|
||||
import { isOrganizationAdminRole } from "../lib/user-roles";
|
||||
import { BusinessExecutionPath } from "../components/BusinessExecutionPath";
|
||||
import type {
|
||||
DashboardGate,
|
||||
@ -84,11 +85,11 @@ function WorkforceSummaryPanel({ summary }: { summary: DashboardSummary | null }
|
||||
</div>
|
||||
{(workforce?.items || []).map((item: DashboardWorkforceMetric, index) => (
|
||||
<div
|
||||
key={`${item.userId}-${item.vendorId}-${item.workgroupId}-${index}`}
|
||||
key={`${item.userId}-${item.supplierId}-${index}`}
|
||||
className="grid grid-cols-[1.2fr_1fr_repeat(4,0.8fr)] gap-3 border-b border-[#202227] px-4 py-3 text-sm text-gray-300"
|
||||
>
|
||||
<span>{item.userName || item.userId || "系统"}</span>
|
||||
<span>{item.vendorId || "--"}</span>
|
||||
<span>{item.supplierId || "内部成员"}</span>
|
||||
<span>{item.outputCount}</span>
|
||||
<span>{formatRate(item.reworkRate)}</span>
|
||||
<span>{formatRate(item.qualityPassRate)}</span>
|
||||
@ -141,7 +142,7 @@ export default function Dashboard() {
|
||||
}, []);
|
||||
|
||||
const loadWorkbench = useCallback(() => {
|
||||
if (currentUser?.role !== "admin") {
|
||||
if (!isOrganizationAdminRole(currentUser?.role)) {
|
||||
setWorkbench(emptyWorkbench);
|
||||
setWorkbenchError("");
|
||||
return;
|
||||
@ -198,7 +199,7 @@ export default function Dashboard() {
|
||||
useEffect(() => {
|
||||
loadSummary();
|
||||
loadWorkbench();
|
||||
if (currentUser?.role === "admin") void loadServices();
|
||||
if (isOrganizationAdminRole(currentUser?.role)) void loadServices();
|
||||
}, [currentUser?.role, loadSummary, loadWorkbench, loadServices]);
|
||||
|
||||
const staleAuditRuns = workbench.waitingForAudit.filter(
|
||||
@ -224,7 +225,7 @@ export default function Dashboard() {
|
||||
};
|
||||
|
||||
const poc = summary?.poc;
|
||||
if (currentUser && currentUser.role !== "admin") {
|
||||
if (currentUser && !isOrganizationAdminRole(currentUser.role)) {
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div>
|
||||
@ -428,7 +429,7 @@ export default function Dashboard() {
|
||||
<h2 className="text-xl font-bold text-white">任务工作台</h2>
|
||||
<p className="mt-1 text-sm text-gray-500">优先处理正在运行、失败、过期待审核与最近产物。</p>
|
||||
</div>
|
||||
{currentUser?.role === "admin" && staleAuditRuns.length > 0 && (
|
||||
{isOrganizationAdminRole(currentUser?.role) && staleAuditRuns.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={bulkCancelPending}
|
||||
|
||||
@ -4,6 +4,7 @@ import { useTimeZone } from "../context/TimeZoneContext";
|
||||
import { useUser } from "../context/UserContext";
|
||||
import { PageSubnav } from "../components/PageSubnav";
|
||||
import { BusinessExecutionPath } from "../components/BusinessExecutionPath";
|
||||
import { ProjectMembersPanel } from "../components/ProjectMembersPanel";
|
||||
import {
|
||||
AlertCircle,
|
||||
Plus,
|
||||
@ -122,6 +123,7 @@ const formatBytes = (bytes?: number) => {
|
||||
|
||||
const captureStatusLabel: Record<CaptureRecordStatus, string> = {
|
||||
incomplete: "等待文件齐全",
|
||||
stabilizing: "确认文件稳定中",
|
||||
ready: "已就绪",
|
||||
launching: "正在创建运行",
|
||||
requeueing: "正在重新处理",
|
||||
@ -280,6 +282,7 @@ export default function ProjectDetail() {
|
||||
manifestName: "source-manifest.json",
|
||||
workflowInputId: "sourceDirectory",
|
||||
pollIntervalSeconds: 30,
|
||||
stabilityWindowSeconds: 30,
|
||||
maxRetryAttempts: 2,
|
||||
retryBackoffSeconds: 60,
|
||||
});
|
||||
@ -449,31 +452,12 @@ export default function ProjectDetail() {
|
||||
}, [activeTab, id, modeFilter, statusFilter, deferredSearchQuery, pageCursor]);
|
||||
|
||||
const reloadProjectMembers = async () => {
|
||||
if (!id) return;
|
||||
setMembersLoading(true);
|
||||
setMembersError("");
|
||||
try {
|
||||
const [memberships, workgroups, humanItems] = await Promise.all([
|
||||
annotationOperationsApi.listMemberships(id),
|
||||
annotationOperationsApi.listWorkgroups(),
|
||||
humanLoopApi.listItems({ projectId: id, pool: "all" }),
|
||||
]);
|
||||
setProjectMemberships(memberships);
|
||||
setAnnotationWorkgroups(workgroups.filter((item) => item.status === "active"));
|
||||
setProjectHumanItems(humanItems);
|
||||
} catch (error) {
|
||||
console.error("Failed to load project members", error);
|
||||
setMembersError(getActionErrorMessage(error, "加载项目成员失败"));
|
||||
} finally {
|
||||
setMembersLoading(false);
|
||||
}
|
||||
// ProjectMembersPanel owns the new supplier-scoped member API. This
|
||||
// compatibility callback intentionally does not touch removed workgroup
|
||||
// endpoints while older local modal state is being retired.
|
||||
return;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab !== "members" || !id) return;
|
||||
void reloadProjectMembers();
|
||||
}, [activeTab, id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAutomationModalOpen || !automationWorkflow?.id) return;
|
||||
const workflowId = automationWorkflow.id;
|
||||
@ -1081,6 +1065,7 @@ export default function ProjectDetail() {
|
||||
manifestName: response.config?.manifestName || "source-manifest.json",
|
||||
workflowInputId: response.config?.workflowInputId || directoryInput?.id || "sourceDirectory",
|
||||
pollIntervalSeconds: response.config?.pollIntervalSeconds || 30,
|
||||
stabilityWindowSeconds: response.config?.stabilityWindowSeconds || 30,
|
||||
requiredPatterns: response.config?.requiredPatterns,
|
||||
maxRetryAttempts: response.config?.maxRetryAttempts ?? fullWorkflow.maxRetryAttempts ?? 2,
|
||||
retryBackoffSeconds: response.config?.retryBackoffSeconds ?? fullWorkflow.retryBackoffSeconds ?? 60,
|
||||
@ -1841,125 +1826,7 @@ export default function ProjectDetail() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === "members" && (
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border border-[#2a2b2f] bg-[#151619] p-5">
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-lg font-semibold text-white">
|
||||
<Users className="h-5 w-5 text-blue-400" />
|
||||
项目成员与人工角色
|
||||
</div>
|
||||
<p className="mt-1 text-sm text-gray-500">
|
||||
项目角色决定成员可领取的任务池;删除工作流不会删除这里的成员关系。
|
||||
</p>
|
||||
</div>
|
||||
{canManage && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={openAddMemberModal}
|
||||
className="inline-flex items-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-500"
|
||||
>
|
||||
<UserPlus className="h-4 w-4" />
|
||||
添加项目成员
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{membersError && (
|
||||
<div className="flex items-center gap-2 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-200">
|
||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||
{membersError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="overflow-hidden rounded-xl border border-[#2a2b2f] bg-[#151619]">
|
||||
<table className="w-full text-left text-sm">
|
||||
<thead className="border-b border-[#2a2b2f] bg-[#111214] text-xs uppercase tracking-wider text-gray-500">
|
||||
<tr>
|
||||
<th className="px-5 py-3">成员</th>
|
||||
<th className="px-5 py-3">任务池</th>
|
||||
<th className="px-5 py-3">项目角色</th>
|
||||
<th className="px-5 py-3">已领取任务</th>
|
||||
<th className="px-5 py-3 text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-[#2a2b2f]">
|
||||
{projectMemberRows.map((row) => {
|
||||
const user = users.find((item) => item.id === row.userId);
|
||||
const workgroup = annotationWorkgroups.find((item) => item.id === row.workgroupId);
|
||||
const claimedCount = projectHumanItems.filter(
|
||||
(item) =>
|
||||
item.assignedUserId === row.userId &&
|
||||
item.workgroupId === row.workgroupId &&
|
||||
["claimed", "in_progress", "submitted", "rework"].includes(item.status),
|
||||
).length;
|
||||
return (
|
||||
<tr key={row.key} className="hover:bg-white/[0.02]">
|
||||
<td className="px-5 py-4">
|
||||
<div className="font-medium text-white">{user?.name || row.userId}</div>
|
||||
<div className="mt-0.5 text-xs text-gray-500">{user?.email || "账号信息不可见"}</div>
|
||||
</td>
|
||||
<td className="px-5 py-4">
|
||||
<div className="text-gray-300">{workgroup?.name || row.workgroupId}</div>
|
||||
<div className="mt-0.5 text-xs text-gray-600">
|
||||
{workgroup?.vendorId || row.memberships[0]?.vendorId}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-5 py-4">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{row.memberships.map((membership) => (
|
||||
<span
|
||||
key={membership.id}
|
||||
className="rounded-md border border-blue-500/25 bg-blue-500/10 px-2 py-1 text-xs font-medium text-blue-200"
|
||||
>
|
||||
{projectHumanRoleLabel(membership.assignmentRole)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-5 py-4">
|
||||
<span className={claimedCount > 0 ? "font-semibold text-amber-300" : "text-gray-500"}>
|
||||
{claimedCount} 个
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-5 py-4 text-right">
|
||||
{canManage && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={Boolean(memberActionId)}
|
||||
onClick={() => void removeProjectMember(row.memberships)}
|
||||
className="inline-flex items-center gap-1.5 rounded-md border border-red-500/20 px-3 py-1.5 text-xs font-medium text-red-300 hover:bg-red-500/10 disabled:opacity-50"
|
||||
>
|
||||
{memberActionId === row.key ? (
|
||||
<Loader2 className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
)}
|
||||
移出项目
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
{!membersLoading && projectMemberRows.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={5} className="px-6 py-12 text-center text-gray-500">
|
||||
当前项目还没有标注、审核或最终验收成员。
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
{membersLoading && (
|
||||
<div className="flex items-center justify-center gap-2 border-t border-[#2a2b2f] py-6 text-sm text-gray-500">
|
||||
<Loader2 className="h-4 w-4 animate-spin text-blue-400" />
|
||||
正在加载项目成员与任务占用情况...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{activeTab === "members" && <ProjectMembersPanel projectId={project.id} users={users} canManage={canManage} />}
|
||||
|
||||
{activeTab === "runs" && (
|
||||
<div className="space-y-4">
|
||||
@ -2898,6 +2765,27 @@ export default function ProjectDetail() {
|
||||
<option value={300}>每5分钟</option>
|
||||
</select>
|
||||
</label>
|
||||
<label className="space-y-1.5">
|
||||
<span className="text-xs font-medium text-gray-400">文件稳定等待</span>
|
||||
<select
|
||||
value={automationDraft.stabilityWindowSeconds || 30}
|
||||
onChange={(event) =>
|
||||
setAutomationDraft((current) => ({
|
||||
...current,
|
||||
stabilityWindowSeconds: Number(event.target.value),
|
||||
}))
|
||||
}
|
||||
className="w-full rounded-md border border-[#2a2b2f] bg-[#151619] px-3 py-2 text-sm text-white outline-none focus:border-cyan-500"
|
||||
>
|
||||
<option value={5}>5 秒</option>
|
||||
<option value={30}>30 秒(推荐)</option>
|
||||
<option value={60}>60 秒</option>
|
||||
<option value={120}>120 秒</option>
|
||||
</select>
|
||||
<span className="block text-[11px] leading-4 text-gray-500">
|
||||
文件类型齐全后,需至少两次扫描指纹一致才会创建 Run。
|
||||
</span>
|
||||
</label>
|
||||
<label className="space-y-1.5 md:col-span-2">
|
||||
<span className="text-xs font-medium text-gray-400">完整记录判断</span>
|
||||
<select
|
||||
|
||||
@ -3,17 +3,9 @@ import { cn } from "../lib/utils";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
import { AlertCircle, KeyRound, X, User, Shield, Mail, Plus, Trash2, Loader2, RefreshCw } from "lucide-react";
|
||||
import { useUser } from "../context/UserContext";
|
||||
import type {
|
||||
AnnotationAssignmentRole,
|
||||
AnnotationWorkgroup,
|
||||
Project,
|
||||
ProjectAnnotationMembership,
|
||||
User as UserData,
|
||||
} from "../types";
|
||||
import type { User as UserData } from "../types";
|
||||
import { usersApi } from "../services/api/users";
|
||||
import { projectsApi } from "../services/api/projects";
|
||||
import { annotationOperationsApi } from "../services/api/annotation-operations";
|
||||
import { getUserRoleDescription, getUserRoleLabel, USER_ROLE_OPTIONS } from "../lib/user-roles";
|
||||
import { ACCOUNT_ROLE_OPTIONS, getUserRoleDescription, getUserRoleLabel } from "../lib/user-roles";
|
||||
|
||||
export default function Users() {
|
||||
const { refreshUsers } = useUser();
|
||||
@ -26,16 +18,6 @@ export default function Users() {
|
||||
const [isLoadingUsers, setIsLoadingUsers] = useState(true);
|
||||
const [isSavingUser, setIsSavingUser] = useState(false);
|
||||
const [deletingUserId, setDeletingUserId] = useState<string | null>(null);
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [workgroups, setWorkgroups] = useState<AnnotationWorkgroup[]>([]);
|
||||
const [memberships, setMemberships] = useState<ProjectAnnotationMembership[]>([]);
|
||||
const [membershipDraft, setMembershipDraft] = useState({
|
||||
projectId: "",
|
||||
userId: "",
|
||||
workgroupId: "",
|
||||
assignmentRole: "annotator" as AnnotationAssignmentRole,
|
||||
});
|
||||
const [isSavingMembership, setIsSavingMembership] = useState(false);
|
||||
|
||||
const loadUsers = useCallback(async () => {
|
||||
setError("");
|
||||
@ -56,47 +38,8 @@ export default function Users() {
|
||||
|
||||
useEffect(() => {
|
||||
void loadUsers();
|
||||
Promise.all([projectsApi.list(), annotationOperationsApi.listWorkgroups()])
|
||||
.then(([nextProjects, nextGroups]) => {
|
||||
setProjects(nextProjects);
|
||||
setWorkgroups(nextGroups);
|
||||
setMembershipDraft((current) => ({
|
||||
...current,
|
||||
projectId: current.projectId || nextProjects[0]?.id || "",
|
||||
workgroupId: current.workgroupId || nextGroups[0]?.id || "",
|
||||
}));
|
||||
})
|
||||
.catch((loadError) => setError(getActionErrorMessage(loadError, "加载项目角色数据失败")));
|
||||
}, [loadUsers]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!membershipDraft.projectId) {
|
||||
setMemberships([]);
|
||||
return;
|
||||
}
|
||||
annotationOperationsApi
|
||||
.listMemberships(membershipDraft.projectId)
|
||||
.then(setMemberships)
|
||||
.catch((loadError) => setError(getActionErrorMessage(loadError, "加载项目成员失败")));
|
||||
}, [membershipDraft.projectId]);
|
||||
|
||||
const saveMembership = async () => {
|
||||
if (!membershipDraft.projectId || !membershipDraft.userId || !membershipDraft.workgroupId) {
|
||||
setError("请选择项目、用户和工作组。");
|
||||
return;
|
||||
}
|
||||
setIsSavingMembership(true);
|
||||
setError("");
|
||||
try {
|
||||
await annotationOperationsApi.createMembership(membershipDraft);
|
||||
setMemberships(await annotationOperationsApi.listMemberships(membershipDraft.projectId));
|
||||
} catch (saveError) {
|
||||
setError(getActionErrorMessage(saveError, "分配项目角色失败"));
|
||||
} finally {
|
||||
setIsSavingMembership(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = (user: UserData) => {
|
||||
setError("");
|
||||
setModalMode("edit");
|
||||
@ -113,7 +56,7 @@ export default function Users() {
|
||||
id: "",
|
||||
name: "",
|
||||
email: "",
|
||||
role: "annotator",
|
||||
role: "member",
|
||||
});
|
||||
setIsModalOpen(true);
|
||||
};
|
||||
@ -319,93 +262,6 @@ export default function Users() {
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<section className="rounded-xl border border-[#2a2b2f] bg-[#151619] p-5">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold text-white">项目与角色分配</h2>
|
||||
<p className="mt-1 text-sm text-gray-500">
|
||||
同一用户可在不同项目中分别担任标注员、质检员或验收员;所有任务按项目和工作组隔离。
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-4 grid gap-3 md:grid-cols-4">
|
||||
<select
|
||||
className="rounded-md border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white"
|
||||
value={membershipDraft.projectId}
|
||||
onChange={(event) => setMembershipDraft((current) => ({ ...current, projectId: event.target.value }))}
|
||||
>
|
||||
<option value="">选择项目</option>
|
||||
{projects.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className="rounded-md border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white"
|
||||
value={membershipDraft.userId}
|
||||
onChange={(event) => setMembershipDraft((current) => ({ ...current, userId: event.target.value }))}
|
||||
>
|
||||
<option value="">选择用户</option>
|
||||
{users
|
||||
.filter((item) => item.role !== "admin")
|
||||
.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name} · {getUserRoleLabel(item.role)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className="rounded-md border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white"
|
||||
value={membershipDraft.workgroupId}
|
||||
onChange={(event) => setMembershipDraft((current) => ({ ...current, workgroupId: event.target.value }))}
|
||||
>
|
||||
<option value="">选择工作组</option>
|
||||
{workgroups.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.vendorId} / {item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className="rounded-md border border-[#2a2b2f] bg-[#0a0a0a] px-3 py-2 text-sm text-white"
|
||||
value={membershipDraft.assignmentRole}
|
||||
onChange={(event) =>
|
||||
setMembershipDraft((current) => ({
|
||||
...current,
|
||||
assignmentRole: event.target.value as AnnotationAssignmentRole,
|
||||
}))
|
||||
}
|
||||
>
|
||||
<option value="cutter">人工剪切员</option>
|
||||
<option value="annotator">标注员(剪切审核 + 语义标注)</option>
|
||||
<option value="quality_reviewer">审核员(标注审核 + 最终验收)</option>
|
||||
<option value="vendor_manager">供应商管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
disabled={isSavingMembership}
|
||||
onClick={() => void saveMembership()}
|
||||
className="mt-3 rounded-lg bg-blue-600 px-4 py-2 text-sm text-white disabled:opacity-50"
|
||||
>
|
||||
{isSavingMembership ? "保存中..." : "分配项目角色"}
|
||||
</button>
|
||||
<div className="mt-4 grid gap-2 md:grid-cols-2">
|
||||
{memberships.map((membership) => {
|
||||
const user = users.find((item) => item.id === membership.userId);
|
||||
const group = workgroups.find((item) => item.id === membership.workgroupId);
|
||||
return (
|
||||
<div
|
||||
key={membership.id}
|
||||
className="rounded-lg border border-[#2a2b2f] bg-[#101114] px-3 py-2 text-sm text-gray-300"
|
||||
>
|
||||
{user?.name || membership.userId} · {getUserRoleLabel(membership.assignmentRole as UserData["role"])} ·{" "}
|
||||
{group?.name || membership.workgroupId}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Edit User Modal */}
|
||||
{isModalOpen && editingUser && (
|
||||
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
|
||||
@ -455,14 +311,12 @@ export default function Users() {
|
||||
value={editingUser.role}
|
||||
onChange={(e) => setEditingUser({ ...editingUser, role: e.target.value as UserData["role"] })}
|
||||
>
|
||||
{USER_ROLE_OPTIONS.filter(
|
||||
(option) => option.value !== "acceptance_reviewer" || editingUser.role === "acceptance_reviewer",
|
||||
).map((option) => (
|
||||
{ACCOUNT_ROLE_OPTIONS.map((option) => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
{["operator", "auditor"].includes(editingUser.role) && (
|
||||
{!ACCOUNT_ROLE_OPTIONS.some((option) => option.value === editingUser.role) && (
|
||||
<option value={editingUser.role}>{getUserRoleLabel(editingUser.role)}</option>
|
||||
)}
|
||||
</select>
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
import type {
|
||||
HumanItem,
|
||||
HumanItemStatus,
|
||||
HumanReject,
|
||||
RunArtifactManifestMembersResponse,
|
||||
} from "../../types";
|
||||
import type { HumanItem, HumanItemStatus, HumanReject, RunArtifactManifestMembersResponse } from "../../types";
|
||||
import { apiRequest } from "./client";
|
||||
|
||||
type HumanItemFilters = {
|
||||
@ -79,6 +74,10 @@ export const humanLoopApi = {
|
||||
};
|
||||
},
|
||||
) => apiRequest<HumanItem>(`/api/human-items/${encodeURIComponent(id)}/decisions`, { method: "POST" }, payload),
|
||||
decideEscalation: (
|
||||
id: string,
|
||||
payload: { version: number; action: "reopen" | "close"; targetStageId?: string; comment: string },
|
||||
) => apiRequest<HumanItem>(`/api/human-items/${encodeURIComponent(id)}/escalation`, { method: "POST" }, payload),
|
||||
listRejects: async (
|
||||
filters: { projectId?: string; workflowId?: string; runId?: string; status?: HumanReject["status"] } = {},
|
||||
) => (await apiRequest<{ items: HumanReject[] }>(`/api/human-rejects${queryString(filters)}`)).items,
|
||||
|
||||
@ -4,6 +4,7 @@ import type {
|
||||
ObjectStorageObjectMutationResult,
|
||||
ObjectStorageOverview,
|
||||
} from "../../types";
|
||||
import type { ObjectStorageUploadSessionSummary } from "../../types";
|
||||
import { parseObjectStoragePreviewBytesHeader } from "../../lib/object-storage-preview.js";
|
||||
import {
|
||||
MULTIPART_CONCURRENCY,
|
||||
@ -145,6 +146,21 @@ interface ObjectStorageMultipartUploadPart {
|
||||
eTag: string;
|
||||
}
|
||||
|
||||
export type ObjectStorageUploadSessionFileInput = {
|
||||
relativePath: string;
|
||||
kind: "file" | "directory";
|
||||
sizeBytes?: number;
|
||||
contentType?: string;
|
||||
lastModified?: number;
|
||||
};
|
||||
|
||||
type ObjectStorageUploadSessionStartResult = {
|
||||
session: ObjectStorageUploadSessionSummary;
|
||||
mode: "direct" | "multipart";
|
||||
uploadId?: string;
|
||||
upload?: ObjectStoragePresignedUploadResult;
|
||||
};
|
||||
|
||||
async function uploadWithFormData<T>(path: string, formData: FormData) {
|
||||
const response = await apiFetch(
|
||||
path,
|
||||
@ -302,6 +318,77 @@ async function uploadDirectObject(
|
||||
}
|
||||
|
||||
export const objectStorageApi = {
|
||||
listUploadSessions: async (options: { all?: boolean } = {}) =>
|
||||
(
|
||||
await apiRequest<{ items: ObjectStorageUploadSessionSummary[] }>(
|
||||
`/api/object-storage/upload-sessions${options.all ? "?all=true" : ""}`,
|
||||
)
|
||||
).items,
|
||||
getUploadSession: (id: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(`/api/object-storage/upload-sessions/${encodeURIComponent(id)}`),
|
||||
createUploadSession: (
|
||||
input: {
|
||||
bucket: string;
|
||||
prefix?: string;
|
||||
conflictPolicy?: ObjectStorageBatchConflictPolicy;
|
||||
items: ObjectStorageUploadSessionFileInput[];
|
||||
},
|
||||
options: { connectionId: string },
|
||||
) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions${buildObjectStorageParams({ connectionId: options.connectionId })}`,
|
||||
{ method: "POST" },
|
||||
input,
|
||||
),
|
||||
pauseUploadSession: (id: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(id)}/pause`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
resumeUploadSession: (id: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(id)}/resume`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
cancelUploadSession: (id: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(id)}/cancel`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
startUploadSessionItem: (sessionId: string, itemId: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionStartResult>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(sessionId)}/items/${encodeURIComponent(itemId)}/start`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
uploadSessionPartURL: (sessionId: string, itemId: string, partNumber: number) =>
|
||||
apiRequest<ObjectStorageMultipartUploadPartURLResult>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(sessionId)}/items/${encodeURIComponent(itemId)}/part-url`,
|
||||
{ method: "POST" },
|
||||
{ partNumber },
|
||||
),
|
||||
completeUploadSessionPart: (
|
||||
sessionId: string,
|
||||
itemId: string,
|
||||
partNumber: number,
|
||||
eTag: string,
|
||||
uploadedBytes: number,
|
||||
) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(sessionId)}/items/${encodeURIComponent(itemId)}/parts`,
|
||||
{ method: "POST" },
|
||||
{ partNumber, eTag, uploadedBytes },
|
||||
),
|
||||
completeUploadSessionItem: (sessionId: string, itemId: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(sessionId)}/items/${encodeURIComponent(itemId)}/complete`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
failUploadSessionItem: (sessionId: string, itemId: string, error: string) =>
|
||||
apiRequest<ObjectStorageUploadSessionSummary>(
|
||||
`/api/object-storage/upload-sessions/${encodeURIComponent(sessionId)}/items/${encodeURIComponent(itemId)}/failed`,
|
||||
{ method: "POST" },
|
||||
{ error },
|
||||
),
|
||||
getOverview: (options?: { connectionId?: string }) =>
|
||||
apiRequest<ObjectStorageOverview>(`/api/object-storage${buildObjectStorageParams(options)}`),
|
||||
listObjects: (options: { connectionId: string; bucket?: string; prefix?: string; marker?: string; limit?: number }) =>
|
||||
|
||||
@ -1,4 +1,11 @@
|
||||
import type { Project, ProjectWorkflowInstance, StoragePathFavorite, Workflow } from "../../types";
|
||||
import type {
|
||||
Project,
|
||||
ProjectMember,
|
||||
ProjectMemberRole,
|
||||
ProjectWorkflowInstance,
|
||||
StoragePathFavorite,
|
||||
Workflow,
|
||||
} from "../../types";
|
||||
import { apiRequest } from "./client";
|
||||
|
||||
export const projectsApi = {
|
||||
@ -33,6 +40,20 @@ export const projectsApi = {
|
||||
{ items },
|
||||
),
|
||||
remove: (id: string) => apiRequest<void>(`/api/projects/${id}`, { method: "DELETE" }),
|
||||
listMembers: async (projectId: string) =>
|
||||
(await apiRequest<{ items: ProjectMember[] }>(`/api/projects/${projectId}/members`)).items,
|
||||
createMember: (projectId: string, payload: { userId: string; supplierId?: string; roles: ProjectMemberRole[] }) =>
|
||||
apiRequest<ProjectMember>(`/api/projects/${projectId}/members`, { method: "POST" }, payload),
|
||||
updateMember: (projectId: string, memberId: string, payload: { supplierId?: string; roles: ProjectMemberRole[] }) =>
|
||||
apiRequest<ProjectMember>(`/api/projects/${projectId}/members/${memberId}`, { method: "PATCH" }, payload),
|
||||
removeMember: (projectId: string, memberId: string, releaseTasks = true) =>
|
||||
apiRequest<void>(`/api/projects/${projectId}/members/${memberId}${releaseTasks ? "?releaseTasks=true" : ""}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
bulkMembers: (
|
||||
projectId: string,
|
||||
payload: { action: "set_roles" | "remove"; memberIds: string[]; roles?: ProjectMemberRole[] },
|
||||
) => apiRequest<{ updated: number }>(`/api/projects/${projectId}/members/bulk`, { method: "POST" }, payload),
|
||||
listWorkflows: async (projectId: string) =>
|
||||
(await apiRequest<{ items: Workflow[] }>(`/api/projects/${projectId}/workflows`)).items,
|
||||
createWorkflow: (projectId: string, payload: Partial<Workflow>) =>
|
||||
|
||||
7
src/services/api/suppliers.ts
Normal file
7
src/services/api/suppliers.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import type { Supplier } from "../../types";
|
||||
import { apiRequest } from "./client";
|
||||
|
||||
export const suppliersApi = {
|
||||
list: async () => (await apiRequest<{ items: Supplier[] }>("/api/suppliers")).items,
|
||||
create: (payload: { name: string }) => apiRequest<Supplier>("/api/suppliers", { method: "POST" }, payload),
|
||||
};
|
||||
87
src/types.ts
87
src/types.ts
@ -2,6 +2,8 @@ import type { Edge, Node } from "reactflow";
|
||||
|
||||
export type UserRole =
|
||||
| "admin"
|
||||
| "organization_admin"
|
||||
| "member"
|
||||
| "cutter"
|
||||
| "annotator"
|
||||
| "quality_reviewer"
|
||||
@ -20,6 +22,7 @@ export interface User {
|
||||
name: string;
|
||||
email: string;
|
||||
role: UserRole;
|
||||
supplierId?: string;
|
||||
isSuperAdmin?: boolean;
|
||||
status?: "active" | "disabled";
|
||||
createdAt?: string;
|
||||
@ -825,8 +828,7 @@ export interface DashboardSummary {
|
||||
export interface DashboardWorkforceMetric {
|
||||
userId?: string;
|
||||
userName?: string;
|
||||
vendorId?: string;
|
||||
workgroupId?: string;
|
||||
supplierId?: string;
|
||||
outputCount: number;
|
||||
submittedCount: number;
|
||||
reworkCount: number;
|
||||
@ -1006,6 +1008,7 @@ export interface CaptureAutomationConfig {
|
||||
manifestName?: string;
|
||||
workflowInputId?: string;
|
||||
pollIntervalSeconds?: number;
|
||||
stabilityWindowSeconds?: number;
|
||||
requiredPatterns?: string[];
|
||||
maxRetryAttempts?: number;
|
||||
retryBackoffSeconds?: number;
|
||||
@ -1013,6 +1016,7 @@ export interface CaptureAutomationConfig {
|
||||
|
||||
export type CaptureRecordStatus =
|
||||
| "incomplete"
|
||||
| "stabilizing"
|
||||
| "ready"
|
||||
| "launching"
|
||||
| "requeueing"
|
||||
@ -1054,6 +1058,8 @@ export interface CaptureRecord {
|
||||
fingerprint?: string;
|
||||
status: CaptureRecordStatus;
|
||||
missingTypes?: string[];
|
||||
stabilityChecks?: number;
|
||||
stabilityObservedAt?: string;
|
||||
fileCount: number;
|
||||
totalBytes: number;
|
||||
runId?: string;
|
||||
@ -1737,6 +1743,80 @@ export interface ProjectAnnotationMembership {
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type ProjectMemberRole = "annotator" | "quality_reviewer" | "acceptance_reviewer";
|
||||
|
||||
export interface Supplier {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ProjectMember {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
projectId: string;
|
||||
userId: string;
|
||||
supplierId?: string;
|
||||
roles: ProjectMemberRole[];
|
||||
legacySnapshot?: Record<string, string>;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type ObjectStorageUploadSessionStatus = "prepared" | "running" | "paused" | "completed" | "failed" | "cancelled";
|
||||
export type ObjectStorageUploadItemStatus = "pending" | "uploading" | "success" | "skipped" | "failed" | "cancelled";
|
||||
|
||||
export interface ObjectStorageUploadSessionItem {
|
||||
id: string;
|
||||
relativePath: string;
|
||||
key: string;
|
||||
kind: "file" | "directory";
|
||||
contentType?: string;
|
||||
sizeBytes: number;
|
||||
lastModified?: number;
|
||||
action: "upload" | "create_placeholder" | "skip" | "conflict";
|
||||
status: ObjectStorageUploadItemStatus;
|
||||
mode?: "direct" | "multipart";
|
||||
uploadId?: string;
|
||||
uploadedParts?: Array<{ partNumber: number; eTag: string }>;
|
||||
uploadedBytes?: number;
|
||||
eTag?: string;
|
||||
error?: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ObjectStorageUploadSession {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
userId: string;
|
||||
connectionId: string;
|
||||
bucket: string;
|
||||
prefix?: string;
|
||||
conflictPolicy: "overwrite" | "skip" | "error";
|
||||
status: ObjectStorageUploadSessionStatus;
|
||||
items: ObjectStorageUploadSessionItem[];
|
||||
version: number;
|
||||
expiresAt: string;
|
||||
completedAt?: string;
|
||||
cancelledAt?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ObjectStorageUploadSessionSummary {
|
||||
session: ObjectStorageUploadSession;
|
||||
totalBytes: number;
|
||||
processedBytes: number;
|
||||
uploadedBytes: number;
|
||||
successCount: number;
|
||||
skippedCount: number;
|
||||
failedCount: number;
|
||||
pendingCount: number;
|
||||
}
|
||||
|
||||
export interface SemanticLabelDefinition {
|
||||
id: string;
|
||||
name: string;
|
||||
@ -1834,6 +1914,7 @@ export interface AnnotationTaskRecord {
|
||||
coverageMode?: string;
|
||||
templateId: string;
|
||||
templateVersion: number;
|
||||
supplierId?: string;
|
||||
workgroupId: string;
|
||||
vendorId: string;
|
||||
assignedUserId?: string;
|
||||
@ -1931,6 +2012,7 @@ export interface HumanItem {
|
||||
pluginId: string;
|
||||
batchId: string;
|
||||
projectId: string;
|
||||
supplierId?: string;
|
||||
workflowId: string;
|
||||
runId: string;
|
||||
gateNodeId: string;
|
||||
@ -1992,6 +2074,7 @@ export interface DeliveryPackage {
|
||||
organizationId: string;
|
||||
projectId: string;
|
||||
workflowId: string;
|
||||
supplierId?: string;
|
||||
workgroupId?: string;
|
||||
vendorId?: string;
|
||||
parentRunId: string;
|
||||
|
||||
@ -32,7 +32,7 @@ CONFIG_ENV_KEYS = {
|
||||
"DROBOTICFLOW_BUILD_TIME",
|
||||
"DROSYNC_COORDINATOR_IMAGE",
|
||||
"DEPLOY_ENV",
|
||||
"FANYU_V5_ANNOTATION_WORKGROUP_ID",
|
||||
"FANYU_V5_SUPPLIER_ID",
|
||||
"IMAGE_TAG",
|
||||
"K8S_IMAGE_PULL_SECRET_NAME",
|
||||
"K8S_NAMESPACE",
|
||||
@ -147,7 +147,7 @@ def test_render_manifests_allows_empty_optional_global_runtime_config():
|
||||
assert 'BOS_ENDPOINT: ""' in result.stdout
|
||||
assert 'AI_API_BASE_URL: ""' in result.stdout
|
||||
assert 'AI_MODEL: ""' in result.stdout
|
||||
assert 'FANYU_V5_ANNOTATION_WORKGROUP_ID: ""' in result.stdout
|
||||
assert 'FANYU_V5_SUPPLIER_ID: ""' in result.stdout
|
||||
assert 'DROBOTICFLOW_QWEN_NODE_CACHE_ENABLED: "false"' in result.stdout
|
||||
assert 'DROBOTICFLOW_QWEN_NODE_CACHE_PVC: ""' in result.stdout
|
||||
|
||||
@ -175,13 +175,13 @@ def test_render_manifests_rejects_incomplete_enabled_qwen_node_cache():
|
||||
assert_render_validation_failure(result, "DROBOTICFLOW_QWEN_NODE_CACHE_PVC must be a lowercase DNS subdomain")
|
||||
|
||||
|
||||
def test_render_manifests_wires_fanyu_v5_annotation_workgroup_to_api_only():
|
||||
result = run_render_manifests({"FANYU_V5_ANNOTATION_WORKGROUP_ID": "fanyu-v5-poc-vendor-a"})
|
||||
def test_render_manifests_wires_optional_fanyu_supplier_to_api_only():
|
||||
result = run_render_manifests({"FANYU_V5_SUPPLIER_ID": "fanyu-v5-poc-vendor-a"})
|
||||
|
||||
assert result.returncode == 0, result.stderr + result.stdout
|
||||
assert 'FANYU_V5_ANNOTATION_WORKGROUP_ID: "fanyu-v5-poc-vendor-a"' in result.stdout
|
||||
assert "- name: FANYU_V5_ANNOTATION_WORKGROUP_ID" in result.stdout
|
||||
assert "key: FANYU_V5_ANNOTATION_WORKGROUP_ID" in result.stdout
|
||||
assert 'FANYU_V5_SUPPLIER_ID: "fanyu-v5-poc-vendor-a"' in result.stdout
|
||||
assert "- name: FANYU_V5_SUPPLIER_ID" in result.stdout
|
||||
assert "key: FANYU_V5_SUPPLIER_ID" in result.stdout
|
||||
|
||||
|
||||
def test_render_manifests_rejects_invalid_startup_numeric_configuration():
|
||||
|
||||
@ -23,7 +23,7 @@ def values_text(model_root: Path, deb_sha: str, portable_sha: str, model_sha: st
|
||||
f"FANYU_S100_MODE={mode}",
|
||||
"FANYU_REMOTE_API_BASE_URL=https://control.example",
|
||||
"FANYU_REMOTE_BOS_ENDPOINT=https://bos.example",
|
||||
"FANYU_V5_ANNOTATION_WORKGROUP_ID=vendor-a-left-camera",
|
||||
"FANYU_V5_SUPPLIER_ID=vendor-a-left-camera",
|
||||
"FANYU_HEADPOSE_API_BASE_URL=https://headpose.example",
|
||||
f"FANYU_HEADPOSE_SERVICE_IMAGE_ID={digest}",
|
||||
"FANYU_HEADPOSE_MODEL_SHA256=sha256:" + "b" * 64,
|
||||
|
||||
@ -21,16 +21,16 @@ test("annotation workbench separates available, mine, and administrator task poo
|
||||
assert.match(source, /humanLoopApi\.assign/);
|
||||
});
|
||||
|
||||
test("annotation membership exposes the confirmed three-role responsibilities", async () => {
|
||||
test("project members expose the confirmed three-role responsibilities without workgroup assignment", async () => {
|
||||
const [users, operations, roles] = await Promise.all([
|
||||
readFile(usersURL, "utf8"),
|
||||
readFile(operationsURL, "utf8"),
|
||||
readFile(rolesURL, "utf8"),
|
||||
]);
|
||||
assert.match(users, /value="cutter"/);
|
||||
assert.match(operations, /标注员(真实切分 \+ 语义标注)/);
|
||||
assert.match(operations, /审核员(切分 \+ 标注审核)/);
|
||||
assert.match(operations, /最终验收员(整包验收)/);
|
||||
assert.doesNotMatch(users, /选择工作组/);
|
||||
assert.match(operations, /projectsApi\.listMembers/);
|
||||
assert.match(operations, /projectMembers/);
|
||||
assert.match(users, /role: "member"/);
|
||||
assert.match(roles, /value: "cutter"[\s\S]*label: "旧版剪切员(兼容)"/);
|
||||
assert.match(roles, /value: "quality_reviewer"[\s\S]*label: "审核员"/);
|
||||
assert.match(roles, /value: "acceptance_reviewer"[\s\S]*label: "最终验收员"/);
|
||||
|
||||
@ -14,7 +14,7 @@ test("human work uses claim and release pools without manual assignment", async
|
||||
assert.match(source, /humanLoopApi\.claim/);
|
||||
assert.match(source, /humanLoopApi\.release/);
|
||||
assert.match(source, /领取任务/);
|
||||
assert.match(source, /不指定人员、不发送推送/);
|
||||
assert.match(source, /projectsApi\.listMembers/);
|
||||
assert.doesNotMatch(source, /暂不指定标注员/);
|
||||
});
|
||||
|
||||
@ -23,7 +23,7 @@ test("dashboard renders platform vendor and self workforce scopes", async () =>
|
||||
assert.match(source, /供应商团队工作量与质量/);
|
||||
assert.match(source, /我的工作量与质量/);
|
||||
assert.match(source, /WorkforceSummaryPanel/);
|
||||
assert.match(source, /currentUser\.role !== "admin"/);
|
||||
assert.match(source, /isOrganizationAdminRole\(currentUser\?\.role\)/);
|
||||
});
|
||||
|
||||
test("human roles see only their assigned navigation surfaces", async () => {
|
||||
@ -32,13 +32,16 @@ test("human roles see only their assigned navigation surfaces", async () => {
|
||||
assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/);
|
||||
assert.match(
|
||||
registry,
|
||||
/Label: "切分与语义标注"[\s\S]*GroupLabel: "标注中心"[\s\S]*RequiredRoles: \[\]string\{"admin", "annotator"\}/,
|
||||
/Label: "切分与语义标注"[\s\S]*GroupLabel: "标注中心"[\s\S]*RequiredRoles: \[\]string\{"admin", "organization_admin", "member", "annotator"\}/,
|
||||
);
|
||||
assert.match(
|
||||
registry,
|
||||
/Label: "切分与标注审核"[\s\S]*GroupLabel: "标注中心"[\s\S]*RequiredRoles: \[\]string\{"admin", "quality_reviewer"\}/,
|
||||
/Label: "切分与标注审核"[\s\S]*GroupLabel: "标注中心"[\s\S]*RequiredRoles: \[\]string\{"admin", "organization_admin", "member", "quality_reviewer"\}/,
|
||||
);
|
||||
assert.match(
|
||||
registry,
|
||||
/Label: "最终验收"[\s\S]*RequiredRoles: \[\]string\{"admin", "organization_admin", "member", "acceptance_reviewer"\}/,
|
||||
);
|
||||
assert.match(registry, /Label: "最终验收"[\s\S]*RequiredRoles: \[\]string\{"admin", "acceptance_reviewer"\}/);
|
||||
assert.doesNotMatch(registry, /Navigation:[\s\S]*ID: "clip"[\s\S]*Label: "人工剪切"/);
|
||||
assert.doesNotMatch(sidebar, /path: "\/monitoring",\s+roles: \[.*"supplier_manager".*\]/);
|
||||
});
|
||||
|
||||
@ -29,8 +29,14 @@ test("v5.8 annotator reviewer and acceptance roles receive independent workbench
|
||||
const app = await readFile(appURL, "utf8");
|
||||
const registry = await readFile(pluginRegistryURL, "utf8");
|
||||
assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/);
|
||||
assert.match(registry, /Label: "切分与语义标注"[\s\S]*RequiredRoles: \[\]string\{"admin", "annotator"\}/);
|
||||
assert.match(registry, /Label: "最终验收"[\s\S]*RequiredRoles: \[\]string\{"admin", "acceptance_reviewer"\}/);
|
||||
assert.match(
|
||||
registry,
|
||||
/Label: "切分与语义标注"[\s\S]*RequiredRoles: \[\]string\{"admin", "organization_admin", "member", "annotator"\}/,
|
||||
);
|
||||
assert.match(
|
||||
registry,
|
||||
/Label: "最终验收"[\s\S]*RequiredRoles: \[\]string\{"admin", "organization_admin", "member", "acceptance_reviewer"\}/,
|
||||
);
|
||||
assert.match(registry, /GroupID: "annotation-center"[\s\S]*GroupLabel: "标注中心"/);
|
||||
assert.match(app, /effectiveRole === "annotator"[\s\S]*path\.endsWith\("\/annotate"\)/);
|
||||
assert.match(app, /effectiveRole === "acceptance_reviewer"[\s\S]*path\.endsWith\("\/acceptance"\)/);
|
||||
|
||||
@ -104,14 +104,18 @@ test("directory upload task runner bounds concurrency and retains individual fai
|
||||
assert.equal(settled.length, tasks.length);
|
||||
});
|
||||
|
||||
test("directory upload panel exposes directory selection, conflict policy, progress, and failed-only retry", async () => {
|
||||
test("directory upload panel exposes persistent session controls, dual progress, and complete item history", async () => {
|
||||
const source = await readFile(
|
||||
new URL("../../src/components/object-storage/DirectoryUploadPanel.tsx", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
assert.match(source, /webkitdirectory/);
|
||||
assert.match(source, /directory-upload-conflict-policy/);
|
||||
assert.match(source, /总体进度/);
|
||||
assert.match(source, /仅重试失败项/);
|
||||
assert.match(source, /application\/x-directory/);
|
||||
assert.match(source, /可恢复目录上传/);
|
||||
assert.match(source, /处理进度(成功 \+ 跳过)/);
|
||||
assert.match(source, /实际上传流量/);
|
||||
assert.match(source, /pauseUploadSession/);
|
||||
assert.match(source, /resumeUploadSession/);
|
||||
assert.match(source, /cancelUploadSession/);
|
||||
assert.match(source, /导出 CSV/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user