Compare commits

..

7 Commits
v0.3.3 ... main

Author SHA1 Message Date
b01ec49ebe panicDelyRecoverExit->main()
All checks were successful
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 1m12s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 1m22s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 1m24s
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 1m3s
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 1m7s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 1m8s
Gitea Go Release Actions / Release Go Binary (loong64, linux) (push) Successful in 1m7s
Gitea Go Release Actions / Release Go Binary (mips, linux) (push) Successful in 1m9s
Gitea Go Release Actions / Release Go Binary (riscv64, linux) (push) Successful in 1m8s
2024-08-24 16:51:24 +08:00
316ad15a55 follow upstream update
All checks were successful
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 1m18s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 1m17s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 1m29s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 1m12s
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 1m13s
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 1m13s
Gitea Go Release Actions / Release Go Binary (mips, linux) (push) Successful in 1m7s
Gitea Go Release Actions / Release Go Binary (loong64, linux) (push) Successful in 1m12s
Gitea Go Release Actions / Release Go Binary (riscv64, linux) (push) Successful in 1m7s
2024-08-24 16:43:30 +08:00
fb9a1a0b98 fuck! without token
All checks were successful
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 1m25s
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 1m36s
Gitea Go Release Actions / Release Go Binary (loong64, linux) (push) Successful in 1m23s
Gitea Go Release Actions / Release Go Binary (mips, linux) (push) Successful in 1m16s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 1m6s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 1m28s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 1m38s
Gitea Go Release Actions / Release Go Binary (riscv64, linux) (push) Successful in 1m16s
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 1m14s
EnsureConnection: check GetWorkDetailResponse
2024-07-05 03:29:04 +08:00
022c16c731 chore: clean
All checks were successful
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 1m34s
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 1m49s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 2m5s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 2m6s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 1m27s
Gitea Go Release Actions / Release Go Binary (riscv64, linux) (push) Successful in 1m34s
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 1m20s
Gitea Go Release Actions / Release Go Binary (loong64, linux) (push) Successful in 1m17s
Gitea Go Release Actions / Release Go Binary (mips, linux) (push) Successful in 1m11s
2024-07-05 01:22:18 +08:00
c56c074740 HSJ_USERID: fake 2024-07-05 01:21:30 +08:00
3b00ba2407 hsj_api: ordered url values
All checks were successful
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 1m11s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 1m14s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 1m15s
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 1m5s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 1m4s
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 1m3s
Gitea Go Release Actions / Release Go Binary (loong64, linux) (push) Successful in 1m6s
Gitea Go Release Actions / Release Go Binary (mips, linux) (push) Successful in 1m6s
Gitea Go Release Actions / Release Go Binary (riscv64, linux) (push) Successful in 1m5s
2024-07-04 22:34:28 +08:00
76f7d9a230 chan: panda
All checks were successful
Gitea Go Release Actions / Release Go Binary (amd64, darwin) (push) Successful in 1m8s
Gitea Go Release Actions / Release Go Binary (amd64, linux) (push) Successful in 1m11s
Gitea Go Release Actions / Release Go Binary (amd64, windows) (push) Successful in 1m11s
Gitea Go Release Actions / Release Go Binary (arm, linux) (push) Successful in 59s
Gitea Go Release Actions / Release Go Binary (arm64, darwin) (push) Successful in 1m7s
Gitea Go Release Actions / Release Go Binary (arm64, linux) (push) Successful in 1m7s
Gitea Go Release Actions / Release Go Binary (loong64, linux) (push) Successful in 1m1s
Gitea Go Release Actions / Release Go Binary (mips, linux) (push) Successful in 1m1s
Gitea Go Release Actions / Release Go Binary (riscv64, linux) (push) Successful in 1m7s
2024-07-04 21:34:38 +08:00
2 changed files with 138 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import (
"net/http"
"os"
"os/signal"
"runtime/debug"
"sync"
"time"
@ -25,8 +26,9 @@ var Interrupted = false
var WaitClaimWorker sync.WaitGroup
var WaitProcesserWorker sync.WaitGroup
// 2024/06/08 16:22:36 [huashijie_work] ...
var Logger = log.New(os.Stdout, "[huashijie_work] ", log.Ldate|log.Ltime|log.Lmsgprefix)
var project_id = "huashijie_work"
var Logger *log.Logger
var DEBUG = false
func init() {
@ -41,6 +43,23 @@ func init() {
if os.Getenv("DEBUG") != "" {
DEBUG = true
}
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
project_id = "huashijie_work_pandapaint"
}
// 2024/06/08 16:22:36 [huashijie_work] ...
Logger = log.New(os.Stdout, "["+project_id+"] ", log.Ldate|log.Ltime|log.Lmsgprefix)
}
var custom_delay_lock = sync.Mutex{}
func panicDelyRecoverExit() {
if r := recover(); r != nil {
Logger.Println("Panic:", r)
Logger.Println("debug.Stack():", string(debug.Stack()))
Logger.Println("Sleep 60s before exit...")
time.Sleep(60 * time.Second)
os.Exit(1)
}
}
// ClaimTask 并把任务放入 task_chan
@ -48,10 +67,21 @@ func claimWorker(i int, tracker *savewebtracker.Tracker) {
Logger.Println("[START] ClaimWorker", i)
defer Logger.Println("[STOP] ClaimWorker", i, " exited...")
defer WaitClaimWorker.Done()
defer panicDelyRecoverExit()
for {
if Interrupted {
return
}
if os.Getenv("CUSTOM_DELAY") != "" {
custom_delay_lock.Lock()
// xxxms
custom_delay, _ := time.ParseDuration(os.Getenv("CUSTOM_DELAY"))
Logger.Println("Custom delay:", custom_delay, "...")
time.Sleep(custom_delay)
custom_delay_lock.Unlock()
WITH_DELAY = false
}
task := tracker.ClaimTask(WITH_DELAY)
if task == nil {
notask_sleep := max(
@ -71,6 +101,7 @@ func ProcesserWorker(i int, tracker *savewebtracker.Tracker) {
Logger.Println("[START] ProcesserWorker", i)
defer Logger.Println("[STOP] ProcesserWorker", i, " exited...")
defer WaitProcesserWorker.Done()
defer panicDelyRecoverExit()
for task := range tasks_chan {
Logger.Println("Processing task", task.Id)
@ -167,7 +198,8 @@ func ShowStatus(t *savewebtracker.Tracker) {
}
func main() {
tracker := savewebtracker.GetTracker("huashijie_work", "0.3", savewebtracker.Archivist())
defer panicDelyRecoverExit()
tracker := savewebtracker.GetTracker(project_id, "0.5", savewebtracker.Archivist())
tracker.PING_client = GetRetryableHttpClient(10*time.Second, DEBUG)
tracker.HTTP_client = GetRetryableHttpClient(10*time.Second, DEBUG)
tracker.SelectBestTracker().StartSelectTrackerBackground().StartFetchProjectBackground()
@ -175,6 +207,11 @@ func main() {
go InterruptHandler()
go ShowStatus(tracker)
time.Sleep(3 * time.Second)
Logger.Println("force sleep 10s before start...")
time.Sleep(7 * time.Second)
Logger.Println("start...")
huashijie_api.EnsureConnection(*tracker.HTTP_client)
Logger.Println("-- Start --")

View File

@ -1,11 +1,16 @@
package huashijie_api
import (
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"net/http"
"os"
"strconv"
"strings"
"time"
)
var XIAOMI_MODELS = []string{
@ -22,13 +27,15 @@ var XIAOMI_MODELS = []string{
"MDE5",
}
var Logger = log.New(os.Stdout, "[huashijie_api] ", log.Ldate|log.Ltime|log.Lmsgprefix)
func EnsureConnection(client http.Client) {
// https://app.huashijie.art/api/update/checkUpdate
req, err := http.NewRequest("GET", "https://app.huashijie.art/api/update/checkUpdate", nil)
if err != nil {
panic(err)
}
req.Header.Add("Referer", "https://app.huashijie.art/")
// req.Header.Add("Referer", "https://app.huashijie.art/")
req.Header.Add("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 9; MI 8 SE MIUI/V12.0.2.0.PEBCNXM)")
resp, err := client.Do(req)
@ -42,39 +49,114 @@ func EnsureConnection(client http.Client) {
panic(err)
}
text := string(body)
fmt.Println(text)
Logger.Println(text)
if !strings.Contains(text, "update_ver_code") {
panic("NotImplementedError: " + text)
}
// 125277547
body, r_status := GetWorkDetailResponse(client, "129107778")
if r_status != 200 {
Logger.Println("HTTP status code:", r_status, "body:", string(body))
panic("HTTP status code: " + strconv.Itoa(r_status))
}
var r_json map[string]interface{}
if err := json.Unmarshal(body, &r_json); err != nil {
Logger.Println("failed to parse JSON:", string(body), "error:", err)
panic("failed to parse JSON: " + string(body))
}
if !strings.Contains(string(body), "要你管啦离人家远远") {
Logger.Println("JSON:", string(body))
Logger.Panicln("assertion failed: body not contains '要你管啦离人家远远'")
}
// check if 'status' in r_json
if status, ok := r_json["status"]; ok {
switch status := status.(type) {
case float64:
if status == 1 {
// OK
Logger.Println("len(body):", len(body), "->", string(body[:256]), "...OK")
return
}
}
}
Logger.Println("JSON:", string(body))
panic("assertion failed: status == 1")
}
var cur_fake_user_id = -1
var cur_fake_user_left = time.Now()
func GetWorkDetailResponse(client http.Client, work_id string) ([]byte, int) {
req, err := http.NewRequest("GET", "https://app.huashijie.art/api/work/detailV2", nil)
endpoint := "https://app.huashijie.art/"
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
endpoint = "https://api.pandapaint.net/"
}
req, err := http.NewRequest("GET", endpoint+"api/work/detailV2", nil)
if err != nil {
panic(err)
}
q := req.URL.Query()
q.Add("visitorId", "-1")
q.Add("workId", work_id)
q.Add("cur_user_id", "-1")
q.Add("platform", "android")
visitorId := "-1"
token := ""
if os.Getenv("HSJ_USERID") != "" {
visitorId = os.Getenv("HSJ_USERID")
if visitorId == "random" {
if cur_fake_user_left.Before(time.Now()) { // rotate [1, 15] minutes
cur_fake_user_left = time.Now().Add(time.Duration(rand.Intn(15)) * time.Minute)
// random [30000000, 40000000]
cur_fake_user_id = rand.Intn(40000000-30000000) + 30000000
}
visitorId = fmt.Sprintf("%d", cur_fake_user_id)
}
// fake token = md5(visitorId + "huashijie")
// md5hash := md5.New()
// md5hash.Write([]byte(visitorId + "huashijie"))
// token = fmt.Sprintf("%x", md5hash.Sum(nil))
Logger.Println("USERID:", visitorId, "token:", token, "left", time.Until(cur_fake_user_left))
}
p := ""
p += "visitorId=" + visitorId
p += "&workId=" + work_id
p += "&cur_user_id=" + visitorId
p += "&platform=android"
os_version := rand.Intn(34-28) + 28
q.Add("os_version", fmt.Sprintf("%d", os_version))
q.Add("version_code", "241")
q.Add("device_brand", "xiaomi")
p += fmt.Sprintf("&os_version=%d", os_version)
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
p += "&version_code=170"
} else {
p += "&version_code=247"
}
p += "&device_brand=xiaomi"
device_model := XIAOMI_MODELS[rand.Intn(len(XIAOMI_MODELS))]
q.Add("device_model", device_model)
q.Add("token", "")
q.Add("channel", "main")
p += "&device_model=" + device_model
p += "&token=" + token
if os.Getenv("HSJ_ENDPOINT") == "pandapaint" {
p += "&channel=Panda.main"
} else {
p += "&channel=main"
}
headers := map[string][]string{
"Referer": {"https://app.huashijie.art/"},
"Referer": {endpoint},
"User-Agent": {"okhttp/3.12.0"},
}
for k, v := range headers {
req.Header[k] = v
}
req.URL.RawQuery = q.Encode()
// req.URL.RawQuery = q.Encode()
req.URL.RawQuery = p
resp, err := client.Do(req)
if err != nil {