Skip to content

Commit

Permalink
fix: attach image
Browse files Browse the repository at this point in the history
  • Loading branch information
flydo committed Mar 26, 2024
1 parent abbb529 commit cc8fb41
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
### Discuz!X To XiunoBBS
------
基于 ```Go``` 语言的 ```discuz!x 3.x To xiunobbs 4.x``` 转换工具

---

基于 `Go` 语言的 `Discuz!X 3.x To XiunoBBS 4.x` 转换工具

### 开发进度

- 基础构架 ✔
- 数据转换 ✔
- 附件迁移 ✔
- 数据优化 ✔

### 编译指南
- 拉取主项目 ```git clone https://github.com/xiulab/discuzx-xiuno.git```
- 进入项目目录, 执行 ```go get```
- 编译程序 ```go build```
- 完成,文件在 ```当前目录(go build)```
- 修改配置文件信息 ```config.toml```

- 拉取主项目 `git clone https://github.com/xiulab/discuzx-xiuno.git`
- 进入项目目录, 执行 `go get`
- 编译程序 `go build`
- 完成,文件在 `当前目录(go build)`
- 修改配置文件信息 `config.toml`

**温馨提示:**
> 如果已配置好``GOBIN``或者将 ``$GOPATH/bin`` 环境变量,
即可以在任何目录下执行 **``discuzx-xiuno``** 启动本程序。
程序必须有**可执行权限**

**工具使用教程**
> 如果已配置好`GOBIN`或者将 `$GOPATH/bin` 环境变量,即可以在任何目录下执行 **`discuzx-xiuno`** 启动本程序。
> 程序必须有**可执行权限**
### 工具使用教程

- **操作前, 请仔细查阅 config.toml 配置文件**
- 先建一个 xiuno4 论坛。
- 下载本程序(选择运行平台),Linux、MacOS 需要可执行权限
- 配置```confit.toml```, 执行本程序 ```./discuzx-xiuno```(Windows 平台下, 建议使用 ```powershell```控制台, 执行```discuzx-xiuno.exe```)
- 登录后台,记得更新缓存统计
- 先建一个 `XiunoBBS 4.x` 论坛。
- 下载源码编译的二进制程序(或自行按上述步骤编译)。非 Windows 平台需要可执行权限
- 配置`confit.toml`, 执行本程序 `./discuzx-xiuno`Windows 平台, 建议使用 `PowerShell`控制台, 执行`discuzx-xiuno.exe`
- 登录后台,**记得**更新缓存统计

### 配置文件说明
>请认真查阅配置文件的注释,主要修改 database (数据库)、tables.xiuno.user (用户表) 及 extension.file (附件迁移) 这几部分。

> 请认真查阅配置文件的注释,主要修改 database (数据库)、tables.xiuno.user (用户表) 及 extension.file (附件迁移) 这几部分。
<details>
<summary>配置文件内容</summary>
Expand Down Expand Up @@ -213,16 +219,12 @@
thread_attach_total = true

```

</details>

### 使用到的开源项目
- XiunoBBS https://bbs.xiuno.com
- Discuz!X http://www.discuz.net
-

- **XiunoBBS**
- **Discuz!X**
- https://github.com/gogf/gf (基础框架)
- https://github.com/frustra/bbcode (内容 BBCODE 转 HTML)


### 开源协议
MIT
12 changes: 9 additions & 3 deletions app/controllers/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"database/sql"
"discuzx-xiuno/app/libraries/database"
"fmt"
"path"
"strings"
"time"

"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/util/gconv"
"github.com/skiy/gfutils/lcfg"
"github.com/skiy/gfutils/llog"
"path"
"strings"
"time"
)

// Attach 附件
Expand Down Expand Up @@ -68,6 +69,11 @@ func (t *Attach) ToConvert() (err error) {
isimage = 0
}

// 根据扩展名判断是否为图片
if filetype == "image" {
isimage = 1
}

d := gdb.Map{
"aid": u["aid"],
"tid": u["tid"],
Expand Down
20 changes: 11 additions & 9 deletions app/controllers/extension/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"discuzx-xiuno/app/libraries/lstr"
"errors"
"fmt"
"strings"
"time"

"github.com/skiy/gfutils/lcfg"
"github.com/skiy/gfutils/lfile"
"github.com/skiy/gfutils/llog"
"strings"
"time"

"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
Expand Down Expand Up @@ -178,7 +179,7 @@ func (t *File) avatarImages() (err error) {
xnAvatarFilePath := fmt.Sprintf("%s%s.png", avatarImagesPath, uid)

if err = gfile.Mkdir(avatarImagesPath); err != nil {
err = fmt.Errorf("头像保存目录 (%s) 创建失败, %s", avatarImagesPath, err.Error())
err = fmt.Errorf("头像保存目录 (%s) 创建失败, %s", avatarImagesPath, err)
return
}

Expand All @@ -189,13 +190,13 @@ func (t *File) avatarImages() (err error) {
dxAvatarImagePath := fmt.Sprintf("%s/%s/%s/%s/%s_avatar_big.jpg", dxAvatarPath, dir1, dir2, dir3, dir4)

if !gfile.IsFile(dxAvatarImagePath) {
err = fmt.Errorf("用户 UID (%s) 头像不存在: %s ", uid, dxAvatarImagePath)
return
fmt.Printf("用户 UID (%s) 头像不存在: %s ", uid, dxAvatarImagePath)
continue
}

if err = lfile.CopyFile(dxAvatarImagePath, xnAvatarFilePath); err != nil {
err = fmt.Errorf("\n迁移用户 (%s) 的头像 (%s) \n至 (%s) 失败, \n原因: %s", uid, dxAvatarImagePath, xnAvatarFilePath, err.Error())
return
if err := lfile.CopyFile(dxAvatarImagePath, xnAvatarFilePath); err != nil {
fmt.Printf("\n迁移用户 (%s) 的头像 (%s) \n至 (%s) 失败, \n原因: %s", uid, dxAvatarImagePath, xnAvatarFilePath, err)
continue
}

d := g.Map{
Expand All @@ -208,7 +209,8 @@ func (t *File) avatarImages() (err error) {

res, err := xiunoDB.Table(xiunoTable).Data(d).Where(w).Update()
if err != nil {
return fmt.Errorf("表 %s 用户头像, , %s", xiunoTable, err.Error())
fmt.Printf("表 %s 用户头像, , %s", xiunoTable, err)
continue
}

c, _ := res.RowsAffected()
Expand Down

0 comments on commit cc8fb41

Please sign in to comment.