Skip to content

Commit

Permalink
修复个人专业版无法导出的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
tengfe-xy committed Jun 18, 2024
1 parent 83e75a8 commit 26c2867
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 212 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
docs/
**/.DS_Store
config.yaml*
*.yaml
dist/
wolai
17 changes: 13 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"strings"

log "github.com/tengfei-xy/go-log"
tools "github.com/tengfei-xy/go-tools"
"gopkg.in/yaml.v3"
)
Expand All @@ -17,6 +18,8 @@ func initConfig(config string) (Config, error) {

file := filepath.Join(f, config)

log.Infof("读取配置文件:%s", file)

if !tools.FileExist(file) {
return Config{}, configGenerate(file)
}
Expand Down Expand Up @@ -86,7 +89,7 @@ func (c *Config) isIgnoreSubspace(ws int, subspaceName string) bool {
}

for _, subspace := range c.Ignore[ws].Subspaces {
if subspace.Name == subspaceName {
if subspace.Name == subspaceName && len(subspaceName) != 0 {
return true
}
}
Expand Down Expand Up @@ -116,7 +119,6 @@ func (c *Config) hasHtml() bool {
}
}
return false

}
func (c *Config) hasMarkdown() bool {

Expand All @@ -127,7 +129,9 @@ func (c *Config) hasMarkdown() bool {
}
}
return false

}
func (c *Config) addTimeBackupPath() {
config.BackupPath = filepath.Join(config.BackupPath, timeGetChineseString())
}
func configGenerate(file string) error {
var c Config
Expand Down Expand Up @@ -159,10 +163,15 @@ func configGenerate(file string) error {
}

type Config struct {
Cookie string `yaml:"cookie"`
Cookie string `yaml:"cookie"`

// 作为外部文件使用的变量
BackupPath string `yaml:"backupBackupDir"`
ExportType []string `yaml:"exportType"`
Ignore []Workspace `yaml:"ignore"`

// 作为绝对路径的、内部程序使用的变量
backupPath string
}
type Workspace struct {
Name string `yaml:"workspace"`
Expand Down
5 changes: 0 additions & 5 deletions error.go

This file was deleted.

4 changes: 2 additions & 2 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

func (wsInfo *workspaceInfo) outputIgnore(ws, sb, page string) {
if wsInfo.is_free_plan() {
if wsInfo.isDefaultSubWorkspace() {
log.Warnf("忽略导出 工作区:%s 页面:%s", ws, page)
} else {
log.Warnf("忽略导出 工作区:%s 子空间:%s 页面:%s", ws, sb, page)
}
}
func (wsInfo *workspaceInfo) outputExport(ws, sb, page string) {
if wsInfo.is_free_plan() {
if wsInfo.isDefaultSubWorkspace() {
log.Infof("开始导出 工作区:%s 页面:%s", ws, page)
} else {
log.Infof("开始导出 工作区:%s 子空间:%s 页面:%s", ws, sb, page)
Expand Down
37 changes: 37 additions & 0 deletions flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"fmt"
"os"

log "github.com/tengfei-xy/go-log"
)

type iflag struct {
help bool
version bool
configFile string
loglevel string
}

func (f *iflag) checkHelp() {

if f.help {
description()
os.Exit(0)
}

}
func (f *iflag) checkVersion() {

if f.version {
fmt.Printf("%s\n", version)
os.Exit(0)
}

}
func (f *iflag) checkLogLevel() {
log.SetLevelStr(f.loglevel)
_, v := log.GetLevel()
log.Infof("当前日志等级:%s", v)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module wolai

go 1.19
go 1.21.4

require (
github.com/tengfei-xy/go-log v0.1.2
github.com/tengfei-xy/go-log v0.2.4
github.com/tengfei-xy/go-tools v0.1.3
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/tengfei-xy/go-log v0.1.2 h1:4n/x/6YsQF6MzzG5Prhg11OUZOoY11LcQlK5fwPj7TQ=
github.com/tengfei-xy/go-log v0.1.2/go.mod h1:k3W+Vs69F7ldZQ88XqDP1r0b9oo6NvxORmH50FQAnHE=
github.com/tengfei-xy/go-log v0.2.4 h1:Fy1IUgGXwr9taJqeuMrRADUX73yRUzbiOhA8NLT+uPY=
github.com/tengfei-xy/go-log v0.2.4/go.mod h1:WUFar5Siw3S2umNtSxDyeykvgULNqHxsEp2jCnBXj1k=
github.com/tengfei-xy/go-tools v0.1.3 h1:/FE1eItW4oaMF3to3qNUwsN9AYvGr3MM9iqucwHG+R0=
github.com/tengfei-xy/go-tools v0.1.3/go.mod h1:y2mYZiRBQtBInhOtKVsA1cCvf5xalZ/otoF2v2teQr4=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
Expand Down
27 changes: 19 additions & 8 deletions html.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ import (

func (wsInfo *workspaceInfo) exportHTMLMain() {

if !config.hasHtml() {
log.Debugf("忽略导出HTML 名称:%s", wsInfo.name)
return
}

// 获取忽略的工作区序号
wsSeq := config.getIgnoreWorkspace(wsInfo.name)

for _, subspace := range wsInfo.subspace {
if config.isIgnoreSubspace(wsSeq, subspace.name) {
log.Warnf("忽略导出 工作区:%s 子空间:%s", wsInfo.name, subspace.name)
log.Warnf("根据配置文件忽略工作区:%s 子空间:%s", wsInfo.name, subspace.name)
continue
}
spSeq := config.getIgnoreSubspace(wsInfo.is_free_plan(), wsSeq, subspace.name)

spSeq := config.getIgnoreSubspace(wsInfo.isDefaultSubWorkspace(), wsSeq, subspace.name)

for _, page := range subspace.pages {
if config.isIgnorePage(wsSeq, spSeq, page.name) {
Expand All @@ -38,8 +44,8 @@ func (wsInfo *workspaceInfo) exportHTMLMain() {
}

}

}

func (wsInfo *workspaceInfo) exportHtmlSingle(subspaceName, pageId, pageName string) error {
var e exportHtmlUpJson
e.PageID = pageId
Expand All @@ -60,13 +66,18 @@ func (wsInfo *workspaceInfo) exportHtmlSingle(subspaceName, pageId, pageName str
// 设置下载链接和文件名
u, _ := url.ParseRequestURI(fileURL)
filename := filepath.Base(u.Path)
var savePath string = filepath.Join(config.BackupPath, "html", wsInfo.name, subspaceName)
if wsInfo.isDefaultSubWorkspace() {
savePath = filepath.Join(config.BackupPath, "html", wsInfo.name)
}

if wsInfo.is_free_plan() {
filename = filepath.Join(config.BackupPath, "html", wsInfo.name, filename)
} else {
filename = filepath.Join(config.BackupPath, "html", wsInfo.name, subspaceName, filename)
// 创建备份文件夹
if err := mkdir(savePath); err != nil {
log.Fatal(err)
}

filename = filepath.Join(savePath, filename)

// 下载文件
if err := tools.FileDownload(fileURL, filename); err != nil {
return err
Expand Down Expand Up @@ -103,7 +114,7 @@ func exportHtmlHtml(data []byte) ([]byte, bool) {
req.Header.Set("Sec-Fetch-Mode", `cors`)
req.Header.Set("wolai-os-platform", `mac`)
req.Header.Set("x-client-timezone", `Asia/Shanghai`)
req.Header.Set("wolai-app-version", `1.2.0-18`)
req.Header.Set("wolai-app-version", `1.2.2-4`)
req.Header.Set("wolai-client-platform", `web`)
req.Header.Set("x-client-timeoffset", `-480`)
req.Header.Set("wolai-client-version", ``)
Expand Down
138 changes: 57 additions & 81 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,126 +4,102 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"

log "github.com/tengfei-xy/go-log"
)

const version string = "v1.1.1"
const version string = "v1.2.0"

var config Config

func project() {
fmt.Printf("程序版本:%s\n", version)
fmt.Println("项目链接:https://github.com/tengfei-xy/wolai")
func description() {
fmt.Printf(` _ _
__ __ ___ | | __ _ (_)
\ \ /\ / / / _ \ | | / _`+"`"+` || |
\ V V / | (_) || || (_| || | 程序版本: %s
\_/\_/ \___/ |_| \__,_||_| 项目链接: https://github.com/tengfei-xy/wolai
%s`, version, "\n")

}
func mkdir(path string) error {
err := os.MkdirAll(path, 0755)
if err != nil && err != os.ErrExist {
return err
}
log.Infof("创建 保存目标文件夹:%s", path)
log.Infof("创建文件夹 路径:%s", path)
return nil
}

func initFalg() (bool, string) {

var exit bool = false
helpText := flag.Bool("h", false, "查看帮助")
versionText := flag.Bool("v", false, "查看版本")
configFileText := flag.String("c", "config.yaml", "指定配置文件")
func initFlag() iflag {
var v iflag
flag.BoolVar(&v.help, "h", false, "查看帮助")
flag.BoolVar(&v.version, "v", false, "查看版本")
flag.StringVar(&v.configFile, "c", "config.yaml", "指定配置文件")
flag.StringVar(&v.loglevel, "l", log.LEVELINFO, fmt.Sprintf("日志等级,可设置参数:%s", strings.Join(log.GetLevelAll(), "、")))

flag.Parse()
if *helpText {
project()
exit = true

}
if *versionText {
fmt.Printf("%s", version)
exit = true
}
return exit, *configFileText
return v
}
func initTilte() {
description()
}
func main() {
var err error
initTilte()

exit, f := initFalg()
if exit {
return
}
log.Infof("读取配置文件:%s", f)
f := initFlag()
f.checkHelp()
f.checkVersion()
f.checkLogLevel()

// 获取配置
config, err = initConfig(f)
// 从配置文件中获取配置
config, err = initConfig(f.configFile)
if err != nil {
fmt.Println(err.Error())
log.Fatal(err)
}

userid, err := getUserID()
if err != nil {
panic(err)
}
// 在配置文件的保存地址上,增加时间
config.addTimeBackupPath()

// 获取官方API的工作区结构
ws, err := getWorkSpaceStruct()
// 获取用户ID用户所在的空间ID
ui, err := getUserInfo()
if err != nil {
panic(err)
log.Fatal(err)
}

// 将官方API的工作区结构转化为重要字段的结构体 workspaceInfo
wsInfos := ws.getWorkspaceInfo(userid)
// // 获取官方API的工作区结构
// ws, err := getWorkSpaceStruct()
// if err != nil {
// panic(err)
// }

// 获取子空间
for i := range wsInfos {

if wsInfos[i].id == "" {
continue
}
// // 将官方API的工作区结构转化为重要字段的结构体 workspaceInfo
// wsInfos := ws.getWorkspaceInfo(ui.userid)

// 免费版
if wsInfos[i].is_free_plan() {
if err := wsInfos[i].getDefaultSubspace(); err != nil {
panic(err)
}
continue
}
for _, ws := range ui.ws {

// 多人工作区 设定结构体长度并子空间的获取ID
if err := wsInfos[i].getTeamSubspace(); err != nil {
panic(err)
}
// 多人工作区 获取名称
if err := wsInfos[i].getTermPagesMain(); err != nil {
panic(err)
}
// 根据用户所在的空间ID获取用户空间的基本信息
ws.getBasicInfo()

}
// 一个子空间的处理方式
if ws.isDefaultSubWorkspace() {

// 输出将被导出的页面
for _, wsInfo := range wsInfos {
wsInfo.output()
}
// 获取默认子空间的信息
ws.getDefaultSubspace()
} else {
// 设定结构体长度并子空间的获取ID
ws.getTeamSubspace()

config.BackupPath = filepath.Join(config.BackupPath, timeGetChineseString())
for _, wsInfo := range wsInfos {
if err := wsInfo.mkdirBackupFolder(); err != nil {
panic(err)
// 获取名称
ws.getTermPagesMain()
}
}

if config.hasMarkdown() {
// 开始导出
for _, wsInfo := range wsInfos {
wsInfo.exportMDMain()
}
}
if config.hasHtml() {
// 开始导出
for _, wsInfo := range wsInfos {
wsInfo.exportHTMLMain()
}
// 进行导出MD
ws.exportMDMain()

// 进行导出HTML
ws.exportHTMLMain()
}

log.Info("导出结束!欢迎再次使用")
Expand Down
Loading

0 comments on commit 26c2867

Please sign in to comment.