add import rest
This commit is contained in:
@@ -75,8 +75,8 @@ type Comment struct {
|
||||
}
|
||||
|
||||
type Locator struct {
|
||||
SiteID string `json:"site"`
|
||||
URL string `json:"url"`
|
||||
SiteID string `json:"site"` // site id
|
||||
URL string `json:"url"` // post url
|
||||
}
|
||||
```
|
||||
|
||||
@@ -110,4 +110,5 @@ Sort can be `time` or `score`. Supported sort order with prefix -/+, i.e. `-time
|
||||
- `DELETE /api/v1/admin/comment/{id}?site=site-id&url=post-url` - delete comment by `id`. _auth and admin required_
|
||||
- `PUT /api/v1/admin/user/{userid}?site=site-id&block=1` - block or unblock user. _auth and admin required_
|
||||
- `GET /api/v1/admin/export?site=side-id&mode=[stream|file]` - export all comments to json stream or gz file. _auth and admin required_
|
||||
- `POST /api/v1/admin/import?site=side-id` - import comments from the backup. _auth and admin required_
|
||||
- `PUT /api/v1/admin/pin/{id}?site=site-id&url=post-url&pin=1` - pin or unpin comment. _auth and admin required_
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
type admin struct {
|
||||
dataService store.Service
|
||||
exporter migrator.Exporter
|
||||
importer migrator.Importer
|
||||
respCache *cache.Cache
|
||||
}
|
||||
|
||||
@@ -30,6 +31,7 @@ func (a *admin) routes() chi.Router {
|
||||
router.Delete("/comment/{id}", a.deleteCommentCtrl)
|
||||
router.Put("/user/{userid}", a.setBlockCtrl)
|
||||
router.Get("/export", a.exportCtrl)
|
||||
router.Post("/import", a.importCtrl)
|
||||
router.Put("/pin/{id}", a.setPinCtrl)
|
||||
return router
|
||||
}
|
||||
@@ -96,6 +98,15 @@ func (a *admin) exportCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
httpError(w, r, http.StatusInternalServerError, err, "export failed")
|
||||
}
|
||||
}
|
||||
|
||||
// POST /import?site=site-id
|
||||
func (a *admin) importCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
siteID := r.URL.Query().Get("site")
|
||||
if err := a.importer.Import(r.Body, siteID); err != nil {
|
||||
httpError(w, r, http.StatusBadRequest, err, "import failed")
|
||||
}
|
||||
}
|
||||
|
||||
func (a *admin) checkBlocked(locator store.Locator, user store.User) bool {
|
||||
return a.dataService.IsBlocked(locator, user.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user