Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

122 lines
3.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"context"
"fmt"
"strconv"
"time"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/client"
"github.com/hanzoteam/server/server/v8/cmd/mmctl/printer"
"github.com/hanzoteam/server/server/public/model"
"github.com/spf13/cobra"
)
var ExtractCmd = &cobra.Command{
Use: "extract",
Short: "Management of content extraction job.",
}
var ExtractRunCmd = &cobra.Command{
Use: "run",
Example: " extract run",
Short: "Start a content extraction job.",
Args: cobra.NoArgs,
RunE: withClient(extractRunCmdF),
}
var ExtractJobCmd = &cobra.Command{
Use: "job",
Short: "List and show content extraction jobs",
}
var ExtractJobListCmd = &cobra.Command{
Use: "list",
Example: " extract job list",
Short: "List content extraction jobs",
Aliases: []string{"ls"},
Args: cobra.NoArgs,
RunE: withClient(extractJobListCmdF),
}
var ExtractJobShowCmd = &cobra.Command{
Use: "show [extractJobID]",
Example: " extract job show f3d68qkkm7n8xgsfxwuo498rah",
Short: "Show extract job",
Args: cobra.ExactArgs(1),
RunE: withClient(extractJobShowCmdF),
}
func init() {
ExtractRunCmd.Flags().Int64("from", 0, "The timestamp of the earliest file to extract, expressed in seconds since the unix epoch.")
ExtractRunCmd.Flags().Int64("to", 0, "The timestamp of the latest file to extract, expressed in seconds since the unix epoch. Defaults to the current time.")
ExtractJobListCmd.Flags().Int("page", 0, "Page number to fetch for the list of extract jobs")
ExtractJobListCmd.Flags().Int("per-page", DefaultPageSize, "Number of extract jobs to be fetched")
ExtractJobListCmd.Flags().Bool("all", false, "Fetch all extract jobs. --page flag will be ignore if provided")
ExtractJobCmd.AddCommand(
ExtractJobListCmd,
ExtractJobShowCmd,
)
ExtractCmd.AddCommand(
ExtractRunCmd,
ExtractJobCmd,
)
RootCmd.AddCommand(ExtractCmd)
}
func extractRunCmdF(c client.Client, command *cobra.Command, args []string) error {
from, err := command.Flags().GetInt64("from")
if err != nil {
return err
}
to, err := command.Flags().GetInt64("to")
if err != nil {
return err
}
if to == 0 {
to = model.GetMillis() / 1000
}
job, _, err := c.CreateJob(context.TODO(), &model.Job{
Type: model.JobTypeExtractContent,
Data: map[string]string{
"from": strconv.FormatInt(from, 10),
"to": strconv.FormatInt(to, 10),
},
})
if err != nil {
return fmt.Errorf("failed to create content extraction job: %w", err)
}
printer.PrintT("Content extraction job successfully created, ID: {{.Id}}", job)
return nil
}
func extractJobShowCmdF(c client.Client, command *cobra.Command, args []string) error {
job, _, err := c.GetJob(context.TODO(), args[0])
if err != nil {
return fmt.Errorf("failed to get content extraction job: %w", err)
}
printExtractContentJob(job)
return nil
}
func extractJobListCmdF(c client.Client, command *cobra.Command, args []string) error {
return jobListCmdF(c, command, model.JobTypeExtractContent, "")
}
func printExtractContentJob(job *model.Job) {
if job.StartAt > 0 {
printer.PrintT(fmt.Sprintf(" ID: {{.Id}}\n Status: {{.Status}}\n Created: %s\n Started: %s\n Processed: %s\n Errors: %s\n",
time.Unix(job.CreateAt/1000, 0), time.Unix(job.StartAt/1000, 0), job.Data["processed"], job.Data["errors"]), job)
} else {
printer.PrintT(fmt.Sprintf(" ID: {{.Id}}\n Status: {{.Status}}\n Created: %s\n\n",
time.Unix(job.CreateAt/1000, 0)), job)
}
}