Compare commits

..
2 Commits
Author SHA1 Message Date
ygxbnet 15c26f1939 refactor(uploader): 优化文件上传并发处理逻辑
构建上传工具 / build (push) Successful in 1m10s
- 将循环方式从索引遍历改为range方式
- 添加处理进程创建注释说明
- 在进度更新后添加延时避免过度频繁更新
- 修复空行处理时计数器递增逻辑
- 优化panic恢复处理流程
2026-07-28 09:21:13 +08:00
ygxbnet 1a95653894 config: 更新默认服务器地址配置
- 注释掉本地回环地址配置
- 修改默认URL为生产环境地址 http://112.124.71.39:8080
- 保留其他配置项不变
2026-07-28 09:21:12 +08:00
8 changed files with 15 additions and 114 deletions
+9 -21
View File
@@ -9,8 +9,7 @@ import {configModel} from "@/model.ts";
import Config = config.Config; import Config = config.Config;
// const serverUrl = ref('') // const serverUrl = ref('')
const hasVideoToken = ref('') const token = ref('')
const noVideoToken = ref('')
const checkDir = ref('') const checkDir = ref('')
const concurrentFiles = ref(1) const concurrentFiles = ref(1)
const uploadThreads = ref(1) const uploadThreads = ref(1)
@@ -72,8 +71,8 @@ const startRun = () => {
// ElMessage.warning('请输入服务器地址') // ElMessage.warning('请输入服务器地址')
// return // return
// } // }
if (!hasVideoToken.value || !noVideoToken.value) { if (!token.value) {
ElMessage.error('请输入两个上传 Token') ElMessage.error('请输入Token')
return return
} }
if (!checkDir.value) { if (!checkDir.value) {
@@ -106,11 +105,8 @@ const clearLog = () => {
// const writeServerUrl =() => { // const writeServerUrl =() => {
// WriteConfig("url", serverUrl.value) // WriteConfig("url", serverUrl.value)
// } // }
const writeHasVideoToken = () => { const writeToken = () => {
WriteConfig(configModel.HasVideoToken, hasVideoToken.value) WriteConfig(configModel.Token, token.value)
}
const writeNoVideoToken = () => {
WriteConfig(configModel.NoVideoToken, noVideoToken.value)
} }
const writeCheckDir = () => { const writeCheckDir = () => {
WriteConfig(configModel.CheckDir, checkDir.value) WriteConfig(configModel.CheckDir, checkDir.value)
@@ -129,8 +125,7 @@ const writeUploadThreads = () => {
try { try {
GetConfig().then((config: Config) => { GetConfig().then((config: Config) => {
// serverUrl.value = config.url // serverUrl.value = config.url
hasVideoToken.value = config.has_video_token token.value = config.token
noVideoToken.value = config.no_video_token
checkDir.value = config.check_dir checkDir.value = config.check_dir
concurrentFiles.value = config.handle_file_count concurrentFiles.value = config.handle_file_count
uploadThreads.value = config.thread_count uploadThreads.value = config.thread_count
@@ -173,15 +168,8 @@ try {
<!-- </div>--> <!-- </div>-->
<div class="form-item"> <div class="form-item">
<label>有视频 Token</label> <label>Token</label>
<el-input v-model="hasVideoToken" placeholder="有视频账号上传使用的 Token" :disabled="isRunning" <el-input v-model="token" placeholder="请输入Token" :disabled="isRunning" @change="writeToken()"/>
@change="writeHasVideoToken()"/>
</div>
<div class="form-item">
<label>无视频 Token</label>
<el-input v-model="noVideoToken" placeholder="无视频账号上传使用的 Token" :disabled="isRunning"
@change="writeNoVideoToken()"/>
</div> </div>
<div class="form-item"> <div class="form-item">
@@ -200,7 +188,7 @@ try {
<div class="form-item"> <div class="form-item">
<label>单文件上传线程</label> <label>单文件上传线程</label>
<el-input-number v-model="uploadThreads" :min="1" :max="500" :disabled="isRunning" <el-input-number v-model="uploadThreads" :min="1" :max="100" :disabled="isRunning"
@change="writeUploadThreads()"/> @change="writeUploadThreads()"/>
</div> </div>
-2
View File
@@ -1,8 +1,6 @@
export enum configModel { export enum configModel {
Url = "url", Url = "url",
Token = "token", Token = "token",
HasVideoToken = "has-video-token",
NoVideoToken = "no-video-token",
ThreadCount = "thread-count", ThreadCount = "thread-count",
HandleFileCount = "handle-file-count", HandleFileCount = "handle-file-count",
IsRunOnStart = "is-run-on-start", IsRunOnStart = "is-run-on-start",
-4
View File
@@ -3,8 +3,6 @@ export namespace config {
export class Config { export class Config {
url: string; url: string;
token: string; token: string;
has_video_token: string;
no_video_token: string;
thread_count: number; thread_count: number;
handle_file_count: number; handle_file_count: number;
is_run_on_start: boolean; is_run_on_start: boolean;
@@ -19,8 +17,6 @@ export namespace config {
if ('string' === typeof source) source = JSON.parse(source); if ('string' === typeof source) source = JSON.parse(source);
this.url = source["url"]; this.url = source["url"];
this.token = source["token"]; this.token = source["token"];
this.has_video_token = source["has_video_token"];
this.no_video_token = source["no_video_token"];
this.thread_count = source["thread_count"]; this.thread_count = source["thread_count"];
this.handle_file_count = source["handle_file_count"]; this.handle_file_count = source["handle_file_count"];
this.is_run_on_start = source["is_run_on_start"]; this.is_run_on_start = source["is_run_on_start"];
-3
View File
@@ -5,7 +5,6 @@ go 1.26
require ( require (
github.com/fsnotify/fsnotify v1.9.0 github.com/fsnotify/fsnotify v1.9.0
github.com/spf13/viper v1.21.0 github.com/spf13/viper v1.21.0
github.com/tidwall/gjson v1.14.2
github.com/wailsapp/wails/v2 v2.12.0 github.com/wailsapp/wails/v2 v2.12.0
golang.org/x/sync v0.20.0 golang.org/x/sync v0.20.0
) )
@@ -38,8 +37,6 @@ require (
github.com/spf13/cast v1.10.0 // indirect github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tkrajina/go-reflector v0.5.8 // indirect github.com/tkrajina/go-reflector v0.5.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect
-6
View File
@@ -81,12 +81,6 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ= github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4= github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
+3 -67
View File
@@ -7,11 +7,8 @@ import (
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"sync" "sync"
"time" "time"
"github.com/tidwall/gjson"
) )
var httpClient = &http.Client{ var httpClient = &http.Client{
@@ -34,9 +31,9 @@ func init() {
func InitConn() { func InitConn() {
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
for range 10 { for i := 0; i < 10; i++ {
wg.Go(func() { wg.Go(func() {
for range 50 { for i := 0; i < 50; i++ {
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test") resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@@ -59,31 +56,8 @@ func UploadDataToServer(ctx context.Context, data string) error {
<-limit <-limit
}() }()
//根据账号是否有视频判断要存储的token
params := url.Values{} params := url.Values{}
secUserId := strings.Split(data, "----")[1] params.Set("token", config.APPConfig.Token)
hasVideo, err := CheckHasVideo(secUserId)
if err != nil {
for err != nil {
fmt.Println("抖音请求api重试")
//定时器定时100毫秒
ticker := time.NewTicker(100 * time.Millisecond)
select {
case <-ctx.Done():
return err
case <-ticker.C:
ticker.Stop()
hasVideo, err = CheckHasVideo(secUserId)
}
}
}
if hasVideo {
params.Set("token", config.APPConfig.HasVideoToken)
} else {
params.Set("token", config.APPConfig.NoVideoToken)
}
params.Set("data", data) params.Set("data", data)
//http://127.0.0.1:8080/api/data?token=123456&data=123456 //http://127.0.0.1:8080/api/data?token=123456&data=123456
@@ -108,41 +82,3 @@ func UploadDataToServer(ctx context.Context, data string) error {
return err return err
} }
var douYinClient = &http.Client{}
func CheckHasVideo(secUserId string) (bool, error) {
req, err := http.NewRequest(
"GET",
"https://imdesktop.douyin.com/aweme/v1/web/user/profile/other/?sec_user_id="+secUserId,
nil,
)
if err != nil {
fmt.Println(err)
return false, err
}
req.Header.Add("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
req.Header.Add("Accept", "*/*")
req.Header.Add("Host", "imdesktop.douyin.com")
req.Header.Add("Connection", "keep-alive")
res, err := douYinClient.Do(req)
if err != nil {
fmt.Println(err)
return false, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return false, err
}
if gjson.Get(string(body), "user.aweme_count").Int() > 0 {
return true, nil
}
return false, nil
}
-8
View File
@@ -11,8 +11,6 @@ import (
type Config struct { type Config struct {
Url string `json:"url" mapstructure:"url"` Url string `json:"url" mapstructure:"url"`
Token string `json:"token" mapstructure:"token"` Token string `json:"token" mapstructure:"token"`
HasVideoToken string `json:"has_video_token" mapstructure:"has-video-token"`
NoVideoToken string `json:"no_video_token" mapstructure:"no-video-token"`
ThreadCount int `json:"thread_count" mapstructure:"thread-count"` ThreadCount int `json:"thread_count" mapstructure:"thread-count"`
HandleFileCount int `json:"handle_file_count" mapstructure:"handle-file-count"` HandleFileCount int `json:"handle_file_count" mapstructure:"handle-file-count"`
IsRunOnStart bool `json:"is_run_on_start" mapstructure:"is-run-on-start"` IsRunOnStart bool `json:"is_run_on_start" mapstructure:"is-run-on-start"`
@@ -26,8 +24,6 @@ var configMu sync.Mutex
const ( const (
Url = "url" Url = "url"
Token = "token" Token = "token"
HasVideoToken = "has-video-token"
NoVideoToken = "no-video-token"
ThreadCount = "thread-count" ThreadCount = "thread-count"
HandleFileCount = "handle-file-count" HandleFileCount = "handle-file-count"
IsRunOnStart = "is-run-on-start" IsRunOnStart = "is-run-on-start"
@@ -41,8 +37,6 @@ func InitConfig() {
//Url: "http://127.0.0.1:8080", //Url: "http://127.0.0.1:8080",
Url: "http://112.124.71.39:8080", Url: "http://112.124.71.39:8080",
Token: "", Token: "",
HasVideoToken: "1234",
NoVideoToken: "5678",
ThreadCount: 10, ThreadCount: 10,
HandleFileCount: 25, HandleFileCount: 25,
IsRunOnStart: false, IsRunOnStart: false,
@@ -51,8 +45,6 @@ func InitConfig() {
} }
viper.SetDefault(Url, defaultConfig.Url) viper.SetDefault(Url, defaultConfig.Url)
viper.SetDefault(Token, defaultConfig.Token) viper.SetDefault(Token, defaultConfig.Token)
viper.SetDefault(HasVideoToken, defaultConfig.HasVideoToken)
viper.SetDefault(NoVideoToken, defaultConfig.NoVideoToken)
viper.SetDefault(ThreadCount, defaultConfig.ThreadCount) viper.SetDefault(ThreadCount, defaultConfig.ThreadCount)
viper.SetDefault(HandleFileCount, defaultConfig.HandleFileCount) viper.SetDefault(HandleFileCount, defaultConfig.HandleFileCount)
viper.SetDefault(IsRunOnStart, defaultConfig.IsRunOnStart) viper.SetDefault(IsRunOnStart, defaultConfig.IsRunOnStart)
+1 -1
View File
@@ -30,7 +30,7 @@ func main() {
}, },
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1}, BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup, OnStartup: app.startup,
Bind: []any{ Bind: []interface{}{
app, app,
}, },
}) })