diff --git a/backend/app/rest/api/rest_public.go b/backend/app/rest/api/rest_public.go index e1dabc89..16ca2527 100644 --- a/backend/app/rest/api/rest_public.go +++ b/backend/app/rest/api/rest_public.go @@ -135,9 +135,9 @@ func (s *public) previewCommentCtrl(w http.ResponseWriter, r *http.Request) { // check if images are valid for _, id := range s.imageService.ExtractPictures(comment.Text) { - _, err = s.imageService.Load(id) + err = s.imageService.ResetCleanupTimer(id) if err != nil { - rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't load picture from the comment", rest.ErrImgNotFound) + rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't renew staged picture cleanup timer", rest.ErrImgNotFound) return } } diff --git a/backend/app/rest/api/rest_public_test.go b/backend/app/rest/api/rest_public_test.go index 39326c12..0e17575c 100644 --- a/backend/app/rest/api/rest_public_test.go +++ b/backend/app/rest/api/rest_public_test.go @@ -28,7 +28,7 @@ func TestRest_Ping(t *testing.T) { } func TestRest_Preview(t *testing.T) { - ts, _, teardown := startupT(t) + ts, srv, teardown := startupT(t) defer teardown() resp, err := post(t, ts.URL+"/api/v1/preview", `{"text": "test 123", "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`) @@ -43,6 +43,23 @@ func TestRest_Preview(t *testing.T) { assert.NoError(t, err) assert.NoError(t, resp.Body.Close()) assert.Equal(t, 400, resp.StatusCode) + + resp, err = post(t, ts.URL+"/api/v1/preview", fmt.Sprintf(`{"text": "![non-existent.jpg](%s/api/v1/picture/dev_user/bad_picture)", "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`, srv.RemarkURL)) + assert.NoError(t, err) + assert.Equal(t, http.StatusBadRequest, resp.StatusCode) + b, err = ioutil.ReadAll(resp.Body) + assert.NoError(t, err) + assert.NoError(t, resp.Body.Close()) + assert.Contains(t, + string(b), + "{\"code\":20,\"details\":\"can't renew staged picture cleanup timer\","+ + "\"error\":\"can't get image stats for dev_user/bad_picture: stat", + ) + assert.Contains(t, + string(b), + "/pics-remark42/staging/dev_user/62/bad_picture: no such file or directory\"}\n", + ) + } func TestRest_PreviewWithWrongImage(t *testing.T) { @@ -57,8 +74,8 @@ func TestRest_PreviewWithWrongImage(t *testing.T) { assert.NoError(t, resp.Body.Close()) assert.Contains(t, string(b), - "{\"code\":20,\"details\":\"can't load picture from the comment\","+ - "\"error\":\"can't get image file for dev_user/bad_picture: can't get image stats for dev_user/bad_picture: stat ", + "{\"code\":20,\"details\":\"can't renew staged picture cleanup timer\","+ + "\"error\":\"can't get image stats for dev_user/bad_picture: stat ", ) assert.Contains(t, string(b), diff --git a/backend/app/store/image/image.go b/backend/app/store/image/image.go index 52decdce..9632fdde 100644 --- a/backend/app/store/image/image.go +++ b/backend/app/store/image/image.go @@ -193,6 +193,11 @@ func (s *Service) Cleanup(ctx context.Context) { } } +// ResetCleanupTimer resets cleanup timer for the image +func (s *Service) ResetCleanupTimer(id string) error { + return s.store.ResetCleanupTimer(id) +} + // Info returns meta information about storage func (s *Service) Info() (StoreInfo, error) { return s.store.Info()