diff --git a/api/graphql/generated.go b/api/graphql/generated.go index 73b98a48..e93dcfec 100644 --- a/api/graphql/generated.go +++ b/api/graphql/generated.go @@ -87,10 +87,8 @@ type ComplexityRoot struct { } MediaDownload struct { - Height func(childComplexity int) int - Title func(childComplexity int) int - URL func(childComplexity int) int - Width func(childComplexity int) int + MediaURL func(childComplexity int) int + Title func(childComplexity int) int } MediaExif struct { @@ -109,9 +107,10 @@ type ComplexityRoot struct { } MediaURL struct { - Height func(childComplexity int) int - URL func(childComplexity int) int - Width func(childComplexity int) int + FileSize func(childComplexity int) int + Height func(childComplexity int) int + URL func(childComplexity int) int + Width func(childComplexity int) int } Mutation struct { @@ -472,12 +471,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Media.VideoWeb(childComplexity), true - case "MediaDownload.height": - if e.complexity.MediaDownload.Height == nil { + case "MediaDownload.mediaUrl": + if e.complexity.MediaDownload.MediaURL == nil { break } - return e.complexity.MediaDownload.Height(childComplexity), true + return e.complexity.MediaDownload.MediaURL(childComplexity), true case "MediaDownload.title": if e.complexity.MediaDownload.Title == nil { @@ -486,20 +485,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MediaDownload.Title(childComplexity), true - case "MediaDownload.url": - if e.complexity.MediaDownload.URL == nil { - break - } - - return e.complexity.MediaDownload.URL(childComplexity), true - - case "MediaDownload.width": - if e.complexity.MediaDownload.Width == nil { - break - } - - return e.complexity.MediaDownload.Width(childComplexity), true - case "MediaEXIF.aperture": if e.complexity.MediaExif.Aperture == nil { break @@ -584,6 +569,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MediaExif.Media(childComplexity), true + case "MediaURL.fileSize": + if e.complexity.MediaURL.FileSize == nil { + break + } + + return e.complexity.MediaURL.FileSize(childComplexity), true + case "MediaURL.height": if e.complexity.MediaURL.Height == nil { break @@ -1404,13 +1396,13 @@ type MediaURL { width: Int! "Height of the image in pixels" height: Int! + "The file size of the resource in bytes" + fileSize: Int! } type MediaDownload { title: String! - width: Int! - height: Int! - url: String! + mediaUrl: MediaURL! } enum MediaType { @@ -2949,7 +2941,7 @@ func (ec *executionContext) _MediaDownload_title(ctx context.Context, field grap return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _MediaDownload_width(ctx context.Context, field graphql.CollectedField, obj *models.MediaDownload) (ret graphql.Marshaler) { +func (ec *executionContext) _MediaDownload_mediaUrl(ctx context.Context, field graphql.CollectedField, obj *models.MediaDownload) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2966,7 +2958,7 @@ func (ec *executionContext) _MediaDownload_width(ctx context.Context, field grap ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Width, nil + return obj.MediaURL, nil }) if err != nil { ec.Error(ctx, err) @@ -2978,77 +2970,9 @@ func (ec *executionContext) _MediaDownload_width(ctx context.Context, field grap } return graphql.Null } - res := resTmp.(int) + res := resTmp.(*models.MediaURL) fc.Result = res - return ec.marshalNInt2int(ctx, field.Selections, res) -} - -func (ec *executionContext) _MediaDownload_height(ctx context.Context, field graphql.CollectedField, obj *models.MediaDownload) (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - fc := &graphql.FieldContext{ - Object: "MediaDownload", - Field: field, - Args: nil, - IsMethod: false, - } - - ctx = graphql.WithFieldContext(ctx, fc) - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.Height, nil - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(int) - fc.Result = res - return ec.marshalNInt2int(ctx, field.Selections, res) -} - -func (ec *executionContext) _MediaDownload_url(ctx context.Context, field graphql.CollectedField, obj *models.MediaDownload) (ret graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - fc := &graphql.FieldContext{ - Object: "MediaDownload", - Field: field, - Args: nil, - IsMethod: false, - } - - ctx = graphql.WithFieldContext(ctx, fc) - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.URL, nil - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } - return graphql.Null - } - res := resTmp.(string) - fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNMediaURL2ᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐMediaURL(ctx, field.Selections, res) } func (ec *executionContext) _MediaEXIF_id(ctx context.Context, field graphql.CollectedField, obj *models.MediaEXIF) (ret graphql.Marshaler) { @@ -3531,6 +3455,40 @@ func (ec *executionContext) _MediaURL_height(ctx context.Context, field graphql. return ec.marshalNInt2int(ctx, field.Selections, res) } +func (ec *executionContext) _MediaURL_fileSize(ctx context.Context, field graphql.CollectedField, obj *models.MediaURL) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "MediaURL", + Field: field, + Args: nil, + IsMethod: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.FileSize, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + func (ec *executionContext) _Mutation_authorizeUser(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -7303,18 +7261,8 @@ func (ec *executionContext) _MediaDownload(ctx context.Context, sel ast.Selectio if out.Values[i] == graphql.Null { invalids++ } - case "width": - out.Values[i] = ec._MediaDownload_width(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalids++ - } - case "height": - out.Values[i] = ec._MediaDownload_height(ctx, field, obj) - if out.Values[i] == graphql.Null { - invalids++ - } - case "url": - out.Values[i] = ec._MediaDownload_url(ctx, field, obj) + case "mediaUrl": + out.Values[i] = ec._MediaDownload_mediaUrl(ctx, field, obj) if out.Values[i] == graphql.Null { invalids++ } @@ -7407,6 +7355,11 @@ func (ec *executionContext) _MediaURL(ctx context.Context, sel ast.SelectionSet, if out.Values[i] == graphql.Null { invalids++ } + case "fileSize": + out.Values[i] = ec._MediaURL_fileSize(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } diff --git a/api/graphql/models/generated.go b/api/graphql/models/generated.go index 3bc6566d..6db22645 100644 --- a/api/graphql/models/generated.go +++ b/api/graphql/models/generated.go @@ -22,10 +22,8 @@ type Filter struct { } type MediaDownload struct { - Title string `json:"title"` - Width int `json:"width"` - Height int `json:"height"` - URL string `json:"url"` + Title string `json:"title"` + MediaURL *MediaURL `json:"mediaUrl"` } type Notification struct { diff --git a/api/graphql/resolvers/media.go b/api/graphql/resolvers/media.go index de4dffcd..7d7f5331 100644 --- a/api/graphql/resolvers/media.go +++ b/api/graphql/resolvers/media.go @@ -108,10 +108,8 @@ func (r *mediaResolver) Downloads(ctx context.Context, obj *models.Media) ([]*mo } downloads = append(downloads, &models.MediaDownload{ - Title: title, - Width: url.Width, - Height: url.Height, - URL: url.URL(), + Title: title, + MediaURL: url, }) } diff --git a/api/graphql/schema.graphql b/api/graphql/schema.graphql index 6c44e542..2a781bfc 100644 --- a/api/graphql/schema.graphql +++ b/api/graphql/schema.graphql @@ -189,13 +189,13 @@ type MediaURL { width: Int! "Height of the image in pixels" height: Int! + "The file size of the resource in bytes" + fileSize: Int! } type MediaDownload { title: String! - width: Int! - height: Int! - url: String! + mediaUrl: MediaURL! } enum MediaType { diff --git a/ui/src/components/sidebar/SidebarDownload.js b/ui/src/components/sidebar/SidebarDownload.js index 71ce882e..b8929712 100644 --- a/ui/src/components/sidebar/SidebarDownload.js +++ b/ui/src/components/sidebar/SidebarDownload.js @@ -14,9 +14,12 @@ const downloadQuery = gql` id downloads { title - url - width - height + mediaUrl { + url + width + height + fileSize + } } } } @@ -171,10 +174,14 @@ const SidebarDownload = ({ photo }) => { } let downloadRows = downloads.map(x => ( - downloadPhoto(x.url)}> + downloadPhoto(x.mediaUrl.url)} + > {`${x.title}`} - {`${x.width} x ${x.height}`} - {extractExtension(x.url)} + {`${x.mediaUrl.width} x ${x.mediaUrl.height}`} + {`${formatBytes(x.mediaUrl.fileSize)}`} + {extractExtension(x.mediaUrl.url)} )) @@ -187,6 +194,7 @@ const SidebarDownload = ({ photo }) => { Name Dimensions + Size Type