Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
e149f2e8
Commit
e149f2e8
authored
5 years ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Report available thumbnails in media info API
Fixes
https://github.com/turt2live/matrix-media-repo/issues/94
parent
e925fc1a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/unstable/info.go
+34
-6
34 additions, 6 deletions
api/unstable/info.go
with
34 additions
and
6 deletions
api/unstable/info.go
+
34
−
6
View file @
e149f2e8
package
unstable
package
unstable
import
(
import
(
"database/sql"
"net/http"
"net/http"
"strconv"
"strconv"
...
@@ -10,19 +11,27 @@ import (
...
@@ -10,19 +11,27 @@ import (
"github.com/turt2live/matrix-media-repo/api"
"github.com/turt2live/matrix-media-repo/api"
"github.com/turt2live/matrix-media-repo/common"
"github.com/turt2live/matrix-media-repo/common"
"github.com/turt2live/matrix-media-repo/controllers/download_controller"
"github.com/turt2live/matrix-media-repo/controllers/download_controller"
"github.com/turt2live/matrix-media-repo/storage"
)
)
type
mediaInfoHashes
struct
{
type
mediaInfoHashes
struct
{
Sha256
string
`json:"sha256"`
Sha256
string
`json:"sha256"`
}
}
type
mediaInfoThumbnail
struct
{
Width
int
`json:"width"`
Height
int
`json:"height"`
Ready
bool
`json:"ready"`
}
type
MediaInfoResponse
struct
{
type
MediaInfoResponse
struct
{
ContentUri
string
`json:"content_uri"`
ContentUri
string
`json:"content_uri"`
ContentType
string
`json:"content_type"`
ContentType
string
`json:"content_type"`
Width
int
`json:"width,omitempty"`
Width
int
`json:"width,omitempty"`
Height
int
`json:"height,omitempty"`
Height
int
`json:"height,omitempty"`
Size
int64
`json:"size"`
Size
int64
`json:"size"`
Hashes
mediaInfoHashes
`json:"hashes"`
Hashes
mediaInfoHashes
`json:"hashes"`
Thumbnails
[]
*
mediaInfoThumbnail
`json:"thumbnails,omitempty"`
}
}
func
MediaInfo
(
r
*
http
.
Request
,
log
*
logrus
.
Entry
,
user
api
.
UserInfo
)
interface
{}
{
func
MediaInfo
(
r
*
http
.
Request
,
log
*
logrus
.
Entry
,
user
api
.
UserInfo
)
interface
{}
{
...
@@ -76,5 +85,24 @@ func MediaInfo(r *http.Request, log *logrus.Entry, user api.UserInfo) interface{
...
@@ -76,5 +85,24 @@ func MediaInfo(r *http.Request, log *logrus.Entry, user api.UserInfo) interface{
response
.
Height
=
img
.
Bounds
()
.
Max
.
Y
response
.
Height
=
img
.
Bounds
()
.
Max
.
Y
}
}
thumbsDb
:=
storage
.
GetDatabase
()
.
GetThumbnailStore
(
r
.
Context
(),
log
)
thumbs
,
err
:=
thumbsDb
.
GetAllForMedia
(
streamedMedia
.
KnownMedia
.
Origin
,
streamedMedia
.
KnownMedia
.
MediaId
)
if
err
!=
nil
&&
err
!=
sql
.
ErrNoRows
{
log
.
Error
(
"Unexpected error locating media: "
+
err
.
Error
())
return
api
.
InternalServerError
(
"Unexpected Error"
)
}
if
thumbs
!=
nil
&&
len
(
thumbs
)
>
0
{
infoThumbs
:=
make
([]
*
mediaInfoThumbnail
,
0
)
for
_
,
thumb
:=
range
thumbs
{
infoThumbs
=
append
(
infoThumbs
,
&
mediaInfoThumbnail
{
Width
:
thumb
.
Width
,
Height
:
thumb
.
Height
,
Ready
:
true
,
})
}
response
.
Thumbnails
=
infoThumbs
}
return
response
return
response
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment