Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5092d3898 | |||
| 754cfa602c | |||
| 0942490238 | |||
| 4ecce09b73 | |||
| cf871efc23 | |||
| cdd67e35a3 | |||
| 7459b363f6 | |||
| e097e6c8b5 | |||
| 92b96981e2 | |||
| b38c6b0a54 | |||
| ce8f58ed2d | |||
| a4a015a4cc | |||
| a90e43691d | |||
| 54c27ff977 | |||
| 6074dcd419 | |||
| 7fc04591ba | |||
| 519c58f847 | |||
| a9f1b2d3bd | |||
| ba705b25f7 | |||
| 6ea2a3bf54 | |||
| 7c15588651 | |||
| 9beccacda1 | |||
| eaebd96419 | |||
| 61030d84a1 | |||
| a9c51dba33 | |||
| c9db49c367 | |||
| 2dbc8e9a85 | |||
| f29641ae13 |
@@ -1,3 +1,2 @@
|
|||||||
/test
|
/test
|
||||||
/gen
|
/gen
|
||||||
/lemmy/
|
|
||||||
|
|||||||
@@ -1,43 +1,31 @@
|
|||||||
# Go-Lemmy
|
# Go-Lemmy
|
||||||
|
|
||||||
[](https://pkg.go.dev/go.elara.ws/go-lemmy)
|
[](https://pkg.go.dev/go.arsenm.dev/go-lemmy)
|
||||||
|
|
||||||
Go bindings to the [Lemmy](https://join-lemmy.org) API, automatically generated from Lemmy's source code using the generator in [cmd/gen](cmd/gen).
|
Go bindings to the [Lemmy](https://join-lemmy.org) API
|
||||||
|
|
||||||
Examples:
|
Example:
|
||||||
|
|
||||||
- HTTP: [examples/http](examples/http)
|
```go
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
### How to generate
|
c, err := lemmy.New("https://lemmygrad.ml")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
First, clone the [lemmy-js-client](https://github.com/LemmyNet/lemmy-js-client) repo at whatever version you need:
|
err = c.ClientLogin(ctx, types.Login{
|
||||||
|
UsernameOrEmail: "user@example.com",
|
||||||
|
Password: `TestPwd`,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
```bash
|
_, err = c.SaveUserSettings(ctx, types.SaveUserSettings{
|
||||||
git clone https://github.com/LemmyNet/lemmy-js-client -b 0.18.3
|
BotAccount: types.NewOptional(true),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Inside it, build the JSON docs file:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run docs -- --json docs.json
|
|
||||||
```
|
|
||||||
|
|
||||||
Next, build the generator:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go build ./cmd/gen
|
|
||||||
```
|
|
||||||
|
|
||||||
Remove all the existing generated code:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
rm **/*.gen.go
|
|
||||||
```
|
|
||||||
|
|
||||||
Execute the generator:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gen -json-file <path_to_docs.json> -out-dir .
|
|
||||||
```
|
|
||||||
|
|
||||||
And that's it! Your generated code should be ready for use.
|
|
||||||
|
|||||||
@@ -1,192 +0,0 @@
|
|||||||
package extractor
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Route struct {
|
|
||||||
Name string
|
|
||||||
Summary string
|
|
||||||
Method string
|
|
||||||
Path string
|
|
||||||
ParamsName string
|
|
||||||
ParamsID int64
|
|
||||||
ReturnName string
|
|
||||||
ReturnID int64
|
|
||||||
}
|
|
||||||
|
|
||||||
type Struct struct {
|
|
||||||
Name string
|
|
||||||
Fields []Field
|
|
||||||
UnionNames []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Field struct {
|
|
||||||
Name string
|
|
||||||
IsArray bool
|
|
||||||
IsOptional bool
|
|
||||||
Type string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Extractor struct {
|
|
||||||
root gjson.Result
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(path string) (*Extractor, error) {
|
|
||||||
data, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Extractor{gjson.ParseBytes(data)}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Extractor) Routes() []Route {
|
|
||||||
var out []Route
|
|
||||||
routes := e.root.Get("children.#.children.#(kind==2048)#|@flatten")
|
|
||||||
for _, route := range routes.Array() {
|
|
||||||
name := route.Get("name").String()
|
|
||||||
signature := route.Get(`signatures.0`)
|
|
||||||
|
|
||||||
httpInfo := signature.Get(`comment.summary.#(kind=="code").text`).String()
|
|
||||||
if !strings.HasPrefix(httpInfo, "`HTTP") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
method, path := parseHTTPInfo(httpInfo)
|
|
||||||
|
|
||||||
summary := strings.TrimSpace(signature.Get(`comment.summary.#(kind=="text").text`).String())
|
|
||||||
if summary == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
paramsID := signature.Get("parameters.0.type.target").Int()
|
|
||||||
paramsName := signature.Get("parameters.0.type.name").String()
|
|
||||||
returnID := signature.Get("type.typeArguments.0.target").Int()
|
|
||||||
returnName := signature.Get("type.typeArguments.0.name").String()
|
|
||||||
|
|
||||||
out = append(out, Route{
|
|
||||||
Name: name,
|
|
||||||
Summary: summary,
|
|
||||||
Method: method,
|
|
||||||
Path: path,
|
|
||||||
ParamsName: paramsName,
|
|
||||||
ParamsID: paramsID,
|
|
||||||
ReturnName: returnName,
|
|
||||||
ReturnID: returnID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Extractor) Structs(routes []Route) []Struct {
|
|
||||||
var ids []int64
|
|
||||||
for _, route := range routes {
|
|
||||||
ids = append(ids, route.ParamsID)
|
|
||||||
if route.ReturnID != 0 {
|
|
||||||
ids = append(ids, route.ReturnID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
structs := map[int64]Struct{}
|
|
||||||
e.getStructs(ids, structs)
|
|
||||||
return getKeys(structs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Extractor) getStructs(ids []int64, structs map[int64]Struct) {
|
|
||||||
for _, id := range ids {
|
|
||||||
if _, ok := structs[id]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
jstruct := e.root.Get(fmt.Sprintf("children.#(id==%d)", id))
|
|
||||||
if !jstruct.Exists() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
name := jstruct.Get("name").String()
|
|
||||||
|
|
||||||
if jstruct.Get("type.type").String() == "union" {
|
|
||||||
structs[id] = Struct{
|
|
||||||
Name: name,
|
|
||||||
UnionNames: e.unionNames(jstruct),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fields, newIDs := e.fields(jstruct)
|
|
||||||
|
|
||||||
structs[id] = Struct{
|
|
||||||
Name: name,
|
|
||||||
Fields: fields,
|
|
||||||
}
|
|
||||||
|
|
||||||
e.getStructs(newIDs, structs)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Extractor) unionNames(jstruct gjson.Result) []string {
|
|
||||||
jnames := jstruct.Get("type.types").Array()
|
|
||||||
out := make([]string, len(jnames))
|
|
||||||
for i, name := range jnames {
|
|
||||||
out[i] = name.Get("value").String()
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Extractor) fields(jstruct gjson.Result) ([]Field, []int64) {
|
|
||||||
var fields []Field
|
|
||||||
var ids []int64
|
|
||||||
jfields := jstruct.Get("children").Array()
|
|
||||||
for _, jfield := range jfields {
|
|
||||||
var field Field
|
|
||||||
|
|
||||||
field.Name = jfield.Get("name").String()
|
|
||||||
field.IsOptional = jfield.Get("flags.isOptional").Bool()
|
|
||||||
|
|
||||||
if jfield.Get("type.type").String() == "array" {
|
|
||||||
field.IsArray = true
|
|
||||||
field.Type = jfield.Get("type.elementType.name").String()
|
|
||||||
|
|
||||||
switch jfield.Get("type.elementType.type").String() {
|
|
||||||
case "reference":
|
|
||||||
ids = append(ids, jfield.Get("type.elementType.target").Int())
|
|
||||||
case "union":
|
|
||||||
field.Type = "string"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
field.Type = jfield.Get("type.name").String()
|
|
||||||
|
|
||||||
switch jfield.Get("type.type").String() {
|
|
||||||
case "reference":
|
|
||||||
ids = append(ids, jfield.Get("type.target").Int())
|
|
||||||
case "union":
|
|
||||||
field.Type = "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fields = append(fields, field)
|
|
||||||
}
|
|
||||||
return fields, ids
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseHTTPInfo(httpInfo string) (method, path string) {
|
|
||||||
httpInfo = strings.Trim(httpInfo, "`")
|
|
||||||
method, path, _ = strings.Cut(httpInfo, " ")
|
|
||||||
method = strings.TrimPrefix(method, "HTTP.")
|
|
||||||
method = strings.ToUpper(method)
|
|
||||||
return method, path
|
|
||||||
}
|
|
||||||
|
|
||||||
func getKeys(m map[int64]Struct) []Struct {
|
|
||||||
out := make([]Struct, len(m))
|
|
||||||
i := 0
|
|
||||||
for _, s := range m {
|
|
||||||
out[i] = s
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
+17
-45
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dave/jennifer/jen"
|
"github.com/dave/jennifer/jen"
|
||||||
"go.elara.ws/go-lemmy/cmd/gen/extractor"
|
"go.arsenm.dev/go-lemmy/cmd/gen/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RoutesGenerator struct {
|
type RoutesGenerator struct {
|
||||||
@@ -17,30 +17,21 @@ func NewRoutes(w io.Writer, pkgName string) *RoutesGenerator {
|
|||||||
return &RoutesGenerator{w, pkgName}
|
return &RoutesGenerator{w, pkgName}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoutesGenerator) Generate(routes []extractor.Route) error {
|
func (r *RoutesGenerator) Generate(routes []parser.Route, impls map[string]string) error {
|
||||||
f := jen.NewFile(r.PkgName)
|
f := jen.NewFile(r.PkgName)
|
||||||
f.HeaderComment("Code generated by go.elara.ws/go-lemmy/cmd/gen (routes generator). DO NOT EDIT.")
|
|
||||||
|
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
|
resStruct := impls[r.Struct]
|
||||||
|
|
||||||
f.Comment(r.Summary)
|
|
||||||
f.Func().Params(
|
f.Func().Params(
|
||||||
jen.Id("c").Id("*Client"),
|
jen.Id("c").Id("*Client"),
|
||||||
).Id(transformName(r.Name)).Params(
|
).Id(strings.TrimPrefix(r.Struct, "Get")).Params(
|
||||||
jen.Id("ctx").Qual("context", "Context"),
|
jen.Id("ctx").Qual("context", "Context"),
|
||||||
jen.Id("data").Qual("go.elara.ws/go-lemmy/types", r.ParamsName),
|
jen.Id("data").Qual("go.arsenm.dev/go-lemmy/types", r.Struct),
|
||||||
).ParamsFunc(func(g *jen.Group) {
|
).Params(
|
||||||
if r.ReturnName != "" {
|
jen.Op("*").Qual("go.arsenm.dev/go-lemmy/types", resStruct),
|
||||||
g.Op("*").Qual("go.elara.ws/go-lemmy/types", r.ReturnName)
|
jen.Error(),
|
||||||
}
|
).BlockFunc(func(g *jen.Group) {
|
||||||
g.Error()
|
g.Id("resData").Op(":=").Op("&").Qual("go.arsenm.dev/go-lemmy/types", resStruct).Block()
|
||||||
}).BlockFunc(func(g *jen.Group) {
|
|
||||||
returnName := r.ReturnName
|
|
||||||
if returnName == "" {
|
|
||||||
returnName = "EmptyResponse"
|
|
||||||
}
|
|
||||||
|
|
||||||
g.Id("resData").Op(":=").Op("&").Qual("go.elara.ws/go-lemmy/types", returnName).Block()
|
|
||||||
|
|
||||||
var funcName string
|
var funcName string
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
@@ -53,37 +44,18 @@ func (r *RoutesGenerator) Generate(routes []extractor.Route) error {
|
|||||||
g.List(jen.Id("res"), jen.Err()).Op(":=").Id("c").Dot(funcName).Params(
|
g.List(jen.Id("res"), jen.Err()).Op(":=").Id("c").Dot(funcName).Params(
|
||||||
jen.Id("ctx"), jen.Lit(r.Method), jen.Lit(r.Path), jen.Id("data"), jen.Op("&").Id("resData"),
|
jen.Id("ctx"), jen.Lit(r.Method), jen.Lit(r.Path), jen.Id("data"), jen.Op("&").Id("resData"),
|
||||||
)
|
)
|
||||||
g.If(jen.Err().Op("!=").Nil()).BlockFunc(func(g *jen.Group) {
|
g.If(jen.Err().Op("!=").Nil()).Block(
|
||||||
if returnName == "EmptyResponse" {
|
jen.Return(jen.Nil(), jen.Err()),
|
||||||
g.Return(jen.Err())
|
)
|
||||||
} else {
|
|
||||||
g.Return(jen.Nil(), jen.Err())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
g.Err().Op("=").Id("resError").Params(jen.Id("res"), jen.Id("resData").Dot("LemmyResponse"))
|
g.Err().Op("=").Id("resError").Params(jen.Id("res"), jen.Id("resData").Dot("LemmyResponse"))
|
||||||
g.If(jen.Err().Op("!=").Nil()).BlockFunc(func(g *jen.Group) {
|
g.If(jen.Err().Op("!=").Nil()).Block(
|
||||||
if returnName == "EmptyResponse" {
|
jen.Return(jen.Nil(), jen.Err()),
|
||||||
g.Return(jen.Err())
|
)
|
||||||
} else {
|
|
||||||
g.Return(jen.Nil(), jen.Err())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if returnName == "EmptyResponse" {
|
g.Return(jen.Id("resData"), jen.Nil())
|
||||||
g.Return(jen.Nil())
|
|
||||||
} else {
|
|
||||||
g.Return(jen.Id("resData"), jen.Nil())
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.Render(r.w)
|
return f.Render(r.w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func transformName(s string) string {
|
|
||||||
s = strings.ToUpper(s[:1]) + s[1:]
|
|
||||||
s = strings.TrimPrefix(s, "Get")
|
|
||||||
s = strings.TrimPrefix(s, "List")
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|||||||
+19
-84
@@ -3,10 +3,9 @@ package generator
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/dave/jennifer/jen"
|
"github.com/dave/jennifer/jen"
|
||||||
"go.elara.ws/go-lemmy/cmd/gen/extractor"
|
"go.arsenm.dev/go-lemmy/cmd/gen/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StructGenerator struct {
|
type StructGenerator struct {
|
||||||
@@ -18,98 +17,34 @@ func NewStruct(w io.Writer, pkgName string) *StructGenerator {
|
|||||||
return &StructGenerator{w, pkgName}
|
return &StructGenerator{w, pkgName}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StructGenerator) Generate(items []extractor.Struct) error {
|
func (s *StructGenerator) Generate(items []parser.Item) error {
|
||||||
f := jen.NewFile(s.PkgName)
|
f := jen.NewFile(s.PkgName)
|
||||||
f.HeaderComment("Code generated by go.elara.ws/go-lemmy/cmd/gen (struct generator). DO NOT EDIT.")
|
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if len(item.UnionNames) > 0 {
|
if item.Struct != nil {
|
||||||
f.Type().Id(item.Name).String()
|
st := item.Struct
|
||||||
|
f.Type().Id(st.Name).StructFunc(func(g *jen.Group) {
|
||||||
f.Const().DefsFunc(func(g *jen.Group) {
|
for _, field := range st.Fields {
|
||||||
for _, member := range item.UnionNames {
|
g.Id(field.Name).Id(field.Type).Tag(map[string]string{
|
||||||
constName := strings.Replace(item.Name+string(member), " ", "", -1)
|
"json": field.OrigName,
|
||||||
g.Id(constName).Id(item.Name).Op("=").Lit(string(member))
|
"url": field.OrigName + ",omitempty",
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
f.Type().Id(item.Name).StructFunc(func(g *jen.Group) {
|
|
||||||
for _, field := range item.Fields {
|
|
||||||
g.Id(transformFieldName(field.Name)).Id(getType(field)).Tag(map[string]string{
|
|
||||||
"json": field.Name,
|
|
||||||
"url": field.Name + ",omitempty",
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(item.Name, "Response") {
|
if strings.HasSuffix(st.Name, "Response") {
|
||||||
g.Id("LemmyResponse")
|
g.Id("LemmyResponse")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if item.Enum != nil {
|
||||||
|
e := item.Enum
|
||||||
|
f.Type().Id(e.Name).String()
|
||||||
|
|
||||||
|
f.Const().DefsFunc(func(g *jen.Group) {
|
||||||
|
for _, member := range e.Members {
|
||||||
|
g.Id(e.Name + string(member)).Id(e.Name).Op("=").Lit(string(member))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.Render(s.w)
|
return f.Render(s.w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getType(f extractor.Field) string {
|
|
||||||
t := transformType(f.Name, f.Type)
|
|
||||||
if f.IsArray {
|
|
||||||
t = "[]" + t
|
|
||||||
}
|
|
||||||
if f.IsOptional {
|
|
||||||
t = "Optional[" + t + "]"
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func transformType(name, t string) string {
|
|
||||||
// Some time fields are strings in the JS client,
|
|
||||||
// use LemmyTime for those
|
|
||||||
switch name {
|
|
||||||
case "published", "updated":
|
|
||||||
return "LemmyTime"
|
|
||||||
}
|
|
||||||
|
|
||||||
switch t {
|
|
||||||
case "number":
|
|
||||||
return "int64"
|
|
||||||
case "boolean":
|
|
||||||
return "bool"
|
|
||||||
default:
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func transformFieldName(s string) string {
|
|
||||||
s = snakeToCamel(s)
|
|
||||||
s = strings.NewReplacer(
|
|
||||||
"Id", "ID",
|
|
||||||
"Url", "URL",
|
|
||||||
"Nsfw", "NSFW",
|
|
||||||
"Jwt", "JWT",
|
|
||||||
"Crud", "CRUD",
|
|
||||||
"Pm", "PM",
|
|
||||||
"Totp", "TOTP",
|
|
||||||
"2fa", "2FA",
|
|
||||||
).Replace(s)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func snakeToCamel(s string) string {
|
|
||||||
sb := &strings.Builder{}
|
|
||||||
capitalizeNext := true
|
|
||||||
for _, char := range s {
|
|
||||||
if char == '_' {
|
|
||||||
capitalizeNext = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if capitalizeNext {
|
|
||||||
sb.WriteRune(unicode.ToUpper(char))
|
|
||||||
capitalizeNext = false
|
|
||||||
} else {
|
|
||||||
sb.WriteRune(char)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.String()
|
|
||||||
}
|
|
||||||
|
|||||||
+126
-23
@@ -2,56 +2,159 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go.elara.ws/go-lemmy/cmd/gen/extractor"
|
"go.arsenm.dev/go-lemmy/cmd/gen/generator"
|
||||||
"go.elara.ws/go-lemmy/cmd/gen/generator"
|
"go.arsenm.dev/go-lemmy/cmd/gen/parser"
|
||||||
"go.elara.ws/logger"
|
|
||||||
"go.elara.ws/logger/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
var implDirs = [...]string{
|
||||||
log.Logger = logger.NewPretty(os.Stderr)
|
"crates/api_crud/src",
|
||||||
|
"crates/apub/src/api",
|
||||||
|
"crates/api/src",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var structDirs = [...]string{
|
||||||
|
"crates/api_common",
|
||||||
|
"crates/db_schema/src/source",
|
||||||
|
"crates/db_views_actor/src/structs.rs",
|
||||||
|
"crates/db_views/src/structs.rs",
|
||||||
|
"crates/db_views_moderator/src/structs.rs",
|
||||||
|
"crates/db_schema/src/aggregates/structs.rs",
|
||||||
|
"crates/db_schema/src/lib.rs",
|
||||||
|
"crates/websocket/src/lib.rs",
|
||||||
|
}
|
||||||
|
|
||||||
|
const routesFile = "src/api_routes.rs"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
jsonFile := flag.String("json-file", "lemmy.json", "Path to the JSON file generated from lemmy's docs")
|
lemmyDir := flag.String("lemmy-dir", "lemmy", "Path to Lemmy repository")
|
||||||
outDir := flag.String("out-dir", "out", "Directory to write output in")
|
outDir := flag.String("out-dir", "out", "Directory to write output in")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
e, err := extractor.New(*jsonFile)
|
baseStructDir := filepath.Join(*outDir, "types")
|
||||||
if err != nil {
|
sp := parser.NewStruct(nil)
|
||||||
log.Fatal("Error creating extractor").Err(err).Send()
|
sp.Skip = []string{"LemmyContext"}
|
||||||
|
for _, structDir := range structDirs {
|
||||||
|
dir := filepath.Join(*lemmyDir, structDir)
|
||||||
|
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if filepath.Ext(path) != ".rs" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
name := d.Name()
|
||||||
|
if name == "context.rs" ||
|
||||||
|
name == "local_user_language.rs" ||
|
||||||
|
name == "chat_server.rs" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fl, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fl.Close()
|
||||||
|
|
||||||
|
sp.Reset(fl)
|
||||||
|
fileStructs, err := sp.Parse()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
nameNoExt := strings.TrimSuffix(d.Name(), ".rs")
|
||||||
|
goFilePath := filepath.Join(baseStructDir, nameNoExt+".gen.go")
|
||||||
|
|
||||||
|
i := 1
|
||||||
|
_, err = os.Stat(goFilePath)
|
||||||
|
for err == nil {
|
||||||
|
goFilePath = filepath.Join(baseStructDir, nameNoExt+"."+strconv.Itoa(i)+".gen.go")
|
||||||
|
_, err = os.Stat(goFilePath)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
outFl, err := os.Create(goFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer outFl.Close()
|
||||||
|
|
||||||
|
return generator.NewStruct(outFl, "types").Generate(fileStructs)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
routes := e.Routes()
|
ip := parser.NewImpl(nil)
|
||||||
structs := e.Structs(routes)
|
impls := map[string]string{}
|
||||||
|
for _, implDir := range implDirs {
|
||||||
|
dir := filepath.Join(*lemmyDir, implDir)
|
||||||
|
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(filepath.Join(*outDir, "types"), 0o755)
|
if d.IsDir() {
|
||||||
if err != nil {
|
return nil
|
||||||
log.Fatal("Error creating types directory").Err(err).Send()
|
}
|
||||||
|
if filepath.Ext(path) != ".rs" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fl, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fl.Close()
|
||||||
|
|
||||||
|
ip.Reset(fl)
|
||||||
|
implMap, err := ip.Parse()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for reqStruct, resStruct := range implMap {
|
||||||
|
impls[reqStruct] = resStruct
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
otf, err := os.Create(filepath.Join(*outDir, "types/types.gen.go"))
|
rf, err := os.Open(filepath.Join(*lemmyDir, routesFile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error creating types output file").Err(err).Send()
|
panic(err)
|
||||||
}
|
}
|
||||||
defer otf.Close()
|
defer rf.Close()
|
||||||
|
|
||||||
err = generator.NewStruct(otf, "types").Generate(structs)
|
rp := parser.NewRoutes(rf)
|
||||||
|
routes, err := rp.Parse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error generating output routes file").Err(err).Send()
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
orf, err := os.Create(filepath.Join(*outDir, "routes.gen.go"))
|
orf, err := os.Create(filepath.Join(*outDir, "routes.gen.go"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error creating routes output file").Err(err).Send()
|
panic(err)
|
||||||
}
|
}
|
||||||
defer orf.Close()
|
defer orf.Close()
|
||||||
|
|
||||||
err = generator.NewRoutes(orf, "lemmy").Generate(routes)
|
err = generator.NewRoutes(orf, "lemmy").Generate(routes, impls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error generating output routes file").Err(err).Send()
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
implRegex = regexp.MustCompile(`impl Perform.* for (.+) {`)
|
||||||
|
respTypeRegex = regexp.MustCompile(`type Response = (.+);`)
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrNoType = errors.New("type line not found")
|
||||||
|
|
||||||
|
type ImplParser struct {
|
||||||
|
r *bufio.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewImpl(r io.Reader) *ImplParser {
|
||||||
|
return &ImplParser{
|
||||||
|
r: bufio.NewReader(r),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *ImplParser) Parse() (map[string]string, error) {
|
||||||
|
out := map[string]string{}
|
||||||
|
for {
|
||||||
|
line, err := i.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if implRegex.MatchString(line) {
|
||||||
|
im := implRegex.FindStringSubmatch(line)
|
||||||
|
|
||||||
|
line, err := i.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
return nil, io.ErrUnexpectedEOF
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !respTypeRegex.MatchString(line) {
|
||||||
|
return nil, ErrNoType
|
||||||
|
}
|
||||||
|
|
||||||
|
rtm := respTypeRegex.FindStringSubmatch(line)
|
||||||
|
|
||||||
|
out[im[1]] = rtm[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *ImplParser) Reset(r io.Reader) {
|
||||||
|
i.r.Reset(r)
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net/url"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
scopeRegex = regexp.MustCompile(`web::(?:scope|resource)\("(.*)"\)\n`)
|
||||||
|
routeRegex = regexp.MustCompile(`\.route\(\n?\s*(?:"(.*)",[ \n])?\s*web::(.+)\(\)\.to\(route_.*::<(.+)>`)
|
||||||
|
)
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
Path string
|
||||||
|
Method string
|
||||||
|
Struct string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RoutesParser struct {
|
||||||
|
r *bufio.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRoutes(r io.Reader) *RoutesParser {
|
||||||
|
return &RoutesParser{
|
||||||
|
r: bufio.NewReader(r),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RoutesParser) Parse() ([]Route, error) {
|
||||||
|
var out []Route
|
||||||
|
for {
|
||||||
|
line, err := r.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if scopeRegex.MatchString(line) {
|
||||||
|
scopePath := scopeRegex.FindStringSubmatch(line)[1]
|
||||||
|
if scopePath == "/api/v3" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
routes, err := r.parseRoutes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range routes {
|
||||||
|
path, err := url.JoinPath(scopePath, routes[i].Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
routes[i].Path = path
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, routes...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RoutesParser) parseRoutes() ([]Route, error) {
|
||||||
|
var out []Route
|
||||||
|
for {
|
||||||
|
line, err := r.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
if strings.TrimSpace(line)[:1] == ")" {
|
||||||
|
return out, nil
|
||||||
|
} else {
|
||||||
|
return nil, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(line) == ".route(" {
|
||||||
|
lines, err := r.readLines(3)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
line += lines
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(line)[:1] == ")" {
|
||||||
|
return out, nil
|
||||||
|
} else if strings.HasPrefix(line, "//") {
|
||||||
|
continue
|
||||||
|
} else if !routeRegex.MatchString(line) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sm := routeRegex.FindStringSubmatch(line)
|
||||||
|
out = append(out, Route{
|
||||||
|
Path: sm[1],
|
||||||
|
Method: strings.ToUpper(sm[2]),
|
||||||
|
Struct: sm[3],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RoutesParser) readLines(n int) (string, error) {
|
||||||
|
out := ""
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
line, err := r.r.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
out += line
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RoutesParser) Reset(rd io.Reader) {
|
||||||
|
r.r.Reset(rd)
|
||||||
|
}
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
structRegex = regexp.MustCompile(`pub struct (.+) \{`)
|
||||||
|
fieldRegex = regexp.MustCompile(`(?U) {1,1}([^ ]+): (.+),`)
|
||||||
|
|
||||||
|
enumRegex = regexp.MustCompile(`pub enum (.+) \{`)
|
||||||
|
memberRegex = regexp.MustCompile(` ([^ #]+),\n`)
|
||||||
|
)
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
Struct *Struct
|
||||||
|
Enum *Enum
|
||||||
|
}
|
||||||
|
|
||||||
|
type Struct struct {
|
||||||
|
Name string
|
||||||
|
Fields []Field
|
||||||
|
}
|
||||||
|
|
||||||
|
type Field struct {
|
||||||
|
OrigName string
|
||||||
|
Name string
|
||||||
|
Type string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Enum struct {
|
||||||
|
Name string
|
||||||
|
Members []Member
|
||||||
|
}
|
||||||
|
|
||||||
|
type Member string
|
||||||
|
|
||||||
|
type StructParser struct {
|
||||||
|
r *bufio.Reader
|
||||||
|
Skip []string
|
||||||
|
TransformName func(string) string
|
||||||
|
TransformType func(string) string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStruct(r io.Reader) *StructParser {
|
||||||
|
return &StructParser{
|
||||||
|
r: bufio.NewReader(r),
|
||||||
|
TransformName: TransformNameGo,
|
||||||
|
TransformType: TransformTypeGo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StructParser) Parse() ([]Item, error) {
|
||||||
|
var out []Item
|
||||||
|
for {
|
||||||
|
line, err := s.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if structRegex.MatchString(line) {
|
||||||
|
structName := structRegex.FindStringSubmatch(line)[1]
|
||||||
|
if slices.Contains(s.Skip, structName) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the line ends with "}", this is a struct with no fields
|
||||||
|
if strings.HasSuffix(line, "}\n") {
|
||||||
|
out = append(out, Item{
|
||||||
|
Struct: &Struct{
|
||||||
|
Name: structRegex.FindStringSubmatch(line)[1],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fields, err := s.parseStructFields()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, Item{
|
||||||
|
Struct: &Struct{
|
||||||
|
Name: structName,
|
||||||
|
Fields: fields,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else if enumRegex.MatchString(line) {
|
||||||
|
enumName := enumRegex.FindStringSubmatch(line)[1]
|
||||||
|
if slices.Contains(s.Skip, enumName) {
|
||||||
|
continue
|
||||||
|
|
||||||
|
}
|
||||||
|
members, err := s.parseEnumMemebers()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, Item{
|
||||||
|
Enum: &Enum{
|
||||||
|
Name: enumName,
|
||||||
|
Members: members,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StructParser) parseStructFields() ([]Field, error) {
|
||||||
|
var out []Field
|
||||||
|
for {
|
||||||
|
line, err := s.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
if strings.HasPrefix(line, "}") {
|
||||||
|
return out, nil
|
||||||
|
} else {
|
||||||
|
return nil, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(line, "}") {
|
||||||
|
return out, nil
|
||||||
|
} else if strings.HasPrefix(line, "//") {
|
||||||
|
continue
|
||||||
|
} else if !fieldRegex.MatchString(line) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sm := fieldRegex.FindStringSubmatch(line)
|
||||||
|
if sm[1] == "Example" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, Field{
|
||||||
|
OrigName: sm[1],
|
||||||
|
Name: s.TransformName(sm[1]),
|
||||||
|
Type: s.TransformType(sm[2]),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StructParser) parseEnumMemebers() ([]Member, error) {
|
||||||
|
var out []Member
|
||||||
|
for {
|
||||||
|
line, err := s.r.ReadString('\n')
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
if strings.HasPrefix(line, "}") {
|
||||||
|
return out, nil
|
||||||
|
} else {
|
||||||
|
return nil, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(line, "}") {
|
||||||
|
return out, nil
|
||||||
|
} else if strings.HasPrefix(line, "//") {
|
||||||
|
continue
|
||||||
|
} else if !memberRegex.MatchString(line) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sm := memberRegex.FindStringSubmatch(line)
|
||||||
|
|
||||||
|
out = append(out, Member(sm[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransformTypeGo transforms Rust types to Go
|
||||||
|
//
|
||||||
|
// Example: TransformTypeGo("Option<Vec<i64>>") // returns "Optional[[]int64]"
|
||||||
|
func TransformTypeGo(t string) string {
|
||||||
|
prefix := ""
|
||||||
|
suffix := ""
|
||||||
|
|
||||||
|
for strings.HasPrefix(t, "Option<") {
|
||||||
|
t = strings.TrimPrefix(strings.TrimSuffix(t, ">"), "Option<")
|
||||||
|
prefix += "Optional["
|
||||||
|
suffix += "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
for strings.HasPrefix(t, "Vec<") {
|
||||||
|
t = strings.TrimPrefix(strings.TrimSuffix(t, ">"), "Vec<")
|
||||||
|
prefix += "[]"
|
||||||
|
}
|
||||||
|
|
||||||
|
for strings.HasPrefix(t, "Sensitive<") {
|
||||||
|
t = strings.TrimPrefix(strings.TrimSuffix(t, ">"), "Sensitive<")
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(t, "Id") {
|
||||||
|
t = "int"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch t {
|
||||||
|
case "String", "Url", "DbUrl", "Ltree":
|
||||||
|
t = "string"
|
||||||
|
case "usize":
|
||||||
|
t = "uint"
|
||||||
|
case "i64":
|
||||||
|
t = "int64"
|
||||||
|
case "i32":
|
||||||
|
t = "int32"
|
||||||
|
case "i16":
|
||||||
|
t = "int16"
|
||||||
|
case "i8":
|
||||||
|
t = "int8"
|
||||||
|
case "chrono::NaiveDateTime":
|
||||||
|
return "LemmyTime"
|
||||||
|
case "Value":
|
||||||
|
return "any"
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefix + t + suffix
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransformNameGo transforms conventional Rust naming to
|
||||||
|
// conventional Go naming.
|
||||||
|
//
|
||||||
|
// Example: TransformNameGo("post_id") // returns "PostID"
|
||||||
|
func TransformNameGo(s string) string {
|
||||||
|
out := ""
|
||||||
|
|
||||||
|
splitName := strings.Split(s, "_")
|
||||||
|
for _, segment := range splitName {
|
||||||
|
switch segment {
|
||||||
|
case "id":
|
||||||
|
out += "ID"
|
||||||
|
case "url":
|
||||||
|
out += "URL"
|
||||||
|
case "nsfw":
|
||||||
|
out += "NSFW"
|
||||||
|
default:
|
||||||
|
if len(segment) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
out += strings.ToUpper(segment[:1]) + segment[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StructParser) Reset(r io.Reader) {
|
||||||
|
s.r.Reset(r)
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestTransformNameGo(t *testing.T) {
|
||||||
|
type testcase struct {
|
||||||
|
name string
|
||||||
|
expect string
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []testcase{
|
||||||
|
{"post_id", "PostID"},
|
||||||
|
{"nsfw", "NSFW"},
|
||||||
|
{"test_url", "TestURL"},
|
||||||
|
{"some_complex_name_with_id_and_nsfw_and_url", "SomeComplexNameWithIDAndNSFWAndURL"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testcase := range cases {
|
||||||
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
|
got := TransformNameGo(testcase.name)
|
||||||
|
if got != testcase.expect {
|
||||||
|
t.Errorf("Expected %s, got %s", testcase.expect, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTransformTypeGo(t *testing.T) {
|
||||||
|
type testcase struct {
|
||||||
|
typeName string
|
||||||
|
expect string
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []testcase{
|
||||||
|
{"i16", "int16"},
|
||||||
|
{"Option<Vec<i64>>", "Optional[[]int64]"},
|
||||||
|
{"Url", "string"},
|
||||||
|
{"Sensitive<String>", "string"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testcase := range cases {
|
||||||
|
t.Run(testcase.typeName, func(t *testing.T) {
|
||||||
|
got := TransformTypeGo(testcase.typeName)
|
||||||
|
if got != testcase.expect {
|
||||||
|
t.Errorf("Expected %s, got %s", testcase.expect, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"go.elara.ws/go-lemmy"
|
|
||||||
"go.elara.ws/go-lemmy/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
c, err := lemmy.New("https://lemmygrad.ml")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = c.ClientLogin(ctx, types.Login{
|
|
||||||
UsernameOrEmail: "user@example.com",
|
|
||||||
Password: `TestPwd`,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = c.SaveUserSettings(ctx, types.SaveUserSettings{
|
|
||||||
BotAccount: types.NewOptional(true),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,12 @@
|
|||||||
module go.elara.ws/go-lemmy
|
module go.arsenm.dev/go-lemmy
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
|
retract v0.0.0-20230105203020-27ef17a00e22
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dave/jennifer v1.6.0
|
github.com/dave/jennifer v1.6.0
|
||||||
github.com/google/go-querystring v1.1.0
|
github.com/google/go-querystring v1.1.0
|
||||||
github.com/tidwall/gjson v1.17.0
|
github.com/gorilla/websocket v1.4.2
|
||||||
go.elara.ws/logger v0.0.0-20230421022458-e80700db2090
|
|
||||||
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304
|
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/gookit/color v1.5.1 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
|
||||||
github.com/tidwall/pretty v1.2.0 // indirect
|
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
|
||||||
golang.org/x/sys v0.1.0 // indirect
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,37 +1,11 @@
|
|||||||
github.com/dave/jennifer v1.6.0 h1:MQ/6emI2xM7wt0tJzJzyUik2Q3Tcn2eE0vtYgh4GPVI=
|
github.com/dave/jennifer v1.6.0 h1:MQ/6emI2xM7wt0tJzJzyUik2Q3Tcn2eE0vtYgh4GPVI=
|
||||||
github.com/dave/jennifer v1.6.0/go.mod h1:AxTG893FiZKqxy3FP1kL80VMshSMuz2G+EgvszgGRnk=
|
github.com/dave/jennifer v1.6.0/go.mod h1:AxTG893FiZKqxy3FP1kL80VMshSMuz2G+EgvszgGRnk=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||||
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
|
||||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
|
||||||
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
|
|
||||||
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
|
||||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
|
||||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
|
||||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
|
||||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
|
||||||
go.elara.ws/logger v0.0.0-20230421022458-e80700db2090 h1:RVC8XvWo6Yw4HUshqx4TSzuBDScDghafU6QFRJ4xPZg=
|
|
||||||
go.elara.ws/logger v0.0.0-20230421022458-e80700db2090/go.mod h1:qng49owViqsW5Aey93lwBXONw20oGbJIoLVscB16mPM=
|
|
||||||
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304 h1:YUqj+XKtfrn3kXjFIiZ8jwKROD7ioAOOHUuo3ZZ2opc=
|
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304 h1:YUqj+XKtfrn3kXjFIiZ8jwKROD7ioAOOHUuo3ZZ2opc=
|
||||||
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
golang.org/x/exp v0.0.0-20230105000112-eab7a2c85304/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
|
||||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"go.elara.ws/go-lemmy/types"
|
"go.arsenm.dev/go-lemmy/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is a client for Lemmy's HTTP API
|
// Client is a client for Lemmy's HTTP API
|
||||||
@@ -45,7 +45,7 @@ func (c *Client) ClientLogin(ctx context.Context, l types.Login) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Token = lr.JWT.MustValue()
|
c.Token = lr.Jwt.MustValue()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+874
-1105
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Activity struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
Data any `json:"data" url:"data,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ApID string `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Sensitive Optional[bool] `json:"sensitive" url:"sensitive,omitempty"`
|
||||||
|
}
|
||||||
|
type ActivityForm struct {
|
||||||
|
Data any `json:"data" url:"data,omitempty"`
|
||||||
|
Local Optional[bool] `json:"local" url:"local,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ApID string `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Sensitive bool `json:"sensitive" url:"sensitive,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Comment struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
ParentID Optional[int] `json:"parent_id" url:"parent_id,omitempty"`
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
ApID string `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentAlias1 struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
ParentID Optional[int] `json:"parent_id" url:"parent_id,omitempty"`
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
ApID string `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentForm struct {
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
ParentID Optional[int] `json:"parent_id" url:"parent_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
Read Optional[bool] `json:"read" url:"read,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted Optional[bool] `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
ApID Optional[string] `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local Optional[bool] `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentLike struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Score int16 `json:"score" url:"score,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentLikeForm struct {
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Score int16 `json:"score" url:"score,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentSaved struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentSavedForm struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CreateComment struct {
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
ParentID Optional[int] `json:"parent_id" url:"parent_id,omitempty"`
|
||||||
|
FormID Optional[string] `json:"form_id" url:"form_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetComment struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type EditComment struct {
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
FormID Optional[string] `json:"form_id" url:"form_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type DeleteComment struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type RemoveComment struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type MarkCommentAsRead struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type SaveComment struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Save bool `json:"save" url:"save,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentResponse struct {
|
||||||
|
CommentView CommentView `json:"comment_view" url:"comment_view,omitempty"`
|
||||||
|
RecipientIds []int `json:"recipient_ids" url:"recipient_ids,omitempty"`
|
||||||
|
FormID Optional[string] `json:"form_id" url:"form_id,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CreateCommentLike struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Score int16 `json:"score" url:"score,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetComments struct {
|
||||||
|
Type Optional[ListingType] `json:"type_" url:"type_,omitempty"`
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
CommunityName Optional[string] `json:"community_name" url:"community_name,omitempty"`
|
||||||
|
SavedOnly Optional[bool] `json:"saved_only" url:"saved_only,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetCommentsResponse struct {
|
||||||
|
Comments []CommentView `json:"comments" url:"comments,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CreateCommentReport struct {
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Reason string `json:"reason" url:"reason,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentReportResponse struct {
|
||||||
|
CommentReportView CommentReportView `json:"comment_report_view" url:"comment_report_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type ResolveCommentReport struct {
|
||||||
|
ReportID int `json:"report_id" url:"report_id,omitempty"`
|
||||||
|
Resolved bool `json:"resolved" url:"resolved,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ListCommentReports struct {
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
UnresolvedOnly Optional[bool] `json:"unresolved_only" url:"unresolved_only,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ListCommentReportsResponse struct {
|
||||||
|
CommentReports []CommentReportView `json:"comment_reports" url:"comment_reports,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CommentReport struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
OriginalCommentText string `json:"original_comment_text" url:"original_comment_text,omitempty"`
|
||||||
|
Reason string `json:"reason" url:"reason,omitempty"`
|
||||||
|
Resolved bool `json:"resolved" url:"resolved,omitempty"`
|
||||||
|
ResolverID Optional[int] `json:"resolver_id" url:"resolver_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentReportForm struct {
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
OriginalCommentText string `json:"original_comment_text" url:"original_comment_text,omitempty"`
|
||||||
|
Reason string `json:"reason" url:"reason,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Community struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Title string `json:"title" url:"title,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
NSFW bool `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
PrivateKey Optional[string] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey string `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
FollowersURL string `json:"followers_url" url:"followers_url,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
Hidden bool `json:"hidden" url:"hidden,omitempty"`
|
||||||
|
PostingRestrictedToMods bool `json:"posting_restricted_to_mods" url:"posting_restricted_to_mods,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunitySafe struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Title string `json:"title" url:"title,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
NSFW bool `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Hidden bool `json:"hidden" url:"hidden,omitempty"`
|
||||||
|
PostingRestrictedToMods bool `json:"posting_restricted_to_mods" url:"posting_restricted_to_mods,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityForm struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Title string `json:"title" url:"title,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted Optional[bool] `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
NSFW Optional[bool] `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
ActorID Optional[string] `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Local Optional[bool] `json:"local" url:"local,omitempty"`
|
||||||
|
PrivateKey Optional[Optional[string]] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey Optional[string] `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
Icon Optional[Optional[string]] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[Optional[string]] `json:"banner" url:"banner,omitempty"`
|
||||||
|
FollowersURL Optional[string] `json:"followers_url" url:"followers_url,omitempty"`
|
||||||
|
InboxURL Optional[string] `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[Optional[string]] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
Hidden Optional[bool] `json:"hidden" url:"hidden,omitempty"`
|
||||||
|
PostingRestrictedToMods Optional[bool] `json:"posting_restricted_to_mods" url:"posting_restricted_to_mods,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityModerator struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityModeratorForm struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityPersonBan struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityPersonBanForm struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityFollower struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Pending Optional[bool] `json:"pending" url:"pending,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityFollowerForm struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Pending bool `json:"pending" url:"pending,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type GetCommunity struct {
|
||||||
|
ID Optional[int] `json:"id" url:"id,omitempty"`
|
||||||
|
Name Optional[string] `json:"name" url:"name,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetCommunityResponse struct {
|
||||||
|
CommunityView CommunityView `json:"community_view" url:"community_view,omitempty"`
|
||||||
|
Site Optional[Site] `json:"site" url:"site,omitempty"`
|
||||||
|
Moderators []CommunityModeratorView `json:"moderators" url:"moderators,omitempty"`
|
||||||
|
Online uint `json:"online" url:"online,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CreateCommunity struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Title string `json:"title" url:"title,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
NSFW Optional[bool] `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
PostingRestrictedToMods Optional[bool] `json:"posting_restricted_to_mods" url:"posting_restricted_to_mods,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityResponse struct {
|
||||||
|
CommunityView CommunityView `json:"community_view" url:"community_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type ListCommunities struct {
|
||||||
|
Type Optional[ListingType] `json:"type_" url:"type_,omitempty"`
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ListCommunitiesResponse struct {
|
||||||
|
Communities []CommunityView `json:"communities" url:"communities,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type BanFromCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Ban bool `json:"ban" url:"ban,omitempty"`
|
||||||
|
RemoveData Optional[bool] `json:"remove_data" url:"remove_data,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Expires Optional[int64] `json:"expires" url:"expires,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type BanFromCommunityResponse struct {
|
||||||
|
PersonView PersonViewSafe `json:"person_view" url:"person_view,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type AddModToCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Added bool `json:"added" url:"added,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type AddModToCommunityResponse struct {
|
||||||
|
Moderators []CommunityModeratorView `json:"moderators" url:"moderators,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type EditCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Title Optional[string] `json:"title" url:"title,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
NSFW Optional[bool] `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
PostingRestrictedToMods Optional[bool] `json:"posting_restricted_to_mods" url:"posting_restricted_to_mods,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type HideCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Hidden bool `json:"hidden" url:"hidden,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type DeleteCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type RemoveCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Expires Optional[int64] `json:"expires" url:"expires,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type FollowCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Follow bool `json:"follow" url:"follow,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type BlockCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Block bool `json:"block" url:"block,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type BlockCommunityResponse struct {
|
||||||
|
CommunityView CommunityView `json:"community_view" url:"community_view,omitempty"`
|
||||||
|
Blocked bool `json:"blocked" url:"blocked,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type TransferCommunity struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CommunityBlock struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityBlockForm struct {
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type EmailVerification struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
LocalUserID int `json:"local_user_id" url:"local_user_id,omitempty"`
|
||||||
|
Email string `json:"email" url:"email,omitempty"`
|
||||||
|
VerificationCode string `json:"verification_code" url:"verification_code,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type EmailVerificationForm struct {
|
||||||
|
LocalUserID int `json:"local_user_id" url:"local_user_id,omitempty"`
|
||||||
|
Email string `json:"email" url:"email,omitempty"`
|
||||||
|
VerificationToken string `json:"verification_token" url:"verification_token,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type SortType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SortTypeActive SortType = "Active"
|
||||||
|
SortTypeHot SortType = "Hot"
|
||||||
|
SortTypeNew SortType = "New"
|
||||||
|
SortTypeTopDay SortType = "TopDay"
|
||||||
|
SortTypeTopWeek SortType = "TopWeek"
|
||||||
|
SortTypeTopMonth SortType = "TopMonth"
|
||||||
|
SortTypeTopYear SortType = "TopYear"
|
||||||
|
SortTypeTopAll SortType = "TopAll"
|
||||||
|
SortTypeMostComments SortType = "MostComments"
|
||||||
|
SortTypeNewComments SortType = "NewComments"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListingType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ListingTypeAll ListingType = "All"
|
||||||
|
ListingTypeLocal ListingType = "Local"
|
||||||
|
ListingTypeSubscribed ListingType = "Subscribed"
|
||||||
|
ListingTypeCommunity ListingType = "Community"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SearchTypeAll SearchType = "All"
|
||||||
|
SearchTypeComments SearchType = "Comments"
|
||||||
|
SearchTypePosts SearchType = "Posts"
|
||||||
|
SearchTypeCommunities SearchType = "Communities"
|
||||||
|
SearchTypeUsers SearchType = "Users"
|
||||||
|
SearchTypeUrl SearchType = "Url"
|
||||||
|
)
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type UserOperation string
|
||||||
|
|
||||||
|
const (
|
||||||
|
UserOperationLogin UserOperation = "Login"
|
||||||
|
UserOperationGetCaptcha UserOperation = "GetCaptcha"
|
||||||
|
UserOperationMarkCommentAsRead UserOperation = "MarkCommentAsRead"
|
||||||
|
UserOperationSaveComment UserOperation = "SaveComment"
|
||||||
|
UserOperationCreateCommentLike UserOperation = "CreateCommentLike"
|
||||||
|
UserOperationCreateCommentReport UserOperation = "CreateCommentReport"
|
||||||
|
UserOperationResolveCommentReport UserOperation = "ResolveCommentReport"
|
||||||
|
UserOperationListCommentReports UserOperation = "ListCommentReports"
|
||||||
|
UserOperationCreatePostLike UserOperation = "CreatePostLike"
|
||||||
|
UserOperationLockPost UserOperation = "LockPost"
|
||||||
|
UserOperationStickyPost UserOperation = "StickyPost"
|
||||||
|
UserOperationMarkPostAsRead UserOperation = "MarkPostAsRead"
|
||||||
|
UserOperationSavePost UserOperation = "SavePost"
|
||||||
|
UserOperationCreatePostReport UserOperation = "CreatePostReport"
|
||||||
|
UserOperationResolvePostReport UserOperation = "ResolvePostReport"
|
||||||
|
UserOperationListPostReports UserOperation = "ListPostReports"
|
||||||
|
UserOperationGetReportCount UserOperation = "GetReportCount"
|
||||||
|
UserOperationGetUnreadCount UserOperation = "GetUnreadCount"
|
||||||
|
UserOperationVerifyEmail UserOperation = "VerifyEmail"
|
||||||
|
UserOperationFollowCommunity UserOperation = "FollowCommunity"
|
||||||
|
UserOperationGetReplies UserOperation = "GetReplies"
|
||||||
|
UserOperationGetPersonMentions UserOperation = "GetPersonMentions"
|
||||||
|
UserOperationMarkPersonMentionAsRead UserOperation = "MarkPersonMentionAsRead"
|
||||||
|
UserOperationGetModlog UserOperation = "GetModlog"
|
||||||
|
UserOperationBanFromCommunity UserOperation = "BanFromCommunity"
|
||||||
|
UserOperationAddModToCommunity UserOperation = "AddModToCommunity"
|
||||||
|
UserOperationAddAdmin UserOperation = "AddAdmin"
|
||||||
|
UserOperationGetUnreadRegistrationApplicationCount UserOperation = "GetUnreadRegistrationApplicationCount"
|
||||||
|
UserOperationListRegistrationApplications UserOperation = "ListRegistrationApplications"
|
||||||
|
UserOperationApproveRegistrationApplication UserOperation = "ApproveRegistrationApplication"
|
||||||
|
UserOperationBanPerson UserOperation = "BanPerson"
|
||||||
|
UserOperationGetBannedPersons UserOperation = "GetBannedPersons"
|
||||||
|
UserOperationSearch UserOperation = "Search"
|
||||||
|
UserOperationResolveObject UserOperation = "ResolveObject"
|
||||||
|
UserOperationMarkAllAsRead UserOperation = "MarkAllAsRead"
|
||||||
|
UserOperationSaveUserSettings UserOperation = "SaveUserSettings"
|
||||||
|
UserOperationTransferCommunity UserOperation = "TransferCommunity"
|
||||||
|
UserOperationLeaveAdmin UserOperation = "LeaveAdmin"
|
||||||
|
UserOperationPasswordReset UserOperation = "PasswordReset"
|
||||||
|
UserOperationPasswordChange UserOperation = "PasswordChange"
|
||||||
|
UserOperationMarkPrivateMessageAsRead UserOperation = "MarkPrivateMessageAsRead"
|
||||||
|
UserOperationUserJoin UserOperation = "UserJoin"
|
||||||
|
UserOperationGetSiteConfig UserOperation = "GetSiteConfig"
|
||||||
|
UserOperationSaveSiteConfig UserOperation = "SaveSiteConfig"
|
||||||
|
UserOperationPostJoin UserOperation = "PostJoin"
|
||||||
|
UserOperationCommunityJoin UserOperation = "CommunityJoin"
|
||||||
|
UserOperationModJoin UserOperation = "ModJoin"
|
||||||
|
UserOperationChangePassword UserOperation = "ChangePassword"
|
||||||
|
UserOperationGetSiteMetadata UserOperation = "GetSiteMetadata"
|
||||||
|
UserOperationBlockCommunity UserOperation = "BlockCommunity"
|
||||||
|
UserOperationBlockPerson UserOperation = "BlockPerson"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserOperationCrud string
|
||||||
|
|
||||||
|
const (
|
||||||
|
UserOperationCrudCreateSite UserOperationCrud = "CreateSite"
|
||||||
|
UserOperationCrudGetSite UserOperationCrud = "GetSite"
|
||||||
|
UserOperationCrudEditSite UserOperationCrud = "EditSite"
|
||||||
|
UserOperationCrudCreateCommunity UserOperationCrud = "CreateCommunity"
|
||||||
|
UserOperationCrudListCommunities UserOperationCrud = "ListCommunities"
|
||||||
|
UserOperationCrudGetCommunity UserOperationCrud = "GetCommunity"
|
||||||
|
UserOperationCrudEditCommunity UserOperationCrud = "EditCommunity"
|
||||||
|
UserOperationCrudDeleteCommunity UserOperationCrud = "DeleteCommunity"
|
||||||
|
UserOperationCrudRemoveCommunity UserOperationCrud = "RemoveCommunity"
|
||||||
|
UserOperationCrudCreatePost UserOperationCrud = "CreatePost"
|
||||||
|
UserOperationCrudGetPost UserOperationCrud = "GetPost"
|
||||||
|
UserOperationCrudGetPosts UserOperationCrud = "GetPosts"
|
||||||
|
UserOperationCrudEditPost UserOperationCrud = "EditPost"
|
||||||
|
UserOperationCrudDeletePost UserOperationCrud = "DeletePost"
|
||||||
|
UserOperationCrudRemovePost UserOperationCrud = "RemovePost"
|
||||||
|
UserOperationCrudCreateComment UserOperationCrud = "CreateComment"
|
||||||
|
UserOperationCrudGetComment UserOperationCrud = "GetComment"
|
||||||
|
UserOperationCrudGetComments UserOperationCrud = "GetComments"
|
||||||
|
UserOperationCrudEditComment UserOperationCrud = "EditComment"
|
||||||
|
UserOperationCrudDeleteComment UserOperationCrud = "DeleteComment"
|
||||||
|
UserOperationCrudRemoveComment UserOperationCrud = "RemoveComment"
|
||||||
|
UserOperationCrudRegister UserOperationCrud = "Register"
|
||||||
|
UserOperationCrudGetPersonDetails UserOperationCrud = "GetPersonDetails"
|
||||||
|
UserOperationCrudDeleteAccount UserOperationCrud = "DeleteAccount"
|
||||||
|
UserOperationCrudCreatePrivateMessage UserOperationCrud = "CreatePrivateMessage"
|
||||||
|
UserOperationCrudGetPrivateMessages UserOperationCrud = "GetPrivateMessages"
|
||||||
|
UserOperationCrudEditPrivateMessage UserOperationCrud = "EditPrivateMessage"
|
||||||
|
UserOperationCrudDeletePrivateMessage UserOperationCrud = "DeletePrivateMessage"
|
||||||
|
)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package types
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type LocalUser struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
PasswordEncrypted string `json:"password_encrypted" url:"password_encrypted,omitempty"`
|
||||||
|
Email Optional[string] `json:"email" url:"email,omitempty"`
|
||||||
|
ShowNSFW bool `json:"show_nsfw" url:"show_nsfw,omitempty"`
|
||||||
|
Theme string `json:"theme" url:"theme,omitempty"`
|
||||||
|
DefaultSortType int16 `json:"default_sort_type" url:"default_sort_type,omitempty"`
|
||||||
|
DefaultListingType int16 `json:"default_listing_type" url:"default_listing_type,omitempty"`
|
||||||
|
Lang string `json:"lang" url:"lang,omitempty"`
|
||||||
|
ShowAvatars bool `json:"show_avatars" url:"show_avatars,omitempty"`
|
||||||
|
SendNotificationsToEmail bool `json:"send_notifications_to_email" url:"send_notifications_to_email,omitempty"`
|
||||||
|
ValidatorTime LemmyTime `json:"validator_time" url:"validator_time,omitempty"`
|
||||||
|
ShowBotAccounts bool `json:"show_bot_accounts" url:"show_bot_accounts,omitempty"`
|
||||||
|
ShowScores bool `json:"show_scores" url:"show_scores,omitempty"`
|
||||||
|
ShowReadPosts bool `json:"show_read_posts" url:"show_read_posts,omitempty"`
|
||||||
|
ShowNewPostNotifs bool `json:"show_new_post_notifs" url:"show_new_post_notifs,omitempty"`
|
||||||
|
EmailVerified bool `json:"email_verified" url:"email_verified,omitempty"`
|
||||||
|
AcceptedApplication bool `json:"accepted_application" url:"accepted_application,omitempty"`
|
||||||
|
}
|
||||||
|
type LocalUserForm struct {
|
||||||
|
PersonID Optional[int] `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
PasswordEncrypted Optional[string] `json:"password_encrypted" url:"password_encrypted,omitempty"`
|
||||||
|
Email Optional[Optional[string]] `json:"email" url:"email,omitempty"`
|
||||||
|
ShowNSFW Optional[bool] `json:"show_nsfw" url:"show_nsfw,omitempty"`
|
||||||
|
Theme Optional[string] `json:"theme" url:"theme,omitempty"`
|
||||||
|
DefaultSortType Optional[int16] `json:"default_sort_type" url:"default_sort_type,omitempty"`
|
||||||
|
DefaultListingType Optional[int16] `json:"default_listing_type" url:"default_listing_type,omitempty"`
|
||||||
|
Lang Optional[string] `json:"lang" url:"lang,omitempty"`
|
||||||
|
ShowAvatars Optional[bool] `json:"show_avatars" url:"show_avatars,omitempty"`
|
||||||
|
SendNotificationsToEmail Optional[bool] `json:"send_notifications_to_email" url:"send_notifications_to_email,omitempty"`
|
||||||
|
ShowBotAccounts Optional[bool] `json:"show_bot_accounts" url:"show_bot_accounts,omitempty"`
|
||||||
|
ShowScores Optional[bool] `json:"show_scores" url:"show_scores,omitempty"`
|
||||||
|
ShowReadPosts Optional[bool] `json:"show_read_posts" url:"show_read_posts,omitempty"`
|
||||||
|
ShowNewPostNotifs Optional[bool] `json:"show_new_post_notifs" url:"show_new_post_notifs,omitempty"`
|
||||||
|
EmailVerified Optional[bool] `json:"email_verified" url:"email_verified,omitempty"`
|
||||||
|
AcceptedApplication Optional[bool] `json:"accepted_application" url:"accepted_application,omitempty"`
|
||||||
|
}
|
||||||
|
type LocalUserSettings struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Email Optional[string] `json:"email" url:"email,omitempty"`
|
||||||
|
ShowNSFW bool `json:"show_nsfw" url:"show_nsfw,omitempty"`
|
||||||
|
Theme string `json:"theme" url:"theme,omitempty"`
|
||||||
|
DefaultSortType int16 `json:"default_sort_type" url:"default_sort_type,omitempty"`
|
||||||
|
DefaultListingType int16 `json:"default_listing_type" url:"default_listing_type,omitempty"`
|
||||||
|
Lang string `json:"lang" url:"lang,omitempty"`
|
||||||
|
ShowAvatars bool `json:"show_avatars" url:"show_avatars,omitempty"`
|
||||||
|
SendNotificationsToEmail bool `json:"send_notifications_to_email" url:"send_notifications_to_email,omitempty"`
|
||||||
|
ValidatorTime LemmyTime `json:"validator_time" url:"validator_time,omitempty"`
|
||||||
|
ShowBotAccounts bool `json:"show_bot_accounts" url:"show_bot_accounts,omitempty"`
|
||||||
|
ShowScores bool `json:"show_scores" url:"show_scores,omitempty"`
|
||||||
|
ShowReadPosts bool `json:"show_read_posts" url:"show_read_posts,omitempty"`
|
||||||
|
ShowNewPostNotifs bool `json:"show_new_post_notifs" url:"show_new_post_notifs,omitempty"`
|
||||||
|
EmailVerified bool `json:"email_verified" url:"email_verified,omitempty"`
|
||||||
|
AcceptedApplication bool `json:"accepted_application" url:"accepted_application,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package types
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type ModRemovePost struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemovePostForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
}
|
||||||
|
type ModLockPost struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Locked Optional[bool] `json:"locked" url:"locked,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModLockPostForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Locked Optional[bool] `json:"locked" url:"locked,omitempty"`
|
||||||
|
}
|
||||||
|
type ModStickyPost struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Stickied Optional[bool] `json:"stickied" url:"stickied,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModStickyPostForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Stickied Optional[bool] `json:"stickied" url:"stickied,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemoveComment struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemoveCommentForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemoveCommunity struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemoveCommunityForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
}
|
||||||
|
type ModBanFromCommunity struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Banned Optional[bool] `json:"banned" url:"banned,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModBanFromCommunityForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Banned Optional[bool] `json:"banned" url:"banned,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
}
|
||||||
|
type ModBan struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Banned Optional[bool] `json:"banned" url:"banned,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModHideCommunityForm struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
Hidden Optional[bool] `json:"hidden" url:"hidden,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
}
|
||||||
|
type ModHideCommunity struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Hidden Optional[bool] `json:"hidden" url:"hidden,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModBanForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Banned Optional[bool] `json:"banned" url:"banned,omitempty"`
|
||||||
|
Expires LemmyTime `json:"expires" url:"expires,omitempty"`
|
||||||
|
}
|
||||||
|
type ModAddCommunity struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModAddCommunityForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
}
|
||||||
|
type ModTransferCommunity struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModTransferCommunityForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
}
|
||||||
|
type ModAdd struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
When LemmyTime `json:"when_" url:"when_,omitempty"`
|
||||||
|
}
|
||||||
|
type ModAddForm struct {
|
||||||
|
ModPersonID int `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
OtherPersonID int `json:"other_person_id" url:"other_person_id,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
}
|
||||||
@@ -66,14 +66,6 @@ func (o Optional[T]) ValueOr(fallback T) T {
|
|||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Optional[T]) ValueOrEmpty() T {
|
|
||||||
if o.value != nil {
|
|
||||||
return *o.value
|
|
||||||
}
|
|
||||||
var value T
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o Optional[T]) MarshalJSON() ([]byte, error) {
|
func (o Optional[T]) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(o.value)
|
return json.Marshal(o.value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type PasswordResetRequest struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
TokenEncrypted string `json:"token_encrypted" url:"token_encrypted,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
LocalUserID int `json:"local_user_id" url:"local_user_id,omitempty"`
|
||||||
|
}
|
||||||
|
type PasswordResetRequestForm struct {
|
||||||
|
LocalUserID int `json:"local_user_id" url:"local_user_id,omitempty"`
|
||||||
|
TokenEncrypted string `json:"token_encrypted" url:"token_encrypted,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Person struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
PrivateKey Optional[string] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey string `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin bool `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount bool `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonSafe struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin bool `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount bool `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonAlias1 struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
PrivateKey Optional[string] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey string `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin bool `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount bool `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonSafeAlias1 struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin bool `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount bool `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonAlias2 struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
PrivateKey Optional[string] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey string `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin bool `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount bool `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonSafeAlias2 struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[string] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin bool `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount bool `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonForm struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
DisplayName Optional[Optional[string]] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Avatar Optional[Optional[string]] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banned Optional[bool] `json:"banned" url:"banned,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ActorID Optional[string] `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
Bio Optional[Optional[string]] `json:"bio" url:"bio,omitempty"`
|
||||||
|
Local Optional[bool] `json:"local" url:"local,omitempty"`
|
||||||
|
PrivateKey Optional[Optional[string]] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey Optional[string] `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
Banner Optional[Optional[string]] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Deleted Optional[bool] `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
InboxURL Optional[string] `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
SharedInboxURL Optional[Optional[string]] `json:"shared_inbox_url" url:"shared_inbox_url,omitempty"`
|
||||||
|
MatrixUserID Optional[Optional[string]] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
Admin Optional[bool] `json:"admin" url:"admin,omitempty"`
|
||||||
|
BotAccount Optional[bool] `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
BanExpires LemmyTime `json:"ban_expires" url:"ban_expires,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,228 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Login struct {
|
||||||
|
UsernameOrEmail string `json:"username_or_email" url:"username_or_email,omitempty"`
|
||||||
|
Password string `json:"password" url:"password,omitempty"`
|
||||||
|
}
|
||||||
|
type Register struct {
|
||||||
|
Username string `json:"username" url:"username,omitempty"`
|
||||||
|
Password string `json:"password" url:"password,omitempty"`
|
||||||
|
PasswordVerify string `json:"password_verify" url:"password_verify,omitempty"`
|
||||||
|
ShowNSFW bool `json:"show_nsfw" url:"show_nsfw,omitempty"`
|
||||||
|
Email Optional[string] `json:"email" url:"email,omitempty"`
|
||||||
|
CaptchaUuid Optional[string] `json:"captcha_uuid" url:"captcha_uuid,omitempty"`
|
||||||
|
CaptchaAnswer Optional[string] `json:"captcha_answer" url:"captcha_answer,omitempty"`
|
||||||
|
Honeypot Optional[string] `json:"honeypot" url:"honeypot,omitempty"`
|
||||||
|
Answer Optional[string] `json:"answer" url:"answer,omitempty"`
|
||||||
|
}
|
||||||
|
type GetCaptcha struct{}
|
||||||
|
type GetCaptchaResponse struct {
|
||||||
|
Ok Optional[CaptchaResponse] `json:"ok" url:"ok,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CaptchaResponse struct {
|
||||||
|
Png string `json:"png" url:"png,omitempty"`
|
||||||
|
Wav string `json:"wav" url:"wav,omitempty"`
|
||||||
|
Uuid string `json:"uuid" url:"uuid,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type SaveUserSettings struct {
|
||||||
|
ShowNSFW Optional[bool] `json:"show_nsfw" url:"show_nsfw,omitempty"`
|
||||||
|
ShowScores Optional[bool] `json:"show_scores" url:"show_scores,omitempty"`
|
||||||
|
Theme Optional[string] `json:"theme" url:"theme,omitempty"`
|
||||||
|
DefaultSortType Optional[int16] `json:"default_sort_type" url:"default_sort_type,omitempty"`
|
||||||
|
DefaultListingType Optional[int16] `json:"default_listing_type" url:"default_listing_type,omitempty"`
|
||||||
|
Lang Optional[string] `json:"lang" url:"lang,omitempty"`
|
||||||
|
Avatar Optional[string] `json:"avatar" url:"avatar,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
DisplayName Optional[string] `json:"display_name" url:"display_name,omitempty"`
|
||||||
|
Email Optional[string] `json:"email" url:"email,omitempty"`
|
||||||
|
Bio Optional[string] `json:"bio" url:"bio,omitempty"`
|
||||||
|
MatrixUserID Optional[string] `json:"matrix_user_id" url:"matrix_user_id,omitempty"`
|
||||||
|
ShowAvatars Optional[bool] `json:"show_avatars" url:"show_avatars,omitempty"`
|
||||||
|
SendNotificationsToEmail Optional[bool] `json:"send_notifications_to_email" url:"send_notifications_to_email,omitempty"`
|
||||||
|
BotAccount Optional[bool] `json:"bot_account" url:"bot_account,omitempty"`
|
||||||
|
ShowBotAccounts Optional[bool] `json:"show_bot_accounts" url:"show_bot_accounts,omitempty"`
|
||||||
|
ShowReadPosts Optional[bool] `json:"show_read_posts" url:"show_read_posts,omitempty"`
|
||||||
|
ShowNewPostNotifs Optional[bool] `json:"show_new_post_notifs" url:"show_new_post_notifs,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ChangePassword struct {
|
||||||
|
NewPassword string `json:"new_password" url:"new_password,omitempty"`
|
||||||
|
NewPasswordVerify string `json:"new_password_verify" url:"new_password_verify,omitempty"`
|
||||||
|
OldPassword string `json:"old_password" url:"old_password,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type LoginResponse struct {
|
||||||
|
Jwt Optional[string] `json:"jwt" url:"jwt,omitempty"`
|
||||||
|
RegistrationCreated bool `json:"registration_created" url:"registration_created,omitempty"`
|
||||||
|
VerifyEmailSent bool `json:"verify_email_sent" url:"verify_email_sent,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetPersonDetails struct {
|
||||||
|
PersonID Optional[int] `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Username Optional[string] `json:"username" url:"username,omitempty"`
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
SavedOnly Optional[bool] `json:"saved_only" url:"saved_only,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetPersonDetailsResponse struct {
|
||||||
|
PersonView PersonViewSafe `json:"person_view" url:"person_view,omitempty"`
|
||||||
|
Comments []CommentView `json:"comments" url:"comments,omitempty"`
|
||||||
|
Posts []PostView `json:"posts" url:"posts,omitempty"`
|
||||||
|
Moderates []CommunityModeratorView `json:"moderates" url:"moderates,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetRepliesResponse struct {
|
||||||
|
Replies []CommentView `json:"replies" url:"replies,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetPersonMentionsResponse struct {
|
||||||
|
Mentions []PersonMentionView `json:"mentions" url:"mentions,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type MarkAllAsRead struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type AddAdmin struct {
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Added bool `json:"added" url:"added,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type AddAdminResponse struct {
|
||||||
|
Admins []PersonViewSafe `json:"admins" url:"admins,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type BanPerson struct {
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Ban bool `json:"ban" url:"ban,omitempty"`
|
||||||
|
RemoveData Optional[bool] `json:"remove_data" url:"remove_data,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Expires Optional[int64] `json:"expires" url:"expires,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetBannedPersons struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type BannedPersonsResponse struct {
|
||||||
|
Banned []PersonViewSafe `json:"banned" url:"banned,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type BanPersonResponse struct {
|
||||||
|
PersonView PersonViewSafe `json:"person_view" url:"person_view,omitempty"`
|
||||||
|
Banned bool `json:"banned" url:"banned,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type BlockPerson struct {
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Block bool `json:"block" url:"block,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type BlockPersonResponse struct {
|
||||||
|
PersonView PersonViewSafe `json:"person_view" url:"person_view,omitempty"`
|
||||||
|
Blocked bool `json:"blocked" url:"blocked,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetReplies struct {
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
UnreadOnly Optional[bool] `json:"unread_only" url:"unread_only,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetPersonMentions struct {
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
UnreadOnly Optional[bool] `json:"unread_only" url:"unread_only,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type MarkPersonMentionAsRead struct {
|
||||||
|
PersonMentionID int `json:"person_mention_id" url:"person_mention_id,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonMentionResponse struct {
|
||||||
|
PersonMentionView PersonMentionView `json:"person_mention_view" url:"person_mention_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type DeleteAccount struct {
|
||||||
|
Password string `json:"password" url:"password,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type DeleteAccountResponse struct {
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type PasswordReset struct {
|
||||||
|
Email string `json:"email" url:"email,omitempty"`
|
||||||
|
}
|
||||||
|
type PasswordResetResponse struct {
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type PasswordChangeAfterReset struct {
|
||||||
|
Token string `json:"token" url:"token,omitempty"`
|
||||||
|
Password string `json:"password" url:"password,omitempty"`
|
||||||
|
PasswordVerify string `json:"password_verify" url:"password_verify,omitempty"`
|
||||||
|
}
|
||||||
|
type CreatePrivateMessage struct {
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
RecipientID int `json:"recipient_id" url:"recipient_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type EditPrivateMessage struct {
|
||||||
|
PrivateMessageID int `json:"private_message_id" url:"private_message_id,omitempty"`
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type DeletePrivateMessage struct {
|
||||||
|
PrivateMessageID int `json:"private_message_id" url:"private_message_id,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type MarkPrivateMessageAsRead struct {
|
||||||
|
PrivateMessageID int `json:"private_message_id" url:"private_message_id,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetPrivateMessages struct {
|
||||||
|
UnreadOnly Optional[bool] `json:"unread_only" url:"unread_only,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type PrivateMessagesResponse struct {
|
||||||
|
PrivateMessages []PrivateMessageView `json:"private_messages" url:"private_messages,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type PrivateMessageResponse struct {
|
||||||
|
PrivateMessageView PrivateMessageView `json:"private_message_view" url:"private_message_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetReportCount struct {
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetReportCountResponse struct {
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
CommentReports int64 `json:"comment_reports" url:"comment_reports,omitempty"`
|
||||||
|
PostReports int64 `json:"post_reports" url:"post_reports,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetUnreadCount struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetUnreadCountResponse struct {
|
||||||
|
Replies int64 `json:"replies" url:"replies,omitempty"`
|
||||||
|
Mentions int64 `json:"mentions" url:"mentions,omitempty"`
|
||||||
|
PrivateMessages int64 `json:"private_messages" url:"private_messages,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type VerifyEmail struct {
|
||||||
|
Token string `json:"token" url:"token,omitempty"`
|
||||||
|
}
|
||||||
|
type VerifyEmailResponse struct {
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type PersonBlock struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
TargetID int `json:"target_id" url:"target_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonBlockForm struct {
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
TargetID int `json:"target_id" url:"target_id,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type PersonMention struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
RecipientID int `json:"recipient_id" url:"recipient_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonMentionForm struct {
|
||||||
|
RecipientID int `json:"recipient_id" url:"recipient_id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Read Optional[bool] `json:"read" url:"read,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Post struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
URL Optional[string] `json:"url" url:"url,omitempty"`
|
||||||
|
Body Optional[string] `json:"body" url:"body,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Locked bool `json:"locked" url:"locked,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
NSFW bool `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
Stickied bool `json:"stickied" url:"stickied,omitempty"`
|
||||||
|
EmbedTitle Optional[string] `json:"embed_title" url:"embed_title,omitempty"`
|
||||||
|
EmbedDescription Optional[string] `json:"embed_description" url:"embed_description,omitempty"`
|
||||||
|
EmbedHtml Optional[string] `json:"embed_html" url:"embed_html,omitempty"`
|
||||||
|
ThumbnailURL Optional[string] `json:"thumbnail_url" url:"thumbnail_url,omitempty"`
|
||||||
|
ApID string `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
|
type PostForm struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
NSFW Optional[bool] `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
URL Optional[string] `json:"url" url:"url,omitempty"`
|
||||||
|
Body Optional[string] `json:"body" url:"body,omitempty"`
|
||||||
|
Removed Optional[bool] `json:"removed" url:"removed,omitempty"`
|
||||||
|
Locked Optional[bool] `json:"locked" url:"locked,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
Deleted Optional[bool] `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Stickied Optional[bool] `json:"stickied" url:"stickied,omitempty"`
|
||||||
|
EmbedTitle Optional[string] `json:"embed_title" url:"embed_title,omitempty"`
|
||||||
|
EmbedDescription Optional[string] `json:"embed_description" url:"embed_description,omitempty"`
|
||||||
|
EmbedHtml Optional[string] `json:"embed_html" url:"embed_html,omitempty"`
|
||||||
|
ThumbnailURL Optional[string] `json:"thumbnail_url" url:"thumbnail_url,omitempty"`
|
||||||
|
ApID Optional[string] `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local Optional[bool] `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
|
type PostLike struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Score int16 `json:"score" url:"score,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type PostLikeForm struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Score int16 `json:"score" url:"score,omitempty"`
|
||||||
|
}
|
||||||
|
type PostSaved struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type PostSavedForm struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
}
|
||||||
|
type PostRead struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type PostReadForm struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CreatePost struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
URL Optional[string] `json:"url" url:"url,omitempty"`
|
||||||
|
Body Optional[string] `json:"body" url:"body,omitempty"`
|
||||||
|
Honeypot Optional[string] `json:"honeypot" url:"honeypot,omitempty"`
|
||||||
|
NSFW Optional[bool] `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type PostResponse struct {
|
||||||
|
PostView PostView `json:"post_view" url:"post_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetPost struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetPostResponse struct {
|
||||||
|
PostView PostView `json:"post_view" url:"post_view,omitempty"`
|
||||||
|
CommunityView CommunityView `json:"community_view" url:"community_view,omitempty"`
|
||||||
|
Comments []CommentView `json:"comments" url:"comments,omitempty"`
|
||||||
|
Moderators []CommunityModeratorView `json:"moderators" url:"moderators,omitempty"`
|
||||||
|
Online uint `json:"online" url:"online,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetPosts struct {
|
||||||
|
Type Optional[ListingType] `json:"type_" url:"type_,omitempty"`
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
CommunityName Optional[string] `json:"community_name" url:"community_name,omitempty"`
|
||||||
|
SavedOnly Optional[bool] `json:"saved_only" url:"saved_only,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetPostsResponse struct {
|
||||||
|
Posts []PostView `json:"posts" url:"posts,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CreatePostLike struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Score int16 `json:"score" url:"score,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type EditPost struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Name Optional[string] `json:"name" url:"name,omitempty"`
|
||||||
|
URL Optional[string] `json:"url" url:"url,omitempty"`
|
||||||
|
Body Optional[string] `json:"body" url:"body,omitempty"`
|
||||||
|
NSFW Optional[bool] `json:"nsfw" url:"nsfw,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type DeletePost struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type RemovePost struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Removed bool `json:"removed" url:"removed,omitempty"`
|
||||||
|
Reason Optional[string] `json:"reason" url:"reason,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type MarkPostAsRead struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type LockPost struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Locked bool `json:"locked" url:"locked,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type StickyPost struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Stickied bool `json:"stickied" url:"stickied,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type SavePost struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Save bool `json:"save" url:"save,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type CreatePostReport struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Reason string `json:"reason" url:"reason,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type PostReportResponse struct {
|
||||||
|
PostReportView PostReportView `json:"post_report_view" url:"post_report_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type ResolvePostReport struct {
|
||||||
|
ReportID int `json:"report_id" url:"report_id,omitempty"`
|
||||||
|
Resolved bool `json:"resolved" url:"resolved,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ListPostReports struct {
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
UnresolvedOnly Optional[bool] `json:"unresolved_only" url:"unresolved_only,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ListPostReportsResponse struct {
|
||||||
|
PostReports []PostReportView `json:"post_reports" url:"post_reports,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetSiteMetadata struct {
|
||||||
|
URL string `json:"url" url:"url,omitempty"`
|
||||||
|
}
|
||||||
|
type GetSiteMetadataResponse struct {
|
||||||
|
Metadata SiteMetadata `json:"metadata" url:"metadata,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type SiteMetadata struct {
|
||||||
|
Title Optional[string] `json:"title" url:"title,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Image Optional[string] `json:"image" url:"image,omitempty"`
|
||||||
|
Html Optional[string] `json:"html" url:"html,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type PostReport struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
OriginalPostName string `json:"original_post_name" url:"original_post_name,omitempty"`
|
||||||
|
OriginalPostURL Optional[string] `json:"original_post_url" url:"original_post_url,omitempty"`
|
||||||
|
OriginalPostBody Optional[string] `json:"original_post_body" url:"original_post_body,omitempty"`
|
||||||
|
Reason string `json:"reason" url:"reason,omitempty"`
|
||||||
|
Resolved bool `json:"resolved" url:"resolved,omitempty"`
|
||||||
|
ResolverID Optional[int] `json:"resolver_id" url:"resolver_id,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
}
|
||||||
|
type PostReportForm struct {
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
OriginalPostName string `json:"original_post_name" url:"original_post_name,omitempty"`
|
||||||
|
OriginalPostURL Optional[string] `json:"original_post_url" url:"original_post_url,omitempty"`
|
||||||
|
OriginalPostBody Optional[string] `json:"original_post_body" url:"original_post_body,omitempty"`
|
||||||
|
Reason string `json:"reason" url:"reason,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type PrivateMessage struct {
|
||||||
|
ID int `json:"id" url:"id,omitempty"`
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
RecipientID int `json:"recipient_id" url:"recipient_id,omitempty"`
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
Deleted bool `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ApID string `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local bool `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
|
type PrivateMessageForm struct {
|
||||||
|
CreatorID int `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
RecipientID int `json:"recipient_id" url:"recipient_id,omitempty"`
|
||||||
|
Content string `json:"content" url:"content,omitempty"`
|
||||||
|
Deleted Optional[bool] `json:"deleted" url:"deleted,omitempty"`
|
||||||
|
Read Optional[bool] `json:"read" url:"read,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
ApID Optional[string] `json:"ap_id" url:"ap_id,omitempty"`
|
||||||
|
Local Optional[bool] `json:"local" url:"local,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type RegistrationApplication struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
LocalUserID int `json:"local_user_id" url:"local_user_id,omitempty"`
|
||||||
|
Answer string `json:"answer" url:"answer,omitempty"`
|
||||||
|
AdminID Optional[int] `json:"admin_id" url:"admin_id,omitempty"`
|
||||||
|
DenyReason Optional[string] `json:"deny_reason" url:"deny_reason,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type RegistrationApplicationForm struct {
|
||||||
|
LocalUserID Optional[int] `json:"local_user_id" url:"local_user_id,omitempty"`
|
||||||
|
Answer Optional[string] `json:"answer" url:"answer,omitempty"`
|
||||||
|
AdminID Optional[int] `json:"admin_id" url:"admin_id,omitempty"`
|
||||||
|
DenyReason Optional[Optional[string]] `json:"deny_reason" url:"deny_reason,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package types
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Secret struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
JwtSecret string `json:"jwt_secret" url:"jwt_secret,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
package types
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Site struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Sidebar Optional[string] `json:"sidebar" url:"sidebar,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
EnableDownvotes bool `json:"enable_downvotes" url:"enable_downvotes,omitempty"`
|
||||||
|
OpenRegistration bool `json:"open_registration" url:"open_registration,omitempty"`
|
||||||
|
EnableNSFW bool `json:"enable_nsfw" url:"enable_nsfw,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
CommunityCreationAdminOnly bool `json:"community_creation_admin_only" url:"community_creation_admin_only,omitempty"`
|
||||||
|
RequireEmailVerification bool `json:"require_email_verification" url:"require_email_verification,omitempty"`
|
||||||
|
RequireApplication bool `json:"require_application" url:"require_application,omitempty"`
|
||||||
|
ApplicationQuestion Optional[string] `json:"application_question" url:"application_question,omitempty"`
|
||||||
|
PrivateInstance bool `json:"private_instance" url:"private_instance,omitempty"`
|
||||||
|
ActorID string `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
InboxURL string `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
PrivateKey Optional[string] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey string `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
DefaultTheme string `json:"default_theme" url:"default_theme,omitempty"`
|
||||||
|
DefaultPostListingType string `json:"default_post_listing_type" url:"default_post_listing_type,omitempty"`
|
||||||
|
LegalInformation Optional[string] `json:"legal_information" url:"legal_information,omitempty"`
|
||||||
|
}
|
||||||
|
type SiteForm struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Sidebar Optional[Optional[string]] `json:"sidebar" url:"sidebar,omitempty"`
|
||||||
|
Updated LemmyTime `json:"updated" url:"updated,omitempty"`
|
||||||
|
EnableDownvotes Optional[bool] `json:"enable_downvotes" url:"enable_downvotes,omitempty"`
|
||||||
|
OpenRegistration Optional[bool] `json:"open_registration" url:"open_registration,omitempty"`
|
||||||
|
EnableNSFW Optional[bool] `json:"enable_nsfw" url:"enable_nsfw,omitempty"`
|
||||||
|
Icon Optional[Optional[string]] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[Optional[string]] `json:"banner" url:"banner,omitempty"`
|
||||||
|
Description Optional[Optional[string]] `json:"description" url:"description,omitempty"`
|
||||||
|
CommunityCreationAdminOnly Optional[bool] `json:"community_creation_admin_only" url:"community_creation_admin_only,omitempty"`
|
||||||
|
RequireEmailVerification Optional[bool] `json:"require_email_verification" url:"require_email_verification,omitempty"`
|
||||||
|
RequireApplication Optional[bool] `json:"require_application" url:"require_application,omitempty"`
|
||||||
|
ApplicationQuestion Optional[Optional[string]] `json:"application_question" url:"application_question,omitempty"`
|
||||||
|
PrivateInstance Optional[bool] `json:"private_instance" url:"private_instance,omitempty"`
|
||||||
|
ActorID Optional[string] `json:"actor_id" url:"actor_id,omitempty"`
|
||||||
|
LastRefreshedAt LemmyTime `json:"last_refreshed_at" url:"last_refreshed_at,omitempty"`
|
||||||
|
InboxURL Optional[string] `json:"inbox_url" url:"inbox_url,omitempty"`
|
||||||
|
PrivateKey Optional[Optional[string]] `json:"private_key" url:"private_key,omitempty"`
|
||||||
|
PublicKey Optional[string] `json:"public_key" url:"public_key,omitempty"`
|
||||||
|
DefaultTheme Optional[string] `json:"default_theme" url:"default_theme,omitempty"`
|
||||||
|
DefaultPostListingType Optional[string] `json:"default_post_listing_type" url:"default_post_listing_type,omitempty"`
|
||||||
|
LegalInformation Optional[string] `json:"legal_information" url:"legal_information,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Search struct {
|
||||||
|
Q string `json:"q" url:"q,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
CommunityName Optional[string] `json:"community_name" url:"community_name,omitempty"`
|
||||||
|
CreatorID Optional[int] `json:"creator_id" url:"creator_id,omitempty"`
|
||||||
|
Type Optional[SearchType] `json:"type_" url:"type_,omitempty"`
|
||||||
|
Sort Optional[SortType] `json:"sort" url:"sort,omitempty"`
|
||||||
|
ListingType Optional[ListingType] `json:"listing_type" url:"listing_type,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type SearchResponse struct {
|
||||||
|
Type string `json:"type_" url:"type_,omitempty"`
|
||||||
|
Comments []CommentView `json:"comments" url:"comments,omitempty"`
|
||||||
|
Posts []PostView `json:"posts" url:"posts,omitempty"`
|
||||||
|
Communities []CommunityView `json:"communities" url:"communities,omitempty"`
|
||||||
|
Users []PersonViewSafe `json:"users" url:"users,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type ResolveObject struct {
|
||||||
|
Q string `json:"q" url:"q,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ResolveObjectResponse struct {
|
||||||
|
Comment Optional[CommentView] `json:"comment" url:"comment,omitempty"`
|
||||||
|
Post Optional[PostView] `json:"post" url:"post,omitempty"`
|
||||||
|
Community Optional[CommunityView] `json:"community" url:"community,omitempty"`
|
||||||
|
Person Optional[PersonViewSafe] `json:"person" url:"person,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetModlog struct {
|
||||||
|
ModPersonID Optional[int] `json:"mod_person_id" url:"mod_person_id,omitempty"`
|
||||||
|
CommunityID Optional[int] `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetModlogResponse struct {
|
||||||
|
RemovedPosts []ModRemovePostView `json:"removed_posts" url:"removed_posts,omitempty"`
|
||||||
|
LockedPosts []ModLockPostView `json:"locked_posts" url:"locked_posts,omitempty"`
|
||||||
|
StickiedPosts []ModStickyPostView `json:"stickied_posts" url:"stickied_posts,omitempty"`
|
||||||
|
RemovedComments []ModRemoveCommentView `json:"removed_comments" url:"removed_comments,omitempty"`
|
||||||
|
RemovedCommunities []ModRemoveCommunityView `json:"removed_communities" url:"removed_communities,omitempty"`
|
||||||
|
BannedFromCommunity []ModBanFromCommunityView `json:"banned_from_community" url:"banned_from_community,omitempty"`
|
||||||
|
Banned []ModBanView `json:"banned" url:"banned,omitempty"`
|
||||||
|
AddedToCommunity []ModAddCommunityView `json:"added_to_community" url:"added_to_community,omitempty"`
|
||||||
|
TransferredToCommunity []ModTransferCommunityView `json:"transferred_to_community" url:"transferred_to_community,omitempty"`
|
||||||
|
Added []ModAddView `json:"added" url:"added,omitempty"`
|
||||||
|
HiddenCommunities []ModHideCommunityView `json:"hidden_communities" url:"hidden_communities,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CreateSite struct {
|
||||||
|
Name string `json:"name" url:"name,omitempty"`
|
||||||
|
Sidebar Optional[string] `json:"sidebar" url:"sidebar,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
EnableDownvotes Optional[bool] `json:"enable_downvotes" url:"enable_downvotes,omitempty"`
|
||||||
|
OpenRegistration Optional[bool] `json:"open_registration" url:"open_registration,omitempty"`
|
||||||
|
EnableNSFW Optional[bool] `json:"enable_nsfw" url:"enable_nsfw,omitempty"`
|
||||||
|
CommunityCreationAdminOnly Optional[bool] `json:"community_creation_admin_only" url:"community_creation_admin_only,omitempty"`
|
||||||
|
RequireEmailVerification Optional[bool] `json:"require_email_verification" url:"require_email_verification,omitempty"`
|
||||||
|
RequireApplication Optional[bool] `json:"require_application" url:"require_application,omitempty"`
|
||||||
|
ApplicationQuestion Optional[string] `json:"application_question" url:"application_question,omitempty"`
|
||||||
|
PrivateInstance Optional[bool] `json:"private_instance" url:"private_instance,omitempty"`
|
||||||
|
DefaultTheme Optional[string] `json:"default_theme" url:"default_theme,omitempty"`
|
||||||
|
DefaultPostListingType Optional[string] `json:"default_post_listing_type" url:"default_post_listing_type,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type EditSite struct {
|
||||||
|
Name Optional[string] `json:"name" url:"name,omitempty"`
|
||||||
|
Sidebar Optional[string] `json:"sidebar" url:"sidebar,omitempty"`
|
||||||
|
Description Optional[string] `json:"description" url:"description,omitempty"`
|
||||||
|
Icon Optional[string] `json:"icon" url:"icon,omitempty"`
|
||||||
|
Banner Optional[string] `json:"banner" url:"banner,omitempty"`
|
||||||
|
EnableDownvotes Optional[bool] `json:"enable_downvotes" url:"enable_downvotes,omitempty"`
|
||||||
|
OpenRegistration Optional[bool] `json:"open_registration" url:"open_registration,omitempty"`
|
||||||
|
EnableNSFW Optional[bool] `json:"enable_nsfw" url:"enable_nsfw,omitempty"`
|
||||||
|
CommunityCreationAdminOnly Optional[bool] `json:"community_creation_admin_only" url:"community_creation_admin_only,omitempty"`
|
||||||
|
RequireEmailVerification Optional[bool] `json:"require_email_verification" url:"require_email_verification,omitempty"`
|
||||||
|
RequireApplication Optional[bool] `json:"require_application" url:"require_application,omitempty"`
|
||||||
|
ApplicationQuestion Optional[string] `json:"application_question" url:"application_question,omitempty"`
|
||||||
|
PrivateInstance Optional[bool] `json:"private_instance" url:"private_instance,omitempty"`
|
||||||
|
DefaultTheme Optional[string] `json:"default_theme" url:"default_theme,omitempty"`
|
||||||
|
DefaultPostListingType Optional[string] `json:"default_post_listing_type" url:"default_post_listing_type,omitempty"`
|
||||||
|
LegalInformation Optional[string] `json:"legal_information" url:"legal_information,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetSite struct {
|
||||||
|
Auth Optional[string] `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type SiteResponse struct {
|
||||||
|
SiteView SiteView `json:"site_view" url:"site_view,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetSiteResponse struct {
|
||||||
|
SiteView Optional[SiteView] `json:"site_view" url:"site_view,omitempty"`
|
||||||
|
Admins []PersonViewSafe `json:"admins" url:"admins,omitempty"`
|
||||||
|
Online uint `json:"online" url:"online,omitempty"`
|
||||||
|
Version string `json:"version" url:"version,omitempty"`
|
||||||
|
MyUser Optional[MyUserInfo] `json:"my_user" url:"my_user,omitempty"`
|
||||||
|
FederatedInstances Optional[FederatedInstances] `json:"federated_instances" url:"federated_instances,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type MyUserInfo struct {
|
||||||
|
LocalUserView LocalUserSettingsView `json:"local_user_view" url:"local_user_view,omitempty"`
|
||||||
|
Follows []CommunityFollowerView `json:"follows" url:"follows,omitempty"`
|
||||||
|
Moderates []CommunityModeratorView `json:"moderates" url:"moderates,omitempty"`
|
||||||
|
CommunityBlocks []CommunityBlockView `json:"community_blocks" url:"community_blocks,omitempty"`
|
||||||
|
PersonBlocks []PersonBlockView `json:"person_blocks" url:"person_blocks,omitempty"`
|
||||||
|
}
|
||||||
|
type LeaveAdmin struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetSiteConfig struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetSiteConfigResponse struct {
|
||||||
|
ConfigHjson string `json:"config_hjson" url:"config_hjson,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type SaveSiteConfig struct {
|
||||||
|
ConfigHjson string `json:"config_hjson" url:"config_hjson,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type FederatedInstances struct {
|
||||||
|
Linked []string `json:"linked" url:"linked,omitempty"`
|
||||||
|
Allowed Optional[[]string] `json:"allowed" url:"allowed,omitempty"`
|
||||||
|
Blocked Optional[[]string] `json:"blocked" url:"blocked,omitempty"`
|
||||||
|
}
|
||||||
|
type ListRegistrationApplications struct {
|
||||||
|
UnreadOnly Optional[bool] `json:"unread_only" url:"unread_only,omitempty"`
|
||||||
|
Page Optional[int64] `json:"page" url:"page,omitempty"`
|
||||||
|
Limit Optional[int64] `json:"limit" url:"limit,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type ListRegistrationApplicationsResponse struct {
|
||||||
|
RegistrationApplications []RegistrationApplicationView `json:"registration_applications" url:"registration_applications,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type ApproveRegistrationApplication struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
Approve bool `json:"approve" url:"approve,omitempty"`
|
||||||
|
DenyReason Optional[string] `json:"deny_reason" url:"deny_reason,omitempty"`
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type RegistrationApplicationResponse struct {
|
||||||
|
RegistrationApplication RegistrationApplicationView `json:"registration_application" url:"registration_application,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type GetUnreadRegistrationApplicationCount struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type GetUnreadRegistrationApplicationCountResponse struct {
|
||||||
|
RegistrationApplications int64 `json:"registration_applications" url:"registration_applications,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CommentReportView struct {
|
||||||
|
CommentReport CommentReport `json:"comment_report" url:"comment_report,omitempty"`
|
||||||
|
Comment Comment `json:"comment" url:"comment,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
CommentCreator PersonSafeAlias1 `json:"comment_creator" url:"comment_creator,omitempty"`
|
||||||
|
Counts CommentAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
CreatorBannedFromCommunity bool `json:"creator_banned_from_community" url:"creator_banned_from_community,omitempty"`
|
||||||
|
MyVote Optional[int16] `json:"my_vote" url:"my_vote,omitempty"`
|
||||||
|
Resolver Optional[PersonSafeAlias2] `json:"resolver" url:"resolver,omitempty"`
|
||||||
|
}
|
||||||
|
type CommentView struct {
|
||||||
|
Comment Comment `json:"comment" url:"comment,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
Recipient Optional[PersonSafeAlias1] `json:"recipient" url:"recipient,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Counts CommentAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
CreatorBannedFromCommunity bool `json:"creator_banned_from_community" url:"creator_banned_from_community,omitempty"`
|
||||||
|
Subscribed bool `json:"subscribed" url:"subscribed,omitempty"`
|
||||||
|
Saved bool `json:"saved" url:"saved,omitempty"`
|
||||||
|
CreatorBlocked bool `json:"creator_blocked" url:"creator_blocked,omitempty"`
|
||||||
|
MyVote Optional[int16] `json:"my_vote" url:"my_vote,omitempty"`
|
||||||
|
}
|
||||||
|
type LocalUserView struct {
|
||||||
|
LocalUser LocalUser `json:"local_user" url:"local_user,omitempty"`
|
||||||
|
Person Person `json:"person" url:"person,omitempty"`
|
||||||
|
Counts PersonAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
}
|
||||||
|
type LocalUserSettingsView struct {
|
||||||
|
LocalUser LocalUserSettings `json:"local_user" url:"local_user,omitempty"`
|
||||||
|
Person PersonSafe `json:"person" url:"person,omitempty"`
|
||||||
|
Counts PersonAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
}
|
||||||
|
type PostReportView struct {
|
||||||
|
PostReport PostReport `json:"post_report" url:"post_report,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
PostCreator PersonSafeAlias1 `json:"post_creator" url:"post_creator,omitempty"`
|
||||||
|
CreatorBannedFromCommunity bool `json:"creator_banned_from_community" url:"creator_banned_from_community,omitempty"`
|
||||||
|
MyVote Optional[int16] `json:"my_vote" url:"my_vote,omitempty"`
|
||||||
|
Counts PostAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
Resolver Optional[PersonSafeAlias2] `json:"resolver" url:"resolver,omitempty"`
|
||||||
|
}
|
||||||
|
type PostView struct {
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
CreatorBannedFromCommunity bool `json:"creator_banned_from_community" url:"creator_banned_from_community,omitempty"`
|
||||||
|
Counts PostAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
Subscribed bool `json:"subscribed" url:"subscribed,omitempty"`
|
||||||
|
Saved bool `json:"saved" url:"saved,omitempty"`
|
||||||
|
Read bool `json:"read" url:"read,omitempty"`
|
||||||
|
CreatorBlocked bool `json:"creator_blocked" url:"creator_blocked,omitempty"`
|
||||||
|
MyVote Optional[int16] `json:"my_vote" url:"my_vote,omitempty"`
|
||||||
|
}
|
||||||
|
type PrivateMessageView struct {
|
||||||
|
PrivateMessage PrivateMessage `json:"private_message" url:"private_message,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
Recipient PersonSafeAlias1 `json:"recipient" url:"recipient,omitempty"`
|
||||||
|
}
|
||||||
|
type RegistrationApplicationView struct {
|
||||||
|
RegistrationApplication RegistrationApplication `json:"registration_application" url:"registration_application,omitempty"`
|
||||||
|
CreatorLocalUser LocalUserSettings `json:"creator_local_user" url:"creator_local_user,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
Admin Optional[PersonSafeAlias1] `json:"admin" url:"admin,omitempty"`
|
||||||
|
}
|
||||||
|
type SiteView struct {
|
||||||
|
Site Site `json:"site" url:"site,omitempty"`
|
||||||
|
Counts SiteAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type ModAddCommunityView struct {
|
||||||
|
ModAddCommunity ModAddCommunity `json:"mod_add_community" url:"mod_add_community,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
ModdedPerson PersonSafeAlias1 `json:"modded_person" url:"modded_person,omitempty"`
|
||||||
|
}
|
||||||
|
type ModAddView struct {
|
||||||
|
ModAdd ModAdd `json:"mod_add" url:"mod_add,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
ModdedPerson PersonSafeAlias1 `json:"modded_person" url:"modded_person,omitempty"`
|
||||||
|
}
|
||||||
|
type ModBanFromCommunityView struct {
|
||||||
|
ModBanFromCommunity ModBanFromCommunity `json:"mod_ban_from_community" url:"mod_ban_from_community,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
BannedPerson PersonSafeAlias1 `json:"banned_person" url:"banned_person,omitempty"`
|
||||||
|
}
|
||||||
|
type ModBanView struct {
|
||||||
|
ModBan ModBan `json:"mod_ban" url:"mod_ban,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
BannedPerson PersonSafeAlias1 `json:"banned_person" url:"banned_person,omitempty"`
|
||||||
|
}
|
||||||
|
type ModHideCommunityView struct {
|
||||||
|
ModHideCommunity ModHideCommunity `json:"mod_hide_community" url:"mod_hide_community,omitempty"`
|
||||||
|
Admin PersonSafe `json:"admin" url:"admin,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type ModLockPostView struct {
|
||||||
|
ModLockPost ModLockPost `json:"mod_lock_post" url:"mod_lock_post,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemoveCommentView struct {
|
||||||
|
ModRemoveComment ModRemoveComment `json:"mod_remove_comment" url:"mod_remove_comment,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Comment Comment `json:"comment" url:"comment,omitempty"`
|
||||||
|
Commenter PersonSafeAlias1 `json:"commenter" url:"commenter,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemoveCommunityView struct {
|
||||||
|
ModRemoveCommunity ModRemoveCommunity `json:"mod_remove_community" url:"mod_remove_community,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type ModRemovePostView struct {
|
||||||
|
ModRemovePost ModRemovePost `json:"mod_remove_post" url:"mod_remove_post,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type ModStickyPostView struct {
|
||||||
|
ModStickyPost ModStickyPost `json:"mod_sticky_post" url:"mod_sticky_post,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type ModTransferCommunityView struct {
|
||||||
|
ModTransferCommunity ModTransferCommunity `json:"mod_transfer_community" url:"mod_transfer_community,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
ModdedPerson PersonSafeAlias1 `json:"modded_person" url:"modded_person,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CommentAggregates struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommentID int `json:"comment_id" url:"comment_id,omitempty"`
|
||||||
|
Score int64 `json:"score" url:"score,omitempty"`
|
||||||
|
Upvotes int64 `json:"upvotes" url:"upvotes,omitempty"`
|
||||||
|
Downvotes int64 `json:"downvotes" url:"downvotes,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityAggregates struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
Subscribers int64 `json:"subscribers" url:"subscribers,omitempty"`
|
||||||
|
Posts int64 `json:"posts" url:"posts,omitempty"`
|
||||||
|
Comments int64 `json:"comments" url:"comments,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
UsersActiveDay int64 `json:"users_active_day" url:"users_active_day,omitempty"`
|
||||||
|
UsersActiveWeek int64 `json:"users_active_week" url:"users_active_week,omitempty"`
|
||||||
|
UsersActiveMonth int64 `json:"users_active_month" url:"users_active_month,omitempty"`
|
||||||
|
UsersActiveHalfYear int64 `json:"users_active_half_year" url:"users_active_half_year,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonAggregates struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
PersonID int `json:"person_id" url:"person_id,omitempty"`
|
||||||
|
PostCount int64 `json:"post_count" url:"post_count,omitempty"`
|
||||||
|
PostScore int64 `json:"post_score" url:"post_score,omitempty"`
|
||||||
|
CommentCount int64 `json:"comment_count" url:"comment_count,omitempty"`
|
||||||
|
CommentScore int64 `json:"comment_score" url:"comment_score,omitempty"`
|
||||||
|
}
|
||||||
|
type PostAggregates struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
Comments int64 `json:"comments" url:"comments,omitempty"`
|
||||||
|
Score int64 `json:"score" url:"score,omitempty"`
|
||||||
|
Upvotes int64 `json:"upvotes" url:"upvotes,omitempty"`
|
||||||
|
Downvotes int64 `json:"downvotes" url:"downvotes,omitempty"`
|
||||||
|
Stickied bool `json:"stickied" url:"stickied,omitempty"`
|
||||||
|
Published LemmyTime `json:"published" url:"published,omitempty"`
|
||||||
|
NewestCommentTimeNecro LemmyTime `json:"newest_comment_time_necro" url:"newest_comment_time_necro,omitempty"`
|
||||||
|
NewestCommentTime LemmyTime `json:"newest_comment_time" url:"newest_comment_time,omitempty"`
|
||||||
|
}
|
||||||
|
type SiteAggregates struct {
|
||||||
|
ID int32 `json:"id" url:"id,omitempty"`
|
||||||
|
SiteID int32 `json:"site_id" url:"site_id,omitempty"`
|
||||||
|
Users int64 `json:"users" url:"users,omitempty"`
|
||||||
|
Posts int64 `json:"posts" url:"posts,omitempty"`
|
||||||
|
Comments int64 `json:"comments" url:"comments,omitempty"`
|
||||||
|
Communities int64 `json:"communities" url:"communities,omitempty"`
|
||||||
|
UsersActiveDay int64 `json:"users_active_day" url:"users_active_day,omitempty"`
|
||||||
|
UsersActiveWeek int64 `json:"users_active_week" url:"users_active_week,omitempty"`
|
||||||
|
UsersActiveMonth int64 `json:"users_active_month" url:"users_active_month,omitempty"`
|
||||||
|
UsersActiveHalfYear int64 `json:"users_active_half_year" url:"users_active_half_year,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type CommunityBlockView struct {
|
||||||
|
Person PersonSafe `json:"person" url:"person,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityFollowerView struct {
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Follower PersonSafe `json:"follower" url:"follower,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityModeratorView struct {
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Moderator PersonSafe `json:"moderator" url:"moderator,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityPersonBanView struct {
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Person PersonSafe `json:"person" url:"person,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityView struct {
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Subscribed bool `json:"subscribed" url:"subscribed,omitempty"`
|
||||||
|
Blocked bool `json:"blocked" url:"blocked,omitempty"`
|
||||||
|
Counts CommunityAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonBlockView struct {
|
||||||
|
Person PersonSafe `json:"person" url:"person,omitempty"`
|
||||||
|
Target PersonSafeAlias1 `json:"target" url:"target,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonMentionView struct {
|
||||||
|
PersonMention PersonMention `json:"person_mention" url:"person_mention,omitempty"`
|
||||||
|
Comment Comment `json:"comment" url:"comment,omitempty"`
|
||||||
|
Creator PersonSafe `json:"creator" url:"creator,omitempty"`
|
||||||
|
Post Post `json:"post" url:"post,omitempty"`
|
||||||
|
Community CommunitySafe `json:"community" url:"community,omitempty"`
|
||||||
|
Recipient PersonSafeAlias1 `json:"recipient" url:"recipient,omitempty"`
|
||||||
|
Counts CommentAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
CreatorBannedFromCommunity bool `json:"creator_banned_from_community" url:"creator_banned_from_community,omitempty"`
|
||||||
|
Subscribed bool `json:"subscribed" url:"subscribed,omitempty"`
|
||||||
|
Saved bool `json:"saved" url:"saved,omitempty"`
|
||||||
|
CreatorBlocked bool `json:"creator_blocked" url:"creator_blocked,omitempty"`
|
||||||
|
MyVote Optional[int16] `json:"my_vote" url:"my_vote,omitempty"`
|
||||||
|
}
|
||||||
|
type PersonViewSafe struct {
|
||||||
|
Person PersonSafe `json:"person" url:"person,omitempty"`
|
||||||
|
Counts PersonAggregates `json:"counts" url:"counts,omitempty"`
|
||||||
|
}
|
||||||
-1596
File diff suppressed because it is too large
Load Diff
+29
-8
@@ -7,10 +7,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EmptyResponse struct {
|
|
||||||
LemmyResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
type LemmyResponse struct {
|
type LemmyResponse struct {
|
||||||
Error Optional[string] `json:"error" url:"error,omitempty"`
|
Error Optional[string] `json:"error" url:"error,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -36,10 +32,6 @@ type LemmyTime struct {
|
|||||||
time.Time
|
time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lt LemmyTime) MarshalJSON() ([]byte, error) {
|
|
||||||
return json.Marshal(lt.Time.Format("2006-01-02T15:04:05"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lt *LemmyTime) UnmarshalJSON(b []byte) error {
|
func (lt *LemmyTime) UnmarshalJSON(b []byte) error {
|
||||||
var timeStr string
|
var timeStr string
|
||||||
err := json.Unmarshal(b, &timeStr)
|
err := json.Unmarshal(b, &timeStr)
|
||||||
@@ -65,3 +57,32 @@ type LemmyWebSocketMsg struct {
|
|||||||
Op string `json:"op"`
|
Op string `json:"op"`
|
||||||
Data json.RawMessage `json:"data"`
|
Data json.RawMessage `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOneOf checks if the message is one of the given operations.
|
||||||
|
func (msg LemmyWebSocketMsg) IsOneOf(ops ...Operation) bool {
|
||||||
|
for _, op := range ops {
|
||||||
|
switch op := op.(type) {
|
||||||
|
case UserOperation:
|
||||||
|
if string(op) == msg.Op {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
case UserOperationCrud:
|
||||||
|
if string(op) == msg.Op {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type Operation interface {
|
||||||
|
Operation() string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u UserOperation) Operation() string {
|
||||||
|
return string(u)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u UserOperationCrud) Operation() string {
|
||||||
|
return string(u)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
package types
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type UserJoin struct {
|
||||||
|
Auth string `json:"auth" url:"auth,omitempty"`
|
||||||
|
}
|
||||||
|
type UserJoinResponse struct {
|
||||||
|
Joined bool `json:"joined" url:"joined,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type CommunityJoin struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
}
|
||||||
|
type CommunityJoinResponse struct {
|
||||||
|
Joined bool `json:"joined" url:"joined,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type ModJoin struct {
|
||||||
|
CommunityID int `json:"community_id" url:"community_id,omitempty"`
|
||||||
|
}
|
||||||
|
type ModJoinResponse struct {
|
||||||
|
Joined bool `json:"joined" url:"joined,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
|
type PostJoin struct {
|
||||||
|
PostID int `json:"post_id" url:"post_id,omitempty"`
|
||||||
|
}
|
||||||
|
type PostJoinResponse struct {
|
||||||
|
Joined bool `json:"joined" url:"joined,omitempty"`
|
||||||
|
LemmyResponse
|
||||||
|
}
|
||||||
+149
@@ -0,0 +1,149 @@
|
|||||||
|
package lemmy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
"go.arsenm.dev/go-lemmy/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type authData struct {
|
||||||
|
Auth string `json:"auth"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WSClient is a client for Lemmy's WebSocket API
|
||||||
|
type WSClient struct {
|
||||||
|
conn *websocket.Conn
|
||||||
|
baseURL *url.URL
|
||||||
|
respCh chan types.LemmyWebSocketMsg
|
||||||
|
errCh chan error
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWebSocket creates and returns a new WSClient, and
|
||||||
|
// starts a goroutine to read server responses and errors
|
||||||
|
func NewWebSocket(baseURL string) (*WSClient, error) {
|
||||||
|
u, err := url.Parse(baseURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
u = u.JoinPath("/api/v3")
|
||||||
|
|
||||||
|
conn, _, err := websocket.DefaultDialer.Dial(u.JoinPath("ws").String(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
out := &WSClient{
|
||||||
|
conn: conn,
|
||||||
|
baseURL: u,
|
||||||
|
respCh: make(chan types.LemmyWebSocketMsg, 10),
|
||||||
|
errCh: make(chan error, 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
var msg types.LemmyWebSocketMsg
|
||||||
|
err = conn.ReadJSON(&msg)
|
||||||
|
if err != nil {
|
||||||
|
out.errCh <- err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out.respCh <- msg
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientLogin logs in to Lemmy by sending an HTTP request to the
|
||||||
|
// login endpoint. It stores the returned token in the client
|
||||||
|
// for future use.
|
||||||
|
func (c *WSClient) ClientLogin(ctx context.Context, l types.Login) error {
|
||||||
|
u := &url.URL{}
|
||||||
|
*u = *c.baseURL
|
||||||
|
|
||||||
|
if u.Scheme == "ws" {
|
||||||
|
u.Scheme = "http"
|
||||||
|
} else if u.Scheme == "wss" {
|
||||||
|
u.Scheme = "https"
|
||||||
|
}
|
||||||
|
|
||||||
|
hc := &Client{baseURL: u, client: http.DefaultClient}
|
||||||
|
err := hc.ClientLogin(ctx, l)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Token = hc.Token
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request sends a request to the server. If data is nil,
|
||||||
|
// the authentication token will be sent instead. If data
|
||||||
|
// has an Auth field, it will be set to the authentication
|
||||||
|
// token automatically.
|
||||||
|
func (c *WSClient) Request(op types.Operation, data any) error {
|
||||||
|
if data == nil {
|
||||||
|
data = authData{}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = c.setAuth(data)
|
||||||
|
|
||||||
|
d, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.conn.WriteJSON(types.LemmyWebSocketMsg{
|
||||||
|
Op: op.Operation(),
|
||||||
|
Data: d,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Responses returns a channel that receives messages from
|
||||||
|
// Lemmy.
|
||||||
|
func (c *WSClient) Responses() <-chan types.LemmyWebSocketMsg {
|
||||||
|
return c.respCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errors returns a channel that receives errors
|
||||||
|
// received while attempting to read responses
|
||||||
|
func (c *WSClient) Errors() <-chan error {
|
||||||
|
return c.errCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// setAuth uses reflection to automatically
|
||||||
|
// set struct fields called Auth of type
|
||||||
|
// string or types.Optional[string] to the
|
||||||
|
// authentication token, then returns the
|
||||||
|
// updated struct
|
||||||
|
func (c *WSClient) setAuth(data any) any {
|
||||||
|
val := reflect.New(reflect.TypeOf(data))
|
||||||
|
val.Elem().Set(reflect.ValueOf(data))
|
||||||
|
|
||||||
|
authField := val.Elem().FieldByName("Auth")
|
||||||
|
if !authField.IsValid() {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
switch authField.Type().String() {
|
||||||
|
case "string":
|
||||||
|
authField.SetString(c.Token)
|
||||||
|
case "types.Optional[string]":
|
||||||
|
setMtd := authField.MethodByName("Set")
|
||||||
|
out := setMtd.Call([]reflect.Value{reflect.ValueOf(c.Token)})
|
||||||
|
authField.Set(out[0])
|
||||||
|
default:
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
return val.Elem().Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecodeResponse(data json.RawMessage, out any) error {
|
||||||
|
return json.Unmarshal(data, out)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user