@@ 320,23 320,6 @@ func FetchMetaProfile(ctx context.Context, username string, user *AuthContext) e
panic(errors.New("Cannot fetch profile from ourselves"))
}
- type GraphQLProfile struct {
- ID int `json:"id"`
- Username string `json:"username"`
- Email string `json:"email"`
- URL *string `json:"url"`
- Location *string `json:"location"`
- Bio *string `json:"bio"`
- UserType string `json:"userType"`
- SuspensionNotice string `json:"suspensionNotice"`
- }
-
- type GraphQLResponse struct {
- Data struct {
- Me GraphQLProfile `json:"me"`
- } `json:"data"`
- }
-
query := client.GraphQLQuery{
Query: `
query {
@@ 352,13 335,24 @@ func FetchMetaProfile(ctx context.Context, username string, user *AuthContext) e
}`,
}
- var result GraphQLResponse
- if err := client.Execute(ctx, username,
+ var result struct {
+ Me struct {
+ ID int `json:"id"`
+ Username string `json:"username"`
+ Email string `json:"email"`
+ URL *string `json:"url"`
+ Location *string `json:"location"`
+ Bio *string `json:"bio"`
+ UserType string `json:"userType"`
+ SuspensionNotice string `json:"suspensionNotice"`
+ } `json:"me"`
+ }
+ if err := client.Do(ctx, username,
"meta.sr.ht", query, &result); err != nil {
return err
}
- profile := result.Data.Me
+ profile := result.Me
return database.WithTx(ctx, nil, func(tx *sql.Tx) error {
// TODO: Make the database representation consistent with this
ut := strings.ToLower(profile.UserType)
@@ 474,11 468,6 @@ func LookupUser(ctx context.Context, username string, user *AuthContext) error {
// should not be trusted)
func LookupTokenRevocation(ctx context.Context,
username string, hash [64]byte, clientID string) (bool, error) {
- type GraphQLResponse struct {
- Data struct {
- RevocationStatus bool `json:"tokenRevocationStatus"`
- } `json:"data"`
- }
query := client.GraphQLQuery{
Query: `
@@ 491,12 480,14 @@ func LookupTokenRevocation(ctx context.Context,
},
}
- var result GraphQLResponse
- if err := client.Execute(ctx, username,
+ var result struct {
+ RevocationStatus bool `json:"tokenRevocationStatus"`
+ }
+ if err := client.Do(ctx, username,
"meta.sr.ht", query, &result); err != nil {
return true, err
}
- return result.Data.RevocationStatus, nil
+ return result.RevocationStatus, nil
}
func OAuth2(token string, hash [64]byte, w http.ResponseWriter,
@@ 25,7 25,7 @@ type InternalAuth struct {
NodeID string `json:"node_id"`
}
-func Execute(ctx context.Context, username string, svc string,
+func Do(ctx context.Context, username string, svc string,
query GraphQLQuery, result interface{}) error {
body, err := json.Marshal(query)