1
Fork 0

Show file size for media downloads

This closes #63
This commit is contained in:
viktorstrate 2020-08-11 22:34:42 +02:00
parent 849f2f25bf
commit 020321959d
5 changed files with 85 additions and 128 deletions

View File

@ -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))
}

View File

@ -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 {

View File

@ -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,
})
}

View File

@ -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 {

View File

@ -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 => (
<DownloadTableRow key={x.url} onClick={() => downloadPhoto(x.url)}>
<DownloadTableRow
key={x.mediaUrl.url}
onClick={() => downloadPhoto(x.mediaUrl.url)}
>
<Table.Cell>{`${x.title}`}</Table.Cell>
<Table.Cell>{`${x.width} x ${x.height}`}</Table.Cell>
<Table.Cell>{extractExtension(x.url)}</Table.Cell>
<Table.Cell>{`${x.mediaUrl.width} x ${x.mediaUrl.height}`}</Table.Cell>
<Table.Cell>{`${formatBytes(x.mediaUrl.fileSize)}`}</Table.Cell>
<Table.Cell>{extractExtension(x.mediaUrl.url)}</Table.Cell>
</DownloadTableRow>
))
@ -187,6 +194,7 @@ const SidebarDownload = ({ photo }) => {
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Dimensions</Table.HeaderCell>
<Table.HeaderCell>Size</Table.HeaderCell>
<Table.HeaderCell>Type</Table.HeaderCell>
</Table.Row>
</Table.Header>