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 { MediaDownload struct {
Height func(childComplexity int) int MediaURL func(childComplexity int) int
Title func(childComplexity int) int Title func(childComplexity int) int
URL func(childComplexity int) int
Width func(childComplexity int) int
} }
MediaExif struct { MediaExif struct {
@ -109,9 +107,10 @@ type ComplexityRoot struct {
} }
MediaURL struct { MediaURL struct {
Height func(childComplexity int) int FileSize func(childComplexity int) int
URL func(childComplexity int) int Height func(childComplexity int) int
Width func(childComplexity int) int URL func(childComplexity int) int
Width func(childComplexity int) int
} }
Mutation struct { Mutation struct {
@ -472,12 +471,12 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Media.VideoWeb(childComplexity), true return e.complexity.Media.VideoWeb(childComplexity), true
case "MediaDownload.height": case "MediaDownload.mediaUrl":
if e.complexity.MediaDownload.Height == nil { if e.complexity.MediaDownload.MediaURL == nil {
break break
} }
return e.complexity.MediaDownload.Height(childComplexity), true return e.complexity.MediaDownload.MediaURL(childComplexity), true
case "MediaDownload.title": case "MediaDownload.title":
if e.complexity.MediaDownload.Title == nil { 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 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": case "MediaEXIF.aperture":
if e.complexity.MediaExif.Aperture == nil { if e.complexity.MediaExif.Aperture == nil {
break break
@ -584,6 +569,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.MediaExif.Media(childComplexity), true 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": case "MediaURL.height":
if e.complexity.MediaURL.Height == nil { if e.complexity.MediaURL.Height == nil {
break break
@ -1404,13 +1396,13 @@ type MediaURL {
width: Int! width: Int!
"Height of the image in pixels" "Height of the image in pixels"
height: Int! height: Int!
"The file size of the resource in bytes"
fileSize: Int!
} }
type MediaDownload { type MediaDownload {
title: String! title: String!
width: Int! mediaUrl: MediaURL!
height: Int!
url: String!
} }
enum MediaType { enum MediaType {
@ -2949,7 +2941,7 @@ func (ec *executionContext) _MediaDownload_title(ctx context.Context, field grap
return ec.marshalNString2string(ctx, field.Selections, res) 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() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r)) 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) ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children ctx = rctx // use context from middleware stack in children
return obj.Width, nil return obj.MediaURL, nil
}) })
if err != nil { if err != nil {
ec.Error(ctx, err) ec.Error(ctx, err)
@ -2978,77 +2970,9 @@ func (ec *executionContext) _MediaDownload_width(ctx context.Context, field grap
} }
return graphql.Null return graphql.Null
} }
res := resTmp.(int) res := resTmp.(*models.MediaURL)
fc.Result = res fc.Result = res
return ec.marshalNInt2int(ctx, field.Selections, res) return ec.marshalNMediaURL2ᚖgithubᚗcomᚋviktorstrateᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐMediaURL(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)
} }
func (ec *executionContext) _MediaEXIF_id(ctx context.Context, field graphql.CollectedField, obj *models.MediaEXIF) (ret graphql.Marshaler) { 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) 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) { func (ec *executionContext) _Mutation_authorizeUser(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
defer func() { defer func() {
if r := recover(); r != nil { 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 { if out.Values[i] == graphql.Null {
invalids++ invalids++
} }
case "width": case "mediaUrl":
out.Values[i] = ec._MediaDownload_width(ctx, field, obj) out.Values[i] = ec._MediaDownload_mediaUrl(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)
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
invalids++ invalids++
} }
@ -7407,6 +7355,11 @@ func (ec *executionContext) _MediaURL(ctx context.Context, sel ast.SelectionSet,
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
invalids++ invalids++
} }
case "fileSize":
out.Values[i] = ec._MediaURL_fileSize(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default: default:
panic("unknown field " + strconv.Quote(field.Name)) panic("unknown field " + strconv.Quote(field.Name))
} }

View File

@ -22,10 +22,8 @@ type Filter struct {
} }
type MediaDownload struct { type MediaDownload struct {
Title string `json:"title"` Title string `json:"title"`
Width int `json:"width"` MediaURL *MediaURL `json:"mediaUrl"`
Height int `json:"height"`
URL string `json:"url"`
} }
type Notification struct { 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{ downloads = append(downloads, &models.MediaDownload{
Title: title, Title: title,
Width: url.Width, MediaURL: url,
Height: url.Height,
URL: url.URL(),
}) })
} }

View File

@ -189,13 +189,13 @@ type MediaURL {
width: Int! width: Int!
"Height of the image in pixels" "Height of the image in pixels"
height: Int! height: Int!
"The file size of the resource in bytes"
fileSize: Int!
} }
type MediaDownload { type MediaDownload {
title: String! title: String!
width: Int! mediaUrl: MediaURL!
height: Int!
url: String!
} }
enum MediaType { enum MediaType {

View File

@ -14,9 +14,12 @@ const downloadQuery = gql`
id id
downloads { downloads {
title title
url mediaUrl {
width url
height width
height
fileSize
}
} }
} }
} }
@ -171,10 +174,14 @@ const SidebarDownload = ({ photo }) => {
} }
let downloadRows = downloads.map(x => ( 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.title}`}</Table.Cell>
<Table.Cell>{`${x.width} x ${x.height}`}</Table.Cell> <Table.Cell>{`${x.mediaUrl.width} x ${x.mediaUrl.height}`}</Table.Cell>
<Table.Cell>{extractExtension(x.url)}</Table.Cell> <Table.Cell>{`${formatBytes(x.mediaUrl.fileSize)}`}</Table.Cell>
<Table.Cell>{extractExtension(x.mediaUrl.url)}</Table.Cell>
</DownloadTableRow> </DownloadTableRow>
)) ))
@ -187,6 +194,7 @@ const SidebarDownload = ({ photo }) => {
<Table.Row> <Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell> <Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Dimensions</Table.HeaderCell> <Table.HeaderCell>Dimensions</Table.HeaderCell>
<Table.HeaderCell>Size</Table.HeaderCell>
<Table.HeaderCell>Type</Table.HeaderCell> <Table.HeaderCell>Type</Table.HeaderCell>
</Table.Row> </Table.Row>
</Table.Header> </Table.Header>