2023-06-30 09:54:08 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-07-15 13:39:11 +00:00
|
|
|
func GenerateTmpID() string {
|
2023-06-30 09:54:08 +00:00
|
|
|
src := rand.NewSource(time.Now().UnixNano())
|
|
|
|
r := rand.New(src)
|
|
|
|
randNum := r.Int63n(1e12)
|
|
|
|
return fmt.Sprintf("tmp_%012d", randNum)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BuildRelayHeaders(req *http.Request, contentType string, accept string) {
|
2024-02-22 20:37:49 +00:00
|
|
|
//req.Header.Set("host", "instantmessaging-pa.googleapis.com")
|
|
|
|
req.Header.Set("sec-ch-ua", SecUA)
|
|
|
|
req.Header.Set("x-user-agent", XUserAgent)
|
|
|
|
req.Header.Set("x-goog-api-key", GoogleAPIKey)
|
2023-06-30 09:54:08 +00:00
|
|
|
if len(contentType) > 0 {
|
2024-02-22 20:37:49 +00:00
|
|
|
req.Header.Set("content-type", contentType)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
req.Header.Set("sec-ch-ua-mobile", SecUAMobile)
|
|
|
|
req.Header.Set("user-agent", UserAgent)
|
|
|
|
req.Header.Set("sec-ch-ua-platform", "\""+UAPlatform+"\"")
|
|
|
|
req.Header.Set("accept", accept)
|
|
|
|
req.Header.Set("origin", "https://messages.google.com")
|
|
|
|
req.Header.Set("sec-fetch-site", "cross-site")
|
|
|
|
req.Header.Set("sec-fetch-mode", "cors")
|
|
|
|
req.Header.Set("sec-fetch-dest", "empty")
|
|
|
|
req.Header.Set("referer", "https://messages.google.com/")
|
|
|
|
req.Header.Set("accept-language", "en-US,en;q=0.9")
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BuildUploadHeaders(req *http.Request, metadata string) {
|
2024-02-22 20:37:49 +00:00
|
|
|
//req.Header.Set("host", "instantmessaging-pa.googleapis.com")
|
|
|
|
req.Header.Set("x-goog-download-metadata", metadata)
|
|
|
|
req.Header.Set("sec-ch-ua", SecUA)
|
|
|
|
req.Header.Set("sec-ch-ua-mobile", SecUAMobile)
|
|
|
|
req.Header.Set("user-agent", UserAgent)
|
|
|
|
req.Header.Set("sec-ch-ua-platform", "\""+UAPlatform+"\"")
|
|
|
|
req.Header.Set("accept", "*/*")
|
|
|
|
req.Header.Set("origin", "https://messages.google.com")
|
|
|
|
req.Header.Set("sec-fetch-site", "cross-site")
|
|
|
|
req.Header.Set("sec-fetch-mode", "cors")
|
|
|
|
req.Header.Set("sec-fetch-dest", "empty")
|
|
|
|
req.Header.Set("referer", "https://messages.google.com/")
|
|
|
|
req.Header.Set("accept-encoding", "gzip, deflate, br")
|
|
|
|
req.Header.Set("accept-language", "en-US,en;q=0.9")
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMediaUploadHeaders(imageSize string, command string, uploadOffset string, imageContentType string, protocol string) *http.Header {
|
|
|
|
headers := &http.Header{}
|
|
|
|
|
2024-03-11 13:31:15 +00:00
|
|
|
//headers.Set("host", "instantmessaging-pa.googleapis.com")
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("sec-ch-ua", SecUA)
|
2023-06-30 09:54:08 +00:00
|
|
|
if protocol != "" {
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("x-goog-upload-protocol", protocol)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("x-goog-upload-header-content-length", imageSize)
|
|
|
|
headers.Set("sec-ch-ua-mobile", SecUAMobile)
|
|
|
|
headers.Set("user-agent", UserAgent)
|
2023-06-30 09:54:08 +00:00
|
|
|
if imageContentType != "" {
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("x-goog-upload-header-content-type", imageContentType)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("content-type", "application/x-www-form-urlencoded;charset=UTF-8")
|
2023-06-30 09:54:08 +00:00
|
|
|
if command != "" {
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("x-goog-upload-command", command)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
if uploadOffset != "" {
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("x-goog-upload-offset", uploadOffset)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
headers.Set("sec-ch-ua-platform", "\""+UAPlatform+"\"")
|
|
|
|
headers.Set("accept", "*/*")
|
|
|
|
headers.Set("origin", "https://messages.google.com")
|
|
|
|
headers.Set("sec-fetch-site", "cross-site")
|
|
|
|
headers.Set("sec-fetch-mode", "cors")
|
|
|
|
headers.Set("sec-fetch-dest", "empty")
|
|
|
|
headers.Set("referer", "https://messages.google.com/")
|
|
|
|
headers.Set("accept-encoding", "gzip, deflate, br")
|
|
|
|
headers.Set("accept-language", "en-US,en;q=0.9")
|
2023-06-30 09:54:08 +00:00
|
|
|
return headers
|
2023-06-30 09:55:49 +00:00
|
|
|
}
|