Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1616f43f0c | ||
|
|
cc49ee0946 | ||
|
|
a9a368e02d |
@@ -238,6 +238,7 @@ func (s *ServerCommand) newServerApp() (*serverApp, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to make pictures store")
|
return nil, errors.Wrap(err, "failed to make pictures store")
|
||||||
}
|
}
|
||||||
|
log.Printf("[DEBUG] image service for url=%s, ttl=%v", imageService.ImageAPI, imageService.TTL)
|
||||||
|
|
||||||
dataService := &service.DataStore{
|
dataService := &service.DataStore{
|
||||||
Interface: storeEngine,
|
Interface: storeEngine,
|
||||||
@@ -453,7 +454,8 @@ func (s *ServerCommand) makePicturesStore() (*image.Service, error) {
|
|||||||
MaxHeight: s.Image.ResizeHeight,
|
MaxHeight: s.Image.ResizeHeight,
|
||||||
MaxWidth: s.Image.ResizeWidth,
|
MaxWidth: s.Image.ResizeWidth,
|
||||||
},
|
},
|
||||||
TTL: s.EditDuration + time.Second, // add extra second to image TTL for staging
|
ImageAPI: s.RemarkURL + "/api/v1/picture/",
|
||||||
|
TTL: s.EditDuration + time.Second, // add extra second to image TTL for staging
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return nil, errors.Errorf("unsupported pictures store type %s", s.Image.Type)
|
return nil, errors.Errorf("unsupported pictures store type %s", s.Image.Type)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ func (w *WordPress) convert(r io.Reader, siteID string) chan store.Comment {
|
|||||||
commentsCh <- commentFormatter.Format(c)
|
commentsCh <- commentFormatter.Format(c)
|
||||||
stats.inpComments++
|
stats.inpComments++
|
||||||
if stats.inpComments%1000 == 0 {
|
if stats.inpComments%1000 == 0 {
|
||||||
log.Printf("[DEBUG] proccessed %d comments", stats.inpComments)
|
log.Printf("[DEBUG] processed %d comments", stats.inpComments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
func TestWordPress_Import(t *testing.T) {
|
func TestWordPress_Import(t *testing.T) {
|
||||||
siteID := "testWP"
|
siteID := "testWP"
|
||||||
defer os.Remove("/tmp/remark-test.db")
|
defer func() { _ = os.Remove("/tmp/remark-test.db") }()
|
||||||
b, err := engine.NewBoltDB(bolt.Options{}, engine.BoltSite{FileName: "/tmp/remark-test.db", SiteID: siteID})
|
b, err := engine.NewBoltDB(bolt.Options{}, engine.BoltSite{FileName: "/tmp/remark-test.db", SiteID: siteID})
|
||||||
assert.Nil(t, err, "create store")
|
assert.Nil(t, err, "create store")
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ func (f *FileSystem) Cleanup(ctx context.Context, ttl time.Duration) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := filepath.Walk(f.Staging, func(path string, info os.FileInfo, err error) error {
|
err := filepath.Walk(f.Staging, func(fpath string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -131,8 +131,10 @@ func (f *FileSystem) Cleanup(ctx context.Context, ttl time.Duration) error {
|
|||||||
}
|
}
|
||||||
age := time.Since(info.ModTime())
|
age := time.Since(info.ModTime())
|
||||||
if age > ttl {
|
if age > ttl {
|
||||||
log.Printf("[INFO] remove staging image %s, age %v", path, age)
|
log.Printf("[INFO] remove staging image %s, age %v", fpath, age)
|
||||||
return os.Remove(path)
|
rmErr := os.Remove(fpath)
|
||||||
|
_ = os.Remove(path.Dir(fpath)) // try to remove directory
|
||||||
|
return rmErr
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -268,6 +269,9 @@ func TestFsStore_Cleanup(t *testing.T) {
|
|||||||
|
|
||||||
_, err = os.Stat(img1)
|
_, err = os.Stat(img1)
|
||||||
assert.NotNil(t, err, "no file on staging anymore")
|
assert.NotNil(t, err, "no file on staging anymore")
|
||||||
|
_, err = os.Stat(path.Dir(img1))
|
||||||
|
assert.NotNil(t, err, "no dir %s on staging anymore", path.Dir(img1))
|
||||||
|
|
||||||
_, err = os.Stat(img2)
|
_, err = os.Stat(img2)
|
||||||
assert.NoError(t, err, "file on staging")
|
assert.NoError(t, err, "file on staging")
|
||||||
_, err = os.Stat(img3)
|
_, err = os.Stat(img3)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
func TestService_ExtractPictures(t *testing.T) {
|
func TestService_ExtractPictures(t *testing.T) {
|
||||||
svc := Service{ImageAPI: "/blah/"}
|
svc := Service{ImageAPI: "/blah/"}
|
||||||
html := `blah <img src="/blah/user1/pic1.png"/> foo
|
html := `blah <img src="/blah/user1/pic1.png"/> foo
|
||||||
<img src="/blah/user2/pic3.png"/> xyz <p>123</p> <img src="/pic3.png"/>`
|
<img src="/blah/user2/pic3.png"/> xyz <p>123</p> <img src="/pic3.png"/> <img src="https://i.ibb.co/0cqqqnD/ezgif-5-3b07b6b97610.png" alt="">`
|
||||||
ids, err := svc.ExtractPictures(html)
|
ids, err := svc.ExtractPictures(html)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 2, len(ids), "two images")
|
assert.Equal(t, 2, len(ids), "two images")
|
||||||
|
|||||||
Reference in New Issue
Block a user