Add GET /api/v1/character/details with each image's change time
Returns every character image with when it was last changed, in Unix seconds, so clients can cache the images and download only the ones that changed.
This commit is contained in:
1 parent
76a1b946eb
commit
c62b65d7cd
5 files changed
+72
No files matched your search
@@ -167,6 +167,16 @@ func TestCharacterEndpoints(t *testing.T) {
|
||||
require.NoError(t, json.Unmarshal(e.do(http.MethodGet, "/api/v1/character/list").Body.Bytes(), &list))
|
||||
assert.Equal(t, []string{"Adol.png", "Aloy.jpg"}, list)
|
||||
|
||||
var details []struct {
|
||||
Name string `json:"name"`
|
||||
Modified int64 `json:"modified"`
|
||||
}
|
||||
require.NoError(t, json.Unmarshal(e.do(http.MethodGet, "/api/v1/character/details").Body.Bytes(), &details))
|
||||
require.Len(t, details, 2)
|
||||
assert.Equal(t, "Adol.png", details[0].Name)
|
||||
assert.Equal(t, "Aloy.jpg", details[1].Name)
|
||||
assert.Positive(t, details[0].Modified)
|
||||
|
||||
rec := e.do(http.MethodGet, "/api/v1/character?name=Adol.png")
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
assert.Equal(t, "image/png", rec.Header().Get("Content-Type"))
|
||||
|
||||
@@ -57,6 +57,12 @@ func (s *Server) registerMisc(a huma.API) {
|
||||
func(ctx context.Context, _ *struct{}) (*jsonBody[[]string], error) {
|
||||
return ok(s.characters.List())
|
||||
})
|
||||
register(s, a, route{op: get("list-character-details", "/character/details", "characters",
|
||||
"List characters with change times",
|
||||
"Returns every character image with the time it was last changed, so clients can cache images and download only the changed ones.")},
|
||||
func(ctx context.Context, _ *struct{}) (*jsonBody[[]backend.CharacterDetails], error) {
|
||||
return ok(s.characters.ListDetails())
|
||||
})
|
||||
image := get("get-character", "/character", "characters", "Character image",
|
||||
"Returns a character image.", http.StatusBadRequest, http.StatusNotFound)
|
||||
image.Responses = fileResponses("The image", "image/png", "image/jpeg")
|
||||
|
||||
@@ -76,6 +76,7 @@ func TestOpenAPIDocumentsTheV1API(t *testing.T) {
|
||||
assert.Equal(t, []string{
|
||||
"DELETE /api/v1/token",
|
||||
"GET /api/v1/character",
|
||||
"GET /api/v1/character/details",
|
||||
"GET /api/v1/character/list",
|
||||
"GET /api/v1/download",
|
||||
"GET /api/v1/download/linux",
|
||||
@@ -207,6 +208,7 @@ func TestResponsesMatchOpenAPI(t *testing.T) {
|
||||
|
||||
// Characters, downloads, server info.
|
||||
v.check(http.MethodGet, "/api/v1/character/list", "", http.StatusOK)
|
||||
v.check(http.MethodGet, "/api/v1/character/details", "", http.StatusOK)
|
||||
v.check(http.MethodGet, "/api/v1/character?name=Aloy.jpg", "", http.StatusOK)
|
||||
v.check(http.MethodGet, "/api/v1/character?name=../secret.png", "", http.StatusBadRequest)
|
||||
v.check(http.MethodGet, "/api/v1/character?name=Missing.png", "", http.StatusNotFound)
|
||||
|
||||
Reference in new issue
Block a user