Spaces:
Sleeping
Sleeping
Download pkg/qrlogin/encoder.go from codebydante/BrodyFileStreamBot: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/codebydante/BrodyFileStreamBot/resolve/bd894b382ed6a42e3879e3846027d7e6d427f3f2/pkg/qrlogin/encoder.go
- Command line
-
hf download hf://spaces/codebydante/BrodyFileStreamBot@bd894b382ed6a42e3879e3846027d7e6d427f3f2/pkg/qrlogin/encoder.go
-
curl -L -o encoder.go https://huggingface.co/spaces/codebydante/BrodyFileStreamBot/resolve/bd894b382ed6a42e3879e3846027d7e6d427f3f2/pkg/qrlogin/encoder.go
1.43 kB
| // This file is a part of EverythingSuckz/TG-FileStreamBot | |
| // And is licenced under the Affero General Public License. | |
| // Any distributions of this code MUST be accompanied by a copy of the AGPL | |
| // with proper attribution to the original author(s). | |
| package qrlogin | |
| import ( | |
| "bytes" | |
| "encoding/base64" | |
| "encoding/binary" | |
| "errors" | |
| "strings" | |
| "github.com/gotd/td/session" | |
| ) | |
| func EncodeToPyrogramSession(data *session.Data, appID int32) (string, error) { | |
| buf := new(bytes.Buffer) | |
| if err := buf.WriteByte(byte(data.DC)); err != nil { | |
| return "", err | |
| } | |
| if err := binary.Write(buf, binary.BigEndian, appID); err != nil { | |
| return "", err | |
| } | |
| var testMode byte | |
| if data.Config.TestMode { | |
| testMode = 1 | |
| } | |
| if err := buf.WriteByte(testMode); err != nil { | |
| return "", err | |
| } | |
| if len(data.AuthKey) != 256 { | |
| return "", errors.New("auth key must be 256 bytes long") | |
| } | |
| if _, err := buf.Write(data.AuthKey); err != nil { | |
| return "", err | |
| } | |
| if len(data.AuthKeyID) != 8 { | |
| return "", errors.New("auth key ID must be 8 bytes long") | |
| } | |
| if _, err := buf.Write(data.AuthKeyID); err != nil { | |
| return "", err | |
| } | |
| if err := buf.WriteByte(0); err != nil { | |
| return "", err | |
| } | |
| // Convert the bytes buffer to a base64 string | |
| encodedString := base64.URLEncoding.EncodeToString(buf.Bytes()) | |
| trimmedEncoded := strings.TrimRight(encodedString, "=") | |
| return trimmedEncoded, nil | |
| } | |