/
detect_imgmanip.go
46 lines (38 loc) · 1.04 KB
/
detect_imgmanip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cmd
import (
"context"
"log"
"github.com/mediaforensics/medifor/pkg/medifor"
"github.com/spf13/cobra"
)
// detectImgmanipCmd represents the imgmanip command
var detectImgmanipCmd = &cobra.Command{
Use: "imgmanip",
Short: "Send an image manipulation detection request",
Long: `medifor detect imgmanip /path/to/probe`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalf("One image argument required: <probe>")
}
ctx := context.Background()
client := mustClient(ctx)
defer client.Close()
ctx = timeoutFlagCtx(ctx)
detection, err := client.DetectReq(ctx, medifor.NewImageManipulationRequest(args[0],
medifor.WithOutputPrefix(outDir),
medifor.WithDeviceID(devID)))
if err != nil {
if isTimeout(err) {
log.Printf("Detection request timed out, continuing: %v", err)
} else {
log.Fatalf("Failed request: %v", err)
}
}
if err := outputProto(detection); err != nil {
log.Fatalf("Output failed: %v", err)
}
},
}
func init() {
detectCmd.AddCommand(detectImgmanipCmd)
}