some fix
This commit is contained in:
parent
61b976259a
commit
d6387c3528
@ -123,7 +123,7 @@ An `Activity` json might look something like this:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
"summary": "Sally created a note",
|
"summary": status,
|
||||||
"type": "Create",
|
"type": "Create",
|
||||||
"actor": {
|
"actor": {
|
||||||
"type": "Person",
|
"type": "Person",
|
||||||
@ -132,7 +132,7 @@ An `Activity` json might look something like this:
|
|||||||
"object": {
|
"object": {
|
||||||
"type": "Note",
|
"type": "Note",
|
||||||
"name": "A Simple Note",
|
"name": "A Simple Note",
|
||||||
"content": "This is a simple note"
|
"content": status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
type Activity struct {
|
type Activity struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Payload string `json:"note"`
|
Payload string `json:"status"`
|
||||||
Remote bool `json:"remote"`
|
Remote bool `json:"remote"`
|
||||||
Group `json:"group"`
|
Group `json:"group"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
@ -21,9 +21,9 @@ func GetActivity(db *sql.DB, slug string) (*Activity, error) {
|
|||||||
FROM activity WHERE id = $1
|
FROM activity WHERE id = $1
|
||||||
`, slug)
|
`, slug)
|
||||||
|
|
||||||
var note Activity
|
var status Activity
|
||||||
err := row.Scan(¬e.Slug,
|
err := row.Scan(&status.Id,
|
||||||
¬e.Name, ¬e.Note, ¬e.CreatedAt, ¬e.UpdatedAt)
|
&status.Name, &status.Note, &status.CreatedAt, &status.UpdatedAt)
|
||||||
|
|
||||||
// This is not an error from the user's perspective
|
// This is not an error from the user's perspective
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
@ -33,21 +33,21 @@ func GetActivity(db *sql.DB, slug string) (*Activity, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ¬e, nil
|
return &status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// PutNote creates a note with this name and note
|
// PutNote creates a status with this name and status
|
||||||
func PutActivity(db *sql.DB, name string, note string) (string, error) {
|
func PutActivity(db *sql.DB, name string, status string) (string, error) {
|
||||||
// TODO make guid but not slug
|
// TODO make guid but not slug
|
||||||
id := slugify.MakeLang(name, "en")
|
id := slugify.MakeLang(name, "en")
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO activity (id, name, note)
|
INSERT INTO activity (id, name, status)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
`
|
`
|
||||||
|
|
||||||
_, err := db.Exec(query, slug, name, note)
|
_, err := db.Exec(query, slug, name, status)
|
||||||
return slug, err
|
return slug, err
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -13,7 +13,7 @@ type Group struct {
|
|||||||
gorm.Model
|
gorm.Model
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Note string `json:"note"`
|
Note string `json:"status"`
|
||||||
Type string
|
Type string
|
||||||
UserID uint
|
UserID uint
|
||||||
}
|
}
|
||||||
@ -21,12 +21,12 @@ type Group struct {
|
|||||||
// GetGroup returns a single Group object or nil
|
// GetGroup returns a single Group object or nil
|
||||||
func GetGroup(db *sql.DB, slug string) (*Group, error) {
|
func GetGroup(db *sql.DB, slug string) (*Group, error) {
|
||||||
row := db.QueryRow(`
|
row := db.QueryRow(`
|
||||||
select slug, name, note, created_at, updated_at
|
select slug, name, status, created_at, updated_at
|
||||||
from groups where slug = $1
|
from groups where slug = $1
|
||||||
`, slug)
|
`, slug)
|
||||||
|
|
||||||
var group Group
|
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 {
|
if err == sql.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@ -43,7 +43,7 @@ func PutGroup(db *sql.DB, name string, note string) (string, error) {
|
|||||||
slug := slugify.MakeLang(name, "en")
|
slug := slugify.MakeLang(name, "en")
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
insert into groups(slug, name, note)
|
insert into groups(slug, name, status)
|
||||||
values ($1, $2, $3)
|
values ($1, $2, $3)
|
||||||
`
|
`
|
||||||
_, err := db.Exec(query, slug, name, note)
|
_, err := db.Exec(query, slug, name, note)
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
// Get returns a Group
|
// Get returns a Group
|
||||||
//
|
//
|
||||||
// Expects a `{name}` url variable
|
// Expects a `{name}` url variable
|
||||||
// in the route: `/api/group/:name`
|
// in the route: `/group/:name`
|
||||||
func Get(c *gin.Context) {
|
func Get(c *gin.Context) {
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
if name == "" {
|
if name == "" {
|
||||||
@ -31,7 +31,7 @@ func Get(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := handlers.GetFullHostName() + "/activity/group/" + group.Slug
|
url := handlers.GetFullHostName() + "/group/" + group.Id
|
||||||
actor := activitypub.NewPerson(url)
|
actor := activitypub.NewPerson(url)
|
||||||
actor.PreferredUsername = group.Name
|
actor.PreferredUsername = group.Name
|
||||||
actor.Name = group.Name
|
actor.Name = group.Name
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type createGroupRequest struct {
|
type createGroupRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Note string `json:"note"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type createGroupResponse struct {
|
type createGroupResponse struct {
|
||||||
@ -21,8 +21,7 @@ func Create(c *gin.Context) {
|
|||||||
var body createGroupRequest
|
var body createGroupRequest
|
||||||
_ = c.BindJSON(&body)
|
_ = c.BindJSON(&body)
|
||||||
|
|
||||||
db := data.GetDB()
|
slug, err := models.PutGroup(data.GetDB(), body.Name, body.Status)
|
||||||
slug, err := models.PutGroup(db, body.Name, body.Note)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, err.Error())
|
c.String(http.StatusInternalServerError, err.Error())
|
||||||
return
|
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")
|
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)
|
c.JSON(http.StatusOK, actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
main.go
7
main.go
@ -22,6 +22,7 @@ func main() {
|
|||||||
api := r.Group("/api")
|
api := r.Group("/api")
|
||||||
{
|
{
|
||||||
api.GET("/group/:name", groups.Get)
|
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/tags", groups.Get)
|
api.GET("/group/:name/tags", groups.Get)
|
||||||
api.GET("/group/:name/featured", groups.Get)
|
api.GET("/group/:name/featured", groups.Get)
|
||||||
@ -32,12 +33,14 @@ func main() {
|
|||||||
api.POST("/group", groups.Create)
|
api.POST("/group", groups.Create)
|
||||||
}
|
}
|
||||||
// r.GET("/@:name", groups.GetGroup)
|
// r.GET("/@:name", groups.GetGroup)
|
||||||
// r.GET("/note/:noteid", note.GetNote)
|
// r.GET("/status/:noteid", status.GetNote)
|
||||||
|
|
||||||
// Activity pub routes
|
// Activity pub routes
|
||||||
ap := r.Group("/activity")
|
ap := r.Group("/activity")
|
||||||
{
|
{
|
||||||
ap.GET("/group/:name", groups.Get)
|
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/followers", groups.Get)
|
||||||
ap.GET("/group/:name/following", groups.Get)
|
ap.GET("/group/:name/following", groups.Get)
|
||||||
ap.GET("/group/:name/outbox", groups.Get)
|
ap.GET("/group/:name/outbox", groups.Get)
|
||||||
@ -53,7 +56,7 @@ func main() {
|
|||||||
port = fromEnv
|
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))
|
log.Fatal(r.Run(":" + port))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user