Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions etc/anytype-publish-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ publish:
uploadUrlPrefix: "http://127.0.0.1:8383/api/upload"
httpApiAddr: ":8383"
cleanupOn: true
# Limits and URL templates returned to clients. Defaults are used if omitted.
# membershipLimit: 6291456000 # 6000 MB in bytes
# defaultLimit: 10485760 # 10 MB in bytes
# baseUrlTemplate: "https://any.coop/%s"
# inviteLinkUrlTemplate: "https://invite.any.coop/%s#%s"
# memberUrlTemplate: "https://%s.org"
# indexFileName: "index.json.gz"
gateway:
addr: ":8380"
publishFilesUrl: "https://anytype-gobackend-test.s3.eu-central-1.amazonaws.com"
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/anyproto/any-sync v0.11.14
github.com/anyproto/anytype-publish-renderer v0.3.24
github.com/anyproto/anytype-publish-server/publishclient v0.0.0-20250716122732-cdcfe3a126bb
github.com/aws/aws-sdk-go-v2 v1.40.0
github.com/aws/aws-sdk-go-v2 v1.41.5
github.com/aws/aws-sdk-go-v2/config v1.29.14
github.com/aws/aws-sdk-go-v2/credentials v1.17.67
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.0
github.com/aws/smithy-go v1.23.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3
github.com/aws/smithy-go v1.24.2
github.com/golang/snappy v1.0.0
github.com/google/uuid v1.6.0
github.com/redis/go-redis/v9 v9.17.0
Expand All @@ -33,16 +33,16 @@ require (
github.com/anyproto/go-slip10 v1.0.1 // indirect
github.com/anyproto/go-slip21 v1.0.0 // indirect
github.com/anyproto/go-sqlite v1.4.2-any // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.14 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.21 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.30.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.41.2 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ github.com/anyproto/go-sqlite v1.4.2-any h1:ZTIcq/u2mYYJ6rJB4I3Ds5QH/7IlONebMiG1
github.com/anyproto/go-sqlite v1.4.2-any/go.mod h1:nW7TvS+4bzPU2vNaPlPFNPYcejK5RdjH6qZY2kjT3Io=
github.com/aws/aws-sdk-go-v2 v1.40.0 h1:/WMUA0kjhZExjOQN2z3oLALDREea1A7TobfuiBrKlwc=
github.com/aws/aws-sdk-go-v2 v1.40.0/go.mod h1:c9pm7VwuW0UPxAEYGyTmyurVcNrbF6Rt/wixFqDhcjE=
github.com/aws/aws-sdk-go-v2 v1.41.5 h1:dj5kopbwUsVUVFgO4Fi5BIT3t4WyqIDjGKCangnV/yY=
github.com/aws/aws-sdk-go-v2 v1.41.5/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3 h1:DHctwEM8P8iTXFxC/QK0MRjwEpWQeM9yzidCRjldUz0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3/go.mod h1:xdCzcZEtnSTKVDOmUZs4l/j3pSV6rpo1WXl5ugNsL8Y=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8 h1:eBMB84YGghSocM7PsjmmPffTa+1FBUeNvGvFou6V/4o=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8/go.mod h1:lyw7GFp3qENLh7kwzf7iMzAxDn+NzjXEAGjKS2UOKqI=
github.com/aws/aws-sdk-go-v2/config v1.29.14 h1:f+eEi/2cKCg9pqKBoAIwRGzVb70MRKqWX4dg1BDcSJM=
github.com/aws/aws-sdk-go-v2/config v1.29.14/go.mod h1:wVPHWcIFv3WO89w0rE10gzf17ZYy+UVS1Geq8Iei34g=
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 h1:9KxtdcIA/5xPNQyZRgUSpYOE6j9Bc4+D7nZua0KGYOM=
Expand All @@ -39,22 +43,38 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 h1:WZVR5DbDgxzA0BJeudId89
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14/go.mod h1:Dadl9QO0kHgbrH1GRqGiZdYtW5w+IXXaBNCHTIaheM4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 h1:PZHqQACxYb8mYgms4RZbhZG0a7dPW06xOjmaH0EJC/I=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14/go.mod h1:VymhrMJUWs69D8u0/lZ7jSB6WgaG/NqHi3gX0aYf6U0=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21 h1:Rgg6wvjjtX8bNHcvi9OnXWwcE0a2vGpbwmtICOsvcf4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.21/go.mod h1:A/kJFst/nm//cyqonihbdpQZwiUhhzpqTsdbhDdRF9c=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 h1:bOS19y6zlJwagBfHxs0ESzr1XCOU2KXJCWcq3E2vfjY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14/go.mod h1:1ipeGBMAxZ0xcTm6y6paC2C/J6f6OO7LBODV9afuAyM=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21 h1:PEgGVtPoB6NTpPrBgqSE5hE/o47Ij9qk/SEZFbUOe9A=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.21/go.mod h1:p+hz+PRAYlY3zcpJhPwXlLC4C+kqn70WIHwnzAfs6ps=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.14 h1:ITi7qiDSv/mSGDSWNpZ4k4Ve0DQR6Ug2SJQ8zEHoDXg=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.14/go.mod h1:k1xtME53H1b6YpZt74YmwlONMWf4ecM+lut1WQLAF/U=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22 h1:rWyie/PxDRIdhNf4DzRk0lvjVOqFJuNnO8WwaIRVxzQ=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.22/go.mod h1:zd/JsJ4P7oGfUhXn1VyLqaRZwPmZwg44Jf2dS84Dm3Y=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 h1:x2Ibm/Af8Fi+BH+Hsn9TXGdT+hKbDd5XOTZxTMxDk7o=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3/go.mod h1:IW1jwyrQgMdhisceG8fQLmQIydcT/jWY21rFhzgaKwo=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 h1:5EniKhLZe4xzL7a+fU3C2tfUN4nWIqlLesfrjkuPFTY=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7/go.mod h1:x0nZssQ3qZSnIcePWLvcoFisRXJzcTVvYpAAdYX8+GI=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.5 h1:Hjkh7kE6D81PgrHlE/m9gx+4TyyeLHuY8xJs7yXN5C4=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.5/go.mod h1:nPRXgyCfAurhyaTMoBMwRBYBhaHI4lNPAnJmjM0Tslc=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.13 h1:JRaIgADQS/U6uXDqlPiefP32yXTda7Kqfx+LgspooZM=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.13/go.mod h1:CEuVn5WqOMilYl+tbccq8+N2ieCy0gVn3OtRb0vBNNM=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 h1:FIouAnCE46kyYqyhs0XEBDFFSREtdnr8HQuLPQPLCrY=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14/go.mod h1:UTwDc5COa5+guonQU8qBikJo1ZJ4ln2r1MkF7Dqag1E=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21 h1:c31//R3xgIJMSC8S6hEVq+38DcvUlgFY0FM6mSI5oto=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.21/go.mod h1:r6+pf23ouCB718FUxaqzZdbpYFyDtehyZcmP5KL9FkA=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.14 h1:FzQE21lNtUor0Fb7QNgnEyiRCBlolLTX/Z1j65S7teM=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.14/go.mod h1:s1ydyWG9pm3ZwmmYN21HKyG9WzAZhYVW85wMHs5FV6w=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.21 h1:ZlvrNcHSFFWURB8avufQq9gFsheUgjVD9536obIknfM=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.21/go.mod h1:cv3TNhVrssKR0O/xxLJVRfd2oazSnZnkUeTf6ctUwfQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.0 h1:nyuzXooUNJexRT0Oy0UQY6AhOzxPxhtt4DcBIHyCnmw=
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.0/go.mod h1:sT/iQz8JK3u/5gZkT+Hmr7GzVZehUMkRZpOaAwYXeGY=
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3 h1:HwxWTbTrIHm5qY+CAEur0s/figc3qwvLWsNkF4RPToo=
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.3/go.mod h1:uoA43SdFwacedBfSgfFSjjCvYe8aYBS7EnU5GZ/YKMM=
github.com/aws/aws-sdk-go-v2/service/sso v1.30.5 h1:ksUT5KtgpZd3SAiFJNJ0AFEJVva3gjBmN7eXUZjzUwQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.30.5/go.mod h1:av+ArJpoYf3pgyrj6tcehSFW+y9/QvAY8kMooR9bZCw=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.10 h1:GtsxyiF3Nd3JahRBJbxLCCdYW9ltGQYrFWg8XdkGDd8=
Expand All @@ -63,6 +83,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.41.2 h1:a5UTtD4mHBU3t0o6aHQZFJTNKVfx
github.com/aws/aws-sdk-go-v2/service/sts v1.41.2/go.mod h1:6TxbXoDSgBQ225Qd8Q+MbxUxUh6TtNKwbRt/EPS9xso=
github.com/aws/smithy-go v1.23.2 h1:Crv0eatJUQhaManss33hS5r40CG3ZFH+21XSkqMrIUM=
github.com/aws/smithy-go v1.23.2/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
github.com/aws/smithy-go v1.24.2 h1:FzA3bu/nt/vDvmnkg+R8Xl46gmzEDam6mZ1hzmwXFng=
github.com/aws/smithy-go v1.24.2/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
Expand Down
21 changes: 18 additions & 3 deletions publish/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@ type configGetter interface {
GetPublish() Config
}

const (
DefaultMembershipLimit = int64(6000 << 20)
DefaultDefaultLimit = int64(10 << 20)
DefaultBaseUrlTemplate = "https://any.coop/%s"
DefaultInviteLinkUrlTemplate = "https://invite.any.coop/%s#%s"
DefaultMemberUrlTemplate = "https://%s.org"
DefaultIndexFileName = "index.json.gz"
)

type Config struct {
UploadUrlPrefix string `yaml:"uploadUrlPrefix"`
HttpApiAddr string `yaml:"httpApiAddr"`
CleanupOn bool `yaml:"cleanupOn"`
UploadUrlPrefix string `yaml:"uploadUrlPrefix"`
HttpApiAddr string `yaml:"httpApiAddr"`
CleanupOn bool `yaml:"cleanupOn"`
MembershipLimit int64 `yaml:"membershipLimit"`
DefaultLimit int64 `yaml:"defaultLimit"`
BaseUrlTemplate string `yaml:"baseUrlTemplate"`
InviteLinkUrlTemplate string `yaml:"inviteLinkUrlTemplate"`
MemberUrlTemplate string `yaml:"memberUrlTemplate"`
IndexFileName string `yaml:"indexFileName"`
}
46 changes: 46 additions & 0 deletions publish/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,52 @@ import (

var _ publishapi.DRPCWebPublisherServer = (*rpcHandler)(nil)

func (r rpcHandler) GetConfig(ctx context.Context, _ *publishapi.GetConfigRequest) (resp *publishapi.GetConfigResponse, err error) {
st := time.Now()
defer func() {
r.s.metric.RequestLog(ctx, "publish.getConfig",
metric.TotalDur(time.Since(st)),
zap.String("addr", peer.CtxPeerAddr(ctx)),
zap.Error(err),
)
}()

cfg := r.s.config
membershipLimit := cfg.MembershipLimit
if membershipLimit == 0 {
membershipLimit = DefaultMembershipLimit
}
defaultLimit := cfg.DefaultLimit
if defaultLimit == 0 {
defaultLimit = DefaultDefaultLimit
}
baseUrlTemplate := cfg.BaseUrlTemplate
if baseUrlTemplate == "" {
baseUrlTemplate = DefaultBaseUrlTemplate
}
inviteLinkUrlTemplate := cfg.InviteLinkUrlTemplate
if inviteLinkUrlTemplate == "" {
inviteLinkUrlTemplate = DefaultInviteLinkUrlTemplate
}
memberUrlTemplate := cfg.MemberUrlTemplate
if memberUrlTemplate == "" {
memberUrlTemplate = DefaultMemberUrlTemplate
}
indexFileName := cfg.IndexFileName
if indexFileName == "" {
indexFileName = DefaultIndexFileName
}

return &publishapi.GetConfigResponse{
MembershipLimit: membershipLimit,
DefaultLimit: defaultLimit,
BaseUrlTemplate: baseUrlTemplate,
InviteLinkUrlTemplate: inviteLinkUrlTemplate,
MemberUrlTemplate: memberUrlTemplate,
IndexFileName: indexFileName,
}, nil
}

type rpcHandler struct {
s *publishService
}
Expand Down
22 changes: 19 additions & 3 deletions publishclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"

"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/app/logger"
"github.com/anyproto/any-sync/net/peerservice"
"github.com/anyproto/any-sync/net/pool"
"github.com/anyproto/any-sync/net/rpc/rpcerr"
Expand All @@ -19,6 +20,8 @@ import (
"github.com/anyproto/anytype-publish-server/publishclient/publishapi"
)

var log = logger.NewNamed(CName)

func New() Client {
return new(publishClient)
}
Expand All @@ -28,6 +31,7 @@ const CName = "publish.client"
type Client interface {
app.Component
ResolveUri(ctx context.Context, uri string) (publish *publishapi.Publish, err error)
GetPublishConfig(ctx context.Context, req *publishapi.GetConfigRequest) (resp *publishapi.GetConfigResponse, err error)
GetPublishStatus(ctx context.Context, spaceId, objectId string) (publish *publishapi.Publish, err error)
Publish(ctx context.Context, req *publishapi.PublishRequest) (uploadUrl string, err error)
UnPublish(ctx context.Context, req *publishapi.UnPublishRequest) (err error)
Expand All @@ -36,9 +40,10 @@ type Client interface {
}

type publishClient struct {
pool pool.Pool
peerService peerservice.PeerService
peerIds []string
pool pool.Pool
peerService peerservice.PeerService
peerIds []string
publishConfig *publishapi.GetConfigResponse
}

func (p *publishClient) Init(a *app.App) (err error) {
Expand All @@ -56,6 +61,17 @@ func (p *publishClient) Name() (name string) {
return CName
}

func (p *publishClient) GetPublishConfig(ctx context.Context, req *publishapi.GetConfigRequest) (resp *publishapi.GetConfigResponse, err error) {
err = p.doClient(ctx, func(c publishapi.DRPCWebPublisherClient) (err error) {
resp, err = c.GetConfig(ctx, req)
if err != nil {
err = rpcerr.Unwrap(err)
}
return
})
return
}

func (p *publishClient) ResolveUri(ctx context.Context, uri string) (publish *publishapi.Publish, err error) {
var resp *publishapi.ResolveUriResponse
err = p.doClient(ctx, func(c publishapi.DRPCWebPublisherClient) (err error) {
Expand Down
12 changes: 12 additions & 0 deletions publishclient/publishapi/protos/publisher.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ service WebPublisher {
rpc Publish(PublishRequest) returns (PublishResponse);
rpc UnPublish(UnPublishRequest) returns (Ok);
rpc ListPublishes(ListPublishesRequest) returns (ListPublishesResponse);
rpc GetConfig(GetConfigRequest) returns (GetConfigResponse);
}

message ResolveUriRequest {
Expand Down Expand Up @@ -78,3 +79,14 @@ message ListPublishesRequest {
message ListPublishesResponse {
repeated Publish publishes = 1;
}

message GetConfigRequest {}

message GetConfigResponse {
int64 membershipLimit = 1;
int64 defaultLimit = 2;
string baseUrlTemplate = 3;
string inviteLinkUrlTemplate = 4;
string memberUrlTemplate = 5;
string indexFileName = 6;
}
Loading
Loading