mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 22:26:15 -06:00
some more fiddling
This commit is contained in:
parent
3641d47e7e
commit
11d64db5a3
2 changed files with 20 additions and 15 deletions
|
|
@ -20,22 +20,23 @@ package trans
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
"encoding"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
transmodel "github.com/superseriousbusiness/gotosocial/internal/trans/model"
|
transmodel "github.com/superseriousbusiness/gotosocial/internal/trans/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func accountDecode(e transmodel.TransEntry) (*transmodel.Account, error) {
|
func (i *importer) accountDecode(e transmodel.TransEntry) (*transmodel.Account, error) {
|
||||||
a := &transmodel.Account{}
|
a := &transmodel.Account{}
|
||||||
|
|
||||||
decoderConfig := &mapstructure.DecoderConfig{
|
decoderConfig := &mapstructure.DecoderConfig{
|
||||||
DecodeHook: mapstructure.ComposeDecodeHookFunc(
|
DecodeHook: mapstructure.ComposeDecodeHookFunc(
|
||||||
mapstructure.StringToTimeHookFunc(time.RFC3339),
|
mapstructure.StringToTimeHookFunc(time.RFC3339),
|
||||||
PrivateKeyHookFunc(),
|
keyHookFunc(i.log),
|
||||||
),
|
),
|
||||||
Result: a,
|
Result: a,
|
||||||
}
|
}
|
||||||
|
|
@ -51,16 +52,20 @@ func accountDecode(e transmodel.TransEntry) (*transmodel.Account, error) {
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var PrivateKeyHookFunc mapstructure.DecodeHookFunc = func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
|
func keyHookFunc(log *logrus.Logger) mapstructure.DecodeHookFunc {
|
||||||
if t != reflect.TypeOf(rsa.PrivateKey{}) {
|
return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
|
||||||
return data, nil
|
if t != reflect.TypeOf(rsa.PrivateKey{}) {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
result := reflect.New(t).Interface()
|
||||||
|
unmarshaller, ok := result.(encoding.BinaryUnmarshaler)
|
||||||
|
if !ok {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
if err := unmarshaller.UnmarshalBinary([]byte(data.(string))); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rsa.
|
|
||||||
|
|
||||||
// Convert it by parsing
|
|
||||||
_, net, err := net.ParseCIDR(data.(string))
|
|
||||||
return net, err
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func (i *importer) inputEntry(ctx context.Context, entry transmodel.TransEntry)
|
||||||
|
|
||||||
switch transmodel.TransType(t) {
|
switch transmodel.TransType(t) {
|
||||||
case transmodel.TransAccount:
|
case transmodel.TransAccount:
|
||||||
account, err := accountDecode(entry)
|
account, err := i.accountDecode(entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("inputEntry: error decoding entry into account: %s", err)
|
return fmt.Errorf("inputEntry: error decoding entry into account: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue