Implement review suggestions

This commit is contained in:
Daniel
2023-11-16 13:54:04 +01:00
parent 602db080c5
commit 7751f57874
2 changed files with 6 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ func registerAPIEndpoints() error {
if err := api.RegisterEndpoint(api.Endpoint{ if err := api.RegisterEndpoint(api.Endpoint{
Name: "Update Profile Icon", Name: "Update Profile Icon",
Description: "Merge multiple profiles into a new one.", Description: "Updates a profile icon.",
Path: "profile/icon/update", Path: "profile/icon/update",
Write: api.PermitUser, Write: api.PermitUser,
BelongsTo: module, BelongsTo: module,

View File

@@ -48,7 +48,7 @@ type ProfileIcon struct {
Value string `json:"value"` Value string `json:"value"`
} }
// ProfileIcon represents a profile fingerprint. // ProfileFingerprint represents a profile fingerprint.
type ProfileFingerprint struct { type ProfileFingerprint struct {
Type string `json:"type"` Type string `json:"type"`
Key string `json:"key,omitempty"` Key string `json:"key,omitempty"`
@@ -165,12 +165,12 @@ func handleExportProfile(ar *api.Request) (data []byte, err error) {
} }
func handleImportProfile(ar *api.Request) (any, error) { func handleImportProfile(ar *api.Request) (any, error) {
var request *ProfileImportRequest var request ProfileImportRequest
// Get parameters. // Get parameters.
q := ar.URL.Query() q := ar.URL.Query()
if len(q) > 0 { if len(q) > 0 {
request = &ProfileImportRequest{ request = ProfileImportRequest{
ImportRequest: ImportRequest{ ImportRequest: ImportRequest{
ValidateOnly: q.Has("validate"), ValidateOnly: q.Has("validate"),
RawExport: string(ar.InputData), RawExport: string(ar.InputData),
@@ -180,8 +180,7 @@ func handleImportProfile(ar *api.Request) (any, error) {
AllowReplace: q.Has("allowReplace"), AllowReplace: q.Has("allowReplace"),
} }
} else { } else {
request = &ProfileImportRequest{} if err := json.Unmarshal(ar.InputData, &request); err != nil {
if err := json.Unmarshal(ar.InputData, request); err != nil {
return nil, fmt.Errorf("%w: failed to parse import request: %w", ErrInvalidImportRequest, err) return nil, fmt.Errorf("%w: failed to parse import request: %w", ErrInvalidImportRequest, err)
} }
} }
@@ -204,7 +203,7 @@ func handleImportProfile(ar *api.Request) (any, error) {
} }
// Import. // Import.
return ImportProfile(request, profile.SourceLocal) return ImportProfile(&request, profile.SourceLocal)
} }
// ExportProfile exports a profile. // ExportProfile exports a profile.