diff --git a/.github/workflows/release_tag.yml b/.github/workflows/release_tag.yml new file mode 100644 index 0000000..3f0935c --- /dev/null +++ b/.github/workflows/release_tag.yml @@ -0,0 +1,94 @@ +name: CreateRelease + +on: + release: + types: + - prereleased + # - released + push: + tags: + - "v*" + +jobs: + create_release: + if: github.event_name == 'push' + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + if: github.event_name == 'push' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref_name }} + body: 修复了一些已知问题。 + draft: false + prerelease: true + + build: + # if: github.event_name == 'release' + # needs: create_release + strategy: + matrix: + goos: [linux, darwin, windows] + + permissions: # 需要设置写权限才能自动发布 + contents: write + + runs-on: ubuntu-latest + env: + GOOS: ${{ matrix.goos }} + CGO_ENABLED: 0 + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.22.x' + + - name: Install dependencies + run: | + go env -w GO111MODULE=on + sudo apt-get update -y + sudo apt-get install -y gcc libgl1-mesa-dev xorg-dev + go mod tidy + go install fyne.io/fyne/v2/cmd/fyne@latest + + - name: Get File Name + id: get_filename + run: | + export _NAME=DownUtils-${{ matrix.goos }}.tar.gz + echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME" + echo "ASSET_NAME=$_NAME" >> $GITHUB_OUTPUT + echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV + + - name: Build + run: | + fyne package -os ${{ matrix.goos }} -icon resource/images/logo.png + ls *.exe *.tar* + + - name: Package + run: tar zcvf ${{ steps.get_filename.outputs.ASSET_NAME }} *.exe *.tar* + + # 上传附件 + - name: Upload file to Artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.get_filename.outputs.ASSET_NAME }} + path: ${{ steps.get_filename.outputs.ASSET_NAME }} + + - name: Upload files to GitHub release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file_glob: true + file: ./${{ steps.get_filename.outputs.ASSET_NAME }} + tag: ${{ github.ref }} + overwrite: true \ No newline at end of file diff --git a/conf/conf_default.go b/conf/conf_default.go index d67b6e0..d4a513c 100644 --- a/conf/conf_default.go +++ b/conf/conf_default.go @@ -20,6 +20,8 @@ const DEFAULT_RETRY_TIMES = 3 const DEFAULT_DELAY = 1 const DEFAULT_RANDOM_DELAY = 1 const DEFAULT_PARALLELISM = 12 +const DEFAULT_IMAGE_HEIGHT = 76 +const DEFAULT_COL_WIDTH = 76 const DEFAULT_IMAGES_PATH = "runtime/images" const DEFAULT_DOWNLOADS_PATH = "runtime/downloads" const DEFAULT_RUNTIME_DIR = "runtime" @@ -46,6 +48,8 @@ RETRY_TIMES = %d DELAY = %d RANDOM_DELAY = %d PARALLELISM = %d +IMAGE_HEIGHT = %d +COL_WIDTH = %d # 该目录存放程序运行时产生的文件 RUNTIME_DIR = "%s" @@ -59,6 +63,6 @@ func getAllConfEnvStrDefault() string { return fmt.Sprintf(ENV_FILE_CONTENT, DEFAULT_DB_DRIVER, DEFAULT_DB_HOST, DEFAULT_DB_PORT, DEFAULT_DB_NAME, DEFAULT_DB_USERNAME, DEFAULT_DB_PASSWORD, DEFAULT_DB_NODE_ID, DEFAULT_USER_AGENT, "", "", DEFAULT_TIMEOUT, DEFAULT_RETRY_TIMES, DEFAULT_DELAY, - DEFAULT_RANDOM_DELAY, DEFAULT_PARALLELISM, DEFAULT_RUNTIME_DIR, DEFAULT_IMAGES_PATH, + DEFAULT_RANDOM_DELAY, DEFAULT_PARALLELISM, DEFAULT_IMAGE_HEIGHT, DEFAULT_COL_WIDTH, DEFAULT_RUNTIME_DIR, DEFAULT_IMAGES_PATH, DEFAULT_DOWNLOADS_PATH, DEFAULT_FYNE_FONT, DEFAULT_FYNE_TITLE) } diff --git a/conf/conf_file.go b/conf/conf_file.go index ac43a1d..cb303c4 100644 --- a/conf/conf_file.go +++ b/conf/conf_file.go @@ -23,7 +23,6 @@ func setEnvFile() { func initEnvFile() []string { var err error var files []string - var createNewEnvfile bool if !miniutils.IsPathExists(WorkEnvFile) { err = createEnvFile(WorkEnvFile) if err != nil { @@ -31,23 +30,17 @@ func initEnvFile() []string { } files = append(files, WorkEnvFile) fmt.Printf("Create file %s SUCCESS\n", WorkEnvFile) - createNewEnvfile = true } files = append(files, WorkEnvFile) - - if miniutils.IsPathExists(DEFAULT_ENV_FILE) { - files = append(files, DEFAULT_ENV_FILE) - } else { - if createNewEnvfile { - err = createEnvFile(DEFAULT_ENV_FILE) - if err != nil { - fmt.Printf("--------initEnvFile(%s)err(%v)\n", DEFAULT_ENV_FILE, err) - return files - } - files = append(files, DEFAULT_ENV_FILE) - fmt.Printf("Create file %s SUCCESS\n", DEFAULT_ENV_FILE) + if !miniutils.IsPathExists(DEFAULT_ENV_FILE) { + err = createEnvFile(DEFAULT_ENV_FILE) + if err != nil { + fmt.Printf("--------initEnvFile(%s)err(%v)\n", DEFAULT_ENV_FILE, err) + return files } + fmt.Printf("Create file %s SUCCESS\n", DEFAULT_ENV_FILE) } + files = append(files, DEFAULT_ENV_FILE) return files } diff --git a/conf/conf_val.go b/conf/conf_val.go index d10755f..b4977e4 100644 --- a/conf/conf_val.go +++ b/conf/conf_val.go @@ -13,6 +13,7 @@ var userAgent, imgsPath, cookie, httpProxy, runtimeDir, downloadsPath, FyneFont, var timeout, retry, delay, randomDelay, parallelism int var dbDriver, dbName, dbUsername, dbPassword, dbHost string var dbPort, dbNodeId int +var ImageHeight, ColWidth int func getConfByEnv() { FyneTitle = getEnvDefaultStr("FYNE_TITLE", DEFAULT_FYNE_TITLE) @@ -27,6 +28,8 @@ func getConfByEnv() { delay = getEnvDefaultInt("DELAY", DEFAULT_DELAY) randomDelay = getEnvDefaultInt("RANDOM_DELAY", DEFAULT_RANDOM_DELAY) parallelism = getEnvDefaultInt("PARALLELISM", DEFAULT_PARALLELISM) + ImageHeight = getEnvDefaultInt("IMAGE_HEIGHT", DEFAULT_IMAGE_HEIGHT) + ColWidth = getEnvDefaultInt("COL_WIDTH", DEFAULT_COL_WIDTH) dbDriver = getEnvDefaultStr("DB_DRIVER", DEFAULT_DB_DRIVER) dbName = getEnvDefaultStr("DB_NAME", DEFAULT_DB_NAME) diff --git a/fyne/form_downimg.go b/fyne/form_downimg.go index 6f80ddf..129bbfc 100644 --- a/fyne/form_downimg.go +++ b/fyne/form_downimg.go @@ -41,7 +41,7 @@ func RenderFormDownImg(w fyne.Window) fyne.CanvasObject { imgdirItem.HintText = "文件夹名。留空则从Referer值生成。" refererInput := widget.NewEntry() - refererInput.Text = "" + refererInput.Text = "https://image.baidu.com/" refererInput.PlaceHolder = "填网站主页。例: https://www.amazon.com/" excelWithPicInput := widget.NewCheck("启用", nil) // NewFyRadio(map[bool]string{false: "否", true: "是"}, false, nil) withPicItem := widget.NewFormItem("另存为含图片的xlsx文件", excelWithPicInput) @@ -67,8 +67,7 @@ func RenderFormDownImg(w fyne.Window) fyne.CanvasObject { } refererUrl := refererInput.Text if refererUrl == "" { - CheckError(fmt.Errorf("Referer不能为空"), w) - return + refererUrl = "https://image.baidu.com/" } if strings.Index(refererUrl, "http") != 0 { CheckError(fmt.Errorf("Referer必须以http开头"), w) diff --git a/service/excel.go b/service/excel.go index c565f31..ef5ae71 100644 --- a/service/excel.go +++ b/service/excel.go @@ -281,6 +281,8 @@ func (e *ExcelService) setLocalImages(sheetName, imgTitle, baseUrl, dirname stri } sconf := conf.GetSpiderConf() miniutils.Mkdir(sconf.ImagesPath + "/" + dirname) + colHeiht := conf.ImageHeight + colWidth := conf.ColWidth // 遍历数据列 imgTitleExist := false @@ -300,8 +302,10 @@ func (e *ExcelService) setLocalImages(sheetName, imgTitle, baseUrl, dirname stri imgTitleExist = true rowI := 1 + f.SetColWidth(sheetName, fmt.Sprintf("%c", colI), fmt.Sprintf("%c", colI), float64(colWidth)) for i, cell := range col { - f.SetRowHeight(sheetName, rowI, 76) + f.SetRowHeight(sheetName, rowI, float64(colHeiht)) + if i == 0 { rowI++ continue @@ -384,6 +388,9 @@ func DownloadImagesByExcel(filepath, sheetName, imgTitle, referer, dirname strin return err } updateExcel := NewExcelService(f) + if referer == "" { + referer = "https://image.baidu.com/" + } err = updateExcel.DownloadImagesByColly(sheetName, imgTitle, referer, dirname, onResp, withImgFile) // err = updateExcel.DownloadImages(sheetName, imgTitle, referer, dirname) if err != nil {