some fix
This commit is contained in:
parent
61b976259a
commit
d6387c3528
@ -123,7 +123,7 @@ An `Activity` json might look something like this:
|
||||
```json
|
||||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"summary": "Sally created a note",
|
||||
"summary": status,
|
||||
"type": "Create",
|
||||
"actor": {
|
||||
"type": "Person",
|
||||
@ -132,7 +132,7 @@ An `Activity` json might look something like this:
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"name": "A Simple Note",
|
||||
"content": "This is a simple note"
|
||||
"content": status
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
type Activity struct {
|
||||
Id string `json:"id"`
|
||||
Payload string `json:"note"`
|
||||
Payload string `json:"status"`
|
||||
Remote bool `json:"remote"`
|
||||
Group `json:"group"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
@ -21,9 +21,9 @@ func GetActivity(db *sql.DB, slug string) (*Activity, error) {
|
||||
FROM activity WHERE id = $1
|
||||
`, slug)
|
||||
|
||||
var note Activity
|
||||
err := row.Scan(¬e.Slug,
|
||||
¬e.Name, ¬e.Note, ¬e.CreatedAt, ¬e.UpdatedAt)
|
||||
var status Activity
|
||||
err := row.Scan(&status.Id,
|
||||
&status.Name, &status.Note, &status.CreatedAt, &status.UpdatedAt)
|
||||
|
||||
// This is not an error from the user's perspective
|
||||
if err == sql.ErrNoRows {
|
||||
@ -33,21 +33,21 @@ func GetActivity(db *sql.DB, slug string) (*Activity, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ¬e, nil
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
/*
|
||||
// PutNote creates a note with this name and note
|
||||
func PutActivity(db *sql.DB, name string, note string) (string, error) {
|
||||
// PutNote creates a status with this name and status
|
||||
func PutActivity(db *sql.DB, name string, status string) (string, error) {
|
||||
// TODO make guid but not slug
|
||||
id := slugify.MakeLang(name, "en")
|
||||
|
||||
query := `
|
||||
INSERT INTO activity (id, name, note)
|
||||
INSERT INTO activity (id, name, status)
|
||||
VALUES ($1, $2, $3)
|
||||
`
|
||||
|
||||
_, err := db.Exec(query, slug, name, note)
|
||||
_, err := db.Exec(query, slug, name, status)
|
||||
return slug, err
|
||||
}
|
||||
*/
|
||||
|
@ -13,7 +13,7 @@ type Group struct {
|
||||
gorm.Model
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Note string `json:"note"`
|
||||
Note string `json:"status"`
|
||||
Type string
|
||||
UserID uint
|
||||
}
|
||||
@ -21,12 +21,12 @@ type Group struct {
|
||||
// GetGroup returns a single Group object or nil
|
||||
func GetGroup(db *sql.DB, slug string) (*Group, error) {
|
||||
row := db.QueryRow(`
|
||||
select slug, name, note, created_at, updated_at
|
||||
select slug, name, status, created_at, updated_at
|
||||
from groups where slug = $1
|
||||
`, slug)
|
||||
|
||||
var group Group
|
||||
err := row.Scan(&group.id, &group.Name, &group.Note, &group.CreatedAt, &group.UpdatedAt)
|
||||
err := row.Scan(&group.Id, &group.Name, &group.Note, &group.CreatedAt, &group.UpdatedAt)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
@ -43,7 +43,7 @@ func PutGroup(db *sql.DB, name string, note string) (string, error) {
|
||||
slug := slugify.MakeLang(name, "en")
|
||||
|
||||
query := `
|
||||
insert into groups(slug, name, note)
|
||||
insert into groups(slug, name, status)
|
||||
values ($1, $2, $3)
|
||||
`
|
||||
_, err := db.Exec(query, slug, name, note)
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
// Get returns a Group
|
||||
//
|
||||
// Expects a `{name}` url variable
|
||||
// in the route: `/api/group/:name`
|
||||
// in the route: `/group/:name`
|
||||
func Get(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
if name == "" {
|
||||
@ -31,7 +31,7 @@ func Get(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
url := handlers.GetFullHostName() + "/activity/group/" + group.Slug
|
||||
url := handlers.GetFullHostName() + "/group/" + group.Id
|
||||
actor := activitypub.NewPerson(url)
|
||||
actor.PreferredUsername = group.Name
|
||||
actor.Name = group.Name
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
type createGroupRequest struct {
|
||||
Name string `json:"name"`
|
||||
Note string `json:"note"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type createGroupResponse struct {
|
||||
@ -21,8 +21,7 @@ func Create(c *gin.Context) {
|
||||
var body createGroupRequest
|
||||
_ = c.BindJSON(&body)
|
||||
|
||||
db := data.GetDB()
|
||||
slug, err := models.PutGroup(db, body.Name, body.Note)
|
||||
slug, err := models.PutGroup(data.GetDB(), body.Name, body.Status)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
@ -1,53 +0,0 @@
|
||||
package note
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Get returns a Note
|
||||
//
|
||||
// Expects a `{noteid}` url variable
|
||||
// in the route: `/api/note/{noteid}`
|
||||
func Get(c *gin.Context) {
|
||||
noteId := c.Param("noteid")
|
||||
|
||||
if noteId == "" {
|
||||
c.String(http.StatusInternalServerError, "Bad request, no slug in url")
|
||||
return
|
||||
}
|
||||
|
||||
// Attempt to grab the Note
|
||||
note, err := models.GetNote(data.GetPool(), noteId)
|
||||
|
||||
// 500 because something went wrong with the database
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// 404 because something we couldn't find the show
|
||||
if show == nil {
|
||||
http.Error(w, slug+" does not exist on this server", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Convert to an ActivityPub object
|
||||
url, err := url.Parse(handlers.GetFullHostname() + "/api/show/" + slug)
|
||||
actor := activity.NewOrganization(show.Name, url)
|
||||
|
||||
// Turn the show into JSON
|
||||
bytes, err := json.Marshal(actor)
|
||||
|
||||
// 500 because something went wrong marshaling the show
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Success!
|
||||
w.Write(bytes)
|
||||
}
|
44
handlers/status/get.go
Normal file
44
handlers/status/get.go
Normal file
@ -0,0 +1,44 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Get returns a Note
|
||||
//
|
||||
// Expects a `{statusid}` url variable
|
||||
// in the route: `/status/{statusid}`
|
||||
func Get(c *gin.Context) {
|
||||
/*
|
||||
statusId := c.Param("statusid")
|
||||
|
||||
if statusId == "" {
|
||||
c.String(http.StatusInternalServerError, "Bad request, no status id in url")
|
||||
return
|
||||
}
|
||||
|
||||
// Attempt to grab the Activity
|
||||
status, err := models.GetActivity(data.GetDB(), statusId)
|
||||
|
||||
// 500 because something went wrong with the database
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 404 because something we couldn't find the status
|
||||
if status == nil {
|
||||
c.String(http.StatusNotFound, statusId+" does not exist on this server")
|
||||
return
|
||||
}
|
||||
|
||||
// Convert to an ActivityPub object
|
||||
url, err := url.Parse(handlers.GetFullHostName() + "/status/" + statusId)
|
||||
o := activitypub.NewAnounceObject()
|
||||
activity := activitypub.NewCreateActivity(0)
|
||||
|
||||
c.JSON(http.StatusOK, activity)
|
||||
//w.Write(bytes)
|
||||
*/
|
||||
}
|
@ -33,11 +33,6 @@ func Get(c *gin.Context) {
|
||||
c.String(http.StatusBadRequest, "Account not found")
|
||||
}
|
||||
|
||||
// bytes, err := json.Marshal(actor)
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
// return
|
||||
// }
|
||||
c.JSON(http.StatusOK, actor)
|
||||
}
|
||||
|
||||
|
7
main.go
7
main.go
@ -22,6 +22,7 @@ func main() {
|
||||
api := r.Group("/api")
|
||||
{
|
||||
api.GET("/group/:name", groups.Get)
|
||||
api.GET("/group/:name/status/:statusid", groups.Get)
|
||||
api.GET("/group/:name/tags", groups.Get)
|
||||
api.GET("/group/:name/tags", groups.Get)
|
||||
api.GET("/group/:name/featured", groups.Get)
|
||||
@ -32,12 +33,14 @@ func main() {
|
||||
api.POST("/group", groups.Create)
|
||||
}
|
||||
// r.GET("/@:name", groups.GetGroup)
|
||||
// r.GET("/note/:noteid", note.GetNote)
|
||||
// r.GET("/status/:noteid", status.GetNote)
|
||||
|
||||
// Activity pub routes
|
||||
ap := r.Group("/activity")
|
||||
{
|
||||
ap.GET("/group/:name", groups.Get)
|
||||
ap.GET("/group/:name/status/:statusid", groups.Get)
|
||||
// TODO api.GET("/status/:statusid", groups.Get)
|
||||
ap.GET("/group/:name/followers", groups.Get)
|
||||
ap.GET("/group/:name/following", groups.Get)
|
||||
ap.GET("/group/:name/outbox", groups.Get)
|
||||
@ -53,7 +56,7 @@ func main() {
|
||||
port = fromEnv
|
||||
}
|
||||
|
||||
log.WithField("port", port).Info("starting pubcast api server")
|
||||
log.WithField("port", port).Info("starting subhub api server")
|
||||
log.Fatal(r.Run(":" + port))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user