Skip to content

Commit

Permalink
Fix save db
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jul 1, 2023
1 parent 3371d64 commit 2014e22
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 2 additions & 0 deletions internal/db/db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -47,6 +48,7 @@ func (s *sqliteDb) Open() *sqliteDb {
conf.Logger = logger.Default.LogMode(logger.Info)
}

fmt.Printf("Load db path: %s\n", s.path)
db, err := gorm.Open(sqlite.Open(s.path), conf)
if err != nil {
panic("failed to open database")
Expand Down
4 changes: 2 additions & 2 deletions model/installed_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type InstalledApp struct {
IpaPath string `json:"ipa_path"`
Description string `json:"description,omitempty"`
Device string `json:"device"`
UDID string `json:"udid"`
Acount string `json:"account"`
UDID string `gorm:"column:udid" json:"udid"`
Account string `json:"account"`
Password string `json:"-"`
InstalledDate *time.Time `json:"installed_date"`
RefreshedDate *time.Time `json:"refreshed_date"`
Expand Down
3 changes: 2 additions & 1 deletion service/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func GetEnableAppList() ([]model.InstalledApp, error) {
func SaveApp(app model.InstalledApp) (*model.InstalledApp, error) {
// 查找之前的安装记录,存在记录直接更新旧的
var cur model.InstalledApp
result := db.Store().Where("udid=? and bundle_identifier=? and account=?", app.UDID, app.BundleIdentifier, app.Acount).First(&cur)
result := db.Store().Where("udid=? and bundle_identifier=? and account=?", app.UDID, app.BundleIdentifier, app.Account).First(&cur)
if result.Error != nil && result.Error != gorm.ErrRecordNotFound {
log.Err(result.Error).Msg("保存安装记录时出错.")
return nil, result.Error
}

Expand Down
8 changes: 4 additions & 4 deletions task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,23 @@ func (t *Task) RunImmediately(v model.InstalledApp) {
_ = service.UpdateAppRefreshResult(v)

// 发送安装失败通知
_ = notify.Send(fmt.Sprintf("[%s]刷新任务执行失败", v.IpaName), fmt.Sprintf("帐号:%s\n错误日志:%s", v.Acount, err.Error()))
_ = notify.Send(fmt.Sprintf("[%s]刷新任务执行失败", v.IpaName), fmt.Sprintf("帐号:%s\n错误日志:%s", v.Account, err.Error()))
}
}

func (t *Task) runInternal(v model.InstalledApp) error {
t.InstallingApp = &v

if v.Acount == "" || v.Password == "" || v.UDID == "" {
if v.Account == "" || v.Password == "" || v.UDID == "" {
log.Info("任务帐号,密码,UDID为空")
return fmt.Errorf("任务帐号,密码,UDID为空")
}

// 为每个appleid创建对应的工作目录,用于存储AltServer生成的签名证书
dirName := regValidName.ReplaceAllString(strings.ToLower(v.Acount), "")
dirName := regValidName.ReplaceAllString(strings.ToLower(v.Account), "")
workdir := filepath.Join(cfg.Server.WorkDir, "AltServer", dirName)

cmd := exec.Command("AltServer", "-u", v.UDID, "-a", v.Acount, "-p", v.Password, v.IpaPath)
cmd := exec.Command("AltServer", "-u", v.UDID, "-a", v.Account, "-p", v.Password, v.IpaPath)
cmd.Dir = workdir
cmd.Env = []string{"ALTSERVER_ANISETTE_SERVER=http://127.0.0.1:6969"}
stdin, err := cmd.StdinPipe()
Expand Down
5 changes: 0 additions & 5 deletions view/src/page/install/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,6 @@ export default {
})
.then((res) => {
toast.success("安装成功");
})
.catch(function (e) {
toast.error(
"安装成功,但保存安装记录时失败。错误信息:" + e.message
);
});
return;
Expand Down

0 comments on commit 2014e22

Please sign in to comment.