mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-12 17:59:06 +02:00
The iOS SDK package gets the same platform handle the Android bindings carry: transfers, receiving policy, and per-sender rules on one profile, attached to the engine when the client starts. Payloads are path-based rather than stream-based, since the app group container is readable from both processes, and the platform sink is dropped for the same reason: delivery lands on the filesystem directly. The default destination is seeded in the constructor because the app process opens handles of its own while the extension is down.
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
//go:build ios
|
|
|
|
package NetBirdSDK
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/filedrop"
|
|
)
|
|
|
|
// FileDropPayloads collects the items of one outgoing transfer.
|
|
type FileDropPayloads struct {
|
|
items []filedrop.Payload
|
|
}
|
|
|
|
// NewFileDropPayloads returns an empty payload list to fill before sending.
|
|
func NewFileDropPayloads() *FileDropPayloads {
|
|
return &FileDropPayloads{}
|
|
}
|
|
|
|
// AddFile appends a file item backed by a filesystem path the extension can read.
|
|
func (p *FileDropPayloads) AddFile(name string, size int64, contentType, path string) error {
|
|
if name == "" {
|
|
return errors.New("file name is required")
|
|
}
|
|
if path == "" {
|
|
return fmt.Errorf("file %s has no path", name)
|
|
}
|
|
|
|
p.items = append(p.items, filedrop.Payload{
|
|
Meta: filedrop.FileMeta{
|
|
Name: name,
|
|
Size: size,
|
|
ContentType: contentType,
|
|
},
|
|
Open: func(offset int64) (io.ReadCloser, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if offset > 0 {
|
|
if _, err := f.Seek(offset, io.SeekStart); err != nil {
|
|
_ = f.Close()
|
|
return nil, err
|
|
}
|
|
}
|
|
return f, nil
|
|
},
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// AddText appends an inline text item.
|
|
func (p *FileDropPayloads) AddText(name, text string) error {
|
|
if len(text) > filedrop.MaxInlineTextSize {
|
|
return fmt.Errorf("text exceeds %d bytes", filedrop.MaxInlineTextSize)
|
|
}
|
|
if name == "" {
|
|
name = "text"
|
|
}
|
|
p.items = append(p.items, filedrop.TextPayload(name, text))
|
|
return nil
|
|
}
|
|
|
|
// Length returns the number of items.
|
|
func (p *FileDropPayloads) Length() int {
|
|
return len(p.items)
|
|
}
|