forked from stashapp/stash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for disabling plugins (stashapp#4141)
* Move timestamp to own file * Backend changes * UI changes
- Loading branch information
1 parent
ec0db30
commit 6127fb8
Showing
18 changed files
with
260 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ scalar Timestamp | |
# generic JSON object | ||
scalar Map | ||
|
||
# string, boolean map | ||
scalar BoolMap | ||
|
||
scalar Any | ||
|
||
scalar Int64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/99designs/gqlgen/graphql" | ||
) | ||
|
||
func MarshalBoolMap(val map[string]bool) graphql.Marshaler { | ||
return graphql.WriterFunc(func(w io.Writer) { | ||
err := json.NewEncoder(w).Encode(val) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}) | ||
} | ||
|
||
func UnmarshalBoolMap(v interface{}) (map[string]bool, error) { | ||
m, ok := v.(map[string]interface{}) | ||
if !ok { | ||
return nil, fmt.Errorf("%T is not a map", v) | ||
} | ||
|
||
result := make(map[string]bool) | ||
for k, v := range m { | ||
key := k | ||
val, ok := v.(bool) | ||
if !ok { | ||
return nil, fmt.Errorf("key %s (%T) is not a bool", k, v) | ||
} | ||
|
||
result[key] = val | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/99designs/gqlgen/graphql" | ||
"github.com/stashapp/stash/pkg/logger" | ||
"github.com/stashapp/stash/pkg/models" | ||
"github.com/stashapp/stash/pkg/utils" | ||
) | ||
|
||
type BaseFile interface{} | ||
|
||
type GalleryFile struct { | ||
*models.BaseFile | ||
} | ||
|
||
var ErrTimestamp = errors.New("cannot parse Timestamp") | ||
|
||
func MarshalTimestamp(t time.Time) graphql.Marshaler { | ||
if t.IsZero() { | ||
return graphql.Null | ||
} | ||
|
||
return graphql.WriterFunc(func(w io.Writer) { | ||
_, err := io.WriteString(w, strconv.Quote(t.Format(time.RFC3339Nano))) | ||
if err != nil { | ||
logger.Warnf("could not marshal timestamp: %v", err) | ||
} | ||
}) | ||
} | ||
|
||
func UnmarshalTimestamp(v interface{}) (time.Time, error) { | ||
if tmpStr, ok := v.(string); ok { | ||
if len(tmpStr) == 0 { | ||
return time.Time{}, fmt.Errorf("%w: empty string", ErrTimestamp) | ||
} | ||
|
||
switch tmpStr[0] { | ||
case '>', '<': | ||
d, err := time.ParseDuration(tmpStr[1:]) | ||
if err != nil { | ||
return time.Time{}, fmt.Errorf("%w: cannot parse %v-duration: %v", ErrTimestamp, tmpStr[0], err) | ||
} | ||
t := time.Now() | ||
// Compute point in time: | ||
if tmpStr[0] == '<' { | ||
t = t.Add(-d) | ||
} else { | ||
t = t.Add(d) | ||
} | ||
|
||
return t, nil | ||
} | ||
|
||
return utils.ParseDateStringAsTime(tmpStr) | ||
} | ||
|
||
return time.Time{}, fmt.Errorf("%w: not a string", ErrTimestamp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package api | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/99designs/gqlgen/graphql" | ||
"github.com/stashapp/stash/pkg/logger" | ||
"github.com/stashapp/stash/pkg/utils" | ||
) | ||
|
||
var ErrTimestamp = errors.New("cannot parse Timestamp") | ||
|
||
func MarshalTimestamp(t time.Time) graphql.Marshaler { | ||
if t.IsZero() { | ||
return graphql.Null | ||
} | ||
|
||
return graphql.WriterFunc(func(w io.Writer) { | ||
_, err := io.WriteString(w, strconv.Quote(t.Format(time.RFC3339Nano))) | ||
if err != nil { | ||
logger.Warnf("could not marshal timestamp: %v", err) | ||
} | ||
}) | ||
} | ||
|
||
func UnmarshalTimestamp(v interface{}) (time.Time, error) { | ||
if tmpStr, ok := v.(string); ok { | ||
if len(tmpStr) == 0 { | ||
return time.Time{}, fmt.Errorf("%w: empty string", ErrTimestamp) | ||
} | ||
|
||
switch tmpStr[0] { | ||
case '>', '<': | ||
d, err := time.ParseDuration(tmpStr[1:]) | ||
if err != nil { | ||
return time.Time{}, fmt.Errorf("%w: cannot parse %v-duration: %v", ErrTimestamp, tmpStr[0], err) | ||
} | ||
t := time.Now() | ||
// Compute point in time: | ||
if tmpStr[0] == '<' { | ||
t = t.Add(-d) | ||
} else { | ||
t = t.Add(d) | ||
} | ||
|
||
return t, nil | ||
} | ||
|
||
return utils.ParseDateStringAsTime(tmpStr) | ||
} | ||
|
||
return time.Time{}, fmt.Errorf("%w: not a string", ErrTimestamp) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.