-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
action_attach_local_content_by_search.go
42 lines (35 loc) · 1.27 KB
/
action_attach_local_content_by_search.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
package classifier
import (
"github.com/bitmagnet-io/bitmagnet/internal/classifier/classification"
)
const attachLocalContentBySearchName = "attach_local_content_by_search"
type attachLocalContentBySearchAction struct{}
func (attachLocalContentBySearchAction) name() string {
return attachLocalContentBySearchName
}
var attachLocalContentBySearchPayloadSpec = payloadLiteral[string]{
literal: attachLocalContentBySearchName,
description: "Attempt to attach local content with a search on the torrent name",
}
func (a attachLocalContentBySearchAction) compileAction(ctx compilerContext) (action, error) {
if _, err := attachLocalContentBySearchPayloadSpec.Unmarshal(ctx); err != nil {
return action{}, ctx.error(err)
}
return action{
run: func(ctx executionContext) (classification.Result, error) {
cl := ctx.result
if !cl.ContentType.Valid || !cl.BaseTitle.Valid {
return cl, classification.ErrUnmatched
}
content, err := ctx.search.ContentBySearch(ctx.Context, cl.ContentType.ContentType, cl.BaseTitle.String, cl.Date.Year)
if err != nil {
return cl, err
}
cl.AttachContent(&content)
return cl, nil
},
}, nil
}
func (attachLocalContentBySearchAction) JsonSchema() JsonSchema {
return attachLocalContentBySearchPayloadSpec.JsonSchema()
}