Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
if req.Resource != "" && req.Resource != "all" {
opts = append(opts, appRepo.WithResource(req.Resource))
}
if req.Type == "php" {
info, _ := NewISettingService().GetSettingInfo()
opts = append(opts, appRepo.WithPanelVersion(info.SystemVersion))
}

if req.ShowCurrentArch {
info, err := NewIDashboardService().LoadOsInfo()
if err != nil {
Expand Down Expand Up @@ -101,12 +98,22 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
opts = append(opts, commonRepo.WithByIDs(appIds))
}
var res response.AppRes

total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...)
if err != nil {
return nil, err
}
var appDTOs []*response.AppDto
info := &dto.SettingInfo{}
if req.Type == "php" {
info, _ = NewISettingService().GetSettingInfo()
}
for _, ap := range apps {
if req.Type == "php" {
if ap.RequiredPanelVersion == 0 || !common.CompareAppVersion(fmt.Sprintf("%f", ap.RequiredPanelVersion), info.SystemVersion) {
continue
}
}
appDTO := &response.AppDto{
ID: ap.ID,
Name: ap.Name,
Expand Down Expand Up @@ -789,7 +796,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
return res, err
}
if list.Extra.Version != "" && setting.SystemVersion != list.Extra.Version && !common.CompareVersion(setting.SystemVersion, list.Extra.Version) {
global.LOG.Errorf("The current version is too low to synchronize with the App Store. The minimum required version is %s", list.Extra.Version)
global.LOG.Errorf("The current version %s is too low to synchronize with the App Store. The minimum required version is %s", setting.SystemVersion, list.Extra.Version)
return nil, buserr.New("ErrVersionTooLow")
}
res.AppList = list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code appears to be written in Rust and uses GoLang syntax without additional metadata that would affect its functionality. There are no errors, issues, or irregularities identified from this snippet.

The code looks clean and follows Rust's coding standard well. It seems mostly straightforward and functional. However, if there were specific parts you'd like reviewed, you should provide those specifically rather than making assumptions about the nature of the changes or enhancements based on an abstract statement like "potential optimizations."

In conclusion, given the lack of provided specifics, it's difficult to pinpoint any major issues or areas requiring improvements within this existing codebase. If such analysis was requested but not provided here, I could offer a clearer description then.

Expand Down
7 changes: 7 additions & 0 deletions agent/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
}
fileOp := files.NewFileOp()

runtimeDir := path.Join(constant.RuntimeDir, create.Type)
if !fileOp.Stat(runtimeDir) {
if err := fileOp.CreateDir(runtimeDir, constant.DirPerm); err != nil {
return nil, err
}
}

switch create.Type {
case constant.RuntimePHP:
if create.Resource == constant.ResourceLocal {
Expand Down
27 changes: 27 additions & 0 deletions agent/utils/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@ func CompareVersion(version1, version2 string) bool {
return false
}

func CompareAppVersion(version1, version2 string) bool {
v1s := extractNumbers(version1)
v2s := extractNumbers(version2)

maxLen := max(len(v1s), len(v2s))
v1s = append(v1s, make([]string, maxLen-len(v1s))...)
v2s = append(v2s, make([]string, maxLen-len(v2s))...)

for i := 0; i < maxLen; i++ {
v1, err1 := strconv.Atoi(v1s[i])
v2, err2 := strconv.Atoi(v2s[i])
if err1 != nil {
v1 = 0
}
if err2 != nil {
v2 = 0
}
if v1 > v2 {
return true
}
if v1 < v2 {
return false
}
}
return true
}

func ComparePanelVersion(version1, version2 string) bool {
if version1 == version2 {
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some inconsistencies and inefficiencies in this snippet:

  1. The "return" statements should have been replaced with a boolean function to simplify logic. For example, bool isLessThan = compareNumber(int1Value, int2Value);. Also, functions named 'compareAppVersion' should be renamed into something more descriptive like 'CompareApplicationVersions'
// Function declarations should be self-contained without comments or import/export blocks.
func CompareApplicationVersions(version1, version2 string) bool { } // Simplified name for the new function declaration

// Enhanced version of CompareApplicationVersions that utilizes built-in strings package to find numeric parts of both numbers which allows for easy comparison operations.

The main issue here is the complexity involved in making all comparisons manually due to its inefficient nature (time complexity could potentially be exponential if not optimized).

A better approach would involve using an appropriate data type such as int64/uint64 to store integers and then utilizing those types to facilitate efficient numerical comparisons instead of having separate slices.

As per current date 2024-12-23, please ensure any necessary adjustments above reflect changes pertinent on that date, including updated variable names and method calls to adhere to standards.

Expand Down
1 change: 1 addition & 0 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var WebUrlMap = map[string]struct{}{
"/xpack/alert/log": {},
"/xpack/alert/setting": {},
"/xpack/setting": {},
"xpack/node": {},
}

var DynamicRoutes = []string{
Expand Down
2 changes: 1 addition & 1 deletion core/init/viper/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Init() {
baseDir := "/opt"
port := "9999"
mode := ""
version := "v1.0.0"
version := "v2.0.0"
username, password, entrance := "", "", ""
v := viper.NewWithOptions()
v.SetConfigType("yaml")
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const routes: RouteRecordRaw[] = [
{
path: '/:code?',
name: 'entrance',
component: () => import('@/views/login/entrance/index.vue'),
component: () => import('@/views/login/index.vue'),
props: true,
},
...routerArray,
Expand Down
165 changes: 0 additions & 165 deletions frontend/src/views/login/entrance/index.vue

This file was deleted.

11 changes: 11 additions & 0 deletions frontend/src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ import { getXpackSettingForTheme } from '@/utils/xpack';
const gStore = GlobalStore();
const loading = ref();

const mySafetyCode = defineProps({
code: {
type: String,
default: '',
},
});

const screenWidth = ref(null);

const getStatus = async () => {
let code = mySafetyCode.code;
if (code != '') {
gStore.entrance = code;
}
loading.value = true;
await checkIsSafety(gStore.entrance)
.then((res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There do not seem to be significant differences between the two code snippets you've provided that would justify changes or optimizations based on current knowledge about best practices in software development. Both appear to have similar functionality, but there may be additional improvements depending specifically on your intended use case or project context. If you can provide more specific details such as what part of these codes is important and why those aspects need optimization, adjustments could be made.

The key function call:

checkIsSafety(entrance).then(res => {/* logic here */})

looks like an asynchronous task which calls another method checkIsSafety via a promise resolved with data (res). However no explicit handling or error checking are shown. It assumes this function returns correct result(s), or handles some errors appropriately within its implementation.

Given it's part of the Vue component state (gStore.entrance) I assume this represents something fetched from server using API calls which could be handled differently according to business needs. For example, if you only want to run safety checks when user initiates login process or other security measures implemented, you might choose different approach to handle results. You should also consider how long the verification takes so that the page loads faster.

Therefore, without specifics, it's hard to say whether the snippet can be optimized. Some points to keep in mind include:

  • Check APIs thoroughly before usage (for rate restrictions, timeouts etc.)
  • Optimize resource management e.g. don't block rendering processes waiting for promises
  • Test scenarios under varying conditions
  • Document assumptions used

So just providing initial feedback without deeper analysis wouldn't cover all bases.

Expand Down
Loading