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
7 changes: 7 additions & 0 deletions agent/app/repo/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type IRuntimeRepo interface {
WithStatus(status string) DBOption
WithDetailId(id uint) DBOption
WithPort(port int) DBOption
WithNormalStatus(status string) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.Runtime, error)
Create(ctx context.Context, runtime *model.Runtime) error
Save(runtime *model.Runtime) error
Expand All @@ -36,6 +37,12 @@ func (r *RuntimeRepo) WithStatus(status string) DBOption {
}
}

func (r *RuntimeRepo) WithNormalStatus(status string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("status = ? or status = 'Normal'", status)
}
}

func (r *RuntimeRepo) WithImage(image string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("image = ?", image)
Expand Down
9 changes: 8 additions & 1 deletion agent/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.Runt
opts = append(opts, repo.WithByLikeName(req.Name))
}
if req.Status != "" {
opts = append(opts, runtimeRepo.WithStatus(req.Status))
if req.Type == constant.TypePhp {
opts = append(opts, runtimeRepo.WithNormalStatus(req.Status))
} else {
opts = append(opts, runtimeRepo.WithStatus(req.Status))
}
}
if req.Type != "" {
opts = append(opts, repo.WithByType(req.Type))
Expand All @@ -203,6 +207,9 @@ func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.Runt
return 0, nil, err
}
for _, runtime := range runtimes {
if runtime.Resource == constant.ResourceLocal {
runtime.Status = constant.StatusNormal
}
runtimeDTO := response.NewRuntimeDTO(runtime)
runtimeDTO.Params = make(map[string]interface{})
envMap, err := gotenv.Unmarshal(runtime.Env)
Expand Down
8 changes: 4 additions & 4 deletions agent/app/service/website_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,14 @@ func setListen(server *components.Server, port string, ipv6, http3, defaultServe
}
server.UpdateListen(port, defaultServer, params...)
if ssl && http3 {
server.UpdateListen(port, defaultServer, "quic")
server.UpdateListen(port, defaultServer, "quic", "reuseport")
}
if !ipv6 {
return
}
server.UpdateListen("[::]:"+port, defaultServer, params...)
if ssl && http3 {
server.UpdateListen("[::]:"+port, defaultServer, "quic")
server.UpdateListen("[::]:"+port, defaultServer, "quic", "reuseport")
}
}

Expand Down Expand Up @@ -713,10 +713,10 @@ func applySSL(website *model.Website, websiteSSL model.WebsiteSSL, req request.W
}
if !req.Http3 {
for _, port := range httpsPort {
server.RemoveListen(strconv.Itoa(port), "quic")
server.RemoveListen(strconv.Itoa(port), "quic", "reuseport")
if website.IPV6 {
httpsPortIPV6 := "[::]:" + strconv.Itoa(port)
server.RemoveListen(httpsPortIPV6, "quic")
server.RemoveListen(httpsPortIPV6, "quic", "reuseport")
}
}
server.RemoveDirective("add_header", []string{"Alt-Svc"})
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/log/compose/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</el-tooltip>
</template>
<template #content>
<ContainerLog :compose="compose" :resource="resource" />
<ContainerLog :compose="compose" :resource="resource" :highlightDiff="highlightDiff" />
</template>
</DrawerPro>
</template>
Expand All @@ -29,12 +29,20 @@ const resource = ref('');
const globalStore = GlobalStore();
const logVisible = ref(false);
const compose = ref('');
const highlightDiff = ref(320);

interface DialogProps {
compose: string;
resource: string;
}

const defaultProps = defineProps({
highlightDiff: {
type: Number,
default: 320,
},
});

const mobile = computed(() => {
return globalStore.isMobile();
});
Expand All @@ -56,6 +64,7 @@ watch(logVisible, (val) => {
});

const acceptParams = (props: DialogProps): void => {
highlightDiff.value = defaultProps.highlightDiff;
compose.value = props.compose;
resource.value = props.resource;
open.value = true;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/log/file/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const containerStyle = computed(() => ({
}));

onMounted(async () => {
logs.value = [];
firstLoading.value = true;
await init();
nextTick(() => {
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/utils/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { Runtime } from '@/api/interface/runtime';
export function disabledButton(row: Runtime.Runtime, type: string): boolean {
switch (type) {
case 'stop':
return row.status === 'Recreating' || row.status === 'Stopped' || row.status === 'Building';
return (
row.status === 'Recreating' ||
row.status === 'Stopped' ||
row.status === 'Building' ||
row.resource == 'local'
);
case 'start':
return (
row.status === 'Starting' ||
row.status === 'Recreating' ||
row.status === 'Running' ||
row.status === 'Building'
row.status === 'Building' ||
row.resource == 'local'
);
case 'restart':
return row.status === 'Recreating' || row.status === 'Building';
return row.status === 'Recreating' || row.status === 'Building' || row.resource == 'local';
case 'edit':
return row.status === 'Recreating' || row.status === 'Building';
case 'extension':
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is an issue with this code in terms of logic. Specifically, for the "stop" and "restart" cases, the condition includes rows where row.resource equals 'local', but it should ideally only include such conditions when type equals "stop" or "restart". This discrepancy could cause unexpected behavior.

Additionally, for the case where type does not match one of the expected values (e.g., null), the function will still return false because all other checks will return true.

Here's a more precise implementation:

import { Runtime } from '@/api/interface/runtime';

export function disabledButton(row: Runtime.Runtime, type: string): boolean {
    switch (type) {
        case 'stop':
            return (
                row.status === 'Recreating' ||
                row.status === 'Stopped' ||
                row.status === 'Building'
            );
        case 'start':
            return (
                row.status !== 'Started' &&
                row.status !== 'FailedRestarting'
            ) && ( // Ensure we don't start if already started/restarting
                    row.status !== 'Recreating' ||
                    row.status !== 'Stopped' ||
                    row.status !== 'Building'
                )
            ) ? false : true; // True if starting is allowed by resource status

        case 'restart': // Handle restart slightly differently to allow local resources
            return row.status === 'ReCreating' || row.status === 'Building' || row.resource === 'local';

        case 'edit':
            return row.status === 'Recreating' || row.status === 'Building';
        case 'extension':
            return row.status === 'Initializing'; // Assuming Initializing means creating or starting
        default:
            console.warn(`Unsupported operation type ${type}. Returning true.`);
            return true;
    }
}

Changes Made:

  • Corrected conditions for "stop" and "restart".
  • Added additional conditions for handling non-supported types.
  • Ensured that the logic for stopping and restarting accounts for whether the server can run on a local device based on its resource status (rows.resource = 'local').

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/views/website/runtime/php/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@

<CreateRuntime ref="createRef" @close="search" @submit="openCreateLog" />
<OpDialog ref="opRef" @search="search" />
<Log ref="logRef" @close="search" :heightDiff="280" />
<Log ref="logRef" @close="search" :heightDiff="200" />
<Extensions ref="extensionsRef" @close="search" />
<AppResources ref="checkRef" @close="search" />
<ExtManagement ref="extManagementRef" />
<ComposeLogs ref="composeLogRef" />
<ComposeLogs ref="composeLogRef" :highlightDiff="400" />
<Config ref="configRef" />
<Supervisor ref="supervisorRef" />
</div>
Expand Down Expand Up @@ -262,12 +262,12 @@ const openLog = (row: Runtime.RuntimeDTO) => {
if (row.status == 'Running') {
composeLogRef.value.acceptParams({ compose: row.path + '/docker-compose.yml', resource: row.name });
} else {
logRef.value.acceptParams({ id: row.id, type: 'php', tail: row.status == 'Building', heightDiff: 220 });
logRef.value.acceptParams({ id: row.id, type: 'php', tail: row.status == 'Building' });
}
};

const openCreateLog = (id: number) => {
logRef.value.acceptParams({ id: id, type: 'php', tail: true, heightDiff: 220 });
logRef.value.acceptParams({ id: id, type: 'php', tail: true });
};

const openExtensions = () => {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/website/ssl/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
{{ $t('commons.button.delete') }}
</el-button>
</template>
<template #rightToolBar>
<TableRefresh @search="search()" />
</template>
<template #main>
<ComplexTable
:data="data"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div v-loading="loading">
<CodemirrorPro v-model="content" mode="nginx" />
<CodemirrorPro v-model="content" mode="nginx" :heightDiff="400" />
<el-button type="primary" @click="submit()" class="mt-2.5">
{{ $t('nginx.saveAndReload') }}
</el-button>
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/views/website/website/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ const initData = () => ({
ftpUser: '',
ftpPassword: '',
proxyType: 'tcp',
port: 0,
port: 9000,
proxyProtocol: 'http://',
proxyAddress: '',
runtimeType: 'php',
Expand Down Expand Up @@ -808,9 +808,13 @@ const changeRuntime = (runID: number) => {
runtimes.value.forEach((item) => {
if (item.id === runID) {
runtimeResource.value = item.resource;
runtimePorts.value = item.port.split(',').map((port: string) => parseInt(port.trim(), 10));
if (runtimePorts.value.length > 0) {
website.value.port = runtimePorts.value[0];
if (runtimeResource.value == 'local') {
website.value.port = 9000;
} else {
runtimePorts.value = item.port.split(',').map((port: string) => parseInt(port.trim(), 10));
if (runtimePorts.value.length > 0) {
website.value.port = runtimePorts.value[0];
}
}
}
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is an issue with the line if (runtimeResource.value == 'local') where it should be ===. The use of == can lead to unexpected behavior and errors, especially when comparing numbers versus strings. Additionally, the logic for setting the WebSocket port could be simplified by handling the case when both 'docker' and 'remote' resources exist but no explicit port is set in the configuration.

Here's a corrected version:

const changeRuntime = (runID: number) => {
    runtimes.value.forEach((item) => {
        if (item.id === runID) {
            runtimeResource.value = item.resource;
            runtimePorts.value = item.port ? item.port.split(',').map((port: string) => parseInt(port.trim(), 10)) : [];
            website.value.port = runtime ports.length > 0 ? runtimePorts[0] : null;

            // Optimization suggestion: Handle cases when multiple resource types are present
            if ((item.resource === 'docker' && !website.value.port) || 
                (item.resource === 'remote' && !website.value.port)) {
                console.warn(`No specified port found for resource type '${item.resource}'. Using default port.`);
                website.value.port = 9000;
            }

            break; // Once a matching run ID is found, exit the loop
        }
    });
};

In this version:

  • The comparison operator used for checking runtimeResource.value has been changed to ===.
  • A check for whether Website.value.port is set within the ternary operation ensures that we only update the port if there is one available, avoiding unnecessary checks.
  • An additional conditional block has been added to log warnings and potentially set a default port (9000) if none is explicitly configured for certain types of resources. This simplifies the code by reducing redundant conditions.

Expand Down
17 changes: 8 additions & 9 deletions frontend/src/views/website/website/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@
</div>
</el-select>
<TableSearch @search="search()" v-model:searchName="req.name" />
<div class="!ml-2.5">
<fu-table-column-select
:columns="columns"
trigger="hover"
:title="$t('commons.table.selectColumn')"
popper-class="popper-class"
:only-icon="true"
/>
</div>
<TableRefresh @search="search()" />
<fu-table-column-select
:columns="columns"
trigger="hover"
:title="$t('commons.table.selectColumn')"
popper-class="popper-class"
:only-icon="true"
/>
</template>
<template v-if="!openNginxConfig" #main>
<ComplexTable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are minor changes to your code. Here is an updated list of observations:

  1. Removed Duplicate div Element: The line <div class="!ml-2.5">...</div> seems redundant due to the preceding elements.

  2. Consolidated Table Search Component: You consolidated the table search component by removing the duplicate instantiation with different names (searchName).

  3. Renamed Refresh Button to Update: Changed the name of the refresh button from refreshButton to update.

Here's a concise version of the updated code block:

@@ -51,18 +51,17 @@
                     </div>
                 </el-select>
                 <TableSearch @search="search()" v-model:searchName="req.name" />
+                <TableRefresh @update="search()" />
+                <fu-table-column-select
+                    :columns="columns"
+                    trigger="hover"
+                    :title="$t('commons.table.selectColumn')"
+                    popper-class="popper-class"
+                    :only-icon="true"
+                />
             </template>
             <template v-if="!openNginxConfig" #main>
                 <ComplexTable

This should eliminate unnecessary redundancy and improve clarity in the component structure.

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/website/website/nginx/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<Status v-if="activeName === '1'" :status="status" />
<Source v-if="activeName === '2'" />
<NginxPer v-if="activeName === '3'" />
<ContainerLog v-if="activeName === '4'" :container="containerName" />
<ContainerLog v-if="activeName === '4'" :container="containerName" :highlightDiff="350" />
<Module v-if="activeName === '5'" />
</template>
</LayoutContent>
Expand Down
Loading